public override void Execute(ExecutionContext context)
        {
            var project = context.GetWorkItemProject();
            var queryContext = new Hashtable { { "project", project.Name }, { "workitemtypename", _workItemTypeName }};

            const string wiqlTemplate = @"select [System.Id], [{0}], [{1}] from WorkItems where [System.TeamProject] = @project and [System.WorkItemType] = @workitemtypename order by [System.Id]";
            var wiql = string.Format(wiqlTemplate, _fromFieldReferenceName, _toFieldReferenceName);

            var workItems = project.Store.Query(wiql, queryContext);

            foreach (WorkItem workItem in workItems)
            {
                Debug.WriteLine(workItem.Id);
                var hasFromField = workItem.Fields.Contains(_fromFieldReferenceName);
                var hasToField = workItem.Fields.Contains(_toFieldReferenceName);
                if (hasFromField && hasToField)
                {
                    if (!workItem.IsOpen) workItem.Open();
                    workItem.Fields[_toFieldReferenceName].Value = workItem.Fields[_fromFieldReferenceName].Value;
                    workItem.Save();
                }
                else
                {
                    if (!hasFromField)
                    {
                        context.Log(string.Format("Work item '{0}' is missing field '{1}'.", workItem.Id, _fromFieldReferenceName), TraceLevel.Warning);
                    }
                    if (!hasToField)
                    {
                        context.Log(string.Format("Work item '{0}' is missing field '{1}'.", workItem.Id, _toFieldReferenceName), TraceLevel.Warning);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void Apply(Uri collectionUri, string projectName, IEnumerable<MorphAction> actions, string outputPath)
 {
     var context = new ExecutionContext(collectionUri, projectName, outputPath) {TraceLevel = TraceLevel.Verbose};
     foreach (var action in actions)
     {
         action.Execute(context);
     }
 }
        public override void Execute(ExecutionContext context)
        {
            if (!_allFields && _fieldReferenceNames.Count == 0)
            {
                return;
            }

            var project = context.GetWorkItemProject();
            var queryContext = new Hashtable { { "project", project.Name }, { "workitemtypename", _workItemTypeName } };

            if (_allFields)
            {
                _fieldReferenceNames.Clear();
                foreach (FieldDefinition fieldDef in project.WorkItemTypes[_workItemTypeName].FieldDefinitions)
                {
                    if (!fieldDef.ReferenceName.Equals("System.Id", StringComparison.OrdinalIgnoreCase) && !fieldDef.IsComputed)
                    {
                        _fieldReferenceNames.Add(fieldDef.ReferenceName);
                    }
                }
            }

            const string wiqlTemplate = @"select [System.Id], {0} from WorkItems where [System.TeamProject] = @project and [System.WorkItemType] = @workitemtypename order by [System.Id]";
            var wiqlFieldList = BuildWiqlFieldList();
            var wiql = string.Format(wiqlTemplate, wiqlFieldList);

            var workItems = project.Store.Query(wiql, queryContext);

            using (var xw = XmlWriter.Create(Path.Combine(context.OutputPath, string.Format("{0}-data.xml", _workItemTypeName))))
            {
                xw.WriteStartElement("WorkItemDataExport");
                xw.WriteAttributeString("workitemtypename", _workItemTypeName);
                foreach (WorkItem workItem in workItems)
                {
                    Debug.WriteLine(workItem.Id);
                    xw.WriteStartElement("WorkItem");
                    xw.WriteAttributeString("id", workItem.Id.ToString(CultureInfo.InvariantCulture));
                    foreach (var fieldReferenceName in _fieldReferenceNames)
                    {
                        if (workItem.Fields.Contains(fieldReferenceName))
                        {
                            xw.WriteElementString(fieldReferenceName, Convert.ToString(workItem.Fields[fieldReferenceName].Value));
                        }
                        else
                        {
                            xw.WriteElementString(fieldReferenceName, "[missing]");
                        }

                    }
                    xw.WriteEndElement();
                }
                xw.WriteEndElement();
            }
        }
        public override void Execute(ExecutionContext context)
        {
            // most supported implementation would be to run witadmin.exe but that could be tricky with alternate credentials

            var project = context.GetWorkItemProject();

            var workItemType = project.WorkItemTypes[_typeName];

            InternalAdmin.DestroyWorkItemType(workItemType);
            project.Store.RefreshCache(true);
        }
        public override void Execute(ExecutionContext context)
        {
            var project = context.GetWorkItemProject();
            var queryContext = new Hashtable {{"project", project.Name}, {"workitemtypename", _workItemTypeName}, {"fromvalue", _fromValue}};

            const string wiql = @"select [System.Id], [System.State] from WorkItems where [System.TeamProject] = @project and [System.WorkItemType] = @workitemtypename and [System.State] = @fromvalue order by [System.Id]";

            var workItems = project.Store.Query(wiql, queryContext);

            foreach (WorkItem workItem in workItems)
            {
                Debug.WriteLine(workItem.Id);
                if (!workItem.IsOpen) workItem.Open();
                workItem.State = _toValue;
                workItem.Save();
            }
        }
        public override void Execute(ExecutionContext context)
        {
            if (context.TraceLevel >= TraceLevel.Verbose)
            {
                string traceFile;
                int count = 0;
                do
                {
                    count++;
                    traceFile = Path.Combine(context.OutputPath, string.Format("{0}-{1}-definition.xml", WorkItemTypeName, count));

                } while (File.Exists(traceFile));
                _typeDefinition.WITDElement.OwnerDocument.Save(traceFile);
            }

            var project = context.GetWorkItemProject();
            var accumulator = new ImportEventArgsAccumulator();
            project.WorkItemTypes.ImportEventHandler += accumulator.Handler;
            try
            {
                project.WorkItemTypes.Import(_typeDefinition.WITDElement);
                if (accumulator.ImportEventArgs.Count != 0)
                {
                    throw new ProvisionValidationException(string.Format("Could not import work item type definition '{0}'", WorkItemTypeName));
                }
                project.Store.RefreshCache(true);
            }
            catch (ProvisionValidationException)
            {
                foreach (var e in accumulator.ImportEventArgs)
                {
                    context.Log("IMPORT: " + e.Message, TraceLevel.Error);
                }
                throw;
            }
            finally
            {
                project.WorkItemTypes.ImportEventHandler -= accumulator.Handler;
            }
        }
        public override void Execute(ExecutionContext context)
        {
            if (_subActions.Count == 0)
            {
                return;
            }

            var project = context.GetWorkItemProject();
            project.Store.RefreshCache(true);
            var witdElement = project.WorkItemTypes[_workItemTypeName].Export(false).DocumentElement;

            foreach (var action in _subActions)
            {
                action.Execute(witdElement);
            }

            var workItemTypeDefinition = new WorkItemTypeDefinition(witdElement, true); // TODO perform actions on WorkItemTypeDefinition instead of witdElement directly

            var importAction = new ImportWorkItemTypeDefinitionMorphAction(workItemTypeDefinition);
            importAction.Execute(context);
        }