// note this is recursive and can skip ahead on the index value returned
        public int ParseSummaryTasks(Innovator inn, ref List <WbsElement> output, List <Task> tasks, int taskIndexIn, string parentID)
        {
            var taskIndex = taskIndexIn;
            var task      = tasks[taskIndex];

            if (!task.Summary)
            {
                throw new Exception("ParseSummaryTask Invalid param: Not a summary task");
            }

            var wbse = new WbsElement
            {
                ArasID       = inn.getNewID(),
                Name         = task.Name,
                ParentMppID  = parentID,
                OrigMppIndex = task.ID.intValue()
            };

            output.Add(wbse);

            ++taskIndex;

            foreach (Task child in task.ChildTasks.ToIEnumerable())
            {
                taskIndex = ParseTasks(inn, ref output, tasks, taskIndex, wbse.ArasID);
                //_backgroundWorker.ReportProgress(taskIndex);
            }

            // add a milestone to mark the end of this summary task
            var wbsMilestone = new WbsActivityElement
            {
                ArasID             = inn.getNewID(),
                Name               = task.Name + " completed",
                ParentMppID        = wbse.ArasID,
                OrigMppIndex       = task.ID.intValue(),
                Description        = task.Notes,
                WorkEst            = 0,
                DateStart          = task.Finish.ToDateTime(),
                DateDueTarget      = task.Finish.ToDateTime(),
                ExpectedDuration   = 0,
                PercentComplete    = 0,
                IsMilestone        = true,
                IsSummaryMilestone = true
            };

            wbse.SummaryMilestoneID = wbsMilestone.ArasID;
            output.Add(wbsMilestone);

            //_backgroundWorker.ReportProgress(taskIndex);
            return(taskIndex);
        }
        public int ParseTask(Innovator inn, ref List <WbsElement> output, List <Task> tasks, int taskIndex, string parentID)
        {
            var task = tasks[taskIndex];

            if (task.Summary)
            {
                throw new Exception("ParseTask Invalid param: Is a summary task");
            }

            var wbs = new WbsActivityElement
            {
                ArasID       = inn.getNewID(),
                Name         = task.Name,
                ParentMppID  = parentID,
                OrigMppIndex = task.ID.intValue(),
                Description  = task.Notes,
                //WorkEst = task.Milestone ? 0 : Math.Round(task.Work.Duration / 60, 0),
                WorkEst            = task.Milestone ? 0 : Math.Round(task.Work.Duration, 0),
                DateStart          = task.Milestone ? task.Finish.ToDateTime() : task.Start.ToDateTime(),
                DateDueTarget      = task.Finish.ToDateTime(),
                ExpectedDuration   = task.Milestone ? 0 : Math.Round(task.Duration.Duration, 0),
                PercentComplete    = task.PercentageComplete.ToNullableDecimal() != null ? (decimal)task.PercentageComplete.ToNullableDecimal() : 0,
                IsMilestone        = task.Milestone,
                IsSummaryMilestone = false
            };

            // dependencies can be forward so we have to resolve them in another iteration

            output.Add(wbs);
            //_backgroundWorker.ReportProgress(taskIndex + 1);
            return(taskIndex + 1);
        }
Beispiel #3
0
        private void ParseMppFile()
        {
            try
            {
                _wbsOutput = new List <ArasHelpers.WbsElement>();
                var ahelper = new ArasHelpers();

                var tasks   = _mpx.AllTasks.ToTaskList();
                var wbsRoot = _inn.getNewID();

                for (var i = 0; i < tasks.Count; i++)
                {
                    i = ahelper.ParseTasks(_inn, ref _wbsOutput, tasks, i, wbsRoot);
                }

                // parse dependencies.  has to be another iteration because dependencies can be forward references

                foreach (var wbs in _wbsOutput)
                {
                    var ele      = wbs; // looks weird but needed to pass by reference
                    var origID   = ele.OrigMppIndex;
                    var origTask = (from ts in tasks where ts.ID.intValue() == origID select ts).FirstOrDefault();
                    if (origTask != null)
                    {
                        ahelper.ParsePredecessors(_wbsOutput, origTask, ref ele);
                    }
                }


                // parse assignments
                foreach (var wbs in _wbsOutput)
                {
                    var ele      = wbs; // looks weird but needed to pass by reference
                    var origID   = ele.OrigMppIndex;
                    var origTask = (from ts in tasks where ts.ID.intValue() == origID select ts).FirstOrDefault();
                    if (origTask != null)
                    {
                        ahelper.ParseAssignments(_wbsOutput, origTask, ref ele);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("MPP Parser error:" + ex.Message, "Failed", MessageBoxButtons.OK);
                Application.Exit();
            }
        }
Beispiel #4
0
        public string CallAction(string action, string input, IProgressCallback progressReporter)
        {
            XmlNode     fault;
            XmlDocument outputDoc = null;
            var         inputDoc  = new XmlDocument();

            inputDoc.LoadXml(input);
            if (_userInfo == null)
            {
                _userInfo = _inn.applyAML(string.Format("<AML><Item type='User' action='get' select='default_vault' expand='1'><id>{0}</id><Relationships><Item type='ReadPriority' action='get' select='priority, related_id' expand='1' orderBy='priority'/></Relationships></Item></AML>", _inn.getUserID()));
            }

            if (action == "ApplyItem" || action == "ApplyAML")
            {
                var     fileNodes = XPathCache.SelectNodes("descendant-or-self::Item[@type='File' and (@action='add' or @action='update' or @action='create') and actual_filename]", inputDoc.DocumentElement);
                XmlNode locatedNode;
                if (fileNodes.Count > 0)
                {
                    Item fileItem = _inn.newItem();
                    foreach (var fileNode in fileNodes.OfType <XmlElement>())
                    {
                        if (string.IsNullOrEmpty(fileNode.Attribute("id")))
                        {
                            fileNode.Attr("id", _inn.getNewID());
                        }
                        fileNode.Elem("checkedout_path", Path.GetDirectoryName(fileNode.Element("actual_filename", "")));
                        fileNode.Elem("filename", Path.GetFileName(fileNode.Element("actual_filename", "")));
                        locatedNode = XPathCache.SelectSingleNode("Relationships/Item[@type='Located']/related_id", fileNode);
                        if (locatedNode == null)
                        {
                            fileItem.dom      = inputDoc;
                            fileItem.node     = (XmlElement)fileNode;
                            fileItem.nodeList = null;
                            fileItem.attachPhysicalFile(fileNode.Element("actual_filename", ""), _userInfo.getProperty("default_vault"));
                        }
                    }

                    var firstItem = XPathCache.SelectSingleNode("//Item[1]", inputDoc.DocumentElement);
                    IList <XmlElement> items;
                    if (firstItem.ParentNode == null)
                    {
                        items = new XmlElement[] { (XmlElement)firstItem };
                    }
                    else
                    {
                        items = firstItem.Parent().Elements("Item").ToList();
                    }

                    Item       result;
                    XmlElement resultNode = null;

                    for (var i = 0; i < items.Count; i++)
                    {
                        fileItem.dom      = items[i].OwnerDocument;
                        fileItem.node     = items[i];
                        fileItem.nodeList = null;
                        result            = fileItem.apply();
                        fault             = XPathCache.SelectSingleNode(faultXPath, result.dom.DocumentElement);
                        if (fault != null)
                        {
                            fault.AppendChild(result.dom.CreateElement("original_query")).InnerText = input;
                            return(result.dom.DocumentElement.OuterXml);
                        }
                        else if (result.isError())
                        {
                            throw new InvalidOperationException();
                        }

                        if (outputDoc == null)
                        {
                            outputDoc  = result.dom;
                            resultNode = XPathCache.SelectSingleNode("//Item[1]", outputDoc.DocumentElement).Parent() as XmlElement;
                        }
                        else
                        {
                            resultNode.AppendChild(outputDoc.ImportNode(result.node, true));
                        }

                        if (progressReporter != null)
                        {
                            progressReporter.ReportProgress(i + 1, items.Count);
                        }
                    }

                    return(outputDoc.OuterXml);
                }
            }

            outputDoc = new XmlDocument();
            outputDoc.Elem("Empty");
            _inn.getConnection().CallAction(action, inputDoc, outputDoc);
            fault = XPathCache.SelectSingleNode(faultXPath, outputDoc.DocumentElement);
            if (fault != null)
            {
                fault.AppendChild(outputDoc.CreateElement("original_query")).InnerText = input;
            }
            return(outputDoc.DocumentElement.OuterXml);
        }
 public string GetNewId()
 {
     return(Innovator.getNewID());
 }