Beispiel #1
0
 /// <summary>
 /// Performs startup operations for the service.
 /// </summary>
 /// <param name="dependencyScope">
 /// A scope that is used to resolve service dependencies.
 /// </param>
 /// <param name="applicationConfiguration">
 /// Configuration information for the service application.
 /// </param>
 /// <param name="executionLifetime">
 /// An object that provides control over execution lifetime.
 /// </param>
 protected virtual void OnExecutionStarting(IDependencyScope dependencyScope, IConfiguration applicationConfiguration, ServiceExecutionLifetime executionLifetime)
 {
     return;
 }
Beispiel #2
0
        /// <summary>
        /// Performs startup operations for the service.
        /// </summary>
        /// <param name="dependencyScope">
        /// A scope that is used to resolve service dependencies.
        /// </param>
        /// <param name="applicationConfiguration">
        /// Configuration information for the service application.
        /// </param>
        /// <param name="executionLifetime">
        /// An object that provides control over execution lifetime.
        /// </param>
        protected override void OnExecutionStarting(IDependencyScope dependencyScope, IConfiguration applicationConfiguration, ServiceExecutionLifetime executionLifetime)
        {
            Console.WriteLine($"Solid Instruments | {ServiceName}");
            Console.WriteLine($"Copyright (c) RapidField LLC. All rights reserved.{Environment.NewLine}");

            try
            {
                Console.CancelKeyPress += (sender, eventArguments) =>
                {
                    executionLifetime.End();
                    eventArguments.Cancel = true;
                };

                var mediator = dependencyScope.Resolve <ICommandMediator>();
                var applicationStartedMessage = new ApplicationStartingMessage(ServiceName);
                mediator.Process(applicationStartedMessage);
                Thread.Sleep(1600);
            }
            finally
            {
                base.OnExecutionStarting(dependencyScope, applicationConfiguration, executionLifetime);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Begins execution of the service and performs the service operations.
        /// </summary>
        /// <param name="dependencyScope">
        /// A scope that is used to resolve service dependencies.
        /// </param>
        /// <param name="applicationConfiguration">
        /// Configuration information for the service application.
        /// </param>
        /// <param name="executionLifetime">
        /// An object that provides control over execution lifetime.
        /// </param>
        protected sealed override void Execute(IDependencyScope dependencyScope, IConfiguration applicationConfiguration, ServiceExecutionLifetime executionLifetime)
        {
            try
            {
                using (var childScope = dependencyScope.CreateChildScope())
                {
                    OnExecutionStarting(childScope, applicationConfiguration, executionLifetime);
                }

                try
                {
                    AddSubscriptions(SubscriptionProfile, ApplicationConfiguration);
                    StartHeartbeats();
                    executionLifetime.KeepAlive();
                }
                finally
                {
                    StopHeartbeats();

                    using (var childScope = dependencyScope.CreateChildScope())
                    {
                        OnExecutionStopping(childScope, applicationConfiguration);
                    }
                }
            }
            finally
            {
                base.Execute(dependencyScope, applicationConfiguration, executionLifetime);
            }
        }