Ejemplo n.º 1
0
        public override async Task <WorkItemFieldValue> HandleAsync(JsonPatchDocument document, WorkItemFieldValue field, CancellationToken cancellationToken)
        {
            var targetArea = field.Value?.ToString();

            //If the value is empty then we cannot migrate it but we cannot remove it either so we'll ignore the "value"
            if (String.IsNullOrEmpty(targetArea))
            {
                Logger.Warning($"Area is empty (which is illegal) so skipping the update");
                return(null);
            }
            ;

            //If the area has already been migrated then just convert it as is
            var migratedArea = Context.MigratedAreas.FirstOrDefault(a => String.Compare(a.SourcePath.FullPath, targetArea, true) == 0 && (a.Succeeded || a.Skipped));

            if (migratedArea == null)
            {
                //Migrate the area first
                migratedArea = await OnMigrateAsync(targetArea, cancellationToken).ConfigureAwait(false);
            }
            ;

            return(field);
        }
        public override Task <WorkItemFieldValue> HandleAsync(JsonPatchDocument document, WorkItemFieldValue field, CancellationToken cancellationToken)
        {
            Dictionary <string, string> targetTranslate = new Dictionary <string, string>();

            switch (field.Name)
            {
            case WorkItemFields.WorkItemType:
                targetTranslate = Settings.Translate.Types.Where(x => !string.IsNullOrEmpty(x.Source)).ToDictionary(x => x.Source, x => x.Target);
                break;

            case WorkItemFields.State:
                targetTranslate = Settings.Translate.States.Where(x => !string.IsNullOrEmpty(x.Source)).ToDictionary(x => x.Source, x => x.Target);
                break;

            case WorkItemFields.Severity:
                targetTranslate = Settings.Translate.Severity.Where(x => !string.IsNullOrEmpty(x.Source)).ToDictionary(x => x.Source, x => x.Target);
                break;
            }

            if (targetTranslate.TryGetValue(field.Value.ToString(), out string newValue))
            {
                field.Value = newValue;
            }

            return(Task.FromResult(field));
        }
Ejemplo n.º 3
0
 public abstract Task <WorkItemFieldValue> HandleAsync(JsonPatchDocument document, WorkItemFieldValue field, CancellationToken cancellationToken);
Ejemplo n.º 4
0
        private async Task <JsonPatchDocument> CreatePatchDocumentAsync(MigrationContext context, WorkItemUpdate update, CancellationToken cancellationToken)
        {
            var doc = new JsonPatchDocument();

            if (update.Fields == null)
            {
                update.Fields = new Dictionary <string, WorkItemFieldUpdate>(StringComparer.OrdinalIgnoreCase);
            }

            var fields = update.Fields;

            //Ensure that the ChangedBy/Changed Date fields are being set so the history is maintained
            fields.EnsureFieldSet(WorkItemFields.ChangedBy, update.RevisedBy.Name);
            fields.EnsureFieldSet(WorkItemFields.ChangedDate, update.RevisedDate);

            //Copy the fields
            foreach (var field in fields)
            {
                cancellationToken.ThrowIfCancellationRequested();

                context.FieldHandlers.TryGetValue(field.Key, out var handlers);
                if (handlers != null || Settings.IncludeAllFields)
                {
                    var newField = new WorkItemFieldValue()
                    {
                        Name = field.Key, Value = field.Value.NewValue
                    };

                    if (handlers != null)
                    {
                        foreach (var handler in handlers)
                        {
                            newField = await handler.HandleAsync(doc, newField, cancellationToken).ConfigureAwait(false);

                            if (newField == null)
                            {
                                break;
                            }
                        }
                        ;
                    }
                    ;

                    if (newField != null)
                    {
                        //The final check before we add the item is to ensure that the field actually exists in the target system
                        var allowedFields = await context.GetTargetFieldsAsync(cancellationToken).ConfigureAwait(false);

                        if (!allowedFields.Contains(newField.Name, StringComparer.OrdinalIgnoreCase))
                        {
                            Logger.Warning($"{newField.Name} was not found in target, skipping");
                        }
                        else
                        {
                            var name  = (newField.Name != field.Key) ? $"{newField.Name} (renamed from {field.Key})" : newField.Name;
                            var value = newField.Value?.ToString() ?? "";
                            if (value.Length > 75)
                            {
                                value = value.Left(75) + "...";
                            }

                            Logger.Debug($"{name} = {value}");

                            //Add or update it
                            if (field.Value.OldValue != null)
                            {
                                doc.UpdateField(newField.Name, newField.Value);
                            }
                            else
                            {
                                doc.AddField(newField.Name, newField.Value);
                            }
                        };
                    }
                    else
                    {
                        Logger.Debug($"{field.Key} is marked as ignore");
                    }
                }
                else
                {
                    Logger.Debug($"{field.Key} has no handlers, skipping");
                }
            }
            ;

            return(doc);
        }
        public override Task <WorkItemFieldValue> HandleAsync(JsonPatchDocument document, WorkItemFieldValue field, CancellationToken cancellationToken)
        {
            field.Name = NewName;

            return(Task.FromResult(field));
        }
 public override Task <WorkItemFieldValue> HandleAsync(JsonPatchDocument document, WorkItemFieldValue field, CancellationToken cancellationToken)
 {
     return(Task.FromResult <WorkItemFieldValue>(null));
 }
Ejemplo n.º 7
0
        public override Task <WorkItemFieldValue> HandleAsync(JsonPatchDocument document, WorkItemFieldValue field, CancellationToken cancellationToken)
        {
            var match = s_re.Match(field.Value?.ToString() ?? "");

            if (match.Success)
            {
                var username = match.Groups["username"];
                if (username != null)
                {
                    //Find the user in our list
                    if (!Context.TargetUsers.TryGetValue(username.Value, out var user))
                    {
                        Logger.Warning($"User '{username.Value}' not found, ignoring");

                        //Add them so we don't report them again
                        user = username.Value;
                        Context.TargetUsers[username.Value] = user;
                    }
                    ;

                    field.Value = user;
                }
                ;
            }
            ;

            return(Task.FromResult(field));
        }