コード例 #1
0
ファイル: Service1.cs プロジェクト: usermonk/MediaPortal-1
        /// <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>
        /// <param name="args">Data passed by the start command.</param>
        protected override void OnStart(string[] args)
        {
            if (_tvServiceThread == null)
            {
                if (!(args != null && args.Length > 0 && args[0] == "/DEBUG"))
                {
                    RequestAdditionalTime(60000); // starting database can be slow so increase default timeout
                }
                TvServiceThread tvServiceThread      = new TvServiceThread();
                ThreadStart     tvServiceThreadStart = new ThreadStart(tvServiceThread.OnStart);
                _tvServiceThread = new Thread(tvServiceThreadStart);

                _tvServiceThread.IsBackground = false;

                // apply process priority on initial service start.
                if (!_priorityApplied)
                {
                    try
                    {
                        applyProcessPriority();
                        _priorityApplied = true;
                    }
                    catch (Exception ex)
                    {
                        // applyProcessPriority can generate an exception when we cannot connect to the database
                        Log.Error("OnStart: exception applying process priority: {0}", ex.StackTrace);
                    }
                }

                var layer = new TvBusinessLayer();
                layer.SetLogLevel();

                _tvServiceThread.Start();

                while (!TvServiceThread.Started)
                {
                    Thread.Sleep(20);
                }
            }
        }
コード例 #2
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>
    /// <param name="args">Data passed by the start command.</param>
    protected override void OnStart(string[] args)
    {
      if (_tvServiceThread == null)
      {
        if (!(args != null && args.Length > 0 && args[0] == "/DEBUG"))
        {
          RequestAdditionalTime(60000); // starting database can be slow so increase default timeout        
        }
        TvServiceThread tvServiceThread = new TvServiceThread();
        ThreadStart tvServiceThreadStart = new ThreadStart(tvServiceThread.OnStart);
        _tvServiceThread = new Thread(tvServiceThreadStart);

        _tvServiceThread.IsBackground = false;

        // apply process priority on initial service start.
        if (!_priorityApplied)
        {
          try
          {
            applyProcessPriority();
            _priorityApplied = true;
          }
          catch (Exception ex)
          {
            // applyProcessPriority can generate an exception when we cannot connect to the database
            Log.Error("OnStart: exception applying process priority: {0}", ex.StackTrace);
          }
        }

        var layer = new TvBusinessLayer();
        layer.SetLogLevel();

        _tvServiceThread.Start();

        while (!TvServiceThread.Started)
        {
          Thread.Sleep(20);
        }
      }
    }
コード例 #3
0
ファイル: SlimTvService3.cs プロジェクト: aspik/MediaPortal-2
 public override bool DeInit()
 {
   if (_serviceThread != null && _serviceThread.IsAlive)
   {
     bool joined = _serviceThread.Join(MAX_WAIT_MS);
     if (!joined)
     {
       _serviceThread.Abort();
       _serviceThread.Join();
     }
     _tvServiceThread = null;
   }
   return true;
 }
コード例 #4
0
ファイル: SlimTvService3.cs プロジェクト: aspik/MediaPortal-2
    protected override void InitTvCore()
    {
      _tvServiceThread = new TvServiceThread(Environment.GetCommandLineArgs()[0]);
      if (!InitializeGentle())
      {
        DeInit();
        return;
      }

      Start();
      if (!_tvServiceThread.InitializedEvent.WaitOne(MAX_WAIT_MS))
      {
        ServiceRegistration.Get<ILogger>().Error("SlimTvService: Failed to start TV service thread within {0} seconds.", MAX_WAIT_MS / 1000);
      }

      InitializeTVE();
      // Handle events from TvEngine
      if (!RegisterEvents())
      {
        ServiceRegistration.Get<ILogger>().Error("SlimTvService: Failed to register events. This happens only if startup failed. Stopping plugin now.");
        DeInit();
      }
    }
コード例 #5
0
    public bool DeInit()
    {
#if TVE3
      Stop(MAX_WAIT_MS);
#else
      if (_tvServiceThread != null)
      {
        _tvServiceThread.Stop(MAX_WAIT_MS);
        _tvServiceThread = null;
      }
#endif
      return true;
    }
コード例 #6
0
 public void Stop(int maxWaitMsecs)
 {
   if (_serviceThread != null && _serviceThread.IsAlive)
   {
     bool joined = _serviceThread.Join(maxWaitMsecs);
     if (!joined)
     {
       _serviceThread.Abort();
       _serviceThread.Join();
     }
     _tvServiceThread = null;
   }
 }
コード例 #7
0
    private void InitAsync(object sender, ElapsedEventArgs args)
    {
      ISQLDatabase database;
      lock (_timer)
      {
        database = ServiceRegistration.Get<ISQLDatabase>(false);
        if (database == null)
          return;
        _timer.Close();
        _timer.Dispose();
      }

      using (var transaction = database.BeginTransaction())
      {
        // Prepare TV database if required.
        PrepareTvDatabase(transaction);

#if !TVE3
        if (transaction.Connection.GetCloneFactory(TVDB_NAME, out _dbProviderFactory, out _cloneConnection))
        {
          EntityFrameworkHelper.AssureKnownFactory(_dbProviderFactory);
          // Register our factory to create new cloned connections
          ObjectContextManager.SetDbConnectionCreator(ClonedConnectionFactory);
        }
#endif
      }

      // TODO: Get this from project config somehow
#if TVE3
      string servicename = "SlimTv.Service3";
#else
      string servicename = "SlimTv.Service35";
#endif

      IntegrationProviderHelper.Register(@"Plugins\" + servicename, "Plugins\\" + servicename + "\\castle.config");
      var pm = GlobalServiceProvider.Instance.Get<IIntegrationProvider>().PathManager;

      // Needs to be done after the IntegrationProvider is registered, so the TVCORE folder is defined.
      PrepareProgramData();

      _tvServiceThread = new TvServiceThread(Environment.GetCommandLineArgs()[0]);
#if TVE3
      InitializeGentle();
      Start();
#else
      _tvServiceThread.Start();
#endif
      if (!_tvServiceThread.InitializedEvent.WaitOne(MAX_WAIT_MS))
      {
        ServiceRegistration.Get<ILogger>().Error("SlimTvService: Failed to start TV service thread within {0} seconds.", MAX_WAIT_MS / 1000);
      }

#if TVE3
      InitializeTVE();
#endif
      // Handle events from TvEngine
      if (!RegisterEvents())
      {
        ServiceRegistration.Get<ILogger>().Error("SlimTvService: Failed to register events. This happens only if startup failed. Stopping plugin now.");
        DeInit();
      }
    }