Esempio n. 1
0
        public void Raise_error_for_non_existing_file()
        {
            var    logger = Substitute.For <ILogEvents>();
            string file   = "does_not_exists";

            TFSAggregatorSettings.LoadFromFile(file, logger);
        }
        /// <summary>
        /// Return a proper context
        /// </summary>
        /// <returns></returns>
        public static RuntimeContext GetContext(Func <string> settingsPathGetter, IRequestContext requestContext, ILogEvents logger)
        {
            var runtime = (RuntimeContext)Cache.Get(CacheKey);

            if (runtime == null)
            {
                string settingsPath = settingsPathGetter();
                var    settings     = TFSAggregatorSettings.LoadFromFile(settingsPath, logger);
                runtime = MakeRuntimeContext(settingsPath, settings, requestContext, logger);

                var itemPolicy = new CacheItemPolicy();
                itemPolicy.Priority = CacheItemPriority.NotRemovable;
                itemPolicy.ChangeMonitors.Add(new HostFileChangeMonitor(new List <string>()
                {
                    settingsPath
                }));

                Cache.Set(CacheKey, runtime, itemPolicy);
            }
            else
            {
                runtime.RequestContext = requestContext;
            }

            return(runtime.Clone() as RuntimeContext);
        }
        /// <summary>
        /// Return a proper context
        /// </summary>
        /// <returns></returns>
        public static RuntimeContext GetContext(
            Func <string> settingsPathGetter,
            IRequestContext requestContext,
            ILogEvents logger,
            Func <IRuntimeContext, IWorkItemRepository> repoBuilder,
            Func <IRuntimeContext, IScriptLibrary> scriptLibraryBuilder)
        {
            string settingsPath = settingsPathGetter();
            string cacheKey     = CacheKey + settingsPath;
            var    runtime      = (RuntimeContext)Cache.Get(cacheKey);

            if (runtime == null)
            {
                logger.HelloWorld();

                logger.LoadingConfiguration(settingsPath);

                var settings = TFSAggregatorSettings.LoadFromFile(settingsPath, logger);
                runtime = MakeRuntimeContext(settingsPath, settings, requestContext, logger, repoBuilder, scriptLibraryBuilder);

                if (!runtime.HasErrors)
                {
                    var itemPolicy = new CacheItemPolicy();
                    itemPolicy.Priority = CacheItemPriority.NotRemovable;
                    itemPolicy.ChangeMonitors.Add(new HostFileChangeMonitor(new List <string>()
                    {
                        settingsPath
                    }));

                    Cache.Set(cacheKey, runtime, itemPolicy);
                }

                logger.ConfigurationLoaded(settingsPath);
            }
            else
            {
                logger.UsingCachedConfiguration(settingsPath);
            }

            runtime = runtime.Clone() as RuntimeContext;

            // as it changes at each invocation, must be set again here
            runtime.RequestContext     = requestContext;
            runtime.workItemRepository = null;
            return(runtime);
        }