private MppTask GetTask(Mpxj.Task task)
            {
                if (task != null)
                {
                    java.util.Date taskStartDate        = task.Start;
                    java.util.Date taskFinishDate       = task.Finish;
                    java.util.Date taskActualStartDate  = task.ActualStart;
                    java.util.Date taskActualFinishDate = task.ActualFinish;
                    java.util.Date taskConstraintDate   = task.ConstraintDate;

                    Mpxj.Task      parentTask   = task.ParentTask;
                    java.util.List predecessors = task.Predecessors;
                    MppTask        returnTask   = new MppTask();

                    returnTask.Id             = task.ID.longValue();
                    returnTask.UniqueId       = task.UniqueID.longValue();
                    returnTask.ParentTaskId   = (parentTask == null) ? -1 : parentTask.UniqueID.longValue();
                    returnTask.ConstraintType = (MppConstraintType)task.ConstraintType.Value;

                    returnTask.Name = task.Name;

                    returnTask.StartDate        = Utility.GetDateTimme(taskStartDate);
                    returnTask.ConstraintDate   = Utility.GetDateTimme(taskConstraintDate);
                    returnTask.FinishDate       = Utility.GetDateTimme(taskFinishDate);
                    returnTask.ActualStartDate  = Utility.GetDateTimme(taskActualStartDate);
                    returnTask.ActualFinishDate = Utility.GetDateTimme(taskActualFinishDate);

                    returnTask.PercentageComplete = task.PercentageComplete.doubleValue();
                    returnTask.Priority           = (MppPriority)task.Priority.Value;
                    returnTask.ResourceNames      = task.ResourceNames;
                    returnTask.Notes = task.Notes;

                    if (predecessors != null)
                    {
                        for (int i = 0; i < predecessors.size(); i++)
                        {
                            Relation relation = predecessors.get(i) as Mpxj.Relation;
                            if (relation != null)
                            {
                                returnTask.PredecessorTaskIds.Add(relation.TargetTask.ID.longValue());
                            }
                        }
                    }

                    java.util.List resourcesList = task.ResourceAssignments;
                    Mpxj.Resource  resource      = null;

                    for (int i = 0; i < resourcesList.size(); i++)
                    {
                        resource = ((Mpxj.ResourceAssignment)resourcesList.get(i)).Resource as Mpxj.Resource;
                        returnTask.Resources.Add(GetResource(resource, false));
                    }


                    return(returnTask);
                }

                return(null);
            }
 private void PopulateTasks(ProjectFile projectFile, MppProject project)
 {
     java.util.List tasksList = projectFile.AllTasks;
     Mpxj.Task      task      = null;
     for (int i = 0; i < tasksList.size(); i++)
     {
         task = tasksList.get(i) as Mpxj.Task;
         project.AllTasks.Add(GetTask(task));
     }
     BuildTaskHiererchy(project);
 }
示例#3
0
        public static Resource GetResource(this MpTask tsk)
        {
            var ResAs = tsk.getResourceAssignments();

            if (ResAs.size() == 0)
            {
                return(null);
            }

            var ResA = ResAs.get(0) as ResourceAssignment;
            var Reso = ResA.getResource();

            var Res = new Resource()
            {
                Finisher    = Reso.getName().ToMan(),
                FinishedPhs = ResA.getFinish().ToDt(),
                StartedPhs  = ResA.getStart().ToDt()
            };

            return(Res);
        }
示例#4
0
        public void ParseAssignments(List <WbsElement> output, Task origTask, ref WbsElement ele)
        {
            var resAssigns = new List <WbsResourceAssignment>();

            // check if this is a newly created milestone
            var element = ele as WbsActivityElement;

            if (element != null)
            {
                if (!element.IsSummaryMilestone)
                {
                    foreach (ResourceAssignment res in origTask.ResourceAssignments.ToIEnumerable())
                    {
                        try
                        {
                            if (res.Resource != null)
                            {
                                var wbsa = new WbsResourceAssignment
                                {
                                    AssignmentResourceName = res.Resource.Name,
                                    AssignmentPrecentLoad  =
                                        res.PercentageWorkComplete == null ? 0 : Math.Round((decimal)res.PercentageWorkComplete.ToNullableDecimal(), 0),
                                    AssignmentWorkEst =
                                        res.ActualWork != null?Math.Round(res.ActualWork.Duration, 0) : 0
                                };
                                resAssigns.Add(wbsa);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw;
                        }
                    }
                    element.ResourceAssigns = resAssigns;
                }
            }
        }
示例#5
0
        /// <summary>
        ///  Task. 得到所有前置任务。
        ///  0:主任务,1:后续,2:1的后续, ……
        /// </summary>
        public static List <uint> GetPredIds(this MpTask tsk)
        {
            List <uint> Ret = new List <uint>();
            MpTask      Tsk = tsk;

            java.util.List Ps = Tsk.getPredecessors();

            while (Ps.size() > 0)
            {
                var Rel = Ps.get(0) as Relation;
                Tsk = Rel.getTargetTask();

                var TId = Tsk.getID().ToString().ToUint();
                if (TId <= 0)
                {
                    continue;
                }

                Ret.Add(TId);
                Ps = Tsk.getPredecessors();
            }
            Ret.Reverse();
            return(Ret);
        }
示例#6
0
        public static List <MpTask> GetChildTasks(this MpTask tsk)
        {
            var tasks = tsk.getChildTasks();

            return(GetSubTasks(tasks));
        }
示例#7
0
        public void ParsePredecessors(List <WbsElement> output, Task origTask, ref WbsElement ele)
        {
            var preds = new List <WbsPredecessor>();

            // check if this is a newly created milestone
            var element = ele as WbsActivityElement;

            if (element != null)
            {
                if (element.IsSummaryMilestone)
                {
                    //Task prevNonSummary = null;
                    var milestoneIndx = output.Count - 1;

                    for (var pndx = milestoneIndx; pndx >= 0; --pndx)
                    {
                        var findThisTask = output[pndx];

                        if (findThisTask.ArasID == ele.ArasID)
                        {
                            --pndx; // skip the fake milestone
                            // find previous non-summary task
                            while (pndx >= 0)
                            {
                                var findNonSumTask = output[pndx];
                                if (findNonSumTask is WbsActivityElement)
                                {
                                    // found the one and only dependency
                                    var wbsPred = new WbsPredecessor
                                    {
                                        PrecedenceType = getPredType("FS"),
                                        LeadLag        = 0,
                                        RelatedArasID  = findNonSumTask.ArasID,
                                    };
                                    preds.Add(wbsPred);
                                    pndx = 0;
                                    break;
                                }
                                --pndx;
                            }
                        }
                    }
                }
                else // normal task
                {
                    foreach (Relation pred in origTask.Predecessors.ToIEnumerable())
                    {
                        var iPred     = pred.TargetTask.ID.intValue();
                        var linkedWbs = (from o in output where o.OrigMppIndex == iPred select o).FirstOrDefault();
                        if (linkedWbs != null)
                        {
                            var wbsp = new WbsPredecessor
                            {
                                PrecedenceType = getPredType(pred.Type.toString()),
                                RelatedArasID  = linkedWbs.SummaryMilestoneID != null ? linkedWbs.SummaryMilestoneID : linkedWbs.ArasID,
                                //LeadLag = Math.Round(pred.Lag.Duration / 60 / 8, 0)
                                LeadLag = Math.Round(pred.Lag.Duration, 0)
                            };
                            preds.Add(wbsp);
                        }
                    }
                }
            }
            else // WBS (folder)
            {
                foreach (Relation pred in origTask.Predecessors.ToIEnumerable())
                {
                    var iPred     = pred.TargetTask.ID.intValue();
                    var linkedWbs = (from o in output where o.OrigMppIndex == iPred select o).FirstOrDefault();
                    if (linkedWbs != null)
                    {
                        var wbsp = new WbsPredecessor
                        {
                            PrecedenceType = getPredType(pred.Type.toString()),
                            //RelatedArasID = linkedWbs.ArasID,
                            RelatedArasID = linkedWbs.SummaryMilestoneID != null ? linkedWbs.SummaryMilestoneID : linkedWbs.ArasID,
                            //LeadLag = Math.Round(pred.Lag.Duration / 60 / 8, 0)
                            LeadLag = Math.Round(pred.Lag.Duration, 0)
                        };
                        preds.Add(wbsp);
                    }
                }
            }
            ele.Preds = preds;
        }