예제 #1
0
        public void InitializeTests()
        {
            var mockServiceApp = (ServiceAppProcess)Activator.CreateInstance(typeof(ServiceAppProcess), true);

            _serviceAppProcessFactory = Substitute.For <IServiceAppProcessFactory>();
            _serviceAppProcessFactory.CreateServiceAppProcess(null, null).ReturnsForAnyArgs(mockServiceApp);
        }
예제 #2
0
        public void GetIndex_CanReturnServiceAppProcessFromCollectionUsingString()
        {
            ServiceAppProcessCollection collection = new ServiceAppProcessCollection(new ServiceAppProcessComparer());
            ServiceAppProcess           saProc     = _serviceAppProcessFactory.CreateServiceAppProcess(null, null);

            collection.Add(saProc);

            Assert.AreEqual(saProc, collection["__Test"]);
        }
예제 #3
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);
        }