Esempio n. 1
0
        private void JeepServiceCheck()
        {
            try
            {
                ServicesHelper.Exists(Settings.Default.ServiceName, Settings.Default.JeepServicePath, LiveUpdateClient);
            }
            catch (Exception ex)
            {
                throw new FileNotFoundException("Il servizio non esiste!", ex);
            }

            // Servizio presente
            // Versione servizio
            var jeepServiceVersion = ServicesHelper.ServiceVersion(Settings.Default.ServiceName,
                                                                   Settings.Default.JeepServicePath,
                                                                   LiveUpdateClient);

            string serviceExist;
            string serviceStatus;

            if (ServicesHelper.Installed(Settings.Default.ServiceName, Settings.Default.JeepServicePath,
                                         LiveUpdateClient))
            {
                // Il servizio è installato
                jeepServiceInstallToolStripMenuItem.Enabled   = false;
                jeepServiceUninstallToolStripMenuItem.Enabled = true;
                serviceExist = string.Format("Servizio [{0} v.{1}] installato.", Settings.Default.ServiceName,
                                             jeepServiceVersion);
                imgInstallationOFF.Visible = false;
                imgInstallationON.Visible  = true;

                var serviceControllerStatus = ServicesHelper.ServiceStatus(Settings.Default.ServiceName,
                                                                           Settings.Default.JeepServicePath,
                                                                           LiveUpdateClient);
                switch (serviceControllerStatus)
                {
                case ServiceControllerStatus.Running:
                    jeepServiceStartToolStripMenuItem.Enabled        = false;
                    jeepServiceStopToolStripMenuItem.Enabled         = true;
                    jeepServiceRestartToolStripMenuItem.Enabled      = true;
                    jeepServiceStartConsoleToolStripMenuItem.Enabled = false;
                    serviceStatus             = "The Service is Running.";
                    imgStatusPlay.Visible     = true;
                    imgStatusPause.Visible    = false;
                    imgStatusQuestion.Visible = false;
                    break;

                case ServiceControllerStatus.Stopped:
                    jeepServiceStartToolStripMenuItem.Enabled        = true;
                    jeepServiceStartConsoleToolStripMenuItem.Enabled = true;
                    jeepServiceStopToolStripMenuItem.Enabled         = false;
                    jeepServiceRestartToolStripMenuItem.Enabled      = false;
                    serviceStatus             = "The Service is Stopped.";
                    imgStatusPlay.Visible     = false;
                    imgStatusPause.Visible    = true;
                    imgStatusQuestion.Visible = false;
                    break;

                default:
                    jeepServiceStartToolStripMenuItem.Enabled = false;
                    serviceStatus = string.Format("The Service is {0}.", serviceControllerStatus);
                    jeepServiceStopToolStripMenuItem.Enabled    = false;
                    jeepServiceRestartToolStripMenuItem.Enabled = false;
                    imgStatusPlay.Visible     = false;
                    imgStatusPause.Visible    = false;
                    imgStatusQuestion.Visible = true;
                    break;
                }
            }
            else
            {
                // Servizio non installato
                jeepServiceInstallToolStripMenuItem.Enabled   = true;
                jeepServiceUninstallToolStripMenuItem.Enabled = false;
                editToolStripMenuItem.Enabled = true;
                serviceExist = string.Format("Servizio [{0} v.{1}] NON installato.", Settings.Default.ServiceName,
                                             jeepServiceVersion);
                serviceStatus = "";
                imgInstallationOFF.Visible = true;
                imgInstallationON.Visible  = false;

                jeepServiceStartToolStripMenuItem.Enabled        = false;
                jeepServiceStartConsoleToolStripMenuItem.Enabled = File.Exists(Settings.Default.JeepServicePath);
                jeepServiceStopToolStripMenuItem.Enabled         = false;
                jeepServiceRestartToolStripMenuItem.Enabled      = false;

                imgStatusPlay.Visible     = false;
                imgStatusPause.Visible    = false;
                imgStatusQuestion.Visible = false;
            }
            var jeepServiceStatus = string.Format("{0} {1}", serviceExist, serviceStatus);

            jeepServiceStatusLabel.Text = jeepServiceStatus;
            FileLogger.Info(Logger, jeepServiceStatus);
        }