public Task <MessageResult> TryStart(SimpleProcessInfo info) { var simpleProcessFactory = SimpleProcessFactory.Resolve(); var simpleProcess = simpleProcessFactory.GetOrCreate(info); var simpleProcessRunner = new SimpleProcessRunner(simpleProcess); if (_fooClientDaemon == null) { var simpleDaemon = SimpleDaemon.Resolve(); _fooClientDaemon = new FooClientDaemon(simpleDaemon, simpleProcessRunner); } else { if (!info.ProcessName.Equals(_fooClientDaemon.Runner.Process.Info.ProcessName, StringComparison.OrdinalIgnoreCase)) { _fooClientDaemon.Daemon.Dispose(); _fooClientDaemon.Daemon = null; var simpleDaemon = SimpleDaemon.Resolve(); _fooClientDaemon = new FooClientDaemon(simpleDaemon, simpleProcessRunner); } } return(_fooClientDaemon.TryStart()); }
public bool IsRunning(SimpleProcessInfo info) { var simpleProcessFactory = SimpleProcessFactory.Resolve(); var simpleProcess = simpleProcessFactory.GetOrCreate(info); var simpleProcessRunner = new SimpleProcessRunner(simpleProcess); return(simpleProcessRunner.Process.IsRunning()); }
private SimpleProcessInfo ReadUi() { var processName = this.txtProcessName.Text.Trim(); var exePath = this.txtExePath.Text.Trim(); var exeArgs = this.txtExeArgs.Text.Trim(); return(SimpleProcessInfo.Create(processName, exePath, exeArgs)); }
public Task <MessageResult> TryStop(SimpleProcessInfo info) { if (_fooClientDaemon == null) { return(MessageResult.CreateTask(true, "尚未开始")); } _fooClientDaemon.Runner.TryStop(); return(_fooClientDaemon.TryStop()); }
private void MyInitializeComponent() { this.ServiceName = "FooClientDaemon"; var simpleProcessFactory = SimpleProcessFactory.Resolve(); var fooClientInfo = new SimpleProcessInfo() { ProcessName = "FooClient", ExePath = "FooClient.exe", ExeArgs = "" }; simpleProcessFactory.GetOrCreate(fooClientInfo); Daemon = SimpleDaemon.Resolve(); }
private IList <SimpleProcessInfo> GetProcessInfos(string iniFileName) { var processInfos = new List <SimpleProcessInfo>(); var simpleIniFile = SimpleIni.ResolveFile(); var fullPath = Path.GetFullPath(AppDomain.CurrentDomain.Combine(iniFileName)); if (!File.Exists(fullPath)) { LogInfo("IniFile Not Exist: " + fullPath); return(processInfos); } var traceIniItems = simpleIniFile.TryLoadIniFileItems(fullPath); if (traceIniItems == null) { LogInfo(fullPath + " has no items value "); return(processInfos); } LogInfo(string.Format("-----{0}----", iniFileName)); foreach (var item in traceIniItems) { LogInfo(string.Format("{0}: {1}", item.Key, item.Value)); } var processesValue = simpleIniFile.GetValue(traceIniItems, "Daemon", "Processes"); if (processesValue == null) { LogInfo("[Daemon]Processes is null!"); return(processInfos); } var processSections = processesValue.ToString().Trim().Split(new[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()) .ToList(); foreach (var processSection in processSections) { //[TraceApi] //ProcessName="SimpleTrace.Api" //ExePath="TraceApi\SimpleTrace.Api.exe" //ExeArgs= var processNameValue = simpleIniFile.GetValue(traceIniItems, processSection, "ProcessName"); var exePathValue = simpleIniFile.GetValue(traceIniItems, processSection, "ExePath"); var exeArgsValue = simpleIniFile.GetValue(traceIniItems, processSection, "ExeArgs"); var processName = processNameValue == null ? string.Empty : processNameValue.ToString(); var exePath = exePathValue == null ? string.Empty : exePathValue.ToString(); var exeArgs = exeArgsValue == null ? string.Empty : exeArgsValue.ToString(); if (string.IsNullOrWhiteSpace(processName)) { LogInfo(string.Format("SimpleTrace.ini => [{0}]ProcessName is null!", processSection)); continue; } if (string.IsNullOrWhiteSpace(exePath)) { LogInfo(string.Format("SimpleTrace.ini => [{0}]ExePath is null!", processSection)); continue; } var fullExePath = Path.GetFullPath(AppDomain.CurrentDomain.Combine(exePath)); var processInfo = SimpleProcessInfo.Create(processName, fullExePath, exeArgs); LogInfo(string.Format("----{0}----", processSection)); LogInfo(MyModelHelper.MakeIniString(processInfo)); processInfos.Add(processInfo); } return(processInfos); }
public MessageResult Validate(SimpleProcessInfo info) { var success = SimpleProcessInfo.Validate(info, out var message); return(MessageResult.Create(success, message, info)); }
private void SetUi(SimpleProcessInfo info) { this.txtProcessName.Text = info.ProcessName; this.txtExePath.Text = info.ExePath; this.txtExeArgs.Text = info.ExeArgs; }