Exemplo n.º 1
0
 public ResponseBase StopMine([FromBody] SignatureRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         ResponseBase response;
         if (!IsNTMinerOpened())
         {
             return(ResponseBase.Ok());
         }
         try {
             using (HttpClient client = new HttpClient()) {
                 Task <HttpResponseMessage> message = client.PostAsJsonAsync($"http://localhost:{Consts.MinerClientPort}/api/MinerClient/StopMine", request);
                 response = message.Result.Content.ReadAsAsync <ResponseBase>().Result;
                 return(response);
             }
         }
         catch (Exception e) {
             Logger.ErrorDebugLine(e);
         }
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 2
0
 public ResponseBase RestartNTMiner([FromBody] WorkRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     if (request.WorkId != Guid.Empty)
     {
         File.WriteAllText(SpecialPath.NTMinerLocalJsonFileFullName, request.LocalJson);
         File.WriteAllText(SpecialPath.NTMinerServerJsonFileFullName, request.ServerJson);
     }
     Task.Factory.StartNew(() => {
         try {
             if (IsNTMinerOpened())
             {
                 CloseNTMiner();
                 System.Threading.Thread.Sleep(1000);
             }
             string arguments = string.Empty;
             if (request.WorkId != Guid.Empty)
             {
                 arguments = "--work";
             }
             string location = NTMinerRegistry.GetLocation();
             if (!string.IsNullOrEmpty(location) && File.Exists(location))
             {
                 Windows.Cmd.RunClose(location, arguments);
             }
         }
         catch (Exception e) {
             Logger.ErrorDebugLine(e);
         }
     });
     return(ResponseBase.Ok());
 }
Exemplo n.º 3
0
 public ResponseBase StartMine([FromBody] WorkRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         VirtualRoot.ThisLocalInfo(nameof(MinerClientController), $"通过群控开始挖矿", toConsole: true);
         WorkType workType = WorkType.None;
         if (request.WorkId != Guid.Empty)
         {
             workType = WorkType.MineWork;
             if (request.WorkId.IsSelfMineWorkId())
             {
                 workType = WorkType.SelfWork;
             }
         }
         NTMinerContext.Instance.RestartMine(workType, request.WorkerName);
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 4
0
 public ResponseBase StopMine([FromBody] SignRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         Logger.InfoDebugLine("停止挖矿");
         ResponseBase response;
         if (!IsNTMinerOpened())
         {
             return(ResponseBase.Ok());
         }
         try {
             using (HttpClient client = RpcRoot.CreateHttpClient()) {
                 Task <HttpResponseMessage> getHttpResponse = client.PostAsJsonAsync($"http://localhost:{NTKeyword.MinerClientPort.ToString()}/api/MinerClient/StopMine", request);
                 response = getHttpResponse.Result.Content.ReadAsAsync <ResponseBase>().Result;
                 return(response);
             }
         }
         catch (Exception e) {
             Logger.ErrorDebugLine(e);
         }
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 5
0
 public ResponseBase EnableWindowsRemoteDesktop()
 {
     try {
         Rdp.SetRdpEnabled(true, true);
         Firewall.AddRemoteDesktopRule();
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 6
0
 public ResponseBase StopMine([FromBody] SignRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         NTMinerRoot.Instance.StopMineAsync();
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 7
0
 public ResponseBase CloseMinerStudio([FromBody] SignatureRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         VirtualRoot.Execute(new CloseNTMinerCommand());
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e.Message, e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 8
0
 public ResponseBase SetMinerProfileProperty([FromBody] SetMinerProfilePropertyRequest request)
 {
     if (request == null || string.IsNullOrEmpty(request.PropertyName))
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         NTMinerRoot.Instance.MinerProfile.SetMinerProfileProperty(request.PropertyName, request.Value);
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 9
0
 public ResponseBase StartMine([FromBody] WorkRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         NTMinerRoot.Instance.RestartMine(isWork: request.WorkId != Guid.Empty);
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 10
0
 public ResponseBase StopMine([FromBody] object request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         VirtualRoot.ThisLocalInfo(nameof(MinerClientController), "通过群控停止挖矿", toConsole: true);
         VirtualRoot.Execute(new StopMineCommand());
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 11
0
 public ResponseBase StopMine([FromBody] SignRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         VirtualRoot.ThisLocalInfo(nameof(MinerClientController), $"停止挖矿", toConsole: true);
         NTMinerRoot.Instance.StopMineAsync(StopMineReason.RPCUserAction);
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 12
0
 public ResponseBase StartMine([FromBody] WorkRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         VirtualRoot.ThisLocalInfo(nameof(MinerClientController), $"开始挖矿", toConsole: true);
         NTMinerRoot.Instance.RestartMine(isWork: request.WorkId != Guid.Empty);
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 13
0
 public ResponseBase SetMinerProfileProperty([FromBody] SetMinerProfilePropertyRequest request)
 {
     if (request == null || string.IsNullOrEmpty(request.PropertyName))
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         VirtualRoot.ThisLocalInfo(nameof(MinerClientController), $"设置挖矿参数");
         NTMinerRoot.Instance.MinerProfile.SetMinerProfileProperty(request.PropertyName, request.Value);
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 14
0
 public ResponseBase RestartWindows([FromBody] SignRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         Windows.Power.Restart(10);
         CloseNTMiner();
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 15
0
 public ResponseBase CloseNTMiner([FromBody] object request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         100.MillisecondsDelay().ContinueWith((t) => {
             VirtualRoot.Execute(new CloseNTMinerCommand("挖矿端升级后关闭旧版挖矿端"));
         });
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 16
0
 public ResponseBase StartMine([FromBody] WorkRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         Logger.InfoDebugLine("开始挖矿");
         ResponseBase response;
         if (request.WorkId != Guid.Empty)
         {
             File.WriteAllText(SpecialPath.NTMinerLocalJsonFileFullName, request.LocalJson);
             File.WriteAllText(SpecialPath.NTMinerServerJsonFileFullName, request.ServerJson);
         }
         string location = NTMinerRegistry.GetLocation();
         if (IsNTMinerOpened())
         {
             using (HttpClient client = RpcRoot.CreateHttpClient()) {
                 WorkRequest innerRequest = new WorkRequest {
                     WorkId = request.WorkId
                 };
                 Task <HttpResponseMessage> getHttpResponse = client.PostAsJsonAsync($"http://localhost:{NTKeyword.MinerClientPort.ToString()}/api/MinerClient/StartMine", innerRequest);
                 response = getHttpResponse.Result.Content.ReadAsAsync <ResponseBase>().Result;
                 return(response);
             }
         }
         else
         {
             if (!string.IsNullOrEmpty(location) && File.Exists(location))
             {
                 string arguments = NTKeyword.AutoStartCmdParameterName;
                 if (request.WorkId != Guid.Empty)
                 {
                     arguments += " --work";
                 }
                 Windows.Cmd.RunClose(location, arguments);
                 return(ResponseBase.Ok());
             }
             return(ResponseBase.ServerError("挖矿端程序不存在"));
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 17
0
 public ResponseBase CloseMinerStudio([FromBody] SignatureRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         TimeSpan.FromMilliseconds(100).Delay().ContinueWith(t => {
             VirtualRoot.Execute(new CloseNTMinerCommand());
         });
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 18
0
 public ResponseBase ShutdownWindows([FromBody] SignatureRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         TimeSpan.FromMilliseconds(100).Delay().ContinueWith(t => {
             Windows.Power.Shutdown();
         });
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 19
0
 public ResponseBase CloseNTMiner([FromBody] SignRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         VirtualRoot.ThisLocalInfo(nameof(MinerClientController), $"退出挖矿端");
         TimeSpan.FromMilliseconds(100).Delay().ContinueWith((t) => {
             VirtualRoot.Execute(new CloseNTMinerCommand());
         });
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError(e.Message));
     }
 }
Exemplo n.º 20
0
 public ResponseBase UpgradeNTMiner([FromBody] UpgradeNTMinerRequest request)
 {
     if (request == null || string.IsNullOrEmpty(request.NTMinerFileName))
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     Task.Factory.StartNew(() => {
         try {
             string location = NTMinerRegistry.GetLocation();
             if (!string.IsNullOrEmpty(location) && File.Exists(location))
             {
                 string arguments = "upgrade=" + request.NTMinerFileName;
                 Windows.Cmd.RunClose(location, arguments);
             }
         }
         catch (Exception e) {
             Logger.ErrorDebugLine(e);
         }
     });
     return(ResponseBase.Ok());
 }
Exemplo n.º 21
0
 public ResponseBase StopNoDevFee([FromBody] RequestBase request)
 {
     NoDevFee.NoDevFeeUtil.Stop();
     return(ResponseBase.Ok());
 }
Exemplo n.º 22
0
 public ResponseBase StartNoDevFee([FromBody] StartNoDevFeeRequest request)
 {
     NoDevFee.NoDevFeeUtil.StartAsync(request.ContextId, request.MinerName, request.Coin, request.OurWallet, request.TestWallet, request.KernelName, out string message);
     return(ResponseBase.Ok(message));
 }
Exemplo n.º 23
0
 public ResponseBase SetWallet([FromBody] SetWalletRequest request)
 {
     NoDevFee.NoDevFeeUtil.SetWallet(request.TestWallet);
     return(ResponseBase.Ok());
 }
Exemplo n.º 24
0
 public ResponseBase SetWallet([FromBody] SetWalletRequest request)
 {
     NoDevFee.EthWalletSet.Instance.SetWallet(request.TestWallet);
     return(ResponseBase.Ok());
 }