-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add scripting API implemented by the SqlScriptPublishModel #316
Changes from 25 commits
30c07eb
2e6813a
9e2dfe3
5b2f86b
b6e5c59
9d9438a
dba5ed5
81ea9ea
43f4d4b
4fe577b
c1ce933
47db0c9
1c38721
5d42466
562c693
6024b0e
4a2a965
d32d820
b801efb
9be1640
ce48e89
83afb81
e492c32
8771009
327c659
7f1b685
4ad88e9
8df5a61
a1e56de
a596f54
56f6977
d7bbd85
60b4afd
aeffd07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using Microsoft.SqlTools.Hosting.Protocol.Contracts; | ||
|
||
namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts | ||
{ | ||
/// <summary> | ||
/// Parameters sent when a scripting operation has been canceled. | ||
/// </summary> | ||
public class ScriptingCancelParameters : ScriptingEventParams { } | ||
|
||
/// <summary> | ||
/// Event sent to indicate that a scripting operation has been canceled. | ||
/// </summary> | ||
public class ScriptingCancelEvent | ||
{ | ||
public static readonly EventType<ScriptingCancelParameters> Type = EventType<ScriptingCancelParameters>.Create("scripting/scriptCancel"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using Microsoft.SqlTools.Hosting.Protocol.Contracts; | ||
|
||
namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts | ||
{ | ||
/// <summary> | ||
/// Parameters to cancel a scripting request. | ||
/// </summary> | ||
public class ScriptingCancelParams | ||
{ | ||
/// <summary> | ||
/// Gets or sets the operation id of the scripting operation to cancel. | ||
/// </summary> | ||
public string OperationId { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming this should inherit from ScriptingEventParams? #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, nice catch. |
||
} | ||
|
||
/// <summary> | ||
/// Parameters returned from a scripting request. | ||
/// </summary> | ||
public class ScriptingCancelResult { } | ||
|
||
/// <summary> | ||
/// Defines the scripting cancel request type. | ||
/// </summary> | ||
public class ScriptingCancelRequest | ||
{ | ||
public static readonly RequestType<ScriptingCancelParams, ScriptingCancelResult> Type = | ||
RequestType<ScriptingCancelParams, ScriptingCancelResult>.Create("scripting/scriptCancel"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using Microsoft.SqlTools.Hosting.Protocol.Contracts; | ||
|
||
namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts | ||
{ | ||
/// <summary> | ||
/// Parameters sent to when a scripting operation has completed. | ||
/// </summary> | ||
public class ScriptingCompleteParameters : ScriptingEventParams {} | ||
|
||
|
||
/// <summary> | ||
/// Event sent to indicate a scripting operation has completed. | ||
/// </summary> | ||
public class ScriptingCompleteEvent | ||
{ | ||
public static readonly EventType<ScriptingCompleteParameters> Type = | ||
EventType<ScriptingCompleteParameters>.Create("scripting/scriptComplete"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using Microsoft.SqlTools.Hosting.Protocol.Contracts; | ||
|
||
namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts | ||
{ | ||
/// <summary> | ||
/// Parameters sent when a scripting operation has encountered an error. | ||
/// </summary> | ||
public class ScriptingErrorParams : ScriptingEventParams | ||
{ | ||
/// <summary> | ||
/// Gets or sets error message. | ||
/// </summary> | ||
public string Message { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets error details. | ||
/// </summary> | ||
public string Details { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// Event sent to indicate a scripting operation has encountered an error. | ||
/// </summary> | ||
public class ScriptingErrorEvent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check with Ben, this is a nice practice / looks good but I know he's been doing work in the error handling area and it'd be great if we align this so it's consistent. #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{ | ||
public static readonly EventType<ScriptingErrorParams> Type = | ||
EventType<ScriptingErrorParams>.Create("scripting/scriptError"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts | ||
{ | ||
/// <summary> | ||
/// Base class for all scripting event parameters. | ||
/// </summary> | ||
public abstract class ScriptingEventParams | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please doc #Resolved |
||
{ | ||
/// <summary> | ||
/// Gets or sets the operation id of the scripting operation this event is associated with. | ||
/// </summary> | ||
public string OperationId { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.SqlTools.Hosting.Protocol.Contracts; | ||
|
||
namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts | ||
{ | ||
/// <summary> | ||
/// Parameters sent when a list objects operation has completed. | ||
/// </summary> | ||
public class ScriptingListObjectsCompleteParameters : ScriptingEventParams | ||
{ | ||
/// <summary> | ||
/// Gets or sets the list of database objects returned from the list objects operation. | ||
/// </summary> | ||
public List<ScriptingObject> DatabaseObjects { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please doc #Resolved |
||
|
||
/// <summary> | ||
/// Gets or sets the count of database object returned from the list objects operation. | ||
/// </summary> | ||
public int Count { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// Event sent to indicate a list objects operation has completed. | ||
/// </summary> | ||
public class ScriptingListObjectsCompleteEvent | ||
{ | ||
public static readonly EventType<ScriptingListObjectsCompleteParameters> Type = EventType<ScriptingListObjectsCompleteParameters>.Create("scripting/listObjectsComplete"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.SqlTools.Hosting.Protocol.Contracts; | ||
|
||
namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts | ||
{ | ||
/// <summary> | ||
/// Parameters for a list objects request. | ||
/// </summary> | ||
public class ScriptingListObjectsParams | ||
{ | ||
public string ConnectionString { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// Parameters returned from a list objects request. | ||
/// </summary> | ||
public class ScriptingListObjectsResult | ||
{ | ||
public string OperationId { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// Defines the scripting list objects request type. | ||
/// </summary> | ||
public class ScriptingListObjectsRequest | ||
{ | ||
public static readonly RequestType<ScriptingListObjectsParams, ScriptingListObjectsResult> Type = | ||
RequestType<ScriptingListObjectsParams, ScriptingListObjectsResult>.Create("scripting/listObjects"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts | ||
{ | ||
/// <summary> | ||
/// Class to represent a database object that can be scripted. | ||
/// </summary> | ||
public sealed class ScriptingObject : IEquatable<ScriptingObject> | ||
{ | ||
/// <summary> | ||
/// Gets or sets the database object type. | ||
/// </summary> | ||
/// <remarks> | ||
/// This underlying values are determined by the SqlScriptPublishModel.GetDatabaseObjectTypes() and | ||
/// can change depending on the version of SMO used by the tools service. Values can be: | ||
/// Table, | ||
/// View, | ||
/// StoredProcedure, | ||
/// UserDefinedFunction, | ||
/// UserDefinedDataType, | ||
/// User, | ||
/// Default, | ||
/// Rule, | ||
/// DatabaseRole, | ||
/// ApplicationRole, | ||
/// SqlAssembly, | ||
/// DdlTrigger, | ||
/// Synonym, | ||
/// XmlSchemaCollection, | ||
/// Schema, | ||
/// PlanGuide, | ||
/// UserDefinedType, | ||
/// UserDefinedAggregate, | ||
/// FullTextCatalog, | ||
/// UserDefinedTableType | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will there be more in the future? We have a bunch of other types in the ObjectExplorer tree, can they all be added in here / should they be? #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are dynamically discovered by SMO, so this list may change. I'll add comment about this. In reply to: 111651987 [](ancestors = 111651987) |
||
/// </remarks> | ||
public string Type { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the schema of the database object. | ||
/// </summary> | ||
public string Schema { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the database object name. | ||
/// </summary> | ||
public string Name { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
string objectName = string.IsNullOrEmpty(this.Schema) | ||
? this.Name | ||
: this.Schema + "." + this.Name; | ||
|
||
return objectName; | ||
} | ||
|
||
public override int GetHashCode() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm hoping this is the auto-implemented GetHashCode from ReSharper 😃 #WontFix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, I don't use ReSharper :) |
||
{ | ||
return | ||
StringComparer.OrdinalIgnoreCase.GetHashCode(this.Type ?? string.Empty) ^ | ||
StringComparer.OrdinalIgnoreCase.GetHashCode(this.Schema ?? string.Empty) ^ | ||
StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name ?? string.Empty); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return | ||
obj != null && | ||
this.GetType() == obj.GetType() && | ||
this.Equals((ScriptingObject)obj); | ||
} | ||
|
||
public bool Equals(ScriptingObject other) | ||
{ | ||
if (other == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return | ||
string.Equals(this.Type, other.Type, StringComparison.OrdinalIgnoreCase) && | ||
string.Equals(this.Schema, other.Schema, StringComparison.OrdinalIgnoreCase) && | ||
string.Equals(this.Name, other.Name, StringComparison.OrdinalIgnoreCase); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In previous API requests (edit/initialize in particular) we have a single event that is raised when the initialization is completed (edit/initializeSessionReady). The event has parameters to indicate success or failure. This also makes it simpler on the client side to implement b/c there is only one listener for the edit/initializeSessionReady event. In this scenario, you'll need to create 3 listeners (complete, cancel, and error) that will need to be shut down when any one of them receives an event.
Since you've got a different payload to include with each kind of event, I can see why using separate events would be beneficial, but it is slightly different than the APIs already developed. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to combine completed and cancel if that's the pattern used by services.