Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }