Ejemplo n.º 1
0
        /// <summary>
        /// Checks to see if the server can be updated at this time.
        /// </summary>
        private bool CheckIfCanUpdate()
        {
            if (_server == null)
            {
                txtUpdateStatus.Text += "The server was not specified. Cannot perform the update.";
                Log.Write("The server was not specified. Cannot perform the update.");
                _timer.Enabled = false;
                return(false);
            }

            int playCount = _server.GetPlayCount();

            // No item is currently being played
            if (playCount == 0)
            {
                txtUpdateStatus.Text += "The server is not in use continuing to perform the update.";
                Log.Write("The server is not in use continuing to perform the update.");
                lblPlayCount.Text = _server.PlayCount.ToString();
                btnUpdate.Enabled = true;
                _timer.Enabled    = false;
                return(true);
            }
            // At least one item is being played
            else if (playCount > 0)
            {
                lblPlayCount.Text = _server.PlayCount.ToString();
                if (chkWait.Checked)
                {
                    txtUpdateStatus.Text += "Waiting for the server to be free has not been enabled. Server update can begin.";
                    Log.Write("The server is in use. Waiting for all media to be stopped before performing the update.");
                    btnUpdate.Enabled = false;
                    _timer.Interval   =
                        Convert.ToDouble(Math.Abs(numSeconds.Value) * 1000);
                    _timer.Enabled = true;
                    return(false);
                }
                else
                {
                    txtUpdateStatus.Text += "The wait option has been disabled. You can go ahead and update the server.";
                    Log.Write("The wait option has been disabled.You can go ahead and update the server.");
                    btnUpdate.Enabled = true;
                    _timer.Enabled    = false;
                    return(true);
                }
            }
            // Could not determine how many items are being played
            else
            {
                txtUpdateStatus.Text += "The server in use status could not be determined. The server can be updated if you wish.";
                Log.Write("The server in use status could not be determined. The server can be updated if you wish.");
                lblPlayCount.Text = "Unknown";
                btnUpdate.Enabled = true;
                _timer.Enabled    = false;
                return(true);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks to see if the server can be updated at this time.
        /// </summary>
        private bool CheckIfCanUpdate()
        {
            if (_server == null)
            {
                Log.Write("The server was not specified. Cannot perform the update.");
                _timer.Enabled = false;
                return(false);
            }

            int playCount = _server.GetPlayCount();
            int inProgressRecordingCount = _server.GetInProgressRecordingCount();

            // No item is currently being played
            if (playCount == 0 && inProgressRecordingCount == 0)
            {
                Log.Write("The server is not in use continuing to perform the update.");
                _timer.Enabled = false;
                return(true);
            }
            // At least one item is being played
            else if (playCount > 0 || inProgressRecordingCount > 0)
            {
                if (!ForceUpdate)
                {
                    Log.Write("The server is in use. Waiting for all media and/or in progress recordings to be stopped before performing the update.");
                    _timer.Interval =
                        Convert.ToDouble(Math.Abs(WaitTime) * 1000);
                    _timer.Enabled = true;
                    return(false);
                }
                else if (ForceUpdate && inProgressRecordingCount > 0)
                {
                    Log.Write("The server cannot be forcefully updated while there is a recording in progress.  Waiting for all in progress recordings to be stopped before performing the update.");
                    _timer.Interval =
                        Convert.ToDouble(Math.Abs(WaitTime) * 1000);
                    _timer.Enabled = true;
                    return(false);
                }
                else
                {
                    Log.Write("The update is set to be force. The update will continue.");
                    _timer.Enabled = false;
                    return(true);
                }
            }
            // Could not determine how many items are being played
            else
            {
                Log.Write("The server in use status could not be determined. The server can be updated if you wish.");
                _timer.Enabled = false;
                return(true);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the values on the form.
        /// </summary>
        private void Initialize()
        {
            try
            {
                ToBeClosed = false;
                _cts       = new CancellationTokenSource();

                Log.Write("Initializing the timer object.");
                _timer          = new System.Timers.Timer();
                _timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
                _timer.Enabled  = false;
                _timer.Interval = Convert.ToDouble(numSeconds.Value * 1000);

                Log.Write("Initializing the Plex media server object.");
                _server = new MediaServer();

                if (_server == null)
                {
                    Log.Write(
                        "The Plex media server object could not be initialized. Setting the flag to close the application.");
                    ToBeClosed = true;
                    return;
                }

                _server.UpdateMessage += ServerUpdateMessage;

                lblInstalledVersion.Text = _server.CurrentVersion.ToString();
                lblLatestVersion.Text    = _server.LatestVersion.ToString();

                if (_server.LatestVersion > _server.CurrentVersion)
                {
                    btnUpdate.Visible = true;
                    btnCancel.Visible = false;
                    btnExit.Enabled   = true;
                    CheckIfCanUpdate();
                }
                else
                {
                    btnUpdate.Visible = false;
                    btnCancel.Visible = false;
                    btnExit.Enabled   = true;
                    if (_server.GetPlayCount() >= 0)
                    {
                        lblPlayCount.Text = _server.PlayCount.ToString();
                    }
                    else
                    {
                        lblPlayCount.Text = "Unknown";
                    }
                }
            }
            catch (LocalSystem.Msi.MSIException ex)
            {
                MessageBox.Show(
                    $"MSI exception: {ex.Message}",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
            catch (AppNotInstalledException ex)
            {
                MessageBox.Show(
                    "The Plex Server application is not installed.",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
            catch (ServiceNotInstalledException ex)
            {
                MessageBox.Show(
                    "The Plex service is not installed.",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
            catch (PlexDataFolderNotFoundException ex)
            {
                MessageBox.Show(
                    "The Plex data folder could not be found.",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
            catch (LocalSystem.WindowsUserSidNotFound ex)
            {
                MessageBox.Show(
                    "The SID for the Plex service user could not be found.",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }

            catch (Exception ex)
            {
                MessageBox.Show(
                    ex.Message,
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
        }