/// <summary> /// 加载服务 /// </summary> internal static SendCommandResult LoadService() { var sendCommandResult = new SendCommandResult(); try { ServiceConfig.LoadServiceConfigs(); CreateServiceStateInfo(); } catch (Exception ex) { sendCommandResult.Success = true; sendCommandResult.Message = $"加载服务异常:{ex.Message}"; } return(sendCommandResult); }
internal static SendCommandResult UninstallServiceByServiceKey(string serviceKey) { var sendCommandResult = new SendCommandResult(); try { UninstallServiceDomainByserviceKey(serviceKey); var serviceStateInfo = ServiceStateInfoByServuceKey[serviceKey]; serviceStateInfo.ServiceState = ServiceStateEnum.Uninstall; sendCommandResult.Success = true; } catch (Exception ex) { sendCommandResult.Success = true; sendCommandResult.Message = $"卸载服务异常:{ex.Message}"; } return(sendCommandResult); }
internal static SendCommandResult StopServiceByServiceKey(string serviceKey) { var sendCommandResult = new SendCommandResult(); try { var serviceStateInfo = ServiceStateInfoByServuceKey[serviceKey]; serviceStateInfo.ServiceState = ServiceStateEnum.Stopped; serviceStateInfo.ServiceStopTime = DateTime.Now; serviceStateInfo.ServiceStartTime = null; sendCommandResult.Success = true; } catch (Exception ex) { sendCommandResult.Success = true; sendCommandResult.Message = $"停止服务异常:{ex.Message}"; } return(sendCommandResult); }
internal static SendCommandResult ResetStartServiceByServiceKey(string serviceKey) { var sendCommandResult = new SendCommandResult() { Success = true }; try { StopServiceByServiceKey(serviceKey); Thread.Sleep(1000); UninstallServiceDomainByserviceKey(serviceKey); InstallServiceByServiceKey(serviceKey); StartServiceByServiceKey(serviceKey); } catch (Exception ex) { sendCommandResult.Success = false; sendCommandResult.Message = $"重启服务异常:{ex.Message}"; } return(sendCommandResult); }
internal static SendCommandResult InstallServiceByServiceKey(string serviceKey) { var sendCommandResult = new SendCommandResult(); try { CreateAppDomainByServiceKey(serviceKey); CreateServiceByServiceKey(serviceKey); var serviceStateInfo = ServiceStateInfoByServuceKey[serviceKey]; serviceStateInfo.ServiceState = ServiceStateEnum.Stopped; serviceStateInfo.ServiceStartTime = null; serviceStateInfo.ServiceStopTime = null; sendCommandResult.Success = true; } catch (Exception ex) { sendCommandResult.Success = true; sendCommandResult.Message = $"安装服务异常:{ex.Message}"; } return(sendCommandResult); }
internal static SendCommandResult StartServiceByServiceKey(string serviceKey) { var sendCommandResult = new SendCommandResult(); try { var serviceStateInfo = ServiceStateInfoByServuceKey[serviceKey]; CreateAppDomainByServiceKey(serviceKey); CreateServiceByServiceKey(serviceKey); ExecuteServiceByServiceKey(serviceKey); serviceStateInfo.ServiceState = ServiceStateEnum.Normal; serviceStateInfo.ServiceStopTime = null; serviceStateInfo.ServiceStartTime = DateTime.Now; sendCommandResult.Success = true; } catch (Exception ex) { sendCommandResult.Success = true; sendCommandResult.Message = $"启动服务异常:{ex.Message}"; } return(sendCommandResult); }
public async Task<SendCommandResult> SendCommand(uint[] cmdData, int cmdDataCount, uint[] rspData, int rspDataCount) { bool success = false; // Prepare the command message m_Command.Write(cmdData, cmdDataCount); // Send it if (await m_Writer.Send(m_Command)) { // Check the response MessageType type = await m_Reader.ReadHeader(); switch (type) { case MessageType.Command: if (m_Reader.ReadMessage(m_Command)) { m_Command.Read(rspData, ref rspDataCount); success = true; m_State = ConnectionState.Connected; } else { Debug.WriteLine("[Sender.SendMessage] Failed to read response message"); } break; case MessageType.SendError: m_State = ConnectionState.SendError; break; default: case MessageType.Disconnected: m_State = ConnectionState.Disconnected; break; } } else { m_State = ConnectionState.Disconnected; Debug.WriteLine("[Sender.SendMessage] Send failed"); } SendCommandResult result = new SendCommandResult(); result.Success = success; result.RspDataCount = rspDataCount; return result; }