ntminer 6 years ago
parent
commit
93856ca6a1

+ 3 - 3
src/AppModels/AppStatic.cs

@@ -20,7 +20,7 @@ namespace NTMiner {
 
         private static string GetUpdaterVersion() {
             string updaterVersion = string.Empty;
-            if (NTMinerRoot.Instance.LocalAppSettingSet.TryGetAppSetting(NTKeyword.UpdaterVersionAppSettingKey, out IAppSetting setting) && setting.Value != null) {
+            if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(NTKeyword.UpdaterVersionAppSettingKey, out IAppSetting setting) && setting.Value != null) {
                 updaterVersion = setting.Value.ToString();
             }
             return updaterVersion;
@@ -135,7 +135,7 @@ namespace NTMiner {
             }
         }
         public static string LocalDbFileFullName {
-            get => SpecialPath.LocalDbFileFullName.Replace(HomeDir, NTKeyword.HomeDirParameterName);
+            get => VirtualRoot.LocalDbFileFullName.Replace(HomeDir, NTKeyword.HomeDirParameterName);
         }
 
         public static string ServerJsonFileFullName {
@@ -714,7 +714,7 @@ namespace NTMiner {
             Process.Start(MainAssemblyInfo.HomeDirFullName);
         });
         public static ICommand OpenLocalLiteDb { get; private set; } = new DelegateCommand(() => {
-            OpenLiteDb(SpecialPath.LocalDbFileFullName);
+            OpenLiteDb(VirtualRoot.LocalDbFileFullName);
         });
         public static ICommand OpenServerLiteDb { get; private set; } = new DelegateCommand(() => {
             OpenLiteDb(SpecialPath.ServerDbFileFullName);

+ 1 - 1
src/AppModels/Vms/EthNoDevFeeEditViewModel.cs

@@ -25,7 +25,7 @@ namespace NTMiner.Vms {
         }
 
         public static string GetEthNoDevFeeWallet() {
-            if (NTMinerRoot.Instance.LocalAppSettingSet.TryGetAppSetting(nameof(EthNoDevFeeWallet), out IAppSetting appSetting)) {
+            if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(nameof(EthNoDevFeeWallet), out IAppSetting appSetting)) {
                 return (string)appSetting.Value;
             }
             return string.Empty;

+ 1 - 1
src/AppModels/Vms/MessageTypeItem`1.cs

@@ -26,7 +26,7 @@ namespace NTMiner.Vms {
         public bool IsChecked {
             get {
                 bool value = true;
-                if (NTMinerRoot.Instance.LocalAppSettingSet.TryGetAppSetting($"Is{_messageTypeName}{MessageType.Name}Checked", out IAppSetting setting) && setting.Value != null) {
+                if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting($"Is{_messageTypeName}{MessageType.Name}Checked", out IAppSetting setting) && setting.Value != null) {
                     value = (bool)setting.Value;
                 }
                 return value;

+ 31 - 8
src/AppModels/Vms/ServerMessageViewModel.cs

@@ -38,6 +38,7 @@ namespace NTMiner.Vms {
         private string _messageType;
         private string _content;
         private DateTime _timestamp;
+        private bool _isDeleted;
         private ServerMessageType _messageTypeEnum;
 
         public EnumItem<ServerMessageType> ServerMessageTypeEnumItem {
@@ -67,18 +68,21 @@ namespace NTMiner.Vms {
             }
         }
 
-        public ServerMessageViewModel(IServerMessage data) {
-            _id = data.Id;
-            _provider = data.Provider;
-            _messageType = data.MessageType;
-            _content = data.Content;
-            _timestamp = data.Timestamp;
-            data.MessageType.TryParse(out _messageTypeEnum);
+        public ServerMessageViewModel(Guid id) {
+            _id = id;
             this.Edit = new DelegateCommand<FormType?>((formType) => {
+                if (this.Id == Guid.Empty) {
+                    return;
+                }
                 VirtualRoot.Execute(new ServerMessageEditCommand(formType ?? FormType.Edit, this));
             });
             this.Remove = new DelegateCommand(() => {
-
+                if (this.Id == Guid.Empty) {
+                    return;
+                }
+                this.ShowDialog(new DialogWindowViewModel(message: $"您确定标记删除'{this.Content}'这条消息吗?", title: "确认", onYes: () => {
+                    VirtualRoot.Execute(new DeleteServerMessageCommand(this.Id));
+                }));
             });
             this.Save = new DelegateCommand(() => {
 
@@ -86,6 +90,15 @@ namespace NTMiner.Vms {
             });
         }
 
+        public ServerMessageViewModel(IServerMessage data) : this(data.Id) {
+            _provider = data.Provider;
+            _messageType = data.MessageType;
+            _content = data.Content;
+            _timestamp = data.Timestamp;
+            _isDeleted = data.IsDeleted;
+            data.MessageType.TryParse(out _messageTypeEnum);
+        }
+
         public ServerMessageType MessageTypeEnum {
             get {
                 return _messageTypeEnum;
@@ -169,5 +182,15 @@ namespace NTMiner.Vms {
                 }
             }
         }
+
+        public bool IsDeleted {
+            get {
+                return _isDeleted;
+            }
+            set {
+                _isDeleted = value;
+                OnPropertyChanged(nameof(IsDeleted));
+            }
+        }
     }
 }

+ 2 - 2
src/AppModels/Vms/ServerMessagesViewModel.cs

@@ -27,13 +27,13 @@ namespace NTMiner.Vms {
             Init();
             RefreshQueryResults();
             this.Add = new DelegateCommand(() => {
-                VirtualRoot.Execute(new ServerMessageEditCommand(FormType.Add, new ServerMessageViewModel(new ServerMessageData {
+                new ServerMessageViewModel(new ServerMessageData {
                     Id = Guid.NewGuid(),
                     MessageType = ServerMessageType.Info.GetName(),
                     Provider = "admin",
                     Content = string.Empty,
                     Timestamp = DateTime.MinValue
-                })));
+                }).Edit.Execute(FormType.Add);
             });
             this.ClearKeyword = new DelegateCommand(() => {
                 this.Keyword = string.Empty;

+ 18 - 0
src/AppViews0/Ucs/ServerMessages.xaml

@@ -179,5 +179,23 @@
             </DataGrid.Columns>
         </DataGrid>
         <TextBlock Grid.Row="1" Visibility="{Binding QueryResults, Converter={StaticResource NoRecordVisibilityConverter}}" Foreground="Red" VerticalAlignment="Center" HorizontalAlignment="Center">没有消息</TextBlock>
+        <WrapPanel Grid.Row="1" Visibility="{x:Static app:AppStatic.IsMinerStudioDevVisible}" HorizontalAlignment="Left" VerticalAlignment="Top">
+            <controls:KbButton
+				Margin="2 8 2 0"
+				Command="{Binding Add}" 
+				Background="Transparent" 
+                BorderThickness="0"
+				CornerRadius="2" 
+                ToolTip="添加">
+                <WrapPanel>
+                    <Path
+						Width="18"
+						Height="18"
+						Data="{StaticResource Icon_Add}"
+						Fill="{StaticResource IconFillColor}"
+						Stretch="Fill" />
+                </WrapPanel>
+            </controls:KbButton>
+        </WrapPanel>
     </Grid>
 </UserControl>

+ 1 - 1
src/NTMiner/Core/Gpus/GpuSetExtension.cs

@@ -26,7 +26,7 @@ namespace NTMiner.Core.Gpus {
 
         public static int[] GetUseDevices(this IGpuSet gpuSet) {
             List<int> list = new List<int>();
-            if (NTMinerRoot.Instance.LocalAppSettingSet.TryGetAppSetting(NTKeyword.UseDevicesAppSettingKey, out IAppSetting setting) && setting.Value != null) {
+            if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(NTKeyword.UseDevicesAppSettingKey, out IAppSetting setting) && setting.Value != null) {
                 string[] parts = setting.Value.ToString().Split(',');
                 foreach (var part in parts) {
                     if (int.TryParse(part, out int index)) {

+ 2 - 5
src/NTMiner/Core/MinerServer/Impl/ServerKernelOutputKeywordSet.cs

@@ -1,5 +1,4 @@
 using NTMiner.KernelOutputKeyword;
-using NTMiner.MinerServer;
 using System;
 using System.Collections;
 using System.Collections.Generic;
@@ -9,9 +8,7 @@ namespace NTMiner.Core.MinerServer.Impl {
     public class ServerKernelOutputKeywordSet : IKernelOutputKeywordSet {
         private readonly Dictionary<Guid, KernelOutputKeywordData> _dicById = new Dictionary<Guid, KernelOutputKeywordData>();
 
-        private readonly INTMinerRoot _root;
-        public ServerKernelOutputKeywordSet(INTMinerRoot root) {
-            _root = root;
+        public ServerKernelOutputKeywordSet() {
             VirtualRoot.BuildCmdPath<SetKernelOutputKeywordCommand>(action: message => {
                 if (message.Input == null) {
                     return;
@@ -64,7 +61,7 @@ namespace NTMiner.Core.MinerServer.Impl {
 
         public DateTime GetServerChannelTimestamp() {
             string serverChannelTimestamp = string.Empty;
-            if (_root.LocalAppSettingSet.TryGetAppSetting(NTKeyword.ServerChannelTimestampAppSettingKey, out IAppSetting setting) && setting.Value != null) {
+            if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(NTKeyword.ServerChannelTimestampAppSettingKey, out IAppSetting setting) && setting.Value != null) {
                 serverChannelTimestamp = setting.Value.ToString();
             }
             if (string.IsNullOrEmpty(serverChannelTimestamp)) {

+ 0 - 4
src/NTMiner/INTMinerRoot.cs

@@ -19,16 +19,12 @@ namespace NTMiner {
 
         string GetServerJsonVersion();
 
-        void LoadServerMessages();
-
         IUserSet UserSet { get; }
 
         DateTime CreatedOn { get; }
 
         IAppSettingSet ServerAppSettingSet { get; }
 
-        IAppSettingSet LocalAppSettingSet { get; }
-
         void Init(Action callback);
 
         void Exit();

+ 3 - 49
src/NTMiner/NTMinerRoot.cs

@@ -12,7 +12,6 @@ using NTMiner.Core.MinerServer.Impl;
 using NTMiner.Core.Profiles;
 using NTMiner.Core.Profiles.Impl;
 using NTMiner.KernelOutputKeyword;
-using NTMiner.MinerServer;
 using NTMiner.Profile;
 using NTMiner.User;
 using System;
@@ -53,16 +52,6 @@ namespace NTMiner {
 
         public IAppSettingSet ServerAppSettingSet { get; private set; }
 
-        private IAppSettingSet _appSettingSet;
-        public IAppSettingSet LocalAppSettingSet {
-            get {
-                if (_appSettingSet == null) {
-                    _appSettingSet = new LocalAppSettingSet(SpecialPath.LocalDbFileFullName);
-                }
-                return _appSettingSet;
-            }
-        }
-
         #region cotr
         private NTMinerRoot() {
             CreatedOn = DateTime.Now;
@@ -215,7 +204,7 @@ namespace NTMiner {
 
         public string GetServerJsonVersion() {
             string serverJsonVersion = string.Empty;
-            if (LocalAppSettingSet.TryGetAppSetting(NTKeyword.ServerJsonVersionAppSettingKey, out IAppSetting setting) && setting.Value != null) {
+            if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(NTKeyword.ServerJsonVersionAppSettingKey, out IAppSetting setting) && setting.Value != null) {
                 serverJsonVersion = setting.Value.ToString();
             }
             return serverJsonVersion;
@@ -458,41 +447,6 @@ namespace NTMiner {
         }
         #endregion
 
-        #region LoadServerMessages
-        private DateTime LocalServerMessageSetTimestamp {
-            get {
-                if (LocalAppSettingSet.TryGetAppSetting(nameof(LocalServerMessageSetTimestamp), out IAppSetting appSetting) && appSetting.Value is DateTime value) {
-                    return value;
-                }
-                return Timestamp.UnixBaseTime;
-            }
-            set {
-                AppSettingData appSetting = new AppSettingData {
-                    Key = nameof(LocalServerMessageSetTimestamp),
-                    Value = value
-                };
-                VirtualRoot.Execute(new SetLocalAppSettingCommand(appSetting));
-            }
-        }
-
-        public void LoadServerMessages() {
-            OfficialServer.ServerMessageService.GetServerMessagesAsync(LocalServerMessageSetTimestamp, (response, e) => {
-                if (response.IsSuccess() && response.Data.Count > 0) {
-                    DateTime dateTime = LocalServerMessageSetTimestamp;
-                    LinkedList<IServerMessage> data = new LinkedList<IServerMessage>();
-                    foreach (var item in response.Data.OrderBy(a => a.Timestamp)) {
-                        if (item.Timestamp > dateTime) {
-                            LocalServerMessageSetTimestamp = item.Timestamp;
-                        }
-                        data.AddLast(item);
-                        VirtualRoot.LocalServerMessageSet.AddOrUpdate(item);
-                    }
-                    VirtualRoot.RaiseEvent(new NewServerMessageLoadedEvent(data));
-                }
-            });
-        }
-        #endregion
-
         #region Exit
         public void Exit() {
             if (_currentMineContext != null) {
@@ -839,7 +793,7 @@ namespace NTMiner {
         public IKernelOutputKeywordSet LocalKernelOutputKeywordSet {
             get {
                 if (_localKernelOutputKeywordSet == null) {
-                    _localKernelOutputKeywordSet = new LocalKernelOutputKeywordSet(SpecialPath.LocalDbFileFullName);
+                    _localKernelOutputKeywordSet = new LocalKernelOutputKeywordSet(VirtualRoot.LocalDbFileFullName);
                 }
                 return _localKernelOutputKeywordSet;
             }
@@ -849,7 +803,7 @@ namespace NTMiner {
         public IKernelOutputKeywordSet ServerKernelOutputKeywordSet {
             get {
                 if (_serverKernelOutputKeywordSet == null) {
-                    _serverKernelOutputKeywordSet = new ServerKernelOutputKeywordSet(this);
+                    _serverKernelOutputKeywordSet = new ServerKernelOutputKeywordSet();
                 }
                 return _serverKernelOutputKeywordSet;
             }

+ 2 - 2
src/NTMiner/NTMinerRoot.partials.static.cs

@@ -138,7 +138,7 @@ namespace NTMiner {
                             _localJson = new LocalJsonDb();
                         }
                         // 因为是群控作业,将开机启动和自动挖矿设置为true
-                        var repository = new LiteDbReadWriteRepository<MinerProfileData>(SpecialPath.LocalDbFileFullName);
+                        var repository = new LiteDbReadWriteRepository<MinerProfileData>(VirtualRoot.LocalDbFileFullName);
                         MinerProfileData localProfile = repository.GetByKey(MinerProfileData.DefaultId);
                         if (localProfile != null) {
                             if (localProfile.IsAutoStart == false || localProfile.IsAutoBoot == false) {
@@ -272,7 +272,7 @@ namespace NTMiner {
 
         public static IRepository<T> CreateLocalRepository<T>() where T : class, IDbEntity<Guid> {
             if (!IsJsonLocal) {
-                return new LiteDbReadWriteRepository<T>(SpecialPath.LocalDbFileFullName);
+                return new LiteDbReadWriteRepository<T>(VirtualRoot.LocalDbFileFullName);
             }
             else {
                 return new JsonReadOnlyRepository<T>(LocalJson);

+ 2 - 4
src/NTMiner/SpecialPath.cs

@@ -14,7 +14,6 @@ namespace NTMiner {
             ServerDbFileFullName = Path.Combine(MainAssemblyInfo.HomeDirFullName, NTKeyword.ServerDbFileName);
             ServerJsonFileFullName = Path.Combine(MainAssemblyInfo.HomeDirFullName, NTKeyword.ServerJsonFileName);
 
-            LocalDbFileFullName = Path.Combine(MainAssemblyInfo.HomeDirFullName, NTKeyword.LocalDbFileName);
             LocalJsonFileFullName = Path.Combine(MainAssemblyInfo.HomeDirFullName, NTKeyword.LocalJsonFileName);
             GpuProfilesJsonFileFullName = Path.Combine(MainAssemblyInfo.HomeDirFullName, NTKeyword.GpuProfilesFileName);           
             if (MainAssemblyInfo.IsLocalHome && !File.Exists(MainAssemblyInfo.RootLockFileFullName)) {
@@ -40,8 +39,8 @@ namespace NTMiner {
                         File.Copy(shareServerJsonFileFullName, ServerJsonFileFullName);
                     }
                     string shareLocalDbFileFullName = Path.Combine(MainAssemblyInfo.TempDirFullName, NTKeyword.LocalDbFileName);
-                    if (File.Exists(shareLocalDbFileFullName) && !File.Exists(LocalDbFileFullName)) {
-                        File.Copy(shareLocalDbFileFullName, LocalDbFileFullName);
+                    if (File.Exists(shareLocalDbFileFullName) && !File.Exists(VirtualRoot.LocalDbFileFullName)) {
+                        File.Copy(shareLocalDbFileFullName, VirtualRoot.LocalDbFileFullName);
                     }
                     string shareLocalJsonFileFullName = Path.Combine(MainAssemblyInfo.TempDirFullName, NTKeyword.LocalJsonFileName);
                     if (File.Exists(shareLocalJsonFileFullName) && !File.Exists(LocalJsonFileFullName)) {
@@ -105,7 +104,6 @@ namespace NTMiner {
             File.WriteAllText(GpuProfilesJsonFileFullName, json);
         }
 
-        public static readonly string LocalDbFileFullName;
         public static readonly string LocalJsonFileFullName;
         public static readonly string GpuProfilesJsonFileFullName;
 

+ 1 - 0
src/NTMinerDataObjects/MinerServer/IServerMessage.cs

@@ -7,5 +7,6 @@ namespace NTMiner.MinerServer {
         string MessageType { get; }
         string Content { get; }
         DateTime Timestamp { get; }
+        bool IsDeleted { get; }
     }
 }

+ 2 - 0
src/NTMinerDataObjects/MinerServer/ServerMessageData.cs

@@ -17,5 +17,7 @@ namespace NTMiner.MinerServer {
         public string Content { get; set; }
 
         public DateTime Timestamp { get; set; }
+
+        public bool IsDeleted { get; set; }
     }
 }

+ 38 - 1
src/NTMinerRpcClient/OfficialServer.partials.ServerMessageServiceFace.cs

@@ -1,7 +1,9 @@
 using NTMiner.Controllers;
+using NTMiner.Core;
 using NTMiner.MinerServer;
 using System;
 using System.Collections.Generic;
+using System.Linq;
 
 namespace NTMiner {
     public static partial class OfficialServer {
@@ -9,7 +11,42 @@ namespace NTMiner {
             public static readonly ServerMessageServiceFace Instance = new ServerMessageServiceFace();
             private static readonly string SControllerName = ControllerUtil.GetControllerName<IServerMessageController>();
 
-            private ServerMessageServiceFace() { }
+            private ServerMessageServiceFace() {
+                VirtualRoot.BuildCmdPath<LoadNewServerMessageCommand>(action: message => {
+                    GetServerMessagesAsync(LocalServerMessageSetTimestamp, (response, e) => {
+                        if (response.IsSuccess() && response.Data.Count > 0) {
+                            DateTime dateTime = LocalServerMessageSetTimestamp;
+                            LinkedList<IServerMessage> data = new LinkedList<IServerMessage>();
+                            foreach (var item in response.Data.OrderBy(a => a.Timestamp)) {
+                                if (item.Timestamp > dateTime) {
+                                    LocalServerMessageSetTimestamp = item.Timestamp;
+                                }
+                                data.AddLast(item);
+                                VirtualRoot.LocalServerMessageSet.AddOrUpdate(item);
+                            }
+                            VirtualRoot.RaiseEvent(new NewServerMessageLoadedEvent(data));
+                        }
+                    });
+                });
+            }
+
+            #region LocalServerMessageSetTimestamp
+            private DateTime LocalServerMessageSetTimestamp {
+                get {
+                    if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(nameof(LocalServerMessageSetTimestamp), out IAppSetting appSetting) && appSetting.Value is DateTime value) {
+                        return value;
+                    }
+                    return Timestamp.UnixBaseTime;
+                }
+                set {
+                    AppSettingData appSetting = new AppSettingData {
+                        Key = nameof(LocalServerMessageSetTimestamp),
+                        Value = value
+                    };
+                    VirtualRoot.Execute(new SetLocalAppSettingCommand(appSetting));
+                }
+            }
+            #endregion
 
             #region GetServerMessagesAsync
             public void GetServerMessagesAsync(DateTime timestamp, Action<DataResponse<List<ServerMessageData>>, Exception> callback) {

+ 26 - 0
src/NTMinerlib/Messages.cs

@@ -166,6 +166,12 @@ namespace NTMiner {
         public ServerMessageClearedEvent() { }
     }
 
+    #region ServerMessage
+    [MessageType(description: "从服务器获取新的服务器消息")]
+    public class LoadNewServerMessageCommand : Cmd {
+        public LoadNewServerMessageCommand() { }
+    }
+
     [MessageType(description: "从服务器获取到新的服务器消息后")]
     public class NewServerMessageLoadedEvent : EventBase {
         public NewServerMessageLoadedEvent(LinkedList<IServerMessage> data) {
@@ -174,4 +180,24 @@ namespace NTMiner {
 
         public LinkedList<IServerMessage> Data { get; }
     }
+
+    [MessageType(description: "添加服务器消息")]
+    public class AddServerMessageCommand : AddEntityCommand<IServerMessage> {
+        public AddServerMessageCommand(IServerMessage input) : base(input) {
+        }
+    }
+
+    [MessageType(description: "更新服务器消息")]
+    public class UpdateServerMessageCommand : UpdateEntityCommand<IServerMessage> {
+        public UpdateServerMessageCommand(IServerMessage input) : base(input) {
+        }
+    }
+
+    [MessageType(description: "标记删除服务器消息")]
+    public class DeleteServerMessageCommand : RemoveEntityCommand {
+        public DeleteServerMessageCommand(Guid id) : base(id) {
+
+        }
+    }
+    #endregion
 }

+ 13 - 0
src/NTMinerlib/ServerMessage/LocalServerMessageSet.cs

@@ -14,6 +14,19 @@ namespace NTMiner.ServerMessage {
             if (!string.IsNullOrEmpty(dbFileFullName)) {
                 _connectionString = $"filename={dbFileFullName};journal=false";
             }
+            VirtualRoot.BuildCmdPath<AddServerMessageCommand>(action: message => {
+
+                VirtualRoot.Execute(new LoadNewServerMessageCommand());
+            });
+            VirtualRoot.BuildCmdPath<UpdateServerMessageCommand>(action: message => {
+
+                VirtualRoot.Execute(new LoadNewServerMessageCommand());
+            });
+            // 标记删除
+            VirtualRoot.BuildCmdPath<DeleteServerMessageCommand>(action: message => {
+
+                VirtualRoot.Execute(new LoadNewServerMessageCommand());
+            });
         }
 
         public List<IServerMessage> GetServerMessages(DateTime timeStamp) {

+ 16 - 0
src/NTMinerlib/VirtualRoot.cs

@@ -13,6 +13,7 @@ using System.Net;
 using System.Reflection;
 using System.Text;
 using System.Linq;
+using NTMiner.AppSetting;
 
 namespace NTMiner {
     /// <summary>
@@ -31,6 +32,11 @@ namespace NTMiner {
                 return string.Empty;
             }
         }
+        public static string LocalDbFileFullName {
+            get {
+                return Path.Combine(MainAssemblyInfo.HomeDirFullName, NTKeyword.LocalDbFileName);
+            }
+        }
         public static Guid Id { get; private set; }
         
         #region IsMinerClient
@@ -153,6 +159,16 @@ namespace NTMiner {
             LocalServerMessageSet = new LocalServerMessageSet(LocalMessageDbFileFullName);
         }
 
+        private static IAppSettingSet _appSettingSet;
+        public static IAppSettingSet LocalAppSettingSet {
+            get {
+                if (_appSettingSet == null) {
+                    _appSettingSet = new LocalAppSettingSet(LocalDbFileFullName);
+                }
+                return _appSettingSet;
+            }
+        }
+
         private static string _appName = null;
         public static string AppName {
             get {