Exemplo n.º 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());
        }
Exemplo n.º 2
0
        private void Init(SimpleLoopTask loopTask)
        {
            var processInfos = GetProcessInfos("SimpleTrace.ini");

            foreach (var processInfo in processInfos)
            {
                //var jaegerInfo = SimpleProcessInfo.Create("jaeger-all-in-one", "jaeger-all-in-one.exe", "--collector.zipkin.http-port=9411");
                var process       = SimpleProcess.GetOrCreate(processInfo);
                var processRunner = new SimpleProcessRunner(process);
                LogInfo(string.Format("Init ProcessRunner: [{0}]", processInfo.ProcessName));
                Runners.Add(processRunner);
            }

            loopTask.LoopSpan   = TimeSpan.FromSeconds(15);
            loopTask.LoopAction = () =>
            {
                LogInfo("looping check trace service at " + DateHelper.Instance.GetDateNow().ToString("s"));
                foreach (var runner in Runners)
                {
                    runner.TryStart();
                }
            };

            loopTask.AfterExitLoopAction = () =>
            {
                LogInfo("stopping check trace service at " + DateHelper.Instance.GetDateNow().ToString("s"));
                foreach (var runner in Runners)
                {
                    runner.TryStop();
                }
            };
        }
Exemplo n.º 3
0
        public bool IsRunning(SimpleProcessInfo info)
        {
            var simpleProcessFactory = SimpleProcessFactory.Resolve();
            var simpleProcess        = simpleProcessFactory.GetOrCreate(info);
            var simpleProcessRunner  = new SimpleProcessRunner(simpleProcess);

            return(simpleProcessRunner.Process.IsRunning());
        }
        public async Task Stop_NotRunning_Should_NotInvoke()
        {
            var mockSimpleProcess = CreateProcess();
            var runner            = new SimpleProcessRunner(mockSimpleProcess);
            var tryStart          = await runner.TryStop();

            tryStart.Message.Log();
            tryStart.Success.ShouldTrue();
            mockSimpleProcess.StopInvoked.ShouldFalse();
        }
Exemplo n.º 5
0
 private void Init(SimpleLoopTask loopTask, SimpleProcessRunner runner)
 {
     loopTask.LoopSpan   = TimeSpan.FromSeconds(3);
     loopTask.LoopAction = () =>
     {
         runner.TryStart();
     };
     loopTask.AfterExitLoopAction = () =>
     {
         runner.TryStop();
     };
 }
Exemplo n.º 6
0
        public async Task DotNetPack_ManifestNames_Containts_G_Resources_Folder()
        {
            /**
             * This test makes sure, that the resources are contained in the packaged nuget, which is not the case at all times for some reason.
             */
            string tempFolder = null;

            try
            {
                tempFolder = FileUtil.GetNewTempFolder();
                Directory.Exists(tempFolder).ShouldBeTrue();

                var location = typeof(NotificationHostManager).Assembly.Location;
                var libraryAssemblyLocation = Path.GetDirectoryName(location);
                var buildCsproj             = Path.Combine(libraryAssemblyLocation, @"..\..\..\..\..\src\Amusoft.UI.WPF\Amusoft.UI.WPF.csproj");
                buildCsproj = new Uri(buildCsproj).AbsolutePath;
                File.Exists(buildCsproj).ShouldBeTrue();

                using var buildRunner = new SimpleProcessRunner("dotnet", $"build {buildCsproj} -c Release");
                await buildRunner.ExecuteAsync(TimeSpan.FromSeconds(15));

                buildRunner.ExitCode.ShouldBe(0);


                using var packRunner = new SimpleProcessRunner("dotnet", $"pack {buildCsproj} -o {tempFolder} -c Release");
                await packRunner.ExecuteAsync(TimeSpan.FromSeconds(15));

                packRunner.ExitCode.ShouldBe(0);

                var nupkg = Directory.EnumerateFiles(tempFolder, "*.nupkg", SearchOption.AllDirectories).FirstOrDefault();
                nupkg.ShouldNotBeNull();

                var unzipTarget = FileUtil.GetNewTempFolder();
                ZipFile.ExtractToDirectory(nupkg, unzipTarget);

                var libDll = Directory.EnumerateFiles(unzipTarget + "\\lib", "Amusoft.UI.WPF.dll", SearchOption.AllDirectories).FirstOrDefault();
                File.Exists(libDll).ShouldBeTrue();

                var remoteAssembly = Assembly.LoadFile(libDll);
                remoteAssembly.ShouldNotBeNull();

                remoteAssembly.GetManifestResourceNames().ShouldContain("Amusoft.UI.WPF.g.resources");
            }
            catch (Exception e)
            {
                Assert.True(false, $"Unexpected exception occured. {e.ToString()}.");
            }
            finally
            {
                Directory.Delete(tempFolder, true);
            }
        }
Exemplo n.º 7
0
        public DaemonService()
        {
            InitializeComponent();

            //var clientProcess = SimpleProcess.GetOrCreate(new SimpleProcessInfo()
            //{
            //    ProcessName = "FooClient",
            //    ExePath = "FooClient.exe",
            //    ExeArgs = null
            //});


            var jaegerProcess = SimpleProcess.GetOrCreate(new SimpleProcessInfo()
            {
                ProcessName = "jaeger-all-in-one",
                ExePath     = "jaeger-all-in-one.exe",
                ExeArgs     = "--collector.zipkin.http-port=9411"
            });

            var runner = new SimpleProcessRunner(jaegerProcess);

            LoopTask = new SimpleLoopTask();
            Init(LoopTask, runner);
        }
Exemplo n.º 8
0
 public FooClientDaemon(ISimpleDaemon daemon, SimpleProcessRunner runner)
 {
     Daemon = daemon;
     Runner = runner;
 }