public static MorphAction Deserialize(XmlElement element, DeserializationContext context)
        {
            var action = new ExportWorkItemDataMorphAction(element.GetAttribute("typename"), Convert.ToBoolean(element.GetAttribute("allfields")));

            foreach (var fieldElement in element.ChildNodes.OfType<XmlElement>().Where(e => e.Name == "field"))
            {
                action.AddExportField(fieldElement.GetAttribute("refname"));
            }

            return action;
        }
Example #2
0
        public MorphAction[] GenerateActions(IEnumerable<IDifference> differences)
        {
            differences = differences.ToArray(); // avoid multi-enumeration issues

            var actionSet = new MorphActionSet();

            foreach (var witdAdd in differences.OfType<AddedWorkItemTypeDefinitionDifference>())
            {
                actionSet.PrepareWorkItemTypeDefinitions.Add(new ImportWorkItemTypeDefinitionMorphAction(witdAdd.WorkItemTypeDefinition));
            }

            var workItemTypeDifferences = differences
                .OfType<IWorkItemTypeDifference>()
                .GroupBy(d => d.CurrentWorkItemTypeName, StringComparer.OrdinalIgnoreCase);

            foreach (var workItemTypeGroup in workItemTypeDifferences)
            {
                var modifyTypeAction = new ModifyWorkItemTypeDefinitionMorphAction(workItemTypeGroup.Key);
                var exportDataAction = new ExportWorkItemDataMorphAction(workItemTypeGroup.Key);
                var finalModifyTypeAction = new ModifyWorkItemTypeDefinitionMorphAction(workItemTypeGroup.Key);

                actionSet.PrepareWorkItemTypeDefinitions.Add(modifyTypeAction);
                actionSet.ProcessWorkItemData.Add(exportDataAction);
                actionSet.FinaliseWorkItemTypeDefinitions.Add(finalModifyTypeAction);

                foreach (var fieldAdd in workItemTypeGroup.OfType<AddedWorkItemFieldDifference>())
                {
                    modifyTypeAction.AddFieldDefinition(fieldAdd.GoalField);
                }

                foreach (var fieldRename in workItemTypeGroup.OfType<RenamedWorkItemFieldDifference>())
                {
                    modifyTypeAction.AddFieldDefinition(fieldRename.GoalField);
                    // TODO consolidate data copy for multiple fields into one action
                    actionSet.ProcessWorkItemData.Add(new CopyWorkItemDataMorphAction(fieldRename.CurrentWorkItemTypeName, fieldRename.CurrentFieldReferenceName, fieldRename.GoalFieldReferenceName));
                    finalModifyTypeAction.RemoveFieldDefinition(fieldRename.CurrentFieldReferenceName);
                }

                foreach (var stateRename in workItemTypeGroup.OfType<RenamedWorkItemStateDifference>())
                {
                    const string defaultReason = "Process Template Change";
                    var addStateAction = modifyTypeAction.AddWorkflowState(stateRename.GoalState);
                    var addTransitionAction = modifyTypeAction.AddWorkflowTransition(stateRename.CurrentStateName, stateRename.GoalStateName, defaultReason);
                    var modifyStateAction = new ModifyWorkItemStateMorphAction(stateRename.CurrentWorkItemTypeName, stateRename.CurrentStateName, stateRename.GoalStateName);
                    modifyStateAction.LinkedActions.Add(new ActionLink(addStateAction, ActionLinkType.Required));
                    modifyStateAction.LinkedActions.Add(new ActionLink(addTransitionAction, ActionLinkType.Required));
                    actionSet.ProcessWorkItemData.Add(modifyStateAction);
                    finalModifyTypeAction.RemoveWorkflowState(stateRename.CurrentStateName);
                }

                foreach (var fieldRemove in workItemTypeGroup.OfType<RemovedWorkItemFieldDifference>())
                {
                    exportDataAction.AddExportField(fieldRemove.ReferenceFieldName);
                    finalModifyTypeAction.RemoveFieldDefinition(fieldRemove.ReferenceFieldName);
                }

                foreach (var fieldChange in workItemTypeGroup.OfType<ChangedWorkItemFieldDifference>())
                {
                    finalModifyTypeAction.ReplaceFieldDefinition(fieldChange.GoalField);
                }

                foreach (var formChange in workItemTypeGroup.OfType<ChangedWorkItemFormDifference>())
                {
                    finalModifyTypeAction.ReplaceForm(formChange.FormElement);
                }

                foreach (var formChange in workItemTypeGroup.OfType<ChangedWorkItemWorkflowDifference>())
                {
                    finalModifyTypeAction.ReplaceWorkflow(formChange.WorkflowElement);
                }
            }

            foreach (var witdRename in differences.OfType<RenamedWorkItemTypeDefinitionDifference>())
            {
                actionSet.FinaliseWorkItemTypeDefinitions.Add(new RenameWitdMorphAction(witdRename.CurrentTypeName, witdRename.GoalTypeName));
            }

            foreach (var witdRemove in differences.OfType<RemovedWorkItemTypeDefinitionDifference>())
            {
                var exportAction = new ExportWorkItemDataMorphAction(witdRemove.TypeName, allFields: true);
                var destroyAction = new DestroyWitdMorphAction(witdRemove.TypeName);
                destroyAction.LinkedActions.Add(new ActionLink(exportAction, ActionLinkType.Encouraged));
                actionSet.ProcessWorkItemData.Add(exportAction);
                actionSet.FinaliseWorkItemTypeDefinitions.Add(destroyAction);
            }

            return actionSet.Combine().ToArray();
        }