protected internal WorkItem([NotNull] IWorkItemType workItemType, [CanBeNull] Dictionary <string, object> fields) : base(fields) { Contract.Requires(workItemType != null); _type = workItemType ?? throw new ArgumentNullException(nameof(workItemType)); }
protected internal WorkItem([NotNull] IWorkItemType workItemType, [NotNull] Func <IFieldCollection> fieldCollectionFactory) { Contract.Requires(workItemType != null); Contract.Requires(fieldCollectionFactory != null); _type = workItemType ?? throw new ArgumentNullException(nameof(workItemType)); _fieldFactory = fieldCollectionFactory ?? throw new ArgumentNullException(nameof(fieldCollectionFactory)); }
/// <summary> /// Builds the work item. /// </summary> /// <param name="projectName">The project name.</param> /// <param name="workItemTypeName">Name of the work item type.</param> /// <param name="fieldValues">The field values.</param> /// <returns>IWorkItem.</returns> public IWorkItem BuildWorkItem(string projectName, string workItemTypeName, IReadOnlyList <KeyValuePair <string, object> > fieldValues) { Dictionary <string, object> dictionary = fieldValues.ToDictionary(field => field.Key, field => field.Value); IWorkItemStore workItemStore = WorkItemStore(); IProject project = workItemStore.Projects[projectName]; IWorkItemTypeCollection workItemTypes = project.WorkItemTypes; IWorkItemType workItemType = null; foreach (IWorkItemType entry in workItemTypes) { if (entry.Name == workItemTypeName) { workItemType = entry; } } var workItem = new WorkItem(WorkItemTypeWrapper.GetInstance(workItemType)); foreach (KeyValuePair <string, object> pair in dictionary) { string fieldName = pair.Key; object fieldValue = pair.Value; workItem[fieldName] = fieldValue; } return(WorkItemWrapper.GetWrapper(workItem)); }
public MockWorkItem([NotNull] IWorkItemType workItemType, int id, [CanBeNull] params KeyValuePair <string, object>[] fieldValues) : this( workItemType, fieldValues?.Union(new[] { new KeyValuePair <string, object>(CoreFieldRefNames.Id, id) }) .ToDictionary(k => k.Key, e => e.Value, StringComparer.OrdinalIgnoreCase) ?? new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase) { { CoreFieldRefNames.Id, id } }) { Contract.Requires(id > 0); }
/// <summary> /// Get the transitions for this <see cref="WorkItemType"/> /// </summary> private static List <StateTransition> GetTransitions(IWorkItemType workItemType) { List <StateTransition> currentTransitions; // See if this WorkItemType has already had it's transitions figured out. AllTransitions.TryGetValue(workItemType, out currentTransitions); if (currentTransitions != null) { return(currentTransitions); } // Get this worktype type as xml XmlDocument workItemTypeXml = workItemType.Export(false); // Create a dictionary to allow us to look up the "to" state using a "from" state. var newTransistions = new List <StateTransition>(); // get the transitions node. XmlNodeList transitionsList = workItemTypeXml.GetElementsByTagName("TRANSITIONS"); // As there is only one transitions item we can just get the first XmlNode transitions = transitionsList[0]; // Iterate all the transitions foreach (XmlNode transitionXML in transitions.Cast <XmlNode>()) { // See if we have this from state already. string fromState = transitionXML.Attributes["from"].Value; StateTransition transition = newTransistions.Find(trans => trans.From == fromState); if (transition != null) { transition.To.Add(transitionXML.Attributes["to"].Value); } else { // If we could not find this state already then add it. // save off the transition (from first so we can look up state progression. newTransistions.Add(new StateTransition { From = transitionXML.Attributes["from"].Value, To = new List <string> { transitionXML.Attributes["to"].Value } }); } } // Save off this transition so we don't do it again if it is needed. AllTransitions.Add(workItemType, newTransistions); return(newTransistions); }
public WorkItem( [NotNull] Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem item, [NotNull] IWorkItemType wit, [NotNull] Func <string, IWorkItemLinkType> linkFunc) : base(wit) { Contract.Requires(item != null); Contract.Requires(wit != null); Contract.Requires(linkFunc != null); _item = item ?? throw new ArgumentNullException(nameof(item)); _linkFunc = linkFunc ?? throw new ArgumentNullException(nameof(linkFunc)); Url = _item.Url; _uri = new Uri(_item.Url, UriKind.Absolute); }
public MockWorkItem([NotNull] IWorkItemType workItemType, [CanBeNull] Dictionary <string, object> fields = null) : base(workItemType, NormalizeFields(workItemType, fields)) { SetFieldValue(workItemType.FieldDefinitions[CoreFieldRefNames.WorkItemType], workItemType.Name); SetFieldValue(workItemType.FieldDefinitions[CoreFieldRefNames.RevisedDate], new DateTime(9999, 1, 1, 0, 0, 0)); if (IsNew) { _tempId = Interlocked.Decrement(ref tempId); } Links = new HashSet <ILink>(); Revisions = new HashSet <IRevision>(); ApplyRules(); }
public void Copy_UnitTest() { IWorkItemType targetType = default(IWorkItemType); IWorkItemCopyFlags flags = default(IWorkItemCopyFlags); ExecuteMethod( () => { return((IWorkItem)GetInstance()); }, instance => { targetType = WorkItemTypeWrapper_UnitTests.GetInstance(); flags = WorkItemCopyFlagsWrapper_UnitTests.GetInstance(); Copy_PreCondition(instance, ref targetType, ref flags); }, instance => { instance.Copy(targetType, flags); }, instance => { Copy_PostValidate(instance, targetType, flags); }); }
private static Dictionary <string, object> NormalizeFields(IWorkItemType type, Dictionary <string, object> fields) { if (fields == null) { return(null); } var retval = new Dictionary <string, object>(fields.Comparer); foreach (var field in fields) { var fieldDef = type.FieldDefinitions[field.Key]; retval.Add(fieldDef.ReferenceName, field.Value); } return(retval); }
public static IEnumerable <IWorkItem> NewWorkItems( [NotNull] this IWorkItemType wit, [InstantHandle][NotNull] IEnumerable <IEnumerable <KeyValuePair <string, object> > > values) { Contract.Requires(values != null); Contract.Requires(wit != null); if (wit == null) { throw new ArgumentNullException(nameof(wit)); } if (values == null) { throw new ArgumentNullException(nameof(values)); } return(values.Select(wit.NewWorkItem)); }
public static IWorkItem NewWorkItem([NotNull] this IWorkItemType wit, [CanBeNull] IEnumerable <KeyValuePair <string, object> > values) { Contract.Requires(wit != null); if (wit == null) { throw new ArgumentNullException(nameof(wit)); } var wi = wit.NewWorkItem(); if (values == null) { return(wi); } foreach (var kvp in values) { wi[kvp.Key] = kvp.Value; } return(wi); }
/// <summary> /// Used to find the next state on our way to a destination state. /// (Meaning if we are going from a "Not-Started" to a "Done" state, /// we usually have to hit a "in progress" state first. /// </summary> /// <param name="wiType">Work item type</param> /// <param name="fromState">source state</param> /// <param name="toState">target state</param> /// <returns></returns> private static IEnumerable <string> FindNextState(IWorkItemType wiType, string fromState, string toState) { var map = new Dictionary <string, string>(); var edges = GetTransitions(wiType).ToDictionary(i => i.From, i => i.To); var q = new Queue <string>(); map.Add(fromState, null); q.Enqueue(fromState); while (q.Count > 0) { var current = q.Dequeue(); foreach (var s in edges[current]) { if (!map.ContainsKey(s)) { map.Add(s, current); if (s == toState) { var result = new Stack <string>(); var thisNode = s; do { result.Push(thisNode); thisNode = map[thisNode]; }while (thisNode != fromState); while (result.Count > 0) { yield return(result.Pop()); } yield break; } q.Enqueue(s); } } } }
public IWorkItem Copy(IWorkItemType targetType) { throw new NotImplementedException(); }
partial void Copy_PreCondition(IWorkItem instance, ref IWorkItemType targetType, ref IWorkItemCopyFlags flags);
partial void Copy_PostValidate(IWorkItem instance, IWorkItemType targetType, IWorkItemCopyFlags flags);
protected internal WorkItem([NotNull] IWorkItemType workItemType) { Contract.Requires(workItemType != null); _type = workItemType ?? throw new ArgumentNullException(nameof(workItemType)); }
partial void DefaultWorkItemType_SetCondition(ref ICategory instance, ref IWorkItemType setValue);
partial void Export_PreCondition(IWorkItemType instance, ref Boolean includeGlobalListsFlag);
partial void DisplayForm_SetCondition(ref IWorkItemType instance, ref String setValue);
partial void NewWorkItem_PostValidate(IWorkItemType instance);
/// <summary> /// Used to find the next state on our way to a destination state. /// (Meaning if we are going from a "Not-Started" to a "Done" state, /// we usually have to hit a "in progress" state first. /// </summary> /// <param name="wiType">Work item type</param> /// <param name="fromState">source state</param> /// <param name="toState">target state</param> /// <returns></returns> private static IEnumerable<string> FindNextState(IWorkItemType wiType, string fromState, string toState) { var map = new Dictionary<string, string>(); var edges = GetTransitions(wiType).ToDictionary(i => i.From, i => i.To); var q = new Queue<string>(); map.Add(fromState, null); q.Enqueue(fromState); while (q.Count > 0) { var current = q.Dequeue(); foreach (var s in edges[current]) { if (!map.ContainsKey(s)) { map.Add(s, current); if (s == toState) { var result = new Stack<string>(); var thisNode = s; do { result.Push(thisNode); thisNode = map[thisNode]; } while (thisNode != fromState); while (result.Count > 0) { yield return result.Pop(); } yield break; } q.Enqueue(s); } } } }
partial void GetNextState_PreCondition(IWorkItemType instance, ref String currentState, ref String action);
partial void GetNextState_PostValidate(IWorkItemType instance, String currentState, String action);
partial void FieldDefinitions_SetCondition(ref IWorkItemType instance, ref IFieldDefinitionCollection setValue);
/// <summary> /// Copies the specified target type. /// </summary> /// <param name="targetType">Type of the target.</param> /// <param name="flags">The flags.</param> /// <returns>IWorkItem.</returns> /// <exception cref="ToBeImplementedException"></exception> IWorkItem IWorkItem.Copy(IWorkItemType targetType, IWorkItemCopyFlags flags) { throw new ToBeImplementedException(); }
public static IWorkItemStore Store([CanBeNull] this IWorkItemType type) { var t = type as MockWorkItemType; return(t?.Store); }
/// <summary> /// Copies the specified target type. /// </summary> /// <param name="targetType">Type of the target.</param> /// <returns>IWorkItem.</returns> /// <exception cref="ToBeImplementedException"></exception> IWorkItem IWorkItem.Copy(IWorkItemType targetType) { throw new ToBeImplementedException(); }
/// <summary> /// Get the transitions for this <see cref="WorkItemType"/> /// </summary> private static List<StateTransition> GetTransitions(IWorkItemType workItemType) { List<StateTransition> currentTransitions; // See if this WorkItemType has already had it's transitions figured out. AllTransitions.TryGetValue(workItemType, out currentTransitions); if (currentTransitions != null) { return currentTransitions; } // Get this worktype type as xml XmlDocument workItemTypeXml = workItemType.Export(false); // Create a dictionary to allow us to look up the "to" state using a "from" state. var newTransistions = new List<StateTransition>(); // get the transitions node. XmlNodeList transitionsList = workItemTypeXml.GetElementsByTagName("TRANSITIONS"); // As there is only one transitions item we can just get the first XmlNode transitions = transitionsList[0]; // Iterate all the transitions foreach (XmlNode transitionXML in transitions.Cast<XmlNode>()) { // See if we have this from state already. string fromState = transitionXML.Attributes["from"].Value; StateTransition transition = newTransistions.Find(trans => trans.From == fromState); if (transition != null) { transition.To.Add(transitionXML.Attributes["to"].Value); } else { // If we could not find this state already then add it. // save off the transition (from first so we can look up state progression. newTransistions.Add(new StateTransition { From = transitionXML.Attributes["from"].Value, To = new List<string> { transitionXML.Attributes["to"].Value } }); } } // Save off this transition so we don't do it again if it is needed. AllTransitions.Add(workItemType, newTransistions); return newTransistions; }
partial void Project_SetCondition(ref IWorkItemType instance, ref IProject setValue);
partial void Export_PostValidate(IWorkItemType instance, Boolean includeGlobalListsFlag);
partial void NewWorkItem_PreCondition(IWorkItemType instance);
partial void Store_SetCondition(ref IWorkItemType instance, ref IWorkItemStore setValue);