Beispiel #1
0
        /// <summary>
        /// Removes the specified service app from the container.
        /// </summary>
        /// <param name="appName">Name of the application.</param>
        /// <param name="dao">The DAO.</param>
        /// <param name="appListDao">The application list DAO.</param>
        /// <exception cref="System.IndexOutOfRangeException">The app name could not be found.</exception>
        /// <exception cref="System.InvalidOperationException">The ServiceApp was not stopped first.</exception>
        public void RemoveServiceApp(string appName, IServiceAppDao dao, IAppListDao appListDao)
        {
            ServiceAppProcess process = ServiceAppProcesses[appName];

            if (process != null)
            {
                if (process.IsProcessRunning)
                {
                    throw new InvalidOperationException(string.Format("ServiceApp '{0}' must be stopped before it can be updated or removed.", appName));
                }

                ServiceAppProcesses.Remove(process);

                // This will prevent leaks
                process.Started     -= ServiceAppProcess_Started;
                process.Error       -= ServiceAppProcess_Error;
                process.Executed    -= ServiceAppProcess_Executed;
                process.Performance -= ServiceAppProcess_Performance;
                process.Stopped     -= ServiceAppProcess_Stopped;
            }

            if (appListDao != null)
            {
                appListDao.DeleteServiceApp(appName);
            }

            if (dao != null)
            {
                dao.DeleteServiceApp(appName);
            }
        }
Beispiel #2
0
        public void FindAll_CanReturnAllServiceApps()
        {
            IAppListDao dao  = DaoFactory.Create <IAppListDao, AppListDao>(xml);
            var         apps = dao.FindAll();

            Assert.AreEqual(2, apps.Count());
        }
Beispiel #3
0
        public void FindAll_CanReturnServiceAppByName()
        {
            IAppListDao dao = DaoFactory.Create <IAppListDao, AppListDao>(xml);
            var         app = dao.FindAll(a => a.Name == "TestApp1").FirstOrDefault();

            Assert.AreEqual("TestApp1", app.Name);
            Assert.AreEqual("Shows how SACS works", app.Description);
            Assert.AreEqual("Development", app.Environment);
            Assert.AreEqual(@"E:\Development\SACS\Tests\SACS.TestApp\bin\Debug\SACS.TestApp.exe", app.AppFilePath);
            Assert.AreEqual(StartupType.Automatic, app.StartupTypeEnum);
            Assert.AreEqual("* * * * *", app.Schedule);
            Assert.AreEqual("", app.Username);
            Assert.AreEqual("", app.Password);
        }
Beispiel #4
0
        /// <summary>
        /// Updates the service app in the container or adds a new one to it if it does not exist.
        /// </summary>
        /// <param name="serviceApp">The service application.</param>
        /// <param name="dao">The DAO.</param>
        /// <param name="appListDao">The application list DAO.</param>
        /// <returns>
        /// An error message if there was a problem updating the service app
        /// </returns>
        public string UpdateServiceApp(ServiceApp serviceApp, IServiceAppDao dao, IAppListDao appListDao)
        {
            // TODO: move validation outside of here (breaks SRP)
            ServiceAppValidator validator = new ServiceAppValidator();

            if (serviceApp == null)
            {
                return("Cannot update null service app");
            }

            if (!validator.ValidateServiceApp(serviceApp))
            {
                return(string.Format("Service app to update is invalid. Reason: {0}", string.Join(", ", validator.ErrorMessages)));
            }

            return(this.SyncServiceApp(serviceApp, dao, appListDao));
        }
Beispiel #5
0
        /// <summary>
        /// Loads and schedules the service apps.
        /// </summary>
        private void StartServiceApps()
        {
            // load all the services into the container
            IList <string> errors = new List <string>();

            // TODO: inject via abstract factory
            using (IServiceAppDao serviceAppDao = DaoFactory.Create <IServiceAppDao, ServiceAppDao>())
            {
                IAppListDao appListDao = DaoFactory.Create <IAppListDao, AppListDao>();
                this._appManager.InitializeAllServiceApps(appListDao.FindAll(), serviceAppDao, errors);
            }

            errors.ToList().ForEach(error =>
            {
                this._log.Warn(error);
            });
        }
Beispiel #6
0
        /// <summary>
        /// Adds the service app to the container or updates it if it already exists and saves it to the AppList configuration.
        /// </summary>
        /// <param name="app">The application.</param>
        /// <param name="dao">The DAO.</param>
        /// <param name="appListDao">The application list DAO.</param>
        /// <exception cref="System.InvalidOperationException">The service app is added and is still running.</exception>
        public string SyncServiceApp(ServiceApp app, IServiceAppDao dao, IAppListDao appListDao)
        {
            string errorMessage = string.Empty;

            this.RemoveServiceApp(app.Name, dao);

            ServiceAppProcess process = _serviceAppFactory.CreateServiceAppProcess(app, this._log);

            try
            {
                this.ServiceAppProcesses.Add(process);
                process.EntropyValue = dao.SaveServiceApp(app);

                if (appListDao != null)
                {
                    try
                    {
                        appListDao.PersistServiceApp(app);
                    }
                    catch (Exception e)
                    {
                        this._log.Error(string.Format("{0} could not be saved to AppList", app.Name), e);
                        errorMessage = string.Format("ServiceApp '{0}' could not be saved to the configuration.", app.Name);
                    }
                }

                process.Started     += ServiceAppProcess_Started;
                process.Error       += ServiceAppProcess_Error;
                process.Executed    += ServiceAppProcess_Executed;
                process.Performance += ServiceAppProcess_Performance;
                process.Stopped     += ServiceAppProcess_Stopped;
            }
            catch (ArgumentException)
            {
                errorMessage = string.Format("ServiceApp '{0}' is already added.", app.Name);
            }

            return(errorMessage);
        }
Beispiel #7
0
        public void PersistServiceApp_CanAddUserNameAndPassword()
        {
            IAppListDao dao = DaoFactory.Create <IAppListDao, AppListDao>(xml);
            ServiceApp  app = new ServiceApp
            {
                Name            = "TestApp1",
                Description     = "Shows how SACS works",
                Environment     = "Development",
                AppFilePath     = @"E:\Development\SACS\Tests\SACS.TestApp\bin\Debug\SACS.TestApp.exe",
                StartupTypeEnum = StartupType.Automatic,
                Schedule        = "* * * * *",
                Username        = "******",
                Password        = "******"
            };

            dao.PersistServiceApp(app);

            ServiceApp savedApp = dao.FindAll(sa => sa.Name == "TestApp1").FirstOrDefault();

            Assert.AreEqual("NewUsername", savedApp.Username);
            Assert.AreEqual("NewPassword", savedApp.Password);
        }