/// <summary>
 /// Return the total detail estimate for all workitems owned by this member optionally filtered
 /// </summary>
 /// <param name="filter">Criteria to filter workitems on.</param>
 /// <returns></returns>
 public double? GetTotalDone(WorkitemFilter filter) {
     return GetSum("OwnedWorkitems", filter ?? new WorkitemFilter(), "Actuals.Value");
 }
 /// <summary>
 /// Return the total detail estimate for all workitems owned by this member optionally filtered
 /// </summary>
 /// <param name="filter">Criteria to filter workitems on.</param>
 /// <returns></returns>
 public double? GetTotalDetailEstimate(WorkitemFilter filter) {
     return GetSum("OwnedWorkitems", filter ?? new WorkitemFilter(), "DetailEstimate");
 }
 /// <summary>
 /// Return the total to do for all workitems owned by this member optionally filtered
 /// </summary>
 /// <param name="filter">Criteria to filter workitems on.</param>
 /// <returns></returns>
 public double? GetTotalToDo(WorkitemFilter filter) {
     return GetSum("OwnedWorkitems", filter ?? new WorkitemFilter(), "ToDo");
 }
 /// <summary>
 /// Gets the estimate of total effort required to implement this Feature Group.
 /// </summary>
 /// <param name="filter">filter for WorkitemFilter (If null, then all items returned).</param>
 /// <returns>estimate of total effort required to implement this Feature Group.</returns>
 public double? GetTotalDetailEstimate(WorkitemFilter filter) {
     return GetSum("ChildrenMeAndDown", filter ?? new WorkitemFilter(), "DetailEstimate");
 }
 /// <summary>
 /// Gets the total remaining effort required to complete implementation of this Feature Group.
 /// </summary>
 /// <param name="filter">restriction for the work items which have to be counted. 
 /// If null, then all items counted.</param>
 /// <returns>total remaining effort required to complete implementation of this Feature Group.</returns>
 public double? GetTotalToDo(WorkitemFilter filter) {
     return GetSum("ChildrenMeAndDown", filter ?? new WorkitemFilter(), "ToDo");
 }
        public void ExcludeThemesEpicsAndTemplates() {
            var root = SandboxProject.ParentProject;

            var wiFilter = new WorkitemFilter();
			wiFilter.State.Add(State.Active);

            var workitems = Instance.Get.Workitems(wiFilter);
            var totalEstimate = workitems.Where(workitem => workitem.DetailEstimate != null)
                                         .Sum(workitem => workitem.DetailEstimate.HasValue ? workitem.DetailEstimate.Value : 0);

			Assert.AreEqual(totalEstimate, root.GetTotalDetailEstimate(wiFilter, true));
		}
        /// <summary>
        /// Resolve a check-in comment identifier to a PrimaryWorkitem.
        /// </summary>
        /// <param name="reference">The identifier in the check-in comment.</param>
        /// <returns>A collection of matching PrimaryWorkitems.</returns>
        /// <remarks>If the reference matches a SecondaryWorkitem, we need to navigate to the parent.</remarks>
        private IEnumerable<PrimaryWorkitem> ResolveReference(string reference) {
            List<PrimaryWorkitem> result = new List<PrimaryWorkitem>();

            WorkitemFilter filter = new WorkitemFilter();
            filter.Find.SearchString = reference;
            filter.Find.Fields.Add(ReferenceField);
            IEnumerable<Workitem> workitems = Instance.Get.Workitems(filter);
            foreach(Workitem workitem in workitems) {
                if(workitem is PrimaryWorkitem) {
                    result.Add((PrimaryWorkitem)workitem);
                } else if(workitem is SecondaryWorkitem)
                {
                    result.Add((PrimaryWorkitem)((SecondaryWorkitem)workitem).Parent);
                } else {
                    // Shut 'er down, Clancy, she's pumping mud.
                    throw new ApplicationException(string.Format("Found unexpected Workitem type: {0}", workitem.GetType()));
                }
            }

            Trace("Associated {0} PrimaryWorkitem(s) with {1}.", result.Count, reference);

            return result;
        }
 /// <summary>
 /// Gets the total effort already expended to implement this item.
 /// </summary>
 /// <param name="filter"></param>
 /// <returns></returns>
 public double? GetTotalDone(WorkitemFilter filter) {
     return GetSum("ChildrenMeAndDown", filter ?? new WorkitemFilter(), "Actuals.Value");
 }