Exemple #1
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 {
                NumberValue = 1500, Description = "Val 1", Id = 1, Val = "1500"
            };

            resCostAttr.AddLookupValue(value1);

            resCostAttr.AddLookupValue(new Value {
                NumberValue = 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 {
                NumberValue = 18, Description = "Task val 1", Id = 3, Val = "18"
            };

            taskCostAttr.AddLookupValue(taskLookupValue1);

            resCostAttr.AddLookupValue(new Value {
                NumberValue = 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 void ResourceAssignmentExtendedAttributes()
        {
            // ExStart
            // ExFor: ResourceAssignment.ExtendedAttributes
            // ExSummary: Shows how to add extended attributes for an assignment.
            var project = new Project(DataDir + "Blank2010.mpp");

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

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

            project.ExtendedAttributes.Add(definition);

            var firstValue = new Value {
                NumericValue = 1500, Description = "Val 1", Id = 1, Val = "1500"
            };
            var secondValue = new Value {
                NumericValue = 2500, Description = "Val 2", Id = 2
            };

            definition.AddLookupValue(firstValue);
            definition.AddLookupValue(secondValue);

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

            assignment.ExtendedAttributes.Add(attributeValue);

            Console.WriteLine("Number of assignment's extended attribute: " + assignment.ExtendedAttributes.Count);
            foreach (var attribute in assignment.ExtendedAttributes)
            {
                Console.WriteLine("Extended attribute alias: " + attribute.AttributeDefinition.Alias);
            }

            // ExEnd
        }
        public static void Run()
        {
            // This example requires Aspose.Task for .NET, a trial version can be download from  http://www.aspose.com/corporate/purchase/temporary-license.aspx
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

                //ExStart:WriteUpdatedExtendedAttributeDefinitions
                Project project = new Project(dataDir + "WriteUpdatedExtendedAttributeDefinitions.mpp");

                // Add new text3 extended attribute with lookup and one lookup value
                ExtendedAttributeDefinition taskTextAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Text3, "New text3 attribute");
                taskTextAttributeDefinition.ElementType = ElementType.Task;
                project.ExtendedAttributes.Add(taskTextAttributeDefinition);

                Value textVal = new Value();
                textVal.Id          = 1;
                textVal.Description = "Text value descr";
                textVal.Val         = "Text value1";

                taskTextAttributeDefinition.AddLookupValue(textVal);

                // Add new cost1 extended attribute with lookup and two cost values
                ExtendedAttributeDefinition taskCostAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Cost1, "New cost1 attribute");
                project.ExtendedAttributes.Add(taskCostAttributeDefinition);

                Value costVal1 = new Value();
                costVal1.Id          = 2;
                costVal1.Description = "Cost value 1 descr";
                costVal1.Val         = "99900";

                Value costVal2 = new Value();
                costVal2.Id          = 3;
                costVal2.Description = "Cost value 2 descr";
                costVal2.Val         = "11100";

                taskCostAttributeDefinition.AddLookupValue(costVal1);
                taskCostAttributeDefinition.AddLookupValue(costVal2);

                // Add new task and assign attribute lookup value.
                Task task = project.RootTask.Children.Add("New task");

                ExtendedAttribute taskAttr = taskCostAttributeDefinition.CreateExtendedAttribute(costVal1);
                task.ExtendedAttributes.Add(taskAttr);

                ExtendedAttributeDefinition taskStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Start7, "New start 7 attribute");

                Value startVal = new Value();
                startVal.Id            = 4;
                startVal.DateTimeValue = DateTime.Now;
                startVal.Description   = "Start 7 value description";

                taskStartAttributeDefinition.AddLookupValue(startVal);

                project.ExtendedAttributes.Add(taskStartAttributeDefinition);

                ExtendedAttributeDefinition taskFinishAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Finish4, "New finish 4 attribute");

                Value finishVal = new Value();
                finishVal.Id            = 5;
                finishVal.DateTimeValue = DateTime.Now;
                finishVal.Description   = "Finish 4 value description";

                taskFinishAttributeDefinition.ValueList.Add(finishVal);

                project.ExtendedAttributes.Add(taskFinishAttributeDefinition);

                ExtendedAttributeDefinition numberAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Number20, "New number attribute");

                Value val1 = new Value();
                val1.Id          = 6;
                val1.Val         = "1";
                val1.Description = "Number 1 value";
                Value val2 = new Value();
                val2.Id          = 7;
                val2.Val         = "2";
                val2.Description = "Number 2 value";
                Value val3 = new Value();
                val2.Id          = 8;
                val3.Val         = "3";
                val3.Description = "Number 3 value";

                numberAttributeDefinition.AddLookupValue(val1);
                numberAttributeDefinition.AddLookupValue(val2);
                numberAttributeDefinition.AddLookupValue(val3);

                project.ExtendedAttributes.Add(numberAttributeDefinition);

                ExtendedAttributeDefinition rscStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupResourceDefinition(ExtendedAttributeResource.Start5, "New start5 attribute");

                Value startVal2 = new Value();
                startVal2.Id            = 9;
                startVal2.DateTimeValue = DateTime.Now;
                startVal2.Description   = "this is start5 value descr";

                rscStartAttributeDefinition.AddLookupValue(startVal2);

                project.ExtendedAttributes.Add(rscStartAttributeDefinition);

                // Define a duration attribute without lookup.
                ExtendedAttributeDefinition taskDurationAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Duration1, "New Duration");
                project.ExtendedAttributes.Add(taskDurationAttributeDefinition);

                // Add new task and assign duration value to the previously defined duration attribute.
                Task timeTask = project.RootTask.Children.Add("New task");

                ExtendedAttribute durationExtendedAttribute = taskDurationAttributeDefinition.CreateExtendedAttribute();

                durationExtendedAttribute.DurationValue = project.GetDuration(3.0, TimeUnitType.Hour);
                timeTask.ExtendedAttributes.Add(durationExtendedAttribute);

                MPPSaveOptions mppSaveOptions = new MPPSaveOptions();
                mppSaveOptions.WriteViewData = true;

                // Save the project as MPP project file
                project.Save(dataDir + "WriteUpdatedExtendedAttributeDefinitions_out.mpp", mppSaveOptions);
                //ExEnd:WriteUpdatedExtendedAttributeDefinitions
            }
            catch (Exception ex)
            {
                Console.Write(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.");
            }
        }