Пример #1
0
        /// <summary>
        /// Called by the ManyConsole framework to execute the  <i>run</i> command.
        /// </summary>
        /// <param name="remainingArguments">Unparsed command line arguments.</param>
        /// <returns>0 for success, error code otherwise</returns>
        public override int Run(string[] remainingArguments)
        {
            // cache requires absolute path
            this.PolicyFile = System.IO.Path.GetFullPath(this.PolicyFile);

            // need a logger to show errors in config file (Catch 22)
            var logger = new ConsoleEventLogger(LogLevel.Normal);

            var context = new RequestContext(this.TeamProjectCollectionUrl, this.TeamProjectName);
            var runtime = RuntimeContext.GetContext(
                () => this.PolicyFile,
                context,
                logger,
                (collectionUri, toImpersonate, logEvents) =>
                new Core.Facade.WorkItemRepository(collectionUri, toImpersonate, logEvents));

            if (!string.IsNullOrWhiteSpace(this.LogLevelName))
            {
                // command line wins
                LogLevel logLevel = (LogLevel)Enum.Parse(typeof(LogLevel), this.LogLevelName, true);
                runtime.Logger.MinimumLogLevel = logLevel;
            }

            if (runtime.HasErrors)
            {
                return(3);
            }

            using (EventProcessor eventProcessor = new EventProcessor(runtime))
            {
                try
                {
                    var workItemIds = new Queue <int>();
                    workItemIds.Enqueue(this.WorkItemId);

                    ProcessingResult result = null;
                    while (workItemIds.Count > 0)
                    {
                        context.CurrentWorkItemId = workItemIds.Dequeue();
                        var notification = context.Notification;

                        logger.StartingProcessing(context, notification);
                        result = eventProcessor.ProcessEvent(context, notification);
                        logger.ProcessingCompleted(result);

                        foreach (var savedId in eventProcessor.SavedWorkItems)
                        {
                            workItemIds.Enqueue(savedId);
                        }
                    }

                    return(result.StatusCode);
                }
                catch (Exception e)
                {
                    logger.ProcessEventException(e);
                    return(1);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Called by the ManyConsole framework to execute the  <i>run</i> command.
        /// </summary>
        /// <param name="remainingArguments">Unparsed command line arguments.</param>
        /// <returns>0 for success, error code otherwise</returns>
        public override int Run(string[] remainingArguments)
        {
            // cache requires absolute path
            this.PolicyFile = System.IO.Path.GetFullPath(this.PolicyFile);

            // need a logger to show errors in config file (Catch 22)
            var logger = new ConsoleEventLogger(LogLevel.Normal);

            var context = new RequestContext(this.TeamProjectCollectionUrl, this.TeamProjectName);
            var runtime = RuntimeContext.GetContext(
                () => this.PolicyFile,
                context,
                logger,
                (collectionUri, toImpersonate, logEvents) =>
                    new Core.Facade.WorkItemRepository(collectionUri, toImpersonate, logEvents));

            if (!string.IsNullOrWhiteSpace(this.LogLevelName))
            {
                // command line wins
                LogLevel logLevel = (LogLevel)Enum.Parse(typeof(LogLevel), this.LogLevelName, true);
                runtime.Logger.MinimumLogLevel = logLevel;
            }

            if (runtime.HasErrors)
            {
                return 3;
            }

            using (EventProcessor eventProcessor = new EventProcessor(runtime))
            {
                try
                {
                    var workItemIds = new Queue<int>();
                    workItemIds.Enqueue(this.WorkItemId);

                    ProcessingResult result = null;
                    while (workItemIds.Count > 0)
                    {
                        context.CurrentWorkItemId = workItemIds.Dequeue();
                        var notification = context.Notification;

                        logger.StartingProcessing(context, notification);
                        result = eventProcessor.ProcessEvent(context, notification);
                        logger.ProcessingCompleted(result);

                        foreach (var savedId in eventProcessor.SavedWorkItems)
                        {
                            workItemIds.Enqueue(savedId);
                        }
                    }

                    return result.StatusCode;
                }
                catch (Exception e)
                {
                    logger.ProcessEventException(e);
                    return 1;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Called by the ManyConsole framework to execute the  <i>run</i> command.
        /// </summary>
        /// <param name="remainingArguments">Unparsed command line arguments.</param>
        /// <returns>0 for success, error code otherwise</returns>
        public override int Run(string[] remainingArguments)
        {
            // need a logger to show errors in config file (Catch 22)
            var logger = new ConsoleEventLogger(LogLevel.Warning);

            var runtime = RuntimeContext.GetContext(
                () => this.PolicyFile,
                new RequestContext(this.TeamProjectCollectionUrl, this.TeamProjectName),
                logger);

            if (runtime.HasErrors)
            {
                return 99;
            }

            logger.ConfigurationLoaded(this.PolicyFile);
            using (EventProcessor eventProcessor = new EventProcessor(this.TeamProjectCollectionUrl, null, runtime))
            {
                try
                {
                    var context = runtime.RequestContext;
                    var notification = new Notification(this.WorkItemId, this.TeamProjectName);

                    logger.StartingProcessing(context, notification);
                    ProcessingResult result = eventProcessor.ProcessEvent(context, notification);
                    logger.ProcessingCompleted(result);

                    return result.StatusCode;
                }
                catch (Exception e)
                {
                    logger.ProcessEventException(e);
                    return -1;
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Called by the ManyConsole framework to execute the  <i>run</i> command.
        /// </summary>
        /// <param name="remainingArguments">Unparsed command line arguments.</param>
        /// <returns>0 for success, error code otherwise</returns>
        public override int Run(string[] remainingArguments)
        {
            // need a logger to show errors in config file (Catch 22)
            var logger = new ConsoleEventLogger(LogLevel.Warning);

            var runtime = RuntimeContext.GetContext(
                () => this.PolicyFile,
                new RequestContext(this.TeamProjectCollectionUrl, this.TeamProjectName),
                logger);

            if (runtime.HasErrors)
            {
                return(99);
            }

            logger.ConfigurationLoaded(this.PolicyFile);
            using (EventProcessor eventProcessor = new EventProcessor(this.TeamProjectCollectionUrl, null, runtime))
            {
                try
                {
                    var context      = runtime.RequestContext;
                    var notification = new Notification(this.WorkItemId, this.TeamProjectName);

                    logger.StartingProcessing(context, notification);
                    ProcessingResult result = eventProcessor.ProcessEvent(context, notification);
                    logger.ProcessingCompleted(result);

                    return(result.StatusCode);
                }
                catch (Exception e)
                {
                    logger.ProcessEventException(e);
                    return(-1);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Called by the ManyConsole framework to execute the  <i>run</i> command.
        /// </summary>
        /// <param name="remainingArguments">Unparsed command line arguments.</param>
        /// <returns>0 for success, error code otherwise</returns>
        public override int Run(string[] remainingArguments)
        {
            // cache requires absolute path
            this.PolicyFile = System.IO.Path.GetFullPath(this.PolicyFile);

            // need a logger to show errors in config file (Catch 22)
            var logger = new ConsoleEventLogger(LogLevel.Normal);

            var context = new RequestContext(this.TeamProjectCollectionUrl, this.TeamProjectName);

            context.CurrentChangeType = this.ChangeType;
            var runtime = RuntimeContext.GetContext(
                () => this.PolicyFile,
                context,
                logger,
                (runtimeContext) => new Core.Facade.WorkItemRepository(runtimeContext),
                (runtimeContext) => new Core.Script.ScriptLibrary(runtimeContext));

            runtime.Settings.WhatIf = this.WhatIf;

            if (!string.IsNullOrWhiteSpace(this.LogLevelName))
            {
                // command line wins
                LogLevel logLevel = (LogLevel)Enum.Parse(typeof(LogLevel), this.LogLevelName, true);
                runtime.Logger.MinimumLogLevel = logLevel;
            }

            if (runtime.HasErrors)
            {
                return(3);
            }

            logger.WhatIfEnabled();

            var workItemIds = new Queue <int>();

            if (string.IsNullOrWhiteSpace(this.WorkItemQuery))
            {
                foreach (int id in this.WorkItemIds)
                {
                    workItemIds.Enqueue(id);
                }
            }
            else
            {
                var ci = runtime.GetConnectionInfo();
                //HACK should be: ci.ProjectCollectionUri = new Uri(this.TeamProjectCollectionUrl);
                ci.GetType().GetProperty("ProjectCollectionUri").SetValue(ci, new Uri(this.TeamProjectCollectionUrl));
                using (var tfs = ci.Token.GetCollection(ci.ProjectCollectionUri))
                {
                    logger.Connecting(ci);
                    tfs.Authenticate();
                    var workItemStore = tfs.GetService <WorkItemStore>();
                    var qr            = new QueryRunner(workItemStore, this.TeamProjectName);
                    var result        = qr.RunQuery(this.WorkItemQuery);
                    if (result == null)
                    {
                        logger.QueryNotFound(this.WorkItemQuery, this.TeamProjectName);
                    }
                    else
                    {
                        foreach (var pair in result.WorkItems)
                        {
                            workItemIds.Enqueue(pair.Key);
                        }
                    }
                }
            }

            using (EventProcessor eventProcessor = new EventProcessor(runtime))
            {
                try
                {
                    ProcessingResult result = null;
                    while (workItemIds.Count > 0)
                    {
                        context.CurrentWorkItemId = workItemIds.Dequeue();
                        var notification = context.Notification;

                        logger.StartingProcessing(context, notification);
                        result = eventProcessor.ProcessEvent(context, notification);
                        logger.ProcessingCompleted(result);

                        foreach (var savedId in eventProcessor.SavedWorkItems)
                        {
                            // special case: when WhatIf is on, new WI aren't saved and stay with ID 0
                            if (this.WhatIf && savedId == 0)
                            {
                                continue;
                            }

                            workItemIds.Enqueue(savedId);
                        }
                    }

                    return(result?.StatusCode ?? -1);
                }
                catch (Exception e)
                {
                    logger.ProcessEventException(e);
                    return(1);
                }
            }
        }