/// <summary>
        /// Gets the services.
        /// </summary>
        /// <param name="serviceStatusDatabasePath">The service status database path.</param>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <returns>
        /// A generic list of services administered by the hub service.
        /// </returns>
        public static List <Service> GetServices(FileLoggerConfiguration loggerConfiguration)
        {
            List <Service> services = new List <Service>();

            var svcTable = new SC_StatusDbDt.Service();
            var svcs     = svcTable.All();

            foreach (var svc in svcs)
            {
                services.Add(new Service {
                    ServiceId          = (int)svc.ServiceId,
                    ServiceName        = svc.ServiceName,
                    ServiceDescription = svc.ServiceDescription,
                    ServiceStatus      = (Service.ServiceStatusEnum)((int)svc.ServiceStatus),
                    ServiceDisplayName = svc.ServiceDisplayName,
                    LocationId         = (int)svc.LocationId,
                    SystemId           = (int)svc.SystemId,
                    ApplicationId      = (int)svc.ApplicationId,
                    InstallPath        = svc.InstallPath,
                    IsHub           = svc.IsHub,
                    ServiceCommands = GetServiceCommands((int)svc.ServiceId, loggerConfiguration)
                });
            }

            return(services);
        }
Beispiel #2
0
        /// <summary>
        /// Creates the database. This is the method used by the hub set up.
        /// </summary>
        /// <returns>The service ID for the hub.</returns>
        public static int CreateDatabase(Service service, List <string> serviceStatusDbSetupSql, FileLoggerConfiguration loggerConfiguration)
        {
            int serviceId = -1;

            if (!File.Exists(service.ServiceStatusDatabasePath))
            {
                Logging.Log(LogLevelEnum.Info, "Begin SQLite database initialization", loggerConfiguration);

                var db = new SC_StatusDbDt.Service();

                Logging.Log(LogLevelEnum.Debug, "Begin SQL statements", loggerConfiguration);
                foreach (var sqlStatement in serviceStatusDbSetupSql)
                {
                    try {
                        db.Execute(sqlStatement, new object[0]);
                    }
                    catch (Exception ex) {
                        Logging.Log(LogLevelEnum.Fatal, FileLogger.GetInnerException(ex).Message, loggerConfiguration);
                        Logging.HandleException(ex);
                        throw;
                    }
                }
                Logging.Log(LogLevelEnum.Debug, "End SQL statements", loggerConfiguration);

                serviceId = DatabaseInstaller.InitializeService(service, null, loggerConfiguration);

                Logging.Log(LogLevelEnum.Info, "End SQLite database initialization", loggerConfiguration);
            }

            return(serviceId);
        }
        /// <summary>
        /// Gets the service.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="loggerConfiguration">The logger configuration.</param>
        /// <returns>The complete service.</returns>
        internal static Service GetService(Service service, FileLoggerConfiguration loggerConfiguration)
        {
            var svcTbl = new SC_StatusDbDt.Service();

            string where = string.Empty;
            if (string.IsNullOrEmpty(service.ServiceName))
            {
                where = string.Format("{0} = {1}", "ServiceId", service.ServiceId);
            }
            else
            {
                where = string.Format("{0} = '{1}'", "ServiceName", service.ServiceName);
            }
            var svc = svcTbl.Single(where : where);

            return(new Service {
                ServiceId = (int)svc.ServiceId,
                ServiceName = svc.ServiceName,
                ServiceDescription = svc.ServiceDescription,
                ServiceStatus = (Service.ServiceStatusEnum)((int)svc.ServiceStatus),
                ServiceDisplayName = svc.ServiceDisplayName,
                LocationId = (int)svc.LocationId,
                SystemId = (int)svc.SystemId,
                ApplicationId = (int)svc.ApplicationId,
                InstallPath = svc.InstallPath,
                IsHub = svc.IsHub,
                ServiceCommands = GetServiceCommands(service, loggerConfiguration)
            });
        }
Beispiel #4
0
        /// <summary>
        /// Initializes the service.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="sqliteConnection">The sqlite connection.</param>
        /// <returns>The service ID</returns>
        internal static int InitializeService(Service service, SQLiteConnection sqliteConnection, FileLoggerConfiguration loggerConfiguration)
        {
            Logging.Log(LogLevelEnum.Info, string.Format("Beginning service status initialization:\n\t\tService name: {0}", service.ServiceName), loggerConfiguration);

            var svcTbl = new SC_StatusDbDt.Service();

            var newId = svcTbl.Insert(new {
                ServiceName        = service.ServiceName,
                ServiceDescription = service.ServiceDescription,
                ServiceDisplayName = service.ServiceDisplayName,
                LocationId         = service.LocationId,
                ApplicationId      = service.ApplicationId,
                SystemId           = service.SystemId,
                InstallPath        = service.InstallPath,
                ServiceStatus      = (int)Service.ServiceStatusEnum.Stopped,
                IsHub = service.IsHub
            });

            service = DatabaseController.GetService(service, loggerConfiguration);

            Logging.Log(LogLevelEnum.Info, string.Format("Service status initialization finished:\n\t\tService name: {0}\n\t\tService ID: {1}", service.ServiceName, service.ServiceId), loggerConfiguration);

            return(service.ServiceId);
        }
        /// <summary>
        /// Sets the service status.
        /// </summary>
        /// <param name="serviceStatus"></param>
        /// <param name="serviceId"></param>

        public static void SetStatus(Service.ServiceStatusEnum serviceStatus, int serviceId, FileLoggerConfiguration loggerConfiguration)
        {
            var svcTable = new SC_StatusDbDt.Service();

            svcTable.Update(new { ServiceStatus = (int)serviceStatus }, serviceId);
        }