Beispiel #1
0
        public static void OnStart(string[] startupArguments, ServiceStatusReportCallback statusReportCallback)
        {
            StatusReportCallback = statusReportCallback;

            try
            {
                // Start Services flecoqui
                Options opt = new Options();
                opt.TraceLevel = Options.LogLevel.Verbose;
                opt.TraceFile  = "C:\\temp\\ttt.log";
                opt.LogInformation("Starting Service");
                foreach (string s in startupArguments)
                {
                    opt.LogInformation("Starting Service args: " + s);
                }

                bool           bContinue;
                List <Options> list = LaunchServices(ServiceOptions, out bContinue);
                if ((list != null) && (list.Count > 0))
                {
                    OptionsList = list;
                    statusReportCallback(ServiceState.Running, ServiceAcceptedControlCommandsFlags.Stop, win32ExitCode: 0, waitHint: 0);
                }
                else
                {
                    statusReportCallback(ServiceState.Stopped, ServiceAcceptedControlCommandsFlags.Stop, win32ExitCode: 0, waitHint: 0);
                }
            }
            catch
            {
                statusReportCallback(ServiceState.Stopped, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: -1, waitHint: 0);
            }
        }
Beispiel #2
0
        public ServiceLifecycleTests()
        {
            A.CallTo(() => serviceStateMachine.OnStart(A <string[]> ._, A <ServiceStatusReportCallback> ._))
            .Invokes((string[] args, ServiceStatusReportCallback callback) =>
            {
                statusReportCallback = callback;
            });

            var dummy = new ServiceStatus();

            A.CallTo(() => nativeInterop.SetServiceStatus(null, ref dummy))
            .WithAnyArguments()
            .Returns(value: true)
            .AssignsOutAndRefParametersLazily((ServiceStatusHandle handle, ServiceStatus status) =>
            {
                if (handle == serviceStatusHandle)
                {
                    reportedServiceStatuses.Add(status);
                    if (status.State == ServiceState.Stopped)
                    {
                        serviceStoppedEvent.Set();
                    }
                }
                return(new object[] { status });
            });

            sut = new ServiceUtils.Win32ServiceHost(TestServiceName, serviceStateMachine, nativeInterop);
        }
        public void OnStart(string[] startupArguments, ServiceStatusReportCallback statusReportCallback)
        {
            this.statusReportCallback = statusReportCallback;

            try
            {
                serviceImplementation.Start(startupArguments, HandleServiceImplementationStoppedOnItsOwn);

                statusReportCallback(ServiceState.Running, ServiceAcceptedControlCommandsFlags.Stop, win32ExitCode: 0, waitHint: 0);
            }
            catch
            {
                statusReportCallback(ServiceState.Stopped, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: -1, waitHint: 0);
            }
        }
Beispiel #4
0
        public void OnStart(string[] startupArguments, ServiceStatusReportCallback statusReportCallback)
        {
            _statusReportCallback = statusReportCallback;

            try
            {
                _serviceImplementation.Start(startupArguments, HandleServiceImplementationStoppedOnItsOwn);

                if (_serviceImplementation.CanPauseAndContinue)
                {
                    statusReportCallback(ServiceState.Running, ServiceAcceptedControlCommandsFlags.Stop | ServiceAcceptedControlCommandsFlags.PauseContinue, win32ExitCode: 0, waitHint: 0);
                }
                else
                {
                    statusReportCallback(ServiceState.Running, ServiceAcceptedControlCommandsFlags.Stop, win32ExitCode: 0, waitHint: 0);
                }
            }
            catch
            {
                statusReportCallback(ServiceState.Stopped, ServiceAcceptedControlCommandsFlags.None, win32ExitCode: -1, waitHint: 0);
            }
        }