ntminer 6 years ago
parent
commit
268331af15

+ 1 - 25
src/NTMiner/Core/MinerServer/Impl/ServerKernelOutputKeywordSet.cs

@@ -9,7 +9,7 @@ namespace NTMiner.Core.MinerServer.Impl {
         private readonly Dictionary<Guid, KernelOutputKeywordData> _dicById = new Dictionary<Guid, KernelOutputKeywordData>();
 
         public ServerKernelOutputKeywordSet() {
-            VirtualRoot.BuildCmdPath<SetKernelOutputKeywordCommand>(action: message => {
+            VirtualRoot.BuildCmdPath<AddOrUpdateKernelOutputKeywordCommand>(action: message => {
                 if (message.Input == null) {
                     return;
                 }
@@ -34,10 +34,8 @@ namespace NTMiner.Core.MinerServer.Impl {
                             entity.MessageType = oldValue.MessageType;
                         }
                         Write.UserFail(response.ReadMessage(exception));
-                        VirtualRoot.RaiseEvent(new KernelOutputKeyworSetedEvent(entity));
                     }
                 });
-                VirtualRoot.RaiseEvent(new KernelOutputKeyworSetedEvent(entity));
             });
             VirtualRoot.BuildCmdPath<RemoveKernelOutputKeywordCommand>(action: message => {
                 if (message == null || message.EntityId == Guid.Empty) {
@@ -59,28 +57,6 @@ namespace NTMiner.Core.MinerServer.Impl {
             });
         }
 
-        public DateTime GetServerChannelTimestamp() {
-            string serverChannelTimestamp = string.Empty;
-            if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(NTKeyword.ServerChannelTimestampAppSettingKey, out IAppSetting setting) && setting.Value != null) {
-                serverChannelTimestamp = setting.Value.ToString();
-            }
-            if (string.IsNullOrEmpty(serverChannelTimestamp)) {
-                return DateTime.MinValue;
-            }
-            if (DateTime.TryParse(serverChannelTimestamp, out DateTime timestamp)) {
-                return timestamp;
-            }
-            return DateTime.MinValue;
-        }
-
-        private void SetServerChannelTimeStamp(DateTime timestamp) {
-            AppSettingData appSettingData = new AppSettingData() {
-                Key = NTKeyword.ServerChannelTimestampAppSettingKey,
-                Value = timestamp
-            };
-            VirtualRoot.Execute(new SetLocalAppSettingCommand(appSettingData));
-        }
-
         private bool _isInited = false;
 
         private void InitOnece() {

+ 1 - 1
src/NTMinerServices/Controllers/KernelOutputKeywordController.cs

@@ -63,7 +63,7 @@ namespace NTMiner.Controllers {
                 if (!request.IsValid(User, Sign, Timestamp, ClientIp, out ResponseBase response)) {
                     return response;
                 }
-                VirtualRoot.Execute(new SetKernelOutputKeywordCommand(request.Data));
+                VirtualRoot.Execute(new AddOrUpdateKernelOutputKeywordCommand(request.Data));
                 VirtualRoot.Execute(new SetLocalAppSettingCommand(new AppSettingData {
                     Key = NTKeyword.KernelOutputKeywordVersionAppSettingKey,
                     Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")

+ 15 - 13
src/NTMinerlib/KernelOutputKeyword/LocalKernelOutputKeywordSet.cs

@@ -12,14 +12,11 @@ namespace NTMiner.KernelOutputKeyword {
 
         public LocalKernelOutputKeywordSet(string dbFileFullName) {
             _dbFileFullName = dbFileFullName;
-            VirtualRoot.BuildCmdPath<SetKernelOutputKeywordCommand>(action: (message) => {
+            VirtualRoot.BuildCmdPath<AddOrUpdateKernelOutputKeywordCommand>(action: (message) => {
                 InitOnece();
                 if (message == null || message.Input == null || message.Input.GetId() == Guid.Empty) {
                     throw new ArgumentNullException();
                 }
-                if (_dicById.ContainsKey(message.Input.GetId())) {
-                    return;
-                }
                 if (string.IsNullOrEmpty(message.Input.MessageType)) {
                     throw new ValidationException("MessageType can't be null or empty");
                 }
@@ -29,14 +26,21 @@ namespace NTMiner.KernelOutputKeyword {
                 if (_dicById.Values.Any(a => a.KernelOutputId == message.Input.KernelOutputId && a.Keyword == message.Input.Keyword && a.Id != message.Input.GetId())) {
                     throw new ValidationException($"关键字{message.Input.Keyword}已存在");
                 }
-                KernelOutputKeywordData entity = new KernelOutputKeywordData().Update(message.Input);
-                _dicById.Add(entity.Id, entity);
-                using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) {
-                    var col = db.GetCollection<KernelOutputKeywordData>();
-                    col.Upsert(entity);
+                if (_dicById.TryGetValue(message.Input.GetId(), out KernelOutputKeywordData exist)) {
+                    exist.Update(message.Input);
+                    using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) {
+                        var col = db.GetCollection<KernelOutputKeywordData>();
+                        col.Update(exist);
+                    }
+                }
+                else {
+                    KernelOutputKeywordData entity = new KernelOutputKeywordData().Update(message.Input);
+                    _dicById.Add(entity.Id, entity);
+                    using (LiteDatabase db = new LiteDatabase(_dbFileFullName)) {
+                        var col = db.GetCollection<KernelOutputKeywordData>();
+                        col.Insert(entity);
+                    }
                 }
-
-                VirtualRoot.RaiseEvent(new KernelOutputKeyworSetedEvent(entity));
             });
             VirtualRoot.BuildCmdPath<RemoveKernelOutputKeywordCommand>(action: (message) => {
                 InitOnece();
@@ -52,8 +56,6 @@ namespace NTMiner.KernelOutputKeyword {
                     var col = db.GetCollection<KernelOutputKeywordData>();
                     col.Delete(message.EntityId);
                 }
-
-                VirtualRoot.RaiseEvent(new KernelOutputKeywordRemovedEvent(entity));
             });
         }
 

+ 2 - 14
src/NTMinerlib/Messages.cs

@@ -122,8 +122,8 @@ namespace NTMiner {
 
     #region KernelOutputKeyword Messages
     [MessageType(description: "添加或修改内核输出关键字")]
-    public class SetKernelOutputKeywordCommand : Cmd {
-        public SetKernelOutputKeywordCommand(IKernelOutputKeyword input) {
+    public class AddOrUpdateKernelOutputKeywordCommand : Cmd {
+        public AddOrUpdateKernelOutputKeywordCommand(IKernelOutputKeyword input) {
             this.Input = input;
         }
 
@@ -135,18 +135,6 @@ namespace NTMiner {
         public RemoveKernelOutputKeywordCommand(Guid entityId) : base(entityId) {
         }
     }
-
-    [MessageType(description: "添加或修改内核输出关键字后")]
-    public class KernelOutputKeyworSetedEvent : DomainEvent<IKernelOutputKeyword> {
-        public KernelOutputKeyworSetedEvent(IKernelOutputKeyword source) : base(source) {
-        }
-    }
-
-    [MessageType(description: "移除了内核输出关键字后")]
-    public class KernelOutputKeywordRemovedEvent : DomainEvent<IKernelOutputKeyword> {
-        public KernelOutputKeywordRemovedEvent(IKernelOutputKeyword source) : base(source) {
-        }
-    }
     #endregion
 
     #region LocalMessage

+ 0 - 1
src/NTMinerlib/NTKeyword.cs

@@ -65,7 +65,6 @@
         public const string UseDevicesAppSettingKey = "UseDevices";
         public const string UpdaterVersionAppSettingKey = "UpdaterVersion";
         public const string ServerJsonVersionAppSettingKey = "ServerJsonVersion";
-        public const string ServerChannelTimestampAppSettingKey = "ServerChannelTimestamp";
         #endregion
 
         #region ServerAppSettingKey