Exemplo n.º 1
0
        public IEnumerable <ActivityDependency> Read()
        {
            ProjectReader reader = ProjectReaderUtility.getProjectReader(filename);
            ProjectFile   mpx    = reader.read(filename);


            var actDependnecies = new List <ActivityDependency>();

            foreach (net.sf.mpxj.Task task in mpx.AllTasks.ToIEnumerable())
            {
                var id         = task.ID.intValue();
                var duration   = task.Duration.Duration;
                var totalSlack = task.TotalSlack.Duration;

                var predecessors = new List <int>();
                var preds        = task.Predecessors;
                if (preds != null && !preds.isEmpty())
                {
                    foreach (Relation pred in preds.ToIEnumerable())
                    {
                        predecessors.Add(pred.TargetTask.ID.intValue());
                    }
                }

                actDependnecies.Add(
                    new ActivityDependency(
                        new Activity(id, Convert.ToInt32(duration), Convert.ToInt32(totalSlack)), predecessors
                        )
                    );
            }

            return(actDependnecies);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method performs a set of queries to retrieve information
        /// from the an MPP or an MPX file.
        /// </summary>
        /// <param name="filename">name of the project file</param>
        public static void query(String filename)
        {
            ProjectReader reader = ProjectReaderUtility.getProjectReader(filename);
            ProjectFile   mpx    = reader.read(filename);

            System.Console.WriteLine("MPP file type: " + mpx.MppFileType);

            listProjectHeader(mpx);

            listResources(mpx);

            listTasks(mpx);

            listAssignments(mpx);

            listAssignmentsByTask(mpx);

            listAssignmentsByResource(mpx);

            listHierarchy(mpx);

            listTaskNotes(mpx);

            listResourceNotes(mpx);

            listRelationships(mpx);

            listSlack(mpx);

            listCalendars(mpx);
        }
Exemplo n.º 3
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            ProjectReader reader = ProjectReaderUtility.getProjectReader(_filename);

            var oldCursor = Cursor;

            Cursor = Cursors.WaitCursor;

            _mpx = reader.read(_filename);

            Cursor = oldCursor;

            _projectTitle = System.IO.Path.GetFileName(_mpx.ProjectFilePath);

            btnFileOpen.Enabled = false;
            btnLoad.Enabled     = false;
            lblFileName.Enabled = false;

            txtProjectName.Text = _projectTitle;

            ParseMppFile();

            rbProject.Enabled      = true;
            rbTemplate.Enabled     = true;
            btnResources.Enabled   = true;
            btnImport.Enabled      = true;
            txtProjectName.Enabled = true;
        }
Exemplo n.º 4
0
 public void ReadFile(string Path)
 {
     if (!File.Exists(Path))
     {
         throw new IOException("File doesn/'t exist!");
     }
     ProjectFile = projectReader.read(Path);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Reads Microsoft® Project file and returns ProjectFile instance.
        /// </summary>
        /// <param name="mppFile">MPP file to read.</param>
        /// <returns></returns>
        protected ProjectFile readProjectFile(String mppFile)
        {
            //read project file in
            byte[] projFile = File.ReadAllBytes(mppFile);
            //get Java InputStream from file stream
            java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream(projFile);
            //get the reader
            ProjectReader reader = ProjectReaderUtility.getProjectReader(mppFile);

            //read the file out
            return(reader.read(bais));
        }
Exemplo n.º 6
0
        public void process(string inputFile, string outputFile)
        {
            Console.Out.WriteLine("Reading input file started.");
            DateTime      start       = DateTime.Now;
            ProjectReader reader      = ProjectReaderUtility.getProjectReader(inputFile);
            ProjectFile   projectFile = reader.read(inputFile);
            TimeSpan      elapsed     = DateTime.Now - start;

            Console.Out.WriteLine("Reading input file completed in " + elapsed.TotalMilliseconds + "ms.");

            Console.Out.WriteLine("Writing output file started.");
            start = DateTime.Now;
            ProjectWriter writer = ProjectWriterUtility.getProjectWriter(outputFile);

            writer.write(projectFile, outputFile);
            elapsed = DateTime.Now - start;
            Console.Out.WriteLine("Writing output completed in " + elapsed.TotalMilliseconds + "ms.");
        }
Exemplo n.º 7
0
 public MppXml(string localFileName)
 {
     try
     {
         string        xmlFileName = localFileName + ".xml";
         ProjectReader reader      = ProjectReaderUtility.getProjectReader(localFileName);
         ProjectFile   projectFile = reader.read(localFileName);
         ProjectWriter writer      = ProjectWriterUtility.getProjectWriter(xmlFileName);
         writer.write(projectFile, xmlFileName);
         XmlDocument tmpDoc = new XmlDocument();
         tmpDoc.Load(xmlFileName);
         xmlDocument = tmpDoc;
         File.Delete(localFileName);
         File.Delete(xmlFileName);
     }
     catch (Exception)
     {
     }
 }
        private static MicrosoftProjectDto ImportMicrosoftProject(string filename)
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                throw new ArgumentNullException(nameof(filename));
            }
            ProjectReader reader = ProjectReaderUtility.getProjectReader(filename);

            net.sf.mpxj.ProjectFile mpx = reader.read(filename);
            DateTime projectStart       = mpx.ProjectProperties.StartDate.ToDateTime();

            var resources = new List <ResourceDto>();

            foreach (var resource in mpx.Resources.ToIEnumerable <net.sf.mpxj.Resource>())
            {
                int id = resource.ID.intValue();
                if (id == 0)
                {
                    continue;
                }
                string name        = resource.Name;
                var    resourceDto = new ResourceDto
                {
                    Id = id,
                    IsExplicitTarget = true,
                    Name             = name,
                    DisplayOrder     = id,
                    ColorFormat      = new ColorFormatDto()
                };
                resources.Add(resourceDto);
            }

            var dependentActivities = new List <DependentActivityDto>();

            foreach (var task in mpx.Tasks.ToIEnumerable <net.sf.mpxj.Task>())
            {
                int id = task.ID.intValue();
                if (id == 0)
                {
                    continue;
                }
                string name     = task.Name;
                int    duration = Convert.ToInt32(task.Duration.Duration);

                DateTime?minimumEarliestStartDateTime = null;
                if (task.ConstraintType == net.sf.mpxj.ConstraintType.START_NO_EARLIER_THAN)
                {
                    //minimumEarliestStartTime = Convert.ToInt32((task.ConstraintDate.ToDateTime() - projectStart).TotalDays);
                    minimumEarliestStartDateTime = task.ConstraintDate.ToDateTime();
                }

                var targetResources = new List <int>();
                foreach (var resourceAssignment in task.ResourceAssignments.ToIEnumerable <net.sf.mpxj.ResourceAssignment>())
                {
                    if (resourceAssignment.Resource != null)
                    {
                        targetResources.Add(resourceAssignment.Resource.ID.intValue());
                    }
                }

                var dependencies = new List <int>();
                var preds        = task.Predecessors;
                if (preds != null && !preds.isEmpty())
                {
                    foreach (var pred in preds.ToIEnumerable <net.sf.mpxj.Relation>())
                    {
                        dependencies.Add(pred.TargetTask.ID.intValue());
                    }
                }
                var dependentActivityDto = new DependentActivityDto
                {
                    Activity = new ActivityDto
                    {
                        Id              = id,
                        Name            = name,
                        TargetResources = targetResources,
                        Duration        = duration,
                        MinimumEarliestStartDateTime = minimumEarliestStartDateTime
                    },
                    Dependencies         = dependencies,
                    ResourceDependencies = new List <int>()
                };
                dependentActivities.Add(dependentActivityDto);
            }
            return(new MicrosoftProjectDto
            {
                ProjectStart = projectStart,
                DependentActivities = dependentActivities.ToList(),
                Resources = resources.ToList()
            });
        }