Esempio n. 1
0
 public static void SaveWorkItem(this AttachmentOMatic context, WorkItem workItem)
 {
     if (workItem == null)
     {
         throw new ArgumentNullException(nameof(workItem));
     }
     workItem.Fields["System.ChangedBy"].Value = "Migration";
     workItem.Save();
 }
Esempio n. 2
0
        public WorkItemMigrationContext(MigrationEngine me, WorkItemMigrationConfig config)
            : base(me, config)
        {
            _config = config;
            PopulateIgnoreList();

            VssClientCredentials adoCreds = new VssClientCredentials();

            _witClient = new WorkItemTrackingHttpClient(me.Target.Collection.Uri, adoCreds);

            var workItemServer = me.Source.Collection.GetService <WorkItemServer>();

            attachmentOMatic = new AttachmentOMatic(workItemServer, config.AttachmentWorkingPath);
        }
        internal override void InternalExecute()
        {
            if (_config == null)
            {
                throw new Exception("You must call Configure() first");
            }
            var workItemServer = me.Source.Collection.GetService <WorkItemServer>();

            attachmentOMatic = new AttachmentOMatic(workItemServer, _config.AttachmentWorkingPath, _config.AttachmentMazSize);
            repoOMatic       = new RepoOMatic(me);
            VssClientCredentials adoCreds = new VssClientCredentials();

            _witClient = new WorkItemTrackingHttpClient(me.Target.Collection.Uri, adoCreds);
            //Validation: make sure that the ReflectedWorkItemId field name specified in the config exists in the target process, preferably on each work item type.
            ConfigValidation();
            PopulateIgnoreList();

            var stopwatch = Stopwatch.StartNew();
            //////////////////////////////////////////////////
            var sourceStore = new WorkItemStoreContext(me.Source, WorkItemStoreFlags.BypassRules, Telemetry);
            var tfsqc       = new TfsQueryContext(sourceStore, Telemetry);

            tfsqc.AddParameter("TeamProject", me.Source.Config.Project);
            tfsqc.Query =
                string.Format(
                    @"SELECT [System.Id], [System.Tags] FROM WorkItems WHERE [System.TeamProject] = @TeamProject {0} ORDER BY {1}",
                    _config.QueryBit, _config.OrderBit);
            var sourceQueryResult = tfsqc.Execute();
            var sourceWorkItems   = (from WorkItem swi in sourceQueryResult select swi).ToList();

            contextLog.Information("Replay all revisions of {sourceWorkItemsCount} work items?", sourceWorkItems.Count);
            //////////////////////////////////////////////////
            var targetStore = new WorkItemStoreContext(me.Target, WorkItemStoreFlags.BypassRules, Telemetry);
            var destProject = targetStore.GetProject();

            contextLog.Information("Found target project as {@destProject}", destProject.Name);
            //////////////////////////////////////////////////////////FilterCompletedByQuery
            if (_config.FilterWorkItemsThatAlreadyExistInTarget)
            {
                sourceWorkItems = FilterWorkItemsThatAlreadyExistInTarget(sourceWorkItems, targetStore);
            }
            //////////////////////////////////////////////////
            _current       = 1;
            _count         = sourceWorkItems.Count;
            _elapsedms     = 0;
            _totalWorkItem = sourceWorkItems.Count;
            foreach (WorkItem sourceWorkItem in sourceWorkItems)
            {
                workItemLog = contextLog.ForContext("SourceWorkItemId", sourceWorkItem.Id);
                using (LogContext.PushProperty("sourceWorkItemTypeName", sourceWorkItem.Type.Name))
                    using (LogContext.PushProperty("currentWorkItem", _current))
                        using (LogContext.PushProperty("totalWorkItems", _totalWorkItem))
                            using (LogContext.PushProperty("sourceWorkItemId", sourceWorkItem.Id))
                                using (LogContext.PushProperty("sourceRevisionInt", sourceWorkItem.Revision))
                                    using (LogContext.PushProperty("targetWorkItemId", null))
                                    {
                                        ProcessWorkItem(sourceStore, targetStore, destProject, sourceWorkItem, _config.WorkItemCreateRetryLimit);
                                        if (_config.PauseAfterEachWorkItem)
                                        {
                                            Console.WriteLine("Do you want to continue? (y/n)");
                                            if (Console.ReadKey().Key != ConsoleKey.Y)
                                            {
                                                workItemLog.Warning("USER ABORTED");
                                                break;
                                            }
                                        }
                                    }
            }
            //////////////////////////////////////////////////
            stopwatch.Stop();

            contextLog.Information("DONE in {Elapsed}", stopwatch.Elapsed.ToString("c"));
        }