Пример #1
0
        /// <summary>
        /// When implemented in a derived class, executes when a Start command is sent
        /// to the service by the Service Control Manager (SCM) or when the operating
        /// system starts (for a service that starts automatically). Specifies actions
        /// to take when the service starts.
        /// </summary>
        public void OnStart()
        {
            lock (m_Lock)
            {
                if ((m_Uploader != null) || (m_Indexer != null) || (m_Container != null))
                {
                    OnStop();
                }

                m_Container = DependencyInjection.CreateContainer();
                m_Uploader = m_Container.Resolve<IUploadPackages>();
                m_Indexer = m_Container.Resolve<IIndexSymbols>();
                m_Diagnostics = m_Container.Resolve<SystemDiagnostics>();

                m_Diagnostics.Log(
                    LevelToLog.Info,
                    Resources.Log_Messages_ServiceEntryPoint_StartingService);

                m_Indexer.Start();
                m_Uploader.EnableUpload();
            }
        }
Пример #2
0
        /// <summary>
        /// When implemented in a derived class, executes when a Stop command is sent
        /// to the service by the Service Control Manager (SCM). Specifies actions to
        /// take when a service stops running.
        /// </summary>
        public void OnStop()
        {
            lock (m_Lock)
            {
                if (m_Diagnostics != null)
                {
                    m_Diagnostics.Log(
                        LevelToLog.Info,
                        Resources.Log_Messages_ServiceEntryPoint_StoppingService);
                }

                if (m_Uploader != null)
                {
                    m_Uploader.DisableUpload();
                    m_Uploader = null;
                }

                if (m_Indexer != null)
                {
                    var clearingTask = m_Indexer.Stop(true);
                    clearingTask.Wait();
                    m_Indexer = null;
                }

                if (m_Container != null)
                {
                    m_Container.Dispose();
                    m_Container = null;
                }

                if (m_Diagnostics != null)
                {
                    m_Diagnostics.Log(
                        LevelToLog.Info,
                        Resources.Log_Messages_ServiceEntryPoint_ServiceStopped);
                }
            }
        }