static void Main(string[] args)
        {
            Project prj = new Project("Project.mpp");

            //Declare ChildTasksCollector class object
            ChildTasksCollector collector = new ChildTasksCollector();

            //Use TaskUtils to get all children tasks in RootTask
            TaskUtils.Apply(prj.RootTask, collector, 0);

            //Define Resources
            ArrayList resources = new ArrayList();
            for (int i = 1; i <= 5; i++)
            {
                string devloper = "Developer0" + i;
                //Create resource
                Resource rec = new Resource(devloper);
                rec.Type = ResourceType.Work;

                //Add resource to project
                prj.Resources.Add(rec);

                //define assignment
                ResourceAssignment ra = new ResourceAssignment((Aspose.Tasks.Task)collector.Tasks[i], rec);
                prj.ResourceAssignments.Add(ra);
            }

            prj.CalcResourceUids();
            prj.CalcResourceIds();
            prj.CalcResourceFields();
            prj.CalcResourceAssignmentUids();
            prj.CalcResourceAssignmentIds();

            prj.Save("Project1_CSharp_Aspose.mpp", Aspose.Tasks.Saving.SaveFileFormat.MPP);
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Beispiel #2
0
        public static void Run()
        {
            try
            {
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

                // ExStart:CreateResourcesAndLinkToTasks
                Project project1 = new Project(dataDir + "SampleProject.mpp");

                // Declare ChildTasksCollector class object
                ChildTasksCollector collector = new ChildTasksCollector();

                // Use TaskUtils to get all children tasks in RootTask
                TaskUtils.Apply(project1.RootTask, collector, 0);

                // Define Resources
                for (int i = 0; i <= 4; i++)
                {
                    string devloper = "Developer0" + i;

                    // Add resource to project
                    Resource newResource = project1.Resources.Add(devloper);
                    newResource.Set(Rsc.Type, ResourceType.Work);

                    // Define assignment
                    ResourceAssignment newResourceAssignment = project1.ResourceAssignments.Add((Task)collector.Tasks[i], newResource);
                }

                project1.Save(dataDir + "CreateResourcesAndLinkToTasks_out.mpp", SaveFileFormat.MPP);
                // ExEnd:CreateResourcesAndLinkToTasks
            }
            catch (NotSupportedException ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
Beispiel #3
0
 public static string InsertResourceAssignment(ResourceAssignment resourceAssignment)
 {
     resourceAssignment.ID = CreateUniqueId();
     ResourceAssignments.Add(resourceAssignment);
     return(resourceAssignment.ID);
 }
Beispiel #4
0
        public static void Run()
        {
            try
            {
                //ExStart:WriteMetadataToMPP
                string  dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
                Project project = new Project(dataDir + "Project1.mpp");

                // Add working times to project calendar
                WorkingTime wt = new WorkingTime();
                wt.FromTime = new DateTime(2010, 1, 1, 19, 0, 0);
                wt.ToTime   = new DateTime(2010, 1, 1, 20, 0, 0);
                WeekDay day = project.Get(Prj.Calendar).WeekDays.ToList()[1];
                day.WorkingTimes.Add(wt);

                // Change calendar name
                project.Get(Prj.Calendar).Name = "CHANGED NAME!";

                // Add tasks and set task meta data
                Task task = project.RootTask.Children.Add("Task 1");
                task.Set(Tsk.DurationFormat, TimeUnitType.Day);
                task.Set(Tsk.Duration, project.GetDuration(3));
                task.Set(Tsk.Contact, "Rsc 1");
                task.Set(Tsk.IsMarked, true);
                task.Set(Tsk.IgnoreWarnings, true);
                Task task2 = project.RootTask.Children.Add("Task 2");
                task2.Set(Tsk.DurationFormat, TimeUnitType.Day);
                task2.Set(Tsk.Contact, "Rsc 2");

                // Link tasks
                project.TaskLinks.Add(task, task2, TaskLinkType.FinishToStart, project.GetDuration(-1, TimeUnitType.Day));

                // Set project start date
                project.Set(Prj.StartDate, new DateTime(2013, 8, 13, 9, 0, 0));

                // Add resource and set resource meta data
                Resource rsc1 = project.Resources.Add("Rsc 1");
                rsc1.Set(Rsc.Type, ResourceType.Work);
                rsc1.Set(Rsc.Initials, "WR");
                rsc1.Set(Rsc.AccrueAt, CostAccrualType.Prorated);
                rsc1.Set(Rsc.MaxUnits, 1);
                rsc1.Set(Rsc.Code, "Code 1");
                rsc1.Set(Rsc.Group, "Workers");
                rsc1.Set(Rsc.EMailAddress, "*****@*****.**");
                rsc1.Set(Rsc.WindowsUserAccount, "user_acc1");
                rsc1.Set(Rsc.IsGeneric, new NullableBool(true));
                rsc1.Set(Rsc.AccrueAt, CostAccrualType.End);
                rsc1.Set(Rsc.StandardRate, 10);
                rsc1.Set(Rsc.StandardRateFormat, RateFormatType.Day);
                rsc1.Set(Rsc.OvertimeRate, 15);
                rsc1.Set(Rsc.OvertimeRateFormat, RateFormatType.Hour);

                rsc1.Set(Rsc.IsTeamAssignmentPool, true);
                rsc1.Set(Rsc.CostCenter, "Cost Center 1");

                // Create resource assignment and set resource assignment meta data
                ResourceAssignment assn = project.ResourceAssignments.Add(task, rsc1);
                assn.Set(Asn.Uid, 1);
                assn.Set(Asn.Work, task.Get(Tsk.Duration));
                assn.Set(Asn.RemainingWork, assn.Get(Asn.Work));
                assn.Set(Asn.RegularWork, assn.Get(Asn.Work));
                task.Set(Tsk.Work, assn.Get(Asn.Work));

                rsc1.Set(Rsc.Work, task.Get(Tsk.Work));
                assn.Set(Asn.Start, task.Get(Tsk.Start));
                assn.Set(Asn.Finish, task.Get(Tsk.Finish));

                // Add extended attribute for project and task
                ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Flag, ExtendedAttributeTask.Flag1, "My Flag Field");
                project.ExtendedAttributes.Add(attr);

                ExtendedAttribute taskAttr = attr.CreateExtendedAttribute();
                taskAttr.FlagValue = true;
                task2.ExtendedAttributes.Add(taskAttr);

                // Save project as MPP
                project.Save(dataDir + "WriteMetaData_out.mpp", SaveFileFormat.MPP);
                //ExEnd:WriteMetadataToMPP
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
Beispiel #5
0
        public void process(string filename)
        {
            //
            // Create a ProjectFile instance
            //
            ProjectFile file = new ProjectFile();

            //
            // Uncomment these lines to test the use of alternative
            // delimiters and separators for MPX file output.
            //
            //file.setDelimiter(';');
            //file.setDecimalSeparator(',');
            //file.setThousandsSeparator('.');

            //
            // Add a default calendar called "Standard"
            //
            ProjectCalendar calendar = file.addDefaultBaseCalendar();

            //
            // Add a holiday to the calendar to demonstrate calendar exceptions
            //
            calendar.addCalendarException(ParseDate("2006-03-13"), ParseDate("2006-03-13"));

            //
            // Retrieve the project properties and set the start date. Note Microsoft
            // Project appears to reset all task dates relative to this date, so this
            // date must match the start date of the earliest task for you to see
            // the expected results. If this value is not set, it will default to
            // today's date.
            //
            ProjectProperties properties = file.ProjectProperties;

            properties.StartDate = ParseDate("2003-01-01");

            //
            // Set a couple more properties just for fun
            //
            properties.ProjectTitle = "Created by MPXJ";
            properties.Author       = "Jon Iles";

            //
            // Add resources
            //
            Resource resource1 = file.addResource();

            resource1.Name = "Resource1";

            Resource resource2 = file.addResource();

            resource2.Name = "Resource2";

            //
            // This next line is not required, it is here simply to test the
            // output file format when alternative separators and delimiters
            // are used.
            //
            resource2.MaxUnits = NumberHelper.getDouble(50.0);

            //
            // Create a summary task
            //
            Task task1 = file.addTask();

            task1.Name = "Summary Task";

            //
            // Create the first sub task
            //
            Task task2 = task1.addTask();

            task2.Name     = "First Sub Task";
            task2.Duration = Duration.getInstance(10.5, TimeUnit.DAYS);
            task2.Start    = ParseDate("2003-01-01");

            //
            // We'll set this task up as being 50% complete. If we have no resource
            // assignments for this task, this is enough information for MS Project.
            // If we do have resource assignments, the assignment record needs to
            // contain the corresponding work and actual work fields set to the
            // correct values in order for MS project to mark the task as complete
            // or partially complete.
            //
            task2.PercentageComplete = NumberHelper.getDouble(50.0);
            task2.ActualStart        = ParseDate("2003-01-01");

            //
            // Create the second sub task
            //
            Task task3 = task1.addTask();

            task3.Name     = "Second Sub Task";
            task3.Start    = ParseDate("2003-01-11");
            task3.Duration = Duration.getInstance(10, TimeUnit.DAYS);

            //
            // Link these two tasks
            //
            task3.addPredecessor(task2, RelationType.FINISH_START, null);

            //
            // Add a milestone
            //
            Task milestone1 = task1.addTask();

            milestone1.Name     = "Milestone";
            milestone1.Start    = ParseDate("2003-01-21");
            milestone1.Duration = Duration.getInstance(0, TimeUnit.DAYS);
            milestone1.addPredecessor(task3, RelationType.FINISH_START, null);

            //
            // This final task has a percent complete value, but no
            // resource assignments. This is an interesting case it it requires
            // special processing to generate the MSPDI file correctly.
            //
            Task task4 = file.addTask();

            task4.Name               = "Next Task";
            task4.Duration           = Duration.getInstance(8, TimeUnit.DAYS);
            task4.Start              = ParseDate("2003-01-01");
            task4.PercentageComplete = NumberHelper.getDouble(70.0);
            task4.ActualStart        = ParseDate("2003-01-01");

            //
            // Assign resources to tasks
            //
            ResourceAssignment assignment1 = task2.addResourceAssignment(resource1);
            ResourceAssignment assignment2 = task3.addResourceAssignment(resource2);

            //
            // As the first task is partially complete, and we are adding
            // a resource assignment, we must set the work and actual work
            // fields in the assignment to appropriate values, or MS Project
            // won't recognise the task as being complete or partially complete
            //
            assignment1.Work       = Duration.getInstance(80, TimeUnit.HOURS);
            assignment1.ActualWork = Duration.getInstance(40, TimeUnit.HOURS);

            //
            // If we were just generating an MPX file, we would already have enough
            // attributes set to create the file correctly. If we want to generate
            // an MSPDI file, we must also set the assignment start dates and
            // the remaining work attribute. The assignment start dates will normally
            // be the same as the task start dates.
            //
            assignment1.RemainingWork = Duration.getInstance(40, TimeUnit.HOURS);
            assignment2.RemainingWork = Duration.getInstance(80, TimeUnit.HOURS);
            assignment1.Start         = ParseDate("2003-01-01");
            assignment2.Start         = ParseDate("2003-01-11");

            //
            // Write a 100% complete task
            //
            Task task5 = file.addTask();

            task5.Name               = "Last Task";
            task5.Duration           = Duration.getInstance(3, TimeUnit.DAYS);
            task5.Start              = ParseDate("2003-01-01");
            task5.PercentageComplete = NumberHelper.getDouble(100.0);
            task5.ActualStart        = ParseDate("2003-01-01");

            //
            // Write the file
            //
            ProjectWriter writer = ProjectWriterUtility.getProjectWriter(filename);

            writer.write(file, filename);
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            //ExStart:CreateMultipleResourceAssignmentsForOneTask
            Project project = new Project(dataDir + "TemplateResource2010.mpp")
            {
                CalculationMode = CalculationMode.Automatic
            };

            project.Set(Prj.DateFormat, DateFormat.DateDddMmDdYy);
            project.Set(Prj.StartDate, new DateTime(2019, 9, 16, 9, 0, 0));
            project.Set(Prj.NewTasksAreManual, false);
            project.Set(Prj.ActualsInSync, false);

            Resource workResource = project.Resources.Add("Servente (Work)");

            workResource.Set(Rsc.Name, "Servente (Work)");
            workResource.Set(Rsc.Initials, "S");
            workResource.Set(Rsc.Type, ResourceType.Work);
            workResource.Set(Rsc.StandardRateFormat, RateFormatType.Hour);
            workResource.Set(Rsc.Code, "1503");

            Resource materialResource = project.Resources.Add("Tijolo (Material)");

            materialResource.Set(Rsc.Name, "Tijolo (Material)");
            materialResource.Set(Rsc.Initials, "T");
            materialResource.Set(Rsc.Type, ResourceType.Material);
            materialResource.Set(Rsc.StandardRateFormat, RateFormatType.MaterialResourceRate);
            materialResource.Set(Rsc.Code, "21341");

            Task tsk1 = project.RootTask.Children.Add("Task - 01");

            tsk1.Set(Tsk.IsRollup, new NullableBool(true));
            tsk1.Set(Tsk.IsPublished, new NullableBool(false));
            Task tsk2 = tsk1.Children.Add("Task - 01.01");

            tsk2.Set(Tsk.IsRollup, new NullableBool(true));
            tsk2.Set(Tsk.IsPublished, new NullableBool(false));
            Task tsk3 = tsk2.Children.Add("Task - 01.01.001");

            tsk3.Set(Tsk.IsEstimated, new NullableBool(false));
            tsk3.Set(Tsk.Start, new DateTime(2019, 9, 16, 9, 0, 0));
            tsk3.Set(Tsk.Duration, project.GetDuration(10, TimeUnitType.Day));
            tsk3.Set(Tsk.Work, project.GetDuration(10, TimeUnitType.Day));
            tsk3.Set(Tsk.IsRollup, new NullableBool(true));
            tsk3.Set(Tsk.IsPublished, new NullableBool(false));

            ResourceAssignment assignment1 = project.ResourceAssignments.Add(tsk3, materialResource);

            assignment1.Set(Asn.Delay, project.GetDuration(40, TimeUnitType.Hour));
            assignment1.Set(Asn.Start, new DateTime(2019, 9, 23, 9, 0, 0));
            assignment1.Set(Asn.Finish, new DateTime(2019, 9, 27, 18, 0, 0));
            ResourceAssignment assignment2 = project.ResourceAssignments.Add(tsk3, workResource);

            assignment2.Set(Asn.Work, project.GetDuration(56, TimeUnitType.Hour));
            assignment2.Set(Asn.Start, new DateTime(2019, 9, 16, 9, 0, 0));
            assignment2.Set(Asn.Finish, new DateTime(2019, 9, 24, 18, 0, 0));

            // to match expected MPP fully
            assignment2.Set(Asn.WorkContour, WorkContourType.Contoured);
            tsk3.Set(Tsk.IsManual, new NullableBool(true));
            tsk1.Set(Tsk.IsManual, new NullableBool(true));

            project.Save(dataDir + @"Assignment_Dates.mpp", Saving.SaveFileFormat.MPP);
            //ExEnd:CreateMultipleResourceAssignmentsForOneTask
        }
Beispiel #7
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            //ExStart: AddExtendedAttributesToRAWithLookUp
            // Create new project
            Project project = new Project(dataDir + "Blank2010.mpp");

            // Assign resource "1 TRG: Trade Group" to the "TASK 1" by creating a ResourceAssignment object.
            Resource resource = project.Resources.GetById(1);
            Task     task     = project.RootTask.Children.GetById(1);

            ResourceAssignment assignment = project.ResourceAssignments.Add(task, resource);

            // Create custom attribute definition with lookup.
            ExtendedAttributeDefinition resCostAttr = ExtendedAttributeDefinition.CreateLookupResourceDefinition(
                CustomFieldType.Cost,
                ExtendedAttributeResource.Cost5,
                "My lookup resource cost");

            project.ExtendedAttributes.Add(resCostAttr);

            var value1 = new Value {
                NumericValue = 1500, Description = "Val 1", Id = 1, Val = "1500"
            };

            resCostAttr.AddLookupValue(value1);

            resCostAttr.AddLookupValue(new Value {
                NumericValue = 2500, Description = "Val 2", Id = 2
            });

            // This value can be seen in "Resource usage" view of MS Project.
            var attributeValue = resCostAttr.CreateExtendedAttribute(value1);

            assignment.ExtendedAttributes.Add(attributeValue);

            // Create custom attribute definition with lookup.
            ExtendedAttributeDefinition taskCostAttr = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                ExtendedAttributeTask.Cost4,
                "My lookup task cost");

            project.ExtendedAttributes.Add(taskCostAttr);

            var taskLookupValue1 = new Value {
                NumericValue = 18, Description = "Task val 1", Id = 3, Val = "18"
            };

            taskCostAttr.AddLookupValue(taskLookupValue1);

            resCostAttr.AddLookupValue(new Value {
                NumericValue = 30, Description = "Task val 2", Id = 4
            });

            // This value can be seen in "Task usage" view of MS Project.
            assignment.ExtendedAttributes.Add(taskCostAttr.CreateExtendedAttribute(taskLookupValue1));

            project.Save(dataDir + "AddExtendedAttributesToRAWithLookUp_out.mpp", SaveFileFormat.MPP);
            //ExEnd: AddExtendedAttributesToRAWithLookUp
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            // ExStart:GenerateResourceAssignmentTimephasedData
            // Create project instance
            Project project1 = new Project(dataDir + "ResourceAssignmentTimephasedData.mpp");

            // Get the first task of the Project
            Task task = project1.RootTask.Children.GetById(1);

            // Get the First Resource Assignment of the Project
            ResourceAssignment firstRA = project1.ResourceAssignments.ToList()[0];

            // Flat contour is default contour
            Console.WriteLine("Flat contour");

            var tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));

            foreach (TimephasedData td in tdList)
            {
                Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
            }

            // Change contour
            firstRA.Set(Asn.WorkContour, WorkContourType.Turtle);
            Console.WriteLine("Turtle contour");
            tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
            foreach (TimephasedData td in tdList)
            {
                Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
            }

            // Change contour
            firstRA.Set(Asn.WorkContour, WorkContourType.BackLoaded);
            Console.WriteLine("BackLoaded contour");
            tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
            foreach (TimephasedData td in tdList)
            {
                Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
            }

            // Change contour
            firstRA.Set(Asn.WorkContour, WorkContourType.FrontLoaded);
            Console.WriteLine("FrontLoaded contour");
            tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
            foreach (TimephasedData td in tdList)
            {
                Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
            }

            // Change contour
            firstRA.Set(Asn.WorkContour, WorkContourType.Bell);
            Console.WriteLine("Bell contour");
            tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
            foreach (TimephasedData td in tdList)
            {
                Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
            }

            // Change contour
            firstRA.Set(Asn.WorkContour, WorkContourType.EarlyPeak);
            Console.WriteLine("EarlyPeak contour");
            tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
            foreach (TimephasedData td in tdList)
            {
                Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
            }

            // Change contour
            firstRA.Set(Asn.WorkContour, WorkContourType.LatePeak);
            Console.WriteLine("LatePeak contour");
            tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
            foreach (TimephasedData td in tdList)
            {
                Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
            }

            // Change contour
            firstRA.Set(Asn.WorkContour, WorkContourType.DoublePeak);
            Console.WriteLine("DoublePeak contour");
            tdList = task.GetTimephasedData(project1.Get(Prj.StartDate), project1.Get(Prj.FinishDate));
            foreach (TimephasedData td in tdList)
            {
                Console.WriteLine(td.Start.ToShortDateString() + " " + td.Value);
            }
            // ExEnd:GenerateResourceAssignmentTimephasedData
        }