Exemple #1
0
        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());
        }
Exemple #2
0
        public bool IsRunning(SimpleProcessInfo info)
        {
            var simpleProcessFactory = SimpleProcessFactory.Resolve();
            var simpleProcess        = simpleProcessFactory.GetOrCreate(info);
            var simpleProcessRunner  = new SimpleProcessRunner(simpleProcess);

            return(simpleProcessRunner.Process.IsRunning());
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        public Task <MessageResult> TryStop(SimpleProcessInfo info)
        {
            if (_fooClientDaemon == null)
            {
                return(MessageResult.CreateTask(true, "尚未开始"));
            }

            _fooClientDaemon.Runner.TryStop();
            return(_fooClientDaemon.TryStop());
        }
Exemple #5
0
        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();
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        public MessageResult Validate(SimpleProcessInfo info)
        {
            var success = SimpleProcessInfo.Validate(info, out var message);

            return(MessageResult.Create(success, message, info));
        }
Exemple #8
0
 private void SetUi(SimpleProcessInfo info)
 {
     this.txtProcessName.Text = info.ProcessName;
     this.txtExePath.Text     = info.ExePath;
     this.txtExeArgs.Text     = info.ExeArgs;
 }