Пример #1
0
        /// <summary>
        /// This event fires when the plex process we have a reference to exits
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Plex_Exited(object sender, EventArgs e)
        {
            OnPlexStatusChange(this, new StatusChangeEventArgs("Plex Media Server has stopped!"));
            //unsubscribe
            _plex.Exited -= Plex_Exited;

            //kill the supporting processes.
            KillSupportingProcesses();

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

            //restart as required
            Settings settings = SettingsHandler.Load();

            if (State != PlexState.Stopping && settings.AutoRestart)
            {
                OnPlexStatusChange(this, new StatusChangeEventArgs(string.Format("Waiting {0} seconds before re-starting the Plex process.", settings.RestartDelay)));
                State = PlexState.Pending;
                System.Threading.AutoResetEvent autoEvent = new System.Threading.AutoResetEvent(false);
                System.Threading.Timer          t         = new System.Threading.Timer((x) => { Start(); autoEvent.Set(); }, null, settings.RestartDelay * 1000, System.Threading.Timeout.Infinite);
                autoEvent.WaitOne();
                t.Dispose();
            }
            else
            {
                //set the status
                State = PlexState.Stopped;
            }
        }
Пример #2
0
 /// <summary>
 /// Start monitoring plex
 /// </summary>
 internal void Start()
 {
     //Find the plex executable
     _executableFileName = GetPlexExecutable();
     if (string.IsNullOrEmpty(_executableFileName))
     {
         OnPlexStatusChange(this, new StatusChangeEventArgs("Plex Media Server does not appear to be installed!", EventLogEntryType.Error));
         OnPlexStop(this, new EventArgs());
         State = PlexState.Stopped;
     }
     else
     {
         OnPlexStatusChange(this, new StatusChangeEventArgs("Plex executable found at " + _executableFileName));
         StartPlex();
         //load the settings and start a thread that will attempt to bring up all the auxiliary processes
         Settings settings = SettingsHandler.Load();
         //stop any running aux apps
         _auxAppMonitors.ForEach(a => a.Stop());
         _auxAppMonitors.Clear();
         settings.AuxiliaryApplications.ForEach(x => _auxAppMonitors.Add(new AuxiliaryApplicationMonitor(x)));
         //hook up the state change event for all the applications
         _auxAppMonitors.ForEach(x => x.StatusChange += new AuxiliaryApplicationMonitor.StatusChangeHandler(OnPlexStatusChange));
         _auxAppMonitors.AsParallel().ForAll(x => x.Start());
     }
 }
Пример #3
0
        internal PmsMonitor()
        {
            State           = PlexState.Stopped;
            _auxAppMonitors = new List <AuxiliaryApplicationMonitor>();
            Settings settings = SettingsHandler.Load();

            settings.AuxiliaryApplications.ForEach(x => _auxAppMonitors.Add(new AuxiliaryApplicationMonitor(x)));
            //hook up the state change event for all the applications
            _auxAppMonitors.ForEach(x => x.StatusChange += new AuxiliaryApplicationMonitor.StatusChangeHandler(OnPlexStatusChange));
        }
Пример #4
0
        /// <summary>
        /// Start monitoring plex
        /// </summary>
        internal void Start()
        {
            //Find the plex executable
            _executableFileName = GetPlexExecutable();
            if (string.IsNullOrEmpty(_executableFileName))
            {
                OnPlexStatusChange(this, new StatusChangeEventArgs("Plex Media Server does not appear to be installed!", EventLogEntryType.Error));
                OnPlexStop(this, new EventArgs());
                State = PlexState.Stopped;
            }
            else
            {
                //load the settings
                Settings settings = SettingsHandler.Load();

                OnPlexStatusChange(this, new StatusChangeEventArgs("Plex executable found at " + _executableFileName));

                //map network drives
                if (settings.DriveMaps.Count > 0)
                {
                    OnPlexStatusChange(this, new StatusChangeEventArgs("Mapping Network Drives"));
                    foreach (DriveMap map in settings.DriveMaps)
                    {
                        try
                        {
                            map.MapDrive(true);
                            OnPlexStatusChange(this, new StatusChangeEventArgs(string.Format("Map share {0} to letter '{1}' successful", map.ShareName, map.DriveLetter)));
                        }
                        catch (Exception ex)
                        {
                            OnPlexStatusChange(this, new StatusChangeEventArgs(string.Format("Unable to map share {0} to letter '{1}': {2}", map.ShareName, map.DriveLetter, ex.Message), EventLogEntryType.Error));
                        }
                    }
                }


                StartPlex();

                //stop any running aux apps
                _auxAppMonitors.ForEach(a => a.Stop());
                _auxAppMonitors.Clear();
                settings.AuxiliaryApplications.ForEach(x => _auxAppMonitors.Add(new AuxiliaryApplicationMonitor(x)));
                //hook up the state change event for all the applications
                _auxAppMonitors.ForEach(x => x.StatusChange += new AuxiliaryApplicationMonitor.StatusChangeHandler(OnPlexStatusChange));
                _auxAppMonitors.AsParallel().ForAll(x => x.Start());
            }
        }
Пример #5
0
 /// <summary>
 /// Returns the settings file from the server as a json string
 /// </summary>
 /// <returns></returns>
 public string GetSettings()
 {
     return(SettingsHandler.Load().Serialize());
 }