add table designer handlers (#1269)

* add table designer handlers

* add comments
This commit is contained in:
Alan Ren
2021-10-14 13:39:55 -07:00
committed by GitHub
parent 4f12820757
commit 791c3594a9
19 changed files with 557 additions and 2 deletions

View File

@@ -0,0 +1,15 @@
//
// 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.TableDesigner.Contracts
{
/// <summary>
/// Checkbox properties
/// </summary>
public class CheckBoxProperties : ComponentPropertiesBase
{
public bool Checked { get; set; }
}
}

View File

@@ -0,0 +1,28 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
{
/// <summary>
/// Base class for component properties
/// </summary>
public abstract class ComponentPropertiesBase
{
public ComponentPropertiesBase()
{
this.Enabled = true;
}
public string Title { get; set; }
public string AriaLabel { get; set; }
public Nullable<int> Width { get; set; }
public bool Enabled { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
//
// 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.TableDesigner.Contracts
{
/// <summary>
/// Dropdown properties
/// </summary>
public class DropdownProperties : ComponentPropertiesBase
{
public string Value { get; set; }
public string[] Values { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
//
// 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.TableDesigner.Contracts
{
/// <summary>
/// Inputbox properties
/// </summary>
public class InputBoxProperties : ComponentPropertiesBase
{
public string Value { get; set; }
}
}

View File

@@ -0,0 +1,33 @@
//
// 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.TableDesigner.Contracts
{
/// <summary>
/// Table component properties
/// </summary>
public class TableProperties<T> : ComponentPropertiesBase
{
/// <summary>
/// The column names to be displayed
/// </summary>
public string[] Columns { get; set; }
/// <summary>
/// The object type display name of the objects in this table
/// </summary>
public string ObjectTypeDisplayName { get; set; }
/// <summary>
/// All properties of the object.
/// </summary>
public DesignerDataPropertyInfo[] ItemProperties { get; set; }
/// <summary>
/// The object list.
/// </summary>
public T[] Data { get; set; }
}
}

View File

@@ -0,0 +1,31 @@
//
// 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.TableDesigner.Contracts
{
/// <summary>
/// Represents a component/property in the table designer
/// </summary>
public class DesignerDataPropertyInfo
{
/// <summary>
/// The name of the property
/// </summary>
public string PropertyName { get; set; }
public string ComponentType { get; set; }
/// <summary>
/// The name of the group the property will be placed in whe displayed in
/// </summary>
public string Group { get; set; }
/// <summary>
/// The properties of component
/// </summary>
public ComponentPropertiesBase ComponentProperties { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
//
// 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.TableDesigner.Contracts
{
/// <summary>
/// The service request to get the designer information about a table.
/// </summary>
public class GetTableDesignerInfoRequest
{
/// <summary>
/// Request definition
/// </summary>
public static readonly RequestType<TableInfo, TableDesignerInfo> Type = RequestType<TableInfo, TableDesignerInfo>.Create("tabledesigner/gettabledesignerinfo");
}
}

View File

@@ -0,0 +1,39 @@
//
// 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;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
{
public class ProcessTableDesignerEditRequestParams : GeneralRequestDetails
{
public TableInfo TableInfo { get; set; }
public TableDesignerChangeInfo TableChangeInfo { get; set; }
public TableDataModel Data { get; set; }
}
public class ProcessTableDesignerEditResponse
{
public TableDataModel Data { get; set; }
public bool IsValid { get; set; }
public TableDesignerValidationError[] errors { get; set; }
}
/// <summary>
/// The service request to process the changes made in the table designer.
/// </summary>
public class ProcessTableDesignerEditRequest
{
/// <summary>
/// Request definition
/// </summary>
public static readonly RequestType<ProcessTableDesignerEditRequestParams, ProcessTableDesignerEditResponse> Type = RequestType<ProcessTableDesignerEditRequestParams, ProcessTableDesignerEditResponse>.Create("tabledesigner/processedit");
}
}

View File

@@ -0,0 +1,32 @@
//
// 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;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
{
public class SaveTableChangesRequestParams : GeneralRequestDetails
{
public TableInfo TableInfo { get; set; }
public TableDataModel Data { get; set; }
}
public class SaveTableChangesResponse
{
}
/// <summary>
/// The service request to save the changes.
/// </summary>
public class SaveTableChangesRequest
{
/// <summary>
/// Request definition
/// </summary>
public static readonly RequestType<SaveTableChangesRequestParams, SaveTableChangesResponse> Type = RequestType<SaveTableChangesRequestParams, SaveTableChangesResponse>.Create("tabledesigner/savechanges");
}
}

View File

@@ -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.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
{
[JsonConverter(typeof(StringEnumConverter))]
public enum DesignerEditType
{
[EnumMember(Value = "Add")]
Add,
[EnumMember(Value = "Remove")]
Remove,
[EnumMember(Value = "Update")]
Update,
}
/// <summary>
/// The information about a change made inside the table designer.
/// </summary>
public class TableDesignerChangeInfo
{
public DesignerEditType Type { get; set; }
public object Property { get; set; }
public object Value { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
//
// 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.TableDesigner.Contracts
{
/// <summary>
/// The data model of a table column object
/// </summary>
public class TableColumn
{
public InputBoxProperties Name { get; set; }
public DropdownProperties Type { get; set; }
public InputBoxProperties Length { get; set; }
public CheckBoxProperties AllowNulls { get; set; }
public InputBoxProperties DefaultValue { get; set; }
public CheckBoxProperties IsPrimaryKey { get; set; }
}
}

View File

@@ -0,0 +1,27 @@
//
// 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.TableDesigner.Contracts
{
/// <summary>
/// The data model for a table object
/// </summary>
public class TableDataModel
{
public InputBoxProperties Name { get; set; }
public DropdownProperties Schema { get; set; }
public InputBoxProperties Description { get; set; }
public TableColumnCollection Columns { get; set; }
public InputBoxProperties Script { get; set; }
}
public class TableColumnCollection : TableProperties<TableColumn>
{
}
}

View File

@@ -0,0 +1,21 @@
//
// 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.TableDesigner.Contracts
{
/// <summary>
/// The information requested by the table designer UI.
/// </summary>
public class TableDesignerInfo
{
public TableDesignerView View { get; set; }
public TableDataModel Data { get; set; }
public string[] ColumnTypes { get; set; }
public string[] Schemas { get; set; }
}
}

View File

@@ -0,0 +1,19 @@
//
// 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.TableDesigner.Contracts
{
/// <summary>
/// The information that can identify a property in a collection.
/// </summary>
public class TableDesignerPropertyIdentifier
{
public string ParentProperty { get; set; }
public int Index { get; set; }
public string Property { get; set; }
}
}

View File

@@ -0,0 +1,27 @@
//
// 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;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts
{
/// <summary>
/// Validation error
/// </summary>
public class TableDesignerValidationError
{
/// <summary>
/// The error message
/// </summary>
public string Message { get; set; }
/// <summary>
/// The property associated with the message, could be a string or TableDesignerPropertyIdentifier
/// </summary>
public object Property { get; set; }
}
}

View File

@@ -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.TableDesigner.Contracts
{
/// <summary>
/// Table designer's view definition, there are predefined common properties.
/// Specify the additional properties in this class.
/// </summary>
public class TableDesignerView
{
public DesignerDataPropertyInfo[] AdditionalTableProperties { get; set; }
public DesignerDataPropertyInfo[] AdditionalTableColumnProperties { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
//
// 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.TableDesigner.Contracts
{
/// <summary>
/// The information of the table being designed.
/// </summary>
public class TableInfo
{
public string Server { get; set; }
public string Database { get; set; }
public string Schema { get; set; }
public string Name { get; set; }
public bool IsNewTable { get; set; }
public string ConnectionUri { get; set; }
}
}

View File

@@ -0,0 +1,125 @@
//
// 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.Threading.Tasks;
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.TableDesigner
{
/// <summary>
/// Class that handles the Table Designer related requests
/// </summary>
public sealed class TableDesignerService : IDisposable
{
private bool disposed = false;
private static readonly Lazy<TableDesignerService> instance = new Lazy<TableDesignerService>(() => new TableDesignerService());
public TableDesignerService()
{
}
/// <summary>
/// Gets the singleton instance object
/// </summary>
public static TableDesignerService Instance
{
get { return instance.Value; }
}
/// <summary>
/// Service host object for sending/receiving requests/events.
/// </summary>
internal IProtocolEndpoint ServiceHost
{
get;
set;
}
/// <summary>
/// Initializes the table designer service instance
/// </summary>
public void InitializeService(ServiceHost serviceHost)
{
this.ServiceHost = serviceHost;
this.ServiceHost.SetRequestHandler(GetTableDesignerInfoRequest.Type, HandleGetTableDesignerInfoRequest);
this.ServiceHost.SetRequestHandler(ProcessTableDesignerEditRequest.Type, HandleProcessTableDesignerEditRequest);
this.ServiceHost.SetRequestHandler(SaveTableChangesRequest.Type, HandleSaveTableChangesRequest);
}
private async Task HandleGetTableDesignerInfoRequest(TableInfo tableInfo, RequestContext<TableDesignerInfo> requestContext)
{
await Task.Run(async () =>
{
try
{
// TODO
TableDataModel tableModel = new TableDataModel();
TableDesignerView view = new TableDesignerView();
await requestContext.SendResult(new TableDesignerInfo()
{
Data = tableModel,
View = view,
ColumnTypes = new string[] { },
Schemas = new string[] { }
});
}
catch (Exception e)
{
await requestContext.SendError(e);
}
});
}
private async Task HandleProcessTableDesignerEditRequest(ProcessTableDesignerEditRequestParams requestParams, RequestContext<ProcessTableDesignerEditResponse> requestContext)
{
await Task.Run(async () =>
{
try
{
// TODO
await requestContext.SendResult(new ProcessTableDesignerEditResponse()
{
Data = requestParams.Data,
IsValid = true
});
}
catch (Exception e)
{
await requestContext.SendError(e);
}
});
}
private async Task HandleSaveTableChangesRequest(SaveTableChangesRequestParams requestParams, RequestContext<SaveTableChangesResponse> requestContext)
{
await Task.Run(async () =>
{
try
{
// TODO
await requestContext.SendResult(new SaveTableChangesResponse());
}
catch (Exception e)
{
await requestContext.SendError(e);
}
});
}
/// <summary>
/// Disposes the table designer Service
/// </summary>
public void Dispose()
{
if (!disposed)
{
disposed = true;
}
}
}
}