Exemplo n.º 1
0
        /// <summary>
        /// Starts this instance of the CUBED CoDe application.
        /// </summary>
        /// <returns><c>true</c> if application has started successfully; <c>false</c> otherwise.</returns>
        public bool Start()
        {
            bool result = true;

            Bootstrapper bootstrapper = new Bootstrapper();

            try
            {
                bootstrapper.InitialiseApplication();
            }
            catch (ConfigurationException)
            {
                WriteToLocalLog(Resources.ProblemInitialisingApplicationLogMessage);
                result = false;
            }

            if (result)
            {
                _deploymentModel = bootstrapper.DeploymentModel;
                _deploymentModel.ReadConfigurationFromFile();
                WriteToLocalLog(Resources.NextUpdateTimeLogMessage, _deploymentModel.NextUpdateTime);

                if (_deploymentModel.NextUpdateTime.CompareTo(DateTime.Now) <= 0)
                {
                    UpdateRepositories();
                }

                // Calculates the number of milliseconds until the next update is needed.
                double numberOfMillisecondsUntilNextUpdate = _deploymentModel.NextUpdateTime.Subtract(DateTime.Now).TotalMilliseconds;

                // Initialises the timer and set its interval to match the time for the next update. If the time for the next update is negative (meaning it should
                // have happened already) then set the interval to a default of 30 seconds.
                _timer = new Timer();

                if (numberOfMillisecondsUntilNextUpdate <= 0)
                {
                    numberOfMillisecondsUntilNextUpdate = 30000;
                }

                _timer.Interval = numberOfMillisecondsUntilNextUpdate;
                WriteToLocalLog(Resources.NextUpdateIntervalLogMessage, numberOfMillisecondsUntilNextUpdate / 1000);

                // Adds a handler to the timer elapsed event.
                _timer.Elapsed += Timer_Elapsed;

                // Starts the timer.
                _timer.Start();
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    // Dispose managed resources.
                    _deploymentModel = null;
                    _timer.Dispose();
                }

                // Clean-up unmanaged resources.
                _disposed = true;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialises the application reading configuration files, loading dependency injection modules and making model available.
        /// </summary>
        /// <exception cref="System.Configuration.ConfigurationException">When configuration key RepositoriesConfigurationFilePath is not present.</exception>
        /// <remarks>
        /// The interface application should make the following values available through their configuration files:
        ///     RepositoriesConfigurationFilePath - text with the full path of the configuration file used for the repositories.
        /// </remarks>
        public void InitialiseApplication()
        {
            // Reads the configurations from the app.config file.
            string repositoriesConfigurationFilePath = null;

            if (ConfigurationManager.AppSettings.AllKeys.Contains("RepositoriesConfigurationFilePath"))
            {
                repositoriesConfigurationFilePath = ConfigurationManager.AppSettings["RepositoriesConfigurationFilePath"];
            }
            else
            {
                throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, Resources.ConfigurationKeyNotPresentError, "RepositoriesConfigurationFilePath"));
            }

            int processWaitMilliseconds = 0;

            if (ConfigurationManager.AppSettings.AllKeys.Contains("ProcessWaitMilliseconds"))
            {
                if (!int.TryParse(ConfigurationManager.AppSettings["ProcessWaitMilliseconds"], out processWaitMilliseconds))
                {
                    throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, Resources.ConfigurationKeyInvalidValueError, "ProcessWaitMilliseconds"));
                }
            }
            else
            {
                throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, Resources.ConfigurationKeyNotPresentError, "ProcessWaitMilliseconds"));
            }

            // Loads the injection modules.
            using (NinjectModule infraServicesModule = new InfraServicesModule(processWaitMilliseconds), coreServicesModule = new CoreServicesModule(repositoriesConfigurationFilePath), modelModule = new ModelModule())
            {
                using (IKernel kernel = new StandardKernel(infraServicesModule, coreServicesModule, modelModule))
                {
                    _deploymentModel = kernel.Get <IDeploymentModel>();
                }
            }
        }