internal static Sprint GetCommittedToSprint(Task task) 
     {
     HPMUniqueID uid = Session.TaskGetLinkedToSprint(task.RefTaskID);
     if (uid.m_ID != -1)
         return (Sprint) Task.GetTask(uid);
     else
         return null;
 }
 internal static List<User> GetAssignees(Task task)
 {
     List<User> assignees = new List<User>();
     HPMTaskResourceAllocationResource[] allocations = Session.TaskGetResourceAllocation(task.RefTaskID).m_Resources;
     foreach (HPMTaskResourceAllocationResource ra in allocations)
         assignees.Add(User.GetUser(ra.m_ResourceID));
     return assignees;
 }
        public static string Consumers(Task task)
        {
            if (!(task is Release))
                throw new NotAReleaseException();
            var linkedTasks = task.LinkedTasks.Where(m => m is ProductBacklogItem && IsTeamProject(m)).Distinct();

            var projects = linkedTasks.Select(t => t.Project.Name).Distinct();
            var teamNames = projects.Where(p => p.StartsWith(TEAM_PROJECT_PREFIX)).Select(p => p.Substring(TEAM_PROJECT_PREFIX.Length)).Distinct();
            return string.Join(";", teamNames);
        }
 public static string AggregatedStatus(Task feature)
 {
     var status = CalcAggregatedStatus(LinkedTasks(feature));
     var signoff = feature.GetCustomColumnValue(SIGNOFF);
     if (signoff == null)
         return status;
     if (status == "Completed")
         return signoff.ToString() == ACCEPTED ? status : "In progress";
     return status;
 }
 public static void writeHIDStatus(Task task)
 {
     HPMSDKInternalData hid = new HPMSDKInternalData();
     hid.m_Data = BitConverter.GetBytes(DateTime.Now.AddSeconds(5).ToLocalTime().Ticks);
     try
     {
         SessionManager.Session.TaskSetSDKInternalData(task.UniqueTaskID, "LastStatusUpdated", hid);
     }
     catch (HPMSdkException ee)
     {
         Console.WriteLine(ee.Message);
     }
 }
 public static string ChildCount(Task current_task)
 {
     if (!current_task.HasChildren)
         return "";
     int totalCount = 0;
     foreach (Task task in current_task.DeepChildren)
     {
         if (!task.HasChildren)
         {
             totalCount += 1;
         }
     }
     return totalCount.ToString();
 }
示例#7
0
        private void DoUpdate()
        {
            List <Task> targetItems = targetProjectView.Find(targetFind);
            List <Task> sourceItems = sourceProjectView.Find(targetFind);

            foreach (Hansoft.ObjectWrapper.Task targetTask in targetItems)
            {
                Hansoft.ObjectWrapper.Task sourceTask = sourceItems.FirstOrDefault(s => s.LinkedTasks.Contains(targetTask));
                if (sourceTask != null)
                {
                    foreach (ColumnMapping mapping in columnMappings)
                    {
                        // TODO: Simplify the sequence below
                        if (mapping.SourceColumn.IsCustomColumn && mapping.TargetColumn.IsCustomColumn && (mapping.SourceColumn.CustomColumn.m_Type == mapping.TargetColumn.CustomColumn.m_Type))
                        {
                            targetTask.SetCustomColumnValue(mapping.TargetColumn.CustomColumn, CustomColumnValue.FromInternalValue(targetTask, mapping.TargetColumn.CustomColumn, sourceTask.GetCustomColumnValue(mapping.SourceColumn.CustomColumn).InternalValue));
                        }
                        else
                        {
                            object sourceValue;
                            if (mapping.SourceColumn.IsCustomColumn)
                            {
                                sourceValue = sourceTask.GetCustomColumnValue(mapping.SourceColumn.CustomColumn);
                            }
                            else
                            {
                                sourceValue = sourceTask.GetDefaultColumnValue(mapping.SourceColumn.DefaultColumnType);
                            }
                            if (mapping.TargetColumn.IsCustomColumn)
                            {
                                string endUserString;
                                if (sourceValue is float || sourceValue is double)
                                {
                                    endUserString = String.Format(new System.Globalization.CultureInfo("en-US"), "{0:F1}", sourceValue);
                                }
                                else
                                {
                                    endUserString = sourceValue.ToString();
                                }
                                targetTask.SetCustomColumnValue(mapping.TargetColumn.CustomColumn, endUserString);
                            }
                            else
                            {
                                targetTask.SetDefaultColumnValue(mapping.TargetColumn.DefaultColumnType, sourceValue);
                            }
                        }
                    }
                }
            }
        }
 public static string GetShadowValue(Task current_task, string shadowProjectName, string sourceDataBaseIDColumnName, string columnName)
 {
     try
     {
         List<Task> shadowTasks = new List<Task>(HPMUtilities.GetProjects().Find(project => project.Name == shadowProjectName).ProductBacklog.DeepChildren.Cast<Task>());
         Task shadowTask = shadowTasks.Find(shadow => shadow.GetCustomColumnValue(sourceDataBaseIDColumnName).ToInt() == current_task.UniqueID.m_ID);
         if (shadowTask != null)
             return shadowTask.GetCustomColumnValue(columnName).ToString();
         else
             return "";
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         throw e;
     }
 }
 public static string CompletionCount(Task current_task)
 {
     if (!current_task.HasChildren)
         return "";
     int totalCount = 0;
     int completedCount = 0;
     foreach (Task task in current_task.DeepChildren)
     {
         if (!task.HasChildren)
         {
             totalCount += 1;
             if ((EHPMTaskStatus)task.Status.Value == EHPMTaskStatus.Completed)
                 completedCount += 1;
         }
     }
     return completedCount.ToString() + "/" + totalCount.ToString();
 }
 internal static string AssignedAsString(Task task)
 {
     StringBuilder sb = new StringBuilder();
     HPMTaskResourceAllocationResource[] allocations = SessionManager.Session.TaskGetResourceAllocation(task.RefTaskID).m_Resources;
     for (int i = 0; i < allocations.Length; i += 1)
     {
         HPMUniqueID resourceId = allocations[i].m_ResourceID;
         int percentage = allocations[i].m_PercentAllocated;
         sb.Append(User.GetUser(resourceId).Name);
         if (percentage != 100)
         {
             sb.Append('[');
             sb.Append(percentage.ToString());
             sb.Append("]");
         }
         if (i < allocations.Length - 1)
             sb.Append(", ");
     }
     return sb.ToString();
 }
 private static bool NotComittedBacklogItem(Task t)
 {
     return t.GetType() == typeof(ProductBacklogItem);
 }
 private static bool SprintBacklogOnlyItem(Task t)
 {
     if (t.GetType() != typeof(SprintBacklogItem))
         return false;
     return ((SprintBacklogItem)t).IsOnlyInSprintBacklog;
 }
 private static bool LeafStatus(Task t, EHPMTaskStatus status)
 {
     return (EHPMTaskStatus)t.AggregatedStatus.Value == status;
 }
        private static IEnumerable<Task> LinkedTasks(Task feature, bool followTasks = false, bool followMilestones = true)
        {
            if (!(feature is ProductBacklogItem || feature is ScheduledTask || feature is Release))
                throw new NotAFeatureException();

            var linkedMilestones = followMilestones ? feature.LinkedTasks.Where(t => t is Release && IsTeamProject(t)) : new List<Task>();
            var linkedTasks = followTasks ? feature.LinkedTasks.Where(t => NotComittedBacklogItem(t) && IsTeamProject(t)) : new List<Task>();

            if (linkedMilestones.Count() == 0 && linkedTasks.Count() == 0)
                throw new UnlinkedException();

            var linkedMilestonesTasks = linkedMilestones
                .Cast<Release>()
                .SelectMany(ms => ms.GetSummary().dependentTasks)
                .Where(t => NotComittedBacklogItem(t) || SprintBacklogOnlyItem(t));
            var linkedMilestonesTasksChildren = linkedMilestonesTasks.SelectMany(t => t.DeepChildren.Cast<Task>());
            var linkedMilestonesTaskLeaves = linkedMilestonesTasks.Concat(linkedMilestonesTasksChildren).Where(t => !t.HasChildren);

            var linkedTasksChildren = linkedTasks.SelectMany(t => t.DeepChildren.Cast<Task>());
            var linkedTaskLeaves = linkedTasks.Concat(linkedTasksChildren).Where(t => !t.HasChildren);

            return linkedMilestonesTaskLeaves.Concat(linkedTaskLeaves).Where(t => (EHPMTaskStatus)t.AggregatedStatus.Value != EHPMTaskStatus.Deleted).Distinct();
        }
 private static bool IsTeamProject(Task task)
 {
     return task.Project.Name.StartsWith(TEAM_PROJECT_PREFIX);
 }
 private static bool LeafCompleted(Task t)
 {
     return t.IsCompleted || (EHPMTaskStatus)t.AggregatedStatus.Value == EHPMTaskStatus.Completed;
 }
 public static object PointsNotDone(Task feature)
 {
     try
     {
         return LinkedTasks(feature).Where(t => LeafStatus(t, EHPMTaskStatus.NotDone)).Select(t => t.Points).DefaultIfEmpty(0).Sum();
     }
     catch (UnlinkedException)
     {
         return "";
     }
 }
 public static object ItemsCount(Task feature)
 {
     try
     {
         return LinkedTasks(feature).Count();
     }
     catch (UnlinkedException)
     {
         return "";
     }
 }
 private void DoUpdateFromHistory(Task task, HPMDataHistory history)
 {
     // Ensure that we get the custom column of the right project
     HPMProjectCustomColumnsColumn actualCustomColumn = task.ProjectView.GetCustomColumn(trackingColumn.m_Name);
     DateTimeValue storedValue = (DateTimeValue)task.GetCustomColumnValue(actualCustomColumn);
     // ToInt64 will return the value as microseconds since 1970 Jan 1
     ulong storedHpmTime = storedValue.ToHpmDateTime();
     if (history.m_Latests.m_Time > storedHpmTime)
     {
         foreach (HPMDataHistoryEntry entry in history.m_HistoryEntries)
         {
             // Check if it is the status field
             if (entry.m_FieldID == 15)
             {
                 if (entry.m_Time > storedHpmTime)
                 {
                     storedHpmTime = entry.m_Time;
                     task.SetCustomColumnValue(trackingColumn, DateTimeValue.FromHpmDateTime(task, actualCustomColumn, storedHpmTime));
                 }
             }
         }
     }
 }
 public static object PointsNotCompleted(Task feature)
 {
     return LinkedTasks(feature).Where(t => !LeafCompleted(t)).Sum(t => t.Points);
 }
 internal void Apply(Task task)
 {
     if (isCustomColumn)
         task.SetCustomColumnValue(customColumn, defaultValue);
     else
     {
         task.SetDefaultColumnValue(defaultColumnType, defaultValue);
     }
 }
 public static bool IsCompleted(Task feature)
 {
     var tasks = LinkedTasks(feature);
     if (tasks.Count() == 0)
         return false;
     var completed = tasks.All(i => (EHPMTaskStatus)i.AggregatedStatus.Value == EHPMTaskStatus.Completed);
     var signoffValue = feature.GetCustomColumnValue(SIGNOFF);
     if (signoffValue == null)
         return completed;
     var signoff = signoffValue.ToString() == ACCEPTED;
     return completed && signoff;
 }
 public static object ItemsNotDone(Task feature)
 {
     try
     {
         return LinkedTasks(feature).Where(t => LeafStatus(t, EHPMTaskStatus.NotDone)).Count();
     }
     catch (UnlinkedException)
     {
         return "";
     }
 }
 private static string TeamName(Task task)
 {
     return task.Project.Name.Substring(TEAM_PROJECT_PREFIX.Length);
 }
 public static string Team(Task feature)
 {
     try
     {
         return String.Join(";", feature.LinkedTasks.Where(t => t is Release && IsTeamProject(t)).Select(t => TeamName(t)).Distinct());
     }
     catch (UnlinkedException)
     {
         return "";
     }
 }
 public static int Points(Task feature)
 {
     return LinkedTasks(feature).Sum(t => t.Points);
 }
 public static object ItemsCompleted(Task feature)
 {
     try
     {
         return LinkedTasks(feature).Where(t => LeafCompleted(t)).Count();
     }
     catch (UnlinkedException)
     {
         return "";
     }
 }
        public static string FeatureSummary(Task feature)
        {
            IEnumerable<Task> allTasks;
            try
            {
                allTasks = LinkedTasks(feature);
            }
            catch (UnlinkedException)
            {
                if (feature.GetCustomColumnValue("Planned sprint").ToString() != string.Empty)
                    feature.SetCustomColumnValue("Planned sprint", string.Empty);
                return string.Empty;
            }
            var projects = allTasks.Select(t => t.Project.Name).Distinct();
            var allPlannedSprints = new SortedSet<string>();
            var plannedIPSprint = false;

            var summary_builder = new StringBuilder();
            summary_builder.Append(string.Format(FEATURE_SUMMARY_LINE_FORMAT, FEATURE_SUMMARY_HEADINGS));
            summary_builder.Append(FEATURE_SUMMARY_HEADER_SEPARATOR);

            foreach (var project in projects)
            {
                var team = project.Substring(TEAM_PROJECT_PREFIX.Length);
                var teamShort = team.Substring(0, (team.Length > 14) ? 13 : team.Length) + ((team.Length > 14) ? "…" : "");
                var tasks = allTasks.Where(t => t.Project.Name == project);
                var status = CalcAggregatedStatus(tasks);
                var completedPoints = tasks.Where(t => LeafCompleted(t)).Sum(t => t.Points);
                var totalPoints = tasks.Sum(t => t.Points);
                var completedStories = tasks.Where(t => LeafCompleted(t)).Count();
                var totalStories = tasks.Count();
                var plannedSprints = tasks
                    .Where(t => !LeafCompleted(t))
                    .Select(t => t.GetCustomColumnValue("Planned sprint"))
                    .Where(sprintColumn => sprintColumn != null)
                    .Select(sprintColumn => sprintColumn.ToString())
                    .Where(sprint => sprint.Length != 0)
                    .Distinct()
                    .OrderBy(sprint => sprint);
                var plannedSprintsString = plannedSprints.Aggregate(
                        new StringBuilder(),
                        (sb, sprint) => sb.Append(sprint).Append(", "),
                        sb => sb.Length > 0 ? sb.ToString(0, sb.Length-2) : "");
                var productOwner = ProductOwnerConfig.GetProductOwner(team, "unknown");
                var productOwnerShort = productOwner.Substring(0, (productOwner.Length > 14) ? 13 : productOwner.Length) + ((productOwner.Length > 14) ? "…" : "");

                summary_builder.AppendFormat(FEATURE_SUMMARY_LINE_FORMAT,
                    teamShort, status, completedPoints + "/" + totalPoints, completedStories + "/" + totalStories, productOwnerShort, plannedSprintsString);

                if (plannedSprintsString.Length > 0)
                {
                    if (!plannedIPSprint && plannedSprints.Where(t => t == "IP").Any())
                        plannedIPSprint = true;
                    var maxPlannedSprint = plannedSprints.Where(t => t.StartsWith("S")).Max();
                    allPlannedSprints.Add(maxPlannedSprint);
                }
            }

            if (plannedIPSprint)
                feature.SetCustomColumnValue("Planned sprint", "IP");
            else if (allPlannedSprints.Count() > 0)
                feature.SetCustomColumnValue("Planned sprint", allPlannedSprints.Max());

            return summary_builder.ToString();
        }
 public static object PointsCompleted(Task feature)
 {
     try
     {
         return LinkedTasks(feature).Where(t => LeafCompleted(t)).Sum(t => t.Points);
     }
     catch (UnlinkedException)
     {
         return "";
     }
 }
 private EHPMTaskWallItemColor? GetColor(Task task)
 {
     var type = task.GetCustomColumnValue("Type");
     if (type == null)
         return null;
     var color = TypeColorConfig.GetTypeColor(type.ToString());
     if (color == null)
         return EHPMTaskWallItemColor.Orange;
     switch (color)
     {
         case "Yellow":
             return EHPMTaskWallItemColor.Yellow;
         case "Blue":
             return EHPMTaskWallItemColor.Blue;
         case "Green":
             return EHPMTaskWallItemColor.Green;
         case "Red":
             return EHPMTaskWallItemColor.Red;
         case "Magenta":
             return EHPMTaskWallItemColor.Magenta;
         case "Orange":
             return EHPMTaskWallItemColor.Orange;
     }
     return null;
 }
 public static object PointsCount(Task feature)
 {
     try
     {
         return LinkedTasks(feature).Select(t => t.Points).DefaultIfEmpty(0).Sum();
     }
     catch (UnlinkedException)
     {
         return "";
     }
 }