public override Task <RestartResponse> Restart(RestartRequest request, ServerCallContext context) { Logger.Information("{@request}", request); Logger.Warning("Server is being asked to restart"); Environment.Exit(0); return(null); }
/// <summary> /// 通知分站进行重启升级 /// </summary> /// <param name="masProtocol"></param> /// <param name="restartRequest"></param> /// <param name="deviceCode"></param> /// <returns></returns> public byte[] HandRestart(MasProtocol masProtocol, RestartRequest restartRequest, ref string deviceCode) { DeviceInfo deviceinfoobject = null; DeviceTypeInfo devicetypeobject = null; NetworkDeviceInfo netmacobject = null; RestartRequestCommand commandobject = new RestartRequestCommand(); byte[] sendbuff = null; if (masProtocol == null || restartRequest == null) { return(sendbuff); } if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.DeviceControlRequest, restartRequest.DeviceCode)) { return(sendbuff); } if (netmacobject.NetID > 0) { deviceCode = netmacobject.MAC; //向下的发送的MAC地址 commandobject = Basic.Framework.Common.ObjectConverter.Copy <RestartRequest, RestartRequestCommand>(restartRequest); //得到基础数据 commandobject.DeviceId = restartRequest.DeviceId; commandobject.HardVersion = restartRequest.HardVersion; commandobject.FileVersion = restartRequest.FileVersion; commandobject.def = deviceinfoobject; // Framework.Common.ObjectConverter.DeepCopy<DeviceInfo>(deviceinfoobject);//得到分站的对象必须是深度拷贝; sendbuff = commandobject.ToBytes(); //得到通讯命令的返回Buffer数组 //if (sendbuff != null) //{ // sendbuff = Cache.GetPackages(sendbuff, netmacobject, deviceinfoobject, 2, CommandCodes.ExtendCommand, (byte)devicetypeobject.LC2);//通过当前网络模块进行打包 //} } return(sendbuff); }
public async Task API_RestartTest() { var widget = new TestWidget(); var handler = new Restart(); var request = RestartRequest.Create(widget); await handler.Handle(request, CancellationToken.None); }
public override async Task <RestartReply> Restart(RestartRequest request, ServerCallContext context) { var success = await InteropService.Restart(TimeSpan.FromSeconds(request.Delay), request.Force); return(new RestartReply() { Success = success }); }
public override Task <RestartReply> Restart(RestartRequest request, ServerCallContext context) { Log.Info("Executing [{Name}] [{Delay}s] [{Force}]", nameof(Restart), request.Delay, request.Force); var success = MachineStateHelper.TryRestart(TimeSpan.FromSeconds(request.Delay), request.Force); return(Task.FromResult(new RestartReply() { Success = success })); }
public Task Handle(RestartRequest <IISApplicationPool> request, CancellationToken cancellationToken) { using (var iis = ServerManager.OpenRemote(request.DataContext.Host)) { var appPool = iis.ApplicationPools[request.DataContext.ApplicationPoolName]; appPool.Recycle(); request.DataContext.State = appPool.State == ObjectState.Started ? State.Ok : State.Failed; return(Task.CompletedTask); } }
public override Task <RestartResponse> Restart(RestartRequest request, ServerCallContext context) { var response = new RestartResponse() { ResponseBase = CreateResponseBase() }; RunCommand(nameof(Restart), () => { connectionsService.HandleRequest(request.RequestBase); systemService.Restart(); }, request.RequestBase, response.ResponseBase); return(Task.FromResult(response)); }
void restartAction() { AmqpController.amqpControl.exchangeSubscription.Handler = ProcessRestart; RestartRequest json = new RestartRequest(); json.id = id; json.type = "restart"; json.username = PlayerPrefs.GetString("username"); string request = JsonUtility.ToJson(json); AmqpClient.Publish(AmqpController.amqpControl.requestExchangeName, AmqpController.amqpControl.requestRoutingKey, request); }
public async Task Handle(RestartRequest <WindowsService> request, CancellationToken cancellationToken) { var dialog = new ConfirmationDialog($"Are you sure you want to restart {request.DataContext.Name}?"); var result = _dialogService.ShowDialog(dialog); if (result != DialogResult.Yes) { return; } _logger.Info($"Restarting {request.DataContext.Name}."); await RestartAsync(request.DataContext, cancellationToken).ConfigureAwait(false); }
/// <summary> /// Restart TODO: Add Description /// </summary> /// <param name="contentType"></param> /// <param name="body"></param> /// <returns></returns> public void ApplianceTechpreviewShutdownRestartPost(string contentType, RestartRequest body) { // verify the required parameter 'contentType' is set if (contentType == null) { throw new ApiException(400, "Missing required parameter 'contentType' when calling ApplianceTechpreviewShutdownRestartPost"); } // verify the required parameter 'body' is set if (body == null) { throw new ApiException(400, "Missing required parameter 'body' when calling ApplianceTechpreviewShutdownRestartPost"); } string path = "/appliance/techpreview/shutdown/restart"; path = path.Replace("{format}", "json"); Dictionary <string, string> queryParams = new Dictionary <string, string>(); Dictionary <string, string> headerParams = new Dictionary <string, string>(); Dictionary <string, string> formParams = new Dictionary <string, string>(); Dictionary <string, FileParameter> fileParams = new Dictionary <string, FileParameter>(); string postBody = null; if (contentType != null) { headerParams.Add("Content-Type", ApiClient.ParameterToString(contentType)); // header parameter } postBody = ApiClient.Serialize(body); // http body (model) parameter // authentication setting, if any string[] authSettings = new string[] { "auth" }; // make the HTTP request IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); if (((int)response.StatusCode) >= 400) { throw new ApiException((int)response.StatusCode, "Error calling ApplianceTechpreviewShutdownRestartPost: " + response.Content, response.Content); } else if (response.StatusCode == 0) { throw new ApiException((int)response.StatusCode, "Error calling ApplianceTechpreviewShutdownRestartPost: " + response.ErrorMessage, response.ErrorMessage); } return; }
public async Task <ActionResult <BoolResult> > Restart([FromBody] RestartRequest request) { if (!await _authManager.HasAppPermissionsAsync(Types.AppPermissions.PluginsAdd)) { return(Unauthorized()); } _settingsManager.SaveSettings(_settingsManager.IsProtectData, request.IsDisablePlugins, _settingsManager.DatabaseType, _settingsManager.DatabaseConnectionString, _settingsManager.RedisConnectionString, _settingsManager.AdminRestrictionHost, _settingsManager.AdminRestrictionAllowList, _settingsManager.AdminRestrictionBlockList); _hostApplicationLifetime.StopApplication(); return(new BoolResult { Value = true }); }
public static StationUpdateItem GetStationItem(int fzh) { StationUpdateItem item = null; if (fzh >= 0 && fzh < stationItems.Length - 1) { if (stationItems[fzh - 1] == null) { return(item); } item = DeepCopy(stationItems[fzh - 1]); item.isSendBuffer = false; switch (item.updateState) { case StationUpdateState.requesting: //下发请求升级 下发请求升级 StationUpdateRequest stationUpdateRequest = new StationUpdateRequest(); stationUpdateRequest.DeviceCode = fzh.ToString().PadLeft(3, '0') + "0000"; stationUpdateRequest.DeviceId = (byte)updatetTypeid; stationUpdateRequest.HardVersion = (byte)updateHardVersion; stationUpdateRequest.FileVersion = (byte)updateFileVersion; stationUpdateRequest.maxVersion = (byte)updateMaxVersion; stationUpdateRequest.minVersion = (byte)updateMinVersion; stationUpdateRequest.FileCount = updateCount; stationUpdateRequest.Crc = crcValue; item.isSendBuffer = true; item.protocol = stationUpdateRequest; item.protocolType = ProtocolType.StationUpdateRequest; break; case StationUpdateState.recivingFile: //文件接收中 下发文件 if (item.nowNeedSendBuffIndex >= updateCount) { item.updateState = StationUpdateState.reiciveCheck; return(null); } SendUpdateBufferRequest sendUpdateBufferRequest = new SendUpdateBufferRequest(); sendUpdateBufferRequest.DeviceCode = fzh.ToString().PadLeft(3, '0') + "0000"; sendUpdateBufferRequest.DeviceId = (byte)updatetTypeid; sendUpdateBufferRequest.HardVersion = (byte)updateHardVersion; sendUpdateBufferRequest.FileVersion = (byte)updateFileVersion; sendUpdateBufferRequest.NowBufferIndex = item.nowNeedSendBuffIndex; sendUpdateBufferRequest.Buffer = new byte[256]; for (int i = 0; i < sendUpdateBufferRequest.Buffer.Length; i++) { sendUpdateBufferRequest.Buffer[i] = updateBuffer[(item.nowNeedSendBuffIndex - 1) * 256 + i]; } item.isSendBuffer = true; item.protocol = sendUpdateBufferRequest; item.protocolType = ProtocolType.SendUpdateBufferRequest; stationItems[fzh - 1].nowNeedSendBuffIndex += 1; if (stationItems[fzh - 1].nowNeedSendBuffIndex >= updateCount) { stationItems[fzh - 1].updateState = StationUpdateState.reiciveCheck; //下发完成后自动切换到巡检 } break; case StationUpdateState.reiciveCheck: //巡检文件接收情况 下发巡检 InspectionRequest inspectionRequest = new InspectionRequest(); inspectionRequest.DeviceCode = fzh.ToString().PadLeft(3, '0') + "0000"; inspectionRequest.DeviceId = (byte)updatetTypeid; inspectionRequest.HardVersion = (byte)updateHardVersion; inspectionRequest.FileVersion = (byte)updateFileVersion; inspectionRequest.LostFileNum = 0; item.isSendBuffer = true; item.protocol = inspectionRequest; item.protocolType = ProtocolType.InspectionRequest; break; case StationUpdateState.replacement: //补发文件中 补发文件 InspectionRequest replacement = new InspectionRequest(); replacement.DeviceCode = fzh.ToString().PadLeft(3, '0') + "0000"; replacement.DeviceId = (byte)updatetTypeid; replacement.HardVersion = (byte)updateHardVersion; replacement.FileVersion = (byte)updateFileVersion; replacement.LostFileNum = item.nowNeedSendBuffIndex; if (replacement.LostFileNum > 0) { replacement.FileBuffer = new byte[256]; for (int i = 0; i < replacement.FileBuffer.Length; i++) { replacement.FileBuffer[i] = updateBuffer[(item.nowNeedSendBuffIndex - 1) * 256 + i]; } } item.isSendBuffer = true; item.protocol = replacement; item.protocolType = ProtocolType.InspectionRequest; break; case StationUpdateState.restart: //重启升级 下发重启命令 RestartRequest restartRequest = new RestartRequest(); restartRequest.DeviceCode = fzh.ToString().PadLeft(3, '0') + "0000"; restartRequest.DeviceId = (byte)updatetTypeid; restartRequest.HardVersion = (byte)updateHardVersion; restartRequest.FileVersion = (byte)updateFileVersion; item.isSendBuffer = true; item.protocol = restartRequest; item.protocolType = ProtocolType.RestartRequest; break; case StationUpdateState.restore: //恢复备份 下发恢复备份命令 ReductionRequest reductionRequest = new ReductionRequest(); reductionRequest.DeviceCode = fzh.ToString().PadLeft(3, '0') + "0000"; reductionRequest.DeviceId = (byte)updatetTypeid; reductionRequest.HardVersion = (byte)updateHardVersion; reductionRequest.SoftVersion = (byte)updateFileVersion; item.isSendBuffer = true; item.protocol = reductionRequest; item.protocolType = ProtocolType.ReductionRequest; break; case StationUpdateState.updateCancle: //取消升级 //下取消升级命令 UpdateCancleRequest updateCancleRequest = new UpdateCancleRequest(); updateCancleRequest.DeviceCode = fzh.ToString().PadLeft(3, '0') + "0000"; updateCancleRequest.DeviceId = (byte)updatetTypeid; updateCancleRequest.HardVersion = (byte)updateHardVersion; updateCancleRequest.FileVersion = (byte)updateFileVersion; item.isSendBuffer = true; item.protocol = updateCancleRequest; item.protocolType = ProtocolType.UpdateCancleRequest; break; case StationUpdateState.getVersion: //获取分站信息 GetStationUpdateStateRequest getStationUpdateStateRequest = new GetStationUpdateStateRequest(); getStationUpdateStateRequest.DeviceCode = fzh.ToString().PadLeft(3, '0') + "0000"; getStationUpdateStateRequest.GetSoftVersion = 1; getStationUpdateStateRequest.GetUpdateState = 1; getStationUpdateStateRequest.GetDevType = 1; getStationUpdateStateRequest.GetHardVersion = 1; item.isSendBuffer = true; item.protocol = getStationUpdateStateRequest; item.protocolType = ProtocolType.GetStationUpdateStateRequest; break; } } return(item); }
protected override async Task Handle(RestartRequest <ReadOnlyDockerContainerWidget> request, CancellationToken cancellationToken) { using (var client = Endpoint.GetClient()) await client.Containers.RestartContainerAsync(request.Context.ContainerId, new ContainerRestartParameters(), cancellationToken) .ConfigureAwait(false); }
private void UpdateSettings() { settingsList.SaveToDB(); RestartRequest?.Invoke(this, EventArgs.Empty); }
public ClientModule() { Get[PATH_CLIENT + "/getPOApplicationStatus"] = parameter => { try { Process[] processes = Process.GetProcesses(); List <string> processImageName = new List <string>(); try { foreach (Process p in processes) { if (!String.IsNullOrEmpty(p.MainWindowTitle)) { processImageName.Add(p.MainModule.ModuleName); } } } catch { } var isRunning = processImageName.Select(x => string.Compare(x, ProjectName) == 0 || string.Compare(x, ProjectName64) == 0).FirstOrDefault(); var message = "Applikasi Tidak Ditemukan"; if (isRunning) { message = "Aplikasi sedang running"; } return(Response.AsJson(new { IsRunning = isRunning, message = message })); } catch (Exception ex) { return(Response.AsJson(new { IsRunning = false, message = ex.Message }, HttpStatusCode.ExpectationFailed)); } }; //overwrite local file with file from server Post[PATH_CLIENT + "/overwriteXmlSetting"] = parameter => { var message = string.Empty; try { log.Info("Mulai : /client/overwriteXmlSetting"); log.Info($"Request dari IP:{this.Request.UserHostAddress}"); var body = Nancy.IO.RequestStream.FromStream(Request.Body).AsString(); log.Info("Memparsing isi dari request API "); RequestOverwriteXmlSetting setting = JsonConvert.DeserializeObject <RequestOverwriteXmlSetting>(body); log.Info("Parsing sukses"); log.Info($"Mencari file {setting.file_name} di direktori : { AssemblyDirectory }"); System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(AssemblyDirectory); System.IO.FileInfo info = new System.IO.FileInfo(setting.file_name); if (info.Exists) { log.Info($"file {setting.file_name} ditemukan"); //overwrite existing xml with content //StreamReader reader = new StreamReader(info.FullName,false); using (StreamWriter writer = new StreamWriter(info.Name, true)) { { writer.Write(setting.file_content); } writer.Close(); } message = $"Sukses mengganti content xml file {setting.file_name}"; log.Info("End : /client/overwriteXmlSetting"); return(Response.AsJson(new { message = message })); } else { log.Info($"Setting xml {setting.file_name} tidak ditemukan"); message = $"File Setting {setting.file_name} Tidak Ditemukan pada Client"; log.Info("End : /client/overwriteXmlSetting"); return(Response.AsJson(new { message = message }, HttpStatusCode.NotFound)); } } catch (System.Exception ex) { log.Fatal("Error : /client/overwriteXmlSetting", ex); message = $"Error, {ex.Message}"; return(Response.AsJson(new { message = message }, HttpStatusCode.ExpectationFailed)); } }; Post[PATH_CLIENT + "/downloadFile"] = parameter => { log.Info("Start : /client/downloadUpdateFile"); log.Info($"incoming request from IP:{this.Request.UserHostAddress}"); var body = Nancy.IO.RequestStream.FromStream(Request.Body).AsString(); log.Info("Deserialize object from json body"); DownloadUpdate setting = JsonConvert.DeserializeObject <DownloadUpdate>(body); string[] files = Directory.GetFiles(AssemblyDirectory); var result = string.Empty; foreach (string item in files) { FileInfo localFile = new FileInfo(item); if (string.Compare(localFile.Name, setting.fileName) == 0) { result = item; break; } } if (!string.IsNullOrEmpty(result)) { FileInfo info = new FileInfo(result); if (info.Exists) { var file = new System.IO.FileStream(info.FullName, System.IO.FileMode.Open); var response = new Nancy.Responses.StreamResponse(() => file, MimeTypes.GetMimeType(setting.fileName)); return(response.AsAttachment(setting.fileName)); } else { return(Response.AsJson(new { message = "File Tidak Ditemukan" }, HttpStatusCode.NoContent)); } } else { return(Response.AsJson(new { message = "File Tidak Ditemukan" }, HttpStatusCode.NoContent)); } }; Post[PATH_CLIENT + "/restartSender"] = parameter => { log.Info("Start : /client/restartSender"); log.Info($"incoming request from IP:{this.Request.UserHostAddress} @{DateTime.Now}"); var body = Nancy.IO.RequestStream.FromStream(Request.Body).AsString(); log.Info("Deserialize object from json body"); RestartRequest request = JsonConvert.DeserializeObject <RestartRequest>(body); try { System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.CreateNoWindow = false; startInfo.FileName = request.ApplicationName; foreach (var process in System.Diagnostics.Process.GetProcessesByName(request.ApplicationName)) { process.Kill(); break; } System.Diagnostics.Process.Start(startInfo); return(Response.AsJson(new { message = "Aplikasi Sukses Di Restart" }, HttpStatusCode.NoContent)); } catch { return(Response.AsJson(new { message = "Aplikasi Gagal DiRestart" }, HttpStatusCode.NoContent)); } }; }
public void Any(RestartRequest request) { Lifetime.StopApplication(); }
public object Any(RestartRequest request) { Lifetime.StopApplication(); return(new { success = true }); }
public Task Handle(RestartRequest <TestWidget> request, CancellationToken cancellationToken) { return(Task.CompletedTask); }