diff --git a/Common/Cdy.Tag.Driver/IProducterDriver.cs b/Common/Cdy.Tag.Driver/IProducterDriver.cs index 1d18442c930dd78e87309f69b3c54781a6c14a8a..b8fd94e94399a3cb54851d9cd33106d42cfb3c40 100644 --- a/Common/Cdy.Tag.Driver/IProducterDriver.cs +++ b/Common/Cdy.Tag.Driver/IProducterDriver.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace Cdy.Tag.Driver { @@ -47,6 +48,20 @@ namespace Cdy.Tag.Driver /// bool Stop(); + /// + /// + /// + /// + /// + Dictionary GetConfig(string database); + + /// + /// + /// + /// + /// + void UpdateConfig(string database, Dictionary config); + #endregion ...Methods... #region ... Interfaces ... diff --git a/Common/Cdy.Tag/PathHelper.cs b/Common/Cdy.Tag/PathHelper.cs index 558d975afe1a22223ecbaeab17d6e948fbf3c800..02c6db44cdc03b90a653d5a1ef28a8d189307513 100644 --- a/Common/Cdy.Tag/PathHelper.cs +++ b/Common/Cdy.Tag/PathHelper.cs @@ -8,6 +8,7 @@ //============================================================== using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.Text; namespace Cdy.Tag @@ -48,6 +49,29 @@ namespace Cdy.Tag #endregion ...Constructor... #region ... Properties ... + + /// + /// + /// + public string AppPath + { + get + { + return mAppPath; + } + } + + /// + /// + /// + public string DataPath + { + get + { + return mDataPath; + } + } + #endregion ...Properties... @@ -93,7 +117,30 @@ namespace Cdy.Tag return System.IO.Path.Combine(mDataPath,databaseName, path); } + /// + /// + /// + /// + /// + public string GetDatabasePath(string database) + { + return System.IO.Path.Combine(mDataPath, database); + } + /// + /// + /// + /// + /// + public string GetApplicationFilePath(params string[] file) + { + string spath = mAppPath; + foreach(var vv in file) + { + spath = System.IO.Path.Combine(spath, vv); + } + return spath; + } #endregion ...Methods... diff --git a/Develop/DBDevelopClientApi/DevelopServiceHelper.cs b/Develop/DBDevelopClientApi/DevelopServiceHelper.cs index 87d0259dad3a3f239e3089c976e0e86bc6f17168..c139f0f889db6304f894d329e6752088e2d03057 100644 --- a/Develop/DBDevelopClientApi/DevelopServiceHelper.cs +++ b/Develop/DBDevelopClientApi/DevelopServiceHelper.cs @@ -14,6 +14,7 @@ using System.Net.Http; using System.Text; using System.Linq; using Cdy.Tag; +using System.Data.Common; namespace DBDevelopClientApi { @@ -1264,6 +1265,100 @@ namespace DBDevelopClientApi return re; } + /// + /// + /// + /// + /// + public int GetRealServerPort(string database) + { + if (mCurrentClient != null && !string.IsNullOrEmpty(mLoginId)) + { + var res = mCurrentClient.GetRealDataServerPort(new DBDevelopService.DatabasesRequest() { Database = database, LoginId = mLoginId }); + return res.Value; + } + else + { + return -1; + } + } + + /// + /// + /// + /// + /// + /// + public bool SetRealServerPort(string database,int port) + { + if (mCurrentClient != null && !string.IsNullOrEmpty(mLoginId)) + { + var res = mCurrentClient.SetRealDataServerPort(new DBDevelopService.SetRealDataServerPortRequest() { Database = database, LoginId = mLoginId,Port=port }); + return res.Result; + } + else + { + return false; + } + } + + /// + /// 获取驱动配置 + /// + /// + /// + /// + public Dictionary GetDriverSetting(string database,string driver) + { + Dictionary re = new Dictionary(); + if (mCurrentClient != null && !string.IsNullOrEmpty(mLoginId)) + { + var res = mCurrentClient.GetDriverSetting(new DBDevelopService.GetDriverSettingRequest() { Database = database, LoginId = mLoginId }); + var sval = res.SettingString; + if(!string.IsNullOrEmpty(sval)) + { + string[] ss = sval.Split(new char[] { ',' }); + foreach (var vv in ss) + { + string[] svv = vv.Split(new char[] { ':' }); + if (!re.ContainsKey(svv[0])) + { + re.Add(svv[0], svv[1]); + } + } + } + } + return re; + } + + /// + /// 更新驱动配置 + /// + /// + /// + /// + /// + public bool UpdateDriverSetting(string database,string driver,Dictionary settings) + { + if (mCurrentClient != null && !string.IsNullOrEmpty(mLoginId)) + { + if(settings!=null&&settings.Count>0) + { + StringBuilder sb = new StringBuilder(); + foreach (var vv in settings) + { + sb.Append(vv.Key + ":" + vv.Value + ","); + } + sb.Length = sb.Length > 0 ? sb.Length - 1 : sb.Length; + + return mCurrentClient.UpdateDrvierSetting(new DBDevelopService.UpdateDrvierSettingRequest() { Database = database, Driver = driver, LoginId = mLoginId, SettingString = sb.ToString() }).Result; + + } + } + return false; + } + + /// /// /// diff --git a/Develop/DBDevelopClientApi/developService.proto b/Develop/DBDevelopClientApi/developService.proto index 705b5d2b4c21e3e229baab07b72d68c6ff9e3c82..7b92e605a7a3cccc6f1e1cf55a66b833ee6a65d9 100644 --- a/Develop/DBDevelopClientApi/developService.proto +++ b/Develop/DBDevelopClientApi/developService.proto @@ -206,6 +206,7 @@ message GetDriverSettingRequest { string LoginId=1; string Driver=2; + string Database=3; } // @@ -213,14 +214,14 @@ message GetDriverSettingReplay { bool Result =1; string ErroMessage=2; - string Drivers=3; - string SettingString=4; + string SettingString=3; } message UpdateDrvierSettingRequest { string LoginId=1; string Driver=2; + string Database=3; string SettingString=4; } diff --git a/Develop/DBDevelopService/Protos/developService.proto b/Develop/DBDevelopService/Protos/developService.proto index 705b5d2b4c21e3e229baab07b72d68c6ff9e3c82..7b92e605a7a3cccc6f1e1cf55a66b833ee6a65d9 100644 --- a/Develop/DBDevelopService/Protos/developService.proto +++ b/Develop/DBDevelopService/Protos/developService.proto @@ -206,6 +206,7 @@ message GetDriverSettingRequest { string LoginId=1; string Driver=2; + string Database=3; } // @@ -213,14 +214,14 @@ message GetDriverSettingReplay { bool Result =1; string ErroMessage=2; - string Drivers=3; - string SettingString=4; + string SettingString=3; } message UpdateDrvierSettingRequest { string LoginId=1; string Driver=2; + string Database=3; string SettingString=4; } diff --git a/Develop/DBDevelopService/Services/DevelopServerService.cs b/Develop/DBDevelopService/Services/DevelopServerService.cs index 93e820e6696926bb81441682d606e738d08a01de..bf7fd7e1797c9fc3aab4ea022ee7106a09d7b7b0 100644 --- a/Develop/DBDevelopService/Services/DevelopServerService.cs +++ b/Develop/DBDevelopService/Services/DevelopServerService.cs @@ -5,6 +5,9 @@ using System.Threading.Tasks; using Grpc.Core; using Microsoft.Extensions.Logging; using Cdy.Tag; +using System.Text; +using System.Data.Common; + namespace DBDevelopService { public class DevelopServerService : DevelopServer.DevelopServerBase @@ -1971,5 +1974,71 @@ namespace DBDevelopService return Task.FromResult(new IntResultReplay() { Result = false }); } + /// + /// + /// + /// + /// + /// + public override Task GetDriverSetting(GetDriverSettingRequest request, ServerCallContext context) + { + if (!CheckLoginId(request.LoginId, request.Database)) + { + return Task.FromResult(new GetDriverSettingReplay() { Result = false }); + } + if(DriverManager.Manager.Drivers.ContainsKey(request.Driver)) + { + var re = new GetDriverSettingReplay() { Result = true }; + var dd = DriverManager.Manager.Drivers[request.Driver]; + var config = dd.GetConfig(request.Database); + if(config!=null) + { + StringBuilder sb = new StringBuilder(); + foreach(var vv in config) + { + sb.Append(vv.Key + ":" + vv.Value + ","); + } + sb.Length = sb.Length > 0 ? sb.Length - 1 : sb.Length; + re.SettingString = sb.ToString(); + } + return Task.FromResult(re); + } + return Task.FromResult(new GetDriverSettingReplay() { Result = false }); + } + + /// + /// + /// + /// + /// + /// + public override Task UpdateDrvierSetting(UpdateDrvierSettingRequest request, ServerCallContext context) + { + if (!CheckLoginId(request.LoginId, request.Database)) + { + return Task.FromResult(new BoolResultReplay() { Result = false }); + } + if (DriverManager.Manager.Drivers.ContainsKey(request.Driver)) + { + var dd = DriverManager.Manager.Drivers[request.Driver]; + string sval = request.SettingString; + if(!string.IsNullOrEmpty(sval)) + { + Dictionary dtmp = new Dictionary(); + string[] ss = sval.Split(new char[] { ',' }); + foreach(var vv in ss) + { + string[] svv = vv.Split(new char[] { ':' }); + if(!dtmp.ContainsKey(svv[0])) + { + dtmp.Add(svv[0], svv[1]); + } + } + dd.UpdateConfig(request.Database, dtmp); + } + } + return base.UpdateDrvierSetting(request, context); + } + } } diff --git a/Develop/DbManager.Desktop/Properties/Resources.Designer.cs b/Develop/DbManager.Desktop/Properties/Resources.Designer.cs index 353b38717dfbba687ff9fbc00d91c110dcdbb7da..8b8372b21ced963cac0bd841d0d91f76d8daadce 100644 --- a/Develop/DbManager.Desktop/Properties/Resources.Designer.cs +++ b/Develop/DbManager.Desktop/Properties/Resources.Designer.cs @@ -771,6 +771,15 @@ namespace DBInStudio.Desktop.Properties { } } + /// + /// 查找类似 Setting 的本地化字符串。 + /// + internal static string Setting { + get { + return ResourceManager.GetString("Setting", resourceCulture); + } + } + /// /// 查找类似 Slope zone 的本地化字符串。 /// diff --git a/Develop/DbManager.Desktop/Properties/Resources.resx b/Develop/DbManager.Desktop/Properties/Resources.resx index cbd3cfa2cc15115f25662ac67a012b3c4fe9be36..5b684d7f14848571be8199379dd2f70cf3c969b9 100644 --- a/Develop/DbManager.Desktop/Properties/Resources.resx +++ b/Develop/DbManager.Desktop/Properties/Resources.resx @@ -357,6 +357,9 @@ set password seccussfull. + + Setting + Slope zone diff --git a/Develop/DbManager.Desktop/Properties/Resources.zh-CN.resx b/Develop/DbManager.Desktop/Properties/Resources.zh-CN.resx index 6d6a1b3959a8b2f815dcf8c098c1a698ff35f0ab..4d5a5b39c1afc5c6d47f6291495901cf68f8173c 100644 --- a/Develop/DbManager.Desktop/Properties/Resources.zh-CN.resx +++ b/Develop/DbManager.Desktop/Properties/Resources.zh-CN.resx @@ -357,6 +357,9 @@ 设置密码成功. + + 设置 + 斜率区间 diff --git a/Develop/DbManager.Desktop/ViewModel/DatabaseSettingViewModel.cs b/Develop/DbManager.Desktop/ViewModel/DatabaseSettingViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..f315276e69bb446068e639b102f70d4e3e639877 --- /dev/null +++ b/Develop/DbManager.Desktop/ViewModel/DatabaseSettingViewModel.cs @@ -0,0 +1,357 @@ +//============================================================== +// Copyright (C) 2020 Inc. All rights reserved. +// +//============================================================== +// Create by 种道洋 at 2020/9/15 15:36:01. +// Version 1.0 +// 种道洋 +//============================================================== + +using DBDevelopClientApi; +using DBInStudio.Desktop.ViewModel; +using Google.Protobuf.Reflection; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace DBInStudio.Desktop +{ + /// + /// + /// + public class DatabaseSettingViewModel: UserTreeItemViewModel + { + + #region ... Variables ... + + private int mServerPort; + + #endregion ...Variables... + + #region ... Events ... + + #endregion ...Events... + + #region ... Constructor... + + public DatabaseSettingViewModel() + { + Name = Res.Get("Setting"); + } + #endregion ...Constructor... + + #region ... Properties ... + + /// + /// + /// + public int ServerPort + { + get + { + return mServerPort; + } + set + { + if (mServerPort != value) + { + mServerPort = value; + OnPropertyChanged("ServerPort"); + } + } + } + + + #endregion ...Properties... + + #region ... Methods ... + + /// + /// + /// + /// + /// + public override ViewModelBase GetModel(ViewModelBase model) + { + if (model is DatabaseSettingConfigViewModel) + { + (model as DatabaseSettingConfigViewModel).Database = this.Database; + return model; + } + else + { + return new DatabaseSettingConfigViewModel() { Database = this.Database }; + } + } + + + + #endregion ...Methods... + + #region ... Interfaces ... + + #endregion ...Interfaces... + } + + /// + /// + /// + public class DatabaseSettingConfigViewModel : ViewModelBase, IModeSwitch + { + + #region ... Variables ... + private int mServerPort = 0; + + private ObservableCollection mChildren = new ObservableCollection(); + + #endregion ...Variables... + + #region ... Events ... + + #endregion ...Events... + + #region ... Constructor... + + #endregion ...Constructor... + + #region ... Properties ... + + /// + /// + /// + public ObservableCollection Children + { + get + { + return mChildren; + } + } + + /// + /// + /// + public string Database { get; set; } + + /// + /// + /// + public int ServerPort + { + get + { + return mServerPort; + } + set + { + if (mServerPort != value) + { + if(DevelopServiceHelper.Helper.SetRealServerPort(this.Database,value)) + { + mServerPort = value; + } + OnPropertyChanged("ServerPort"); + } + } + } + + + #endregion ...Properties... + + #region ... Methods ... + + /// + /// + /// + private void Init() + { + mServerPort = DevelopServiceHelper.Helper.GetRealServerPort(this.Database); + OnPropertyChanged("ServerPort"); + + var dds = DevelopServiceHelper.Helper.GetRegistorDrivers(this.Database).Keys; + mChildren.Clear(); + foreach (var vv in dds) + { + var ss = DevelopServiceHelper.Helper.GetDriverSetting(this.Database, vv); + if (ss != null && ss.Count > 0) + { + DriverSetViewModel dsm = new DriverSetViewModel() { Name = vv }; + dsm.Init(ss); + mChildren.Add(dsm); + } + } + } + + #endregion ...Methods... + + #region ... Interfaces ... + + #endregion ...Interfaces... + + /// + /// + /// + public void Active() + { + Init(); + } + + /// + /// + /// + public void DeActive() + { + foreach(var vv in mChildren) + { + var item = vv.ToDictionary(); + DevelopServiceHelper.Helper.UpdateDriverSetting(this.Database,vv.Name, item); + } + } + } + + /// + /// + /// + public class DriverSetViewModel : ViewModelBase + { + + #region ... Variables ... + + private string mName; + + private ObservableCollection mChildren = new ObservableCollection(); + + #endregion ...Variables... + + #region ... Events ... + + #endregion ...Events... + + #region ... Constructor... + + #endregion ...Constructor... + + #region ... Properties ... + /// + /// + /// + public string Name + { + get + { + return mName; + } + set + { + if (mName != value) + { + mName = value; + OnPropertyChanged("Name"); + } + } + } + + /// + /// + /// + public ObservableCollection Children + { + get + { + return mChildren; + } + } + + #endregion ...Properties... + + #region ... Methods ... + + /// + /// + /// + /// + public void Init(Dictionary vals) + { + mChildren.Clear(); + foreach(var vv in vals) + { + mChildren.Add(new DriverSettingItem() { Name = vv.Key, Value = vv.Value }); + } + } + + /// + /// + /// + /// + public Dictionary ToDictionary() + { + Dictionary dtmp = new Dictionary(); + foreach(var vv in mChildren) + { + dtmp.Add(vv.Name, vv.Value); + } + return dtmp; + } + + #endregion ...Methods... + + #region ... Interfaces ... + + #endregion ...Interfaces... + } + + public class DriverSettingItem : ViewModelBase + { + + #region ... Variables ... + private string mValue; + #endregion ...Variables... + + #region ... Events ... + + #endregion ...Events... + + #region ... Constructor... + + #endregion ...Constructor... + + #region ... Properties ... + + /// + /// + /// + public string Name { get; set; } + + /// + /// + /// + public string Value + { + get + { + return mValue; + } + set + { + if (mValue != value) + { + mValue = value; + OnPropertyChanged("Value"); + } + } + } + + + #endregion ...Properties... + + #region ... Methods ... + + #endregion ...Methods... + + #region ... Interfaces ... + + #endregion ...Interfaces... + } + + +} diff --git a/Develop/DbManager.Desktop/ViewModel/MainViewModel.cs b/Develop/DbManager.Desktop/ViewModel/MainViewModel.cs index e8713d57ecd552637351ffd3f21d6de91ca7127f..64925093690f0e1658c8f6d5085fcb6603ec5f74 100644 --- a/Develop/DbManager.Desktop/ViewModel/MainViewModel.cs +++ b/Develop/DbManager.Desktop/ViewModel/MainViewModel.cs @@ -653,9 +653,11 @@ namespace DBInStudio.Desktop this.TagGroup.Add(sec); dbitem.Children.Add(mRootTagGroupModel); mRootTagGroupModel.Database = mDatabase; + dbitem.Children.Add(securityModel); securityModel.Database = mDatabase; securityModel.Init(); + Task.Run(() => { TagViewModel.Drivers = DevelopServiceHelper.Helper.GetRegistorDrivers(mDatabase); QueryGroups(); diff --git a/Driver/SimDriver/Driver.cs b/Driver/SimDriver/Driver.cs index 3dd2f65ad166afc0058e9b70ddd4265410eb1233..0b1a79af442394a2bb7624159a4850337ee1883c 100644 --- a/Driver/SimDriver/Driver.cs +++ b/Driver/SimDriver/Driver.cs @@ -297,15 +297,35 @@ namespace SimDriver return true; } - + /// + /// + /// + /// + /// + public Dictionary GetConfig(string database) + { + return null; + } + + /// + /// + /// + /// + /// + public void UpdateConfig(string database, Dictionary config) + { + + } + + #endregion ...Methods... #region ... Interfaces ... #endregion ...Interfaces... - - + + } } diff --git a/Driver/SpiderDriver/Driver.cs b/Driver/SpiderDriver/Driver.cs index bf6d8ff7deea23b1b0b76acde7478c14aba66db9..9b268ac8a64611f0b13b71e4ec3a06127a517c08 100644 --- a/Driver/SpiderDriver/Driver.cs +++ b/Driver/SpiderDriver/Driver.cs @@ -1,4 +1,5 @@ -using Cdy.Tag.Driver; +using Cdy.Tag; +using Cdy.Tag.Driver; using System; using System.Collections.Generic; using System.Reflection; @@ -33,6 +34,16 @@ namespace SpiderDriver string spath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(sfileName), "Config"); sfileName = System.IO.Path.Combine(spath, "SpiderDriver.cfg"); + var dbpath = ServiceLocator.Locator.Resolve("DatabaseLocation"); + if(dbpath!=null) + { + var sdp = System.IO.Path.Combine(dbpath.ToString(), "SpiderDriver.cfg"); + if(System.IO.File.Exists(sdp)) + { + sfileName = sdp; + } + } + if (System.IO.File.Exists(sfileName)) { XElement xe = XElement.Load(sfileName); @@ -52,6 +63,28 @@ namespace SpiderDriver } } + /// + /// + /// + public void Save() + { + Save(PathHelper.helper.GetApplicationFilePath("Config", "SpiderDriver.cfg")); + } + + /// + /// + /// + /// + public void Save(string file) + { + XElement xx = new XElement("Config"); + XElement xe = new XElement("Server"); + xe.SetAttributeValue("StartPort", mPort); + xe.SetAttributeValue("EndPort", mEndPort); + xx.Add(xe); + xx.Save(file); + } + /// /// /// @@ -91,5 +124,25 @@ namespace SpiderDriver vvs.Stop(); return true; } + + /// + /// + /// + /// + /// + public Dictionary GetConfig(string database) + { + throw new NotImplementedException(); + } + + /// + /// + /// + /// + /// + public void UpdateConfig(string database, Dictionary config) + { + throw new NotImplementedException(); + } } } diff --git a/RunTime/DBRuntime.Proxy/Driver/NetTransformDriver.cs b/RunTime/DBRuntime.Proxy/Driver/NetTransformDriver.cs index 3a6564c18435251df1df84b073c1a9902e67b64a..3d7c735ecfd40e074a97f4c9c525ea3fec4bcb6f 100644 --- a/RunTime/DBRuntime.Proxy/Driver/NetTransformDriver.cs +++ b/RunTime/DBRuntime.Proxy/Driver/NetTransformDriver.cs @@ -376,6 +376,26 @@ namespace DBRuntime.Proxy resetEvent.Set(); return true; } + + /// + /// + /// + /// + /// + public Dictionary GetConfig(string database) + { + return null; + } + + /// + /// + /// + /// + /// + public void UpdateConfig(string database, Dictionary config) + { + + } } public static class ApiClientExtends diff --git a/RunTime/DBRuntime/Runner.cs b/RunTime/DBRuntime/Runner.cs index 8c5beeab495ca35821a57d3b51a45071362307a7..0d9d2ea41de7931beb00dc80383a98be8e265064 100644 --- a/RunTime/DBRuntime/Runner.cs +++ b/RunTime/DBRuntime/Runner.cs @@ -130,10 +130,10 @@ namespace Cdy.Tag } - /// - /// 数据库存访路径 - /// - public string DatabasePath { get; set; } + ///// + ///// 数据库存访路径 + ///// + //public string DatabasePath { get; set; } /// /// @@ -271,7 +271,7 @@ namespace Cdy.Tag if (System.IO.Path.IsPathRooted(database)) { this.mDatabaseName = System.IO.Path.GetFileNameWithoutExtension(database); - this.DatabasePath = System.IO.Path.GetDirectoryName(database); + //this.DatabasePath = System.IO.Path.GetDirectoryName(database); } else { @@ -295,6 +295,8 @@ namespace Cdy.Tag ServiceLocator.Locator.Registor(realEnginer); ServiceLocator.Locator.Registor(realEnginer); + ServiceLocator.Locator.Registor("DatabaseLocation", PathHelper.helper.GetDatabasePath(mDatabase.Name)); + hisEnginer = new HisEnginer2(mHisDatabase, realEnginer); hisEnginer.MergeMemoryTime = mHisDatabase.Setting.DataBlockDuration * 60; hisEnginer.LogManager = new LogManager2() { Database = mDatabaseName,Parent=hisEnginer };