Beispiel #1
0
 protected override void OnStartup(StartupEventArgs e)
 {
     BootLog.Log("App.OnStartup start");
     RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
     try {
         appMutex = new Mutex(true, _appPipName, out createdNew);
     }
     catch (Exception) {
         createdNew = false;
     }
     if (createdNew)
     {
         if (!NTMiner.Windows.Role.IsAdministrator)
         {
             AppHelper.RunAsAdministrator();
             return;
         }
         BootLog.Log("new SplashWindow");
         SplashWindow splashWindow = new SplashWindow();
         splashWindow.Show();
         NTMinerRoot.Inited = OnNTMinerRootInited;
     }
     else
     {
         try {
             if (CommandLineArgs.IsWorkEdit)
             {
                 object argumentsValue = NTMiner.Windows.Registry.GetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "Arguments");
                 if (argumentsValue != null && (string)argumentsValue == $"--controlcenter --workid={CommandLineArgs.WorkId}")
                 {
                     AppHelper.ShowMainWindow(this, _appPipName);
                 }
                 else
                 {
                     NTMinerClientDaemon.Instance.RestartNTMiner(NTMinerRoot.MinerClientHost, 3336, CommandLineArgs.WorkId, null);
                     this.Shutdown();
                 }
             }
             else
             {
                 AppHelper.ShowMainWindow(this, _appPipName);
             }
         }
         catch (Exception) {
             DialogWindow.ShowDialog(message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。", title: "alert", icon: "Icon_Error");
             Process   currentProcess = Process.GetCurrentProcess();
             Process[] processes      = Process.GetProcessesByName(currentProcess.ProcessName);
             foreach (var process in processes)
             {
                 if (process.Id != currentProcess.Id)
                 {
                     NTMiner.Windows.TaskKill.Kill(process.Id);
                 }
             }
         }
     }
     base.OnStartup(e);
     BootLog.Log("App.OnStartup end");
     BootLog.SyncToDisk();
 }
Beispiel #2
0
 public App()
 {
     AppHelper.Init(this);
     BootLog.Log("App.InitializeComponent start");
     InitializeComponent();
     BootLog.Log("App.InitializeComponent end");
 }
Beispiel #3
0
        public static void Init(INTMinerRoot root) {
            if (NTMinerRoot.IsInDesignMode) {
                return;
            }

            Global.Access<HasBoot2SecondEvent>(
                Guid.Parse("b4efba26-1f02-42f2-822a-dd38cffd466d"),
                "登录服务器并报告一次0算力",
                LogEnum.None,
                action: message => {
                    Task.Factory.StartNew(() => {
                        Login(root);
                        // 报告0算力从而告知服务器该客户端当前在线的币种
                        ReportSpeed(root);
                    });
                });

            Global.Access<Per2MinuteEvent>(
                Guid.Parse("0b16bbd3-329b-4b46-9ebe-c403cae26018"),
                "每两分钟上报一次",
                LogEnum.None,
                action: message => {
                    Task.Factory.StartNew(() => {
                        ReportSpeed(root);
                    });
                });

            Global.Access<MineStartedEvent>(
                Guid.Parse("6e8ab8a2-7d08-41bd-9410-107793639f7f"),
                "开始挖矿后报告状态",
                LogEnum.Console,
                action: message => {
                    Task.Factory.StartNew(() => {
                        ReportSpeed(root);
                    });
                });

            Global.Access<MineStopedEvent>(
                Guid.Parse("5ff27468-2a01-4ce4-91a3-aa354791d0eb"),
                "停止挖矿后报告状态",
                LogEnum.Console,
                action: message => {
                    Task.Factory.StartNew(() => {
                        ReportState(root);
                    });
                });
            BootLog.Log(typeof(Report).FullName + "接入总线");
        }
Beispiel #4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;

            bool mutexCreated;

            try {
                mutexApp = new Mutex(true, "NTMinerUpdaterAppMutex", out mutexCreated);
            }
            catch {
                mutexCreated = false;
            }
            if (mutexCreated == false)
            {
                Process   thatProcess    = null;
                Process   currentProcess = Process.GetCurrentProcess();
                Process[] Processes      = Process.GetProcessesByName(currentProcess.ProcessName);
                foreach (Process process in Processes)
                {
                    if (process.Id != currentProcess.Id)
                    {
                        if (typeof(App).Assembly.Location.Equals(currentProcess.MainModule.FileName, StringComparison.OrdinalIgnoreCase))
                        {
                            thatProcess = process;
                        }
                    }
                }
                if (thatProcess != null)
                {
                    Show(thatProcess);
                }
                else
                {
                    MessageBox.Show("another Updater is running", "alert", MessageBoxButton.OKCancel);
                }
                Environment.Exit(-1);
                return;
            }

            base.OnStartup(e);

            this.MainWindow = new MainWindow();
            this.MainWindow.Show();
            BootLog.SyncToDisk();
        }
Beispiel #5
0
        public static void Init(Application app)
        {
            BootLog.LogDir = Path.Combine(SpecialPath.ShareDirFullName, "Logs");
            BootLog.Log("AppHelper.Init start");
            AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => {
                var exception = e.ExceptionObject as Exception;
                if (exception != null)
                {
                    Handle(exception);
                }
            };

            app.DispatcherUnhandledException += (object sender, DispatcherUnhandledExceptionEventArgs e) => {
                Handle(e.Exception);
                e.Handled = true;
            };

            Execute.InitializeWithDispatcher();
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");
            BootLog.Log("AppHelper.Init end");
        }
Beispiel #6
0
        public void Init()
        {
            if (!this._isInited)
            {
                lock (this._locker) {
                    if (!this._isInited)
                    {
                        BootLog.Log("SystemRoo.PrivateInit start");
                        this.PackageDownloader         = new PackageDownloader(this);
                        this.SysDicSet                 = new SysDicSet(this);
                        this.SysDicItemSet             = new SysDicItemSet(this);
                        this.CoinSet                   = new CoinSet(this);
                        this.GroupSet                  = new GroupSet(this);
                        this.CoinGroupSet              = new CoinGroupSet(this);
                        this.CalcConfigSet             = new CalcConfigSet(this);
                        this.WalletSet                 = new WalletSet(this);
                        this.PoolSet                   = new PoolSet(this);
                        this.CoinKernelSet             = new CoinKernelSet(this);
                        this.KernelSet                 = new KernelSet(this);
                        this.KernelProfileSet          = new KernelProfileSet(this);
                        this.KernelOutputFilterSet     = new KernelOutputFilterSet(this);
                        this.KernelOutputTranslaterSet = new KernelOutputTranslaterSet(this);
                        this.GpusSpeed                 = new GpusSpeed(this);
                        this.CoinShareSet              = new CoinShareSet(this);
                        this.MineWorkSet               = new MineWorkSet(this);
                        this.MinerGroupSet             = new MinerGroupSet(this);
                        this._minerProfile             = new MinerProfile(this);
                        this.CoinProfileSet            = new CoinProfileSet(this);
                        this.CoinKernelProfileSet      = new CoinKernelProfileSet(this);

                        Inited?.Invoke();
                        BootLog.Log("SystemRoo.PrivateInit end");
                        this._isInited = true;
                    }
                }
            }
        }
Beispiel #7
0
        public App()
        {
            BootLog.LogDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs");
            BootLog.Log("App.ctor start");
            AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => {
                var exception = e.ExceptionObject as Exception;
                if (exception != null)
                {
                    Handle(exception);
                }
            };

            DispatcherUnhandledException += (object sender, DispatcherUnhandledExceptionEventArgs e) => {
                Handle(e.Exception);
                e.Handled = true;
            };

            Execute.InitializeWithDispatcher();
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");
            BootLog.Log("App.InitializeComponent start");
            InitializeComponent();
            BootLog.Log("App.InitializeComponent end");
            BootLog.Log("App.ctor end");
        }
Beispiel #8
0
 protected override void OnStartup(StartupEventArgs e)
 {
     BootLog.Log("App.OnStartup start");
     RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
     try {
         appMutex = new Mutex(true, _appPipName, out createdNew);
     }
     catch (Exception) {
         createdNew = false;
     }
     if (createdNew)
     {
         if (!NTMiner.Windows.Role.IsAdministrator)
         {
             AppHelper.RunAsAdministrator();
             return;
         }
         BootLog.Log("new SplashWindow");
         SplashWindow splashWindow = new SplashWindow();
         splashWindow.Show();
         NTMinerRoot.Inited = () => {
             NTMinerRoot.KernelDownloader = new KernelDownloader();
             Execute.OnUIThread(() => {
                 bool?result = true;
                 if (string.IsNullOrEmpty(Server.LoginName) || string.IsNullOrEmpty(Server.Password))
                 {
                     LoginWindow loginWindow = new LoginWindow();
                     splashWindow.Hide();
                     result = loginWindow.ShowDialog();
                 }
                 if (result.HasValue && result.Value)
                 {
                     BootLog.Log("new MainWindow");
                     ControlCenterWindow window = new ControlCenterWindow();
                     IMainWindow mainWindow     = window;
                     this.MainWindow            = window;
                     this.MainWindow.Show();
                     this.MainWindow.Activate();
                     BootLog.Log("MainWindow showed");
                     notifyIcon = new ExtendedNotifyIcon("pack://application:,,,/ControlCenterApp;component/logo.ico");
                     notifyIcon.Init();
                     #region 处理显示主界面命令
                     Global.Access <ShowMainWindowCommand>(
                         Guid.Parse("01f3c467-f494-42b8-bcb5-848050df59f3"),
                         "处理显示主界面命令",
                         LogEnum.None,
                         action: message => {
                         Execute.OnUIThread(() => {
                             Dispatcher.Invoke((ThreadStart)mainWindow.ShowThisWindow);
                             AppHelper.MainWindowShowed();
                         });
                     });
                     #endregion
                     Task.Factory.StartNew(() => {
                         AppHelper.RunPipeServer(this, _appPipName);
                     });
                 }
                 splashWindow?.Close();
                 BootLog.SyncToDisk();
             });
         };
     }
     else
     {
         try {
             AppHelper.ShowMainWindow(this, _appPipName);
         }
         catch (Exception) {
             DialogWindow.ShowDialog(message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。", title: "alert", icon: "Icon_Error");
             Process   currentProcess = Process.GetCurrentProcess();
             Process[] processes      = Process.GetProcessesByName(currentProcess.ProcessName);
             foreach (var process in processes)
             {
                 if (process.Id != currentProcess.Id)
                 {
                     NTMiner.Windows.TaskKill.Kill(process.Id);
                 }
             }
         }
     }
     base.OnStartup(e);
     BootLog.Log("App.OnStartup end");
     BootLog.SyncToDisk();
 }
Beispiel #9
0
 private void OnNTMinerRootInited()
 {
     NTMinerRoot.KernelDownloader = new KernelDownloader();
     Execute.OnUIThread(() => {
         BootLog.Log("new MainWindow");
         Window splashWindow    = MainWindow;
         MainWindow window      = new MainWindow();
         IMainWindow mainWindow = window;
         this.MainWindow        = window;
         this.MainWindow.Show();
         this.MainWindow.Activate();
         BootLog.Log("MainWindow showed");
         notifyIcon = new ExtendedNotifyIcon("pack://application:,,,/NTMiner;component/logo.ico");
         notifyIcon.Init();
         #region 处理显示主界面命令
         Global.Access <ShowMainWindowCommand>(
             Guid.Parse("01f3c467-f494-42b8-bcb5-848050df59f3"),
             "处理显示主界面命令",
             LogEnum.None,
             action: message => {
             Execute.OnUIThread(() => {
                 Dispatcher.Invoke((ThreadStart)mainWindow.ShowThisWindow);
                 AppHelper.MainWindowShowed();
             });
         });
         #endregion
         #region 处理重启NTMiner命令
         Global.Access <RestartNTMinerCommand>(
             Guid.Parse("d1712c1f-507c-496f-9da2-870cbd9fc57f"),
             "处理重启NTMiner命令",
             LogEnum.None,
             action: message => {
             List <string> args = CommandLineArgs.Args;
             if (message.IsWorkEdit)
             {
                 if (CommandLineArgs.IsWorkEdit && CommandLineArgs.WorkId == message.MineWorkId)
                 {
                     Execute.OnUIThread(() => {
                         Dispatcher.Invoke((ThreadStart)mainWindow.ShowThisWindow);
                     });
                     return;
                 }
                 if (!CommandLineArgs.IsControlCenter)
                 {
                     args.Add("--controlCenter");
                 }
             }
             if (message.MineWorkId != Guid.Empty)
             {
                 if (!CommandLineArgs.IsWorker)
                 {
                     args.Add("--workid=" + message.MineWorkId.ToString());
                 }
                 else
                 {
                     for (int i = 0; i < args.Count; i++)
                     {
                         if (args[i].StartsWith("--workid=", StringComparison.OrdinalIgnoreCase))
                         {
                             args[i] = "--workid=" + message.MineWorkId.ToString();
                             break;
                         }
                     }
                 }
             }
             else
             {
                 if (CommandLineArgs.IsWorker)
                 {
                     int workIdIndex = -1;
                     for (int i = 0; i < args.Count; i++)
                     {
                         if (args[i].ToLower().Contains("--workid="))
                         {
                             workIdIndex = i;
                             break;
                         }
                     }
                     if (workIdIndex != -1)
                     {
                         args.RemoveAt(workIdIndex);
                     }
                 }
             }
             NTMiner.Windows.Cmd.RunClose(ClientId.AppFileFullName, string.Join(" ", args));
             Current.MainWindow.Close();
         });
         #endregion
         Task.Factory.StartNew(() => {
             AppHelper.RunPipeServer(this, _appPipName);
         });
         try {
             NTMinerRoot.Current.Start();
         }
         catch (Exception ex) {
             Global.Logger.Error(ex.Message, ex);
         }
         splashWindow?.Close();
         if (NTMinerRoot.Current.MinerProfile.IsAutoStart || CommandLineArgs.IsAutoStart)
         {
             Global.DebugLine("自动开始挖矿倒计时", ConsoleColor.Yellow);
             Views.Ucs.AutoStartCountdown.ShowDialog();
         }
         BootLog.SyncToDisk();
     });
 }
Beispiel #10
0
        public void Start()
        {
            BootLog.Log("开始启动Wcf服务");
            string      baseUrl = $"http://{MinerClientHost}:{Global.ClientPort}/";
            ServiceHost minerClientServiceHost = new ServiceHost(typeof(Core.Impl.MinerClientService));

            minerClientServiceHost.AddServiceEndpoint(typeof(IMinerClientService), ChannelFactory.BasicHttpBinding, new Uri(new Uri(baseUrl), nameof(IMinerClientService)));
            _serviceHosts = new List <ServiceHost>
            {
                minerClientServiceHost
            };
            foreach (var serviceHost in _serviceHosts)
            {
                ServiceMetadataBehavior serviceMetadata = serviceHost.Description.Behaviors.Find <ServiceMetadataBehavior>();
                if (serviceMetadata == null)
                {
                    serviceMetadata = new ServiceMetadataBehavior();
                    serviceHost.Description.Behaviors.Add(serviceMetadata);
                }
                serviceMetadata.HttpGetEnabled = false;

                serviceHost.Open();
            }

            Global.DebugLine($"服务启动成功: {DateTime.Now}.");
            Global.DebugLine("服务列表:");
            foreach (var serviceHost in _serviceHosts)
            {
                foreach (var endpoint in serviceHost.Description.Endpoints)
                {
                    Global.DebugLine(endpoint.Address.Uri.ToString());
                }
            }
            BootLog.Log("Wcf服务启动完成");

            Server.TimeService.GetTime((remoteTime) => {
                if (Math.Abs((DateTime.Now - remoteTime).TotalSeconds) < Global.DesyncSeconds)
                {
                    Global.DebugLine("时间同步");
                }
                else
                {
                    Global.WriteLine($"本机时间和服务器时间不同步,请调整,本地:{DateTime.Now},服务器:{remoteTime}", ConsoleColor.Red);
                }
            });

            Windows.Registry.SetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "Location", ClientId.AppFileFullName);
            Windows.Registry.SetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "Arguments", string.Join(" ", CommandLineArgs.Args));
            Windows.Registry.SetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "CurrentVersion", CurrentVersion.ToString());
            Windows.Registry.SetValue(Registry.Users, ClientId.NTMinerRegistrySubKey, "CurrentVersionTag", CurrentVersionTag);

            Report.Init(this);

            int      shareCount = 0;
            DateTime shareOn    = DateTime.Now;

            #region 挖矿开始时将无份额内核重启份额计数置0
            Global.Access <MineStartedEvent>(
                Guid.Parse("e69e8729-868b-4b5d-b120-2914fffddf90"),
                "挖矿开始时将无份额内核重启份额计数置0",
                LogEnum.None,
                action: message => {
                shareCount = 0;
                shareOn    = DateTime.Now;
            });
            #endregion
            #region 每10秒钟检查是否需要重启
            Global.Access <Per10SecondEvent>(
                Guid.Parse("16b3b7b4-5e6c-46b0-97a4-90e085614b78"),
                "每10秒钟检查是否需要重启",
                LogEnum.None,
                action: message => {
                #region 重启电脑
                try {
                    if (MinerProfile.IsPeriodicRestartComputer)
                    {
                        if ((DateTime.Now - shareOn).TotalHours > MinerProfile.PeriodicRestartComputerHours)
                        {
                            Global.WriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时重启电脑", ConsoleColor.Red);
                            Windows.Power.Restart();
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Global.Logger.Error(e.Message, e);
                }
                #endregion

                #region 周期重启内核
                try {
                    if (IsMining && MinerProfile.IsPeriodicRestartKernel)
                    {
                        if ((DateTime.Now - shareOn).TotalHours > MinerProfile.PeriodicRestartKernelHours)
                        {
                            Global.WriteLine($"每运行{MinerProfile.PeriodicRestartKernelHours}小时重启内核", ConsoleColor.Red);
                            RestartMine();
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Global.Logger.Error(e.Message, e);
                }
                #endregion

                #region 收益没有增加重启内核
                try {
                    if (IsMining && MinerProfile.IsNoShareRestartKernel)
                    {
                        if ((DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes)
                        {
                            if (this.CurrentMineContext.MainCoin != null)
                            {
                                ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.CurrentMineContext.MainCoin.GetId());
                                int totalShare           = mainCoinShare.TotalShareCount;
                                if ((this.CurrentMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null)
                                {
                                    ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId());
                                    totalShare += dualCoinShare.TotalShareCount;
                                }
                                if (shareCount == totalShare)
                                {
                                    Global.WriteLine($"{MinerProfile.NoShareRestartKernelMinutes}分钟收益没有增加重启内核", ConsoleColor.Red);
                                    RestartMine();
                                }
                                else
                                {
                                    shareCount = totalShare;
                                    shareOn    = DateTime.Now;
                                }
                            }