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

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

            // Create extended attribute definition
            ExtendedAttributeDefinition attributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Start, ExtendedAttributeTask.Start7, "Start 7");

            project.ExtendedAttributes.Add(attributeDefinition);

            // Get zero index task
            Task task = project.RootTask.Children.GetById(1);

            // Add extended attribute
            ExtendedAttribute attribute = attributeDefinition.CreateExtendedAttribute();

            attribute.DateValue = DateTime.Now;

            // Also the following short syntax can be used: ExtendedAttribute attribute = attributeDefinition.CreateExtendedAttribute(DateTime.Now);
            task.ExtendedAttributes.Add(attribute);
            //ExEnd:ExtendedAttributes
        }
        public static void Run()
        {
            try
            {
                var lic = new License();
                lic.SetLicense(@"E:\Aspose\License\Aspose.Tasks.lic");

                // ExStart:WriteFormulasInExtendedAttributesToMPP
                // Create project instance
                string  dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
                Project project = new Project(dataDir + "Project1.mpp");
                project.Set(Prj.NewTasksAreManual, false);

                // Create new custom field (Task Text1) with formula which will double task cost
                ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Custom");
                attr.Alias   = "Double Costs";
                attr.Formula = "[Cost]*2";
                project.ExtendedAttributes.Add(attr);

                // Add a task
                Task task = project.RootTask.Children.Add("Task");

                // Set task cost
                task.Set(Tsk.Cost, 100);

                // Save project
                project.Save(dataDir + "WriteFormulasInExtendedAttributesToMPP_out.mpp", SaveFileFormat.MPP);
                // ExEnd:WriteFormulasInExtendedAttributesToMPP
            }
            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.");
            }
        }
        public static void Run()
        {
            //ExStart:AccessReadOnlyCustomFieldValuesUsingFormulas
            // Create new project and extended attribute definition
            Project project = new Project();

            ExtendedAttributeDefinition attribute = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Cost, ExtendedAttributeTask.Cost1, string.Empty);

            attribute.Formula = "[Cost]-[Actual Cost]";

            project.ExtendedAttributes.Add(attribute);

            // Add task
            Task task = project.RootTask.Children.Add("Task");

            // Create extended attribute
            ExtendedAttribute extendedAttribute = attribute.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(extendedAttribute);

            // Display if extended attributes are read only or not
            Console.WriteLine(extendedAttribute.ValueReadOnly ? "Value is Read only" : "Value is not read only");
            extendedAttribute.NumericValue = -1000000M;
            Console.WriteLine(extendedAttribute.NumericValue == -1000000M ? "Formula values are read-only" : "Values are not read-only");
            //ExEnd:AccessReadOnlyCustomFieldValuesUsingFormulas
        }
예제 #4
0
        public void CreateExtendedAttribute()
        {
            // ExStart:AccessReadOnlyCustomFieldValuesUsingFormulas
            // ExFor: ExtendedAttribute
            // ExFor: ExtendedAttribute.ValueReadOnly
            // ExFor: ExtendedAttribute.NumericValue
            // ExSummary: Shows how to add read-only custom field values by using formulas.
            var project = new Project();

            // create new task extended attribute definition
            var attribute = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Cost, ExtendedAttributeTask.Cost1, string.Empty);

            // Add a formula to the attribute.
            attribute.Formula = "[Cost]-[Actual Cost]";

            project.ExtendedAttributes.Add(attribute);

            var task = project.RootTask.Children.Add("Task");

            // Create extended attribute
            var extendedAttribute = attribute.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(extendedAttribute);

            // Display if extended attributes are read only or not
            Console.WriteLine(extendedAttribute.ValueReadOnly ? "Value is Read only" : "Value is not read only");
            extendedAttribute.NumericValue = -1000000M;
            Console.WriteLine(extendedAttribute.NumericValue != -1000000M ? "Formula values are read-only" : "Values are not read-only");

            // ExEnd:AccessReadOnlyCustomFieldValuesUsingFormulas
        }
예제 #5
0
        // Helper method to create project
        private static Project CreateTestProjectWithCustomField()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            // Create new project instance
            Project project = new Project(dataDir + "Blank2010.mpp");

            project.Set(Prj.StartDate, new DateTime(2015, 3, 6, 8, 0, 0));

            // Add new task with extended attribute
            Task task = project.RootTask.Children.Add("Task");
            ExtendedAttributeDefinition extendedAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text5, "My Ext Attr");

            project.ExtendedAttributes.Add(extendedAttributeDefinition);
            ExtendedAttribute extendedAttribute = extendedAttributeDefinition.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(extendedAttribute);

            // Add resource and resource assignment
            Resource           rsc  = project.Resources.Add("Rsc");
            ResourceAssignment assn = project.ResourceAssignments.Add(task, rsc);

            return(project);
        }
예제 #6
0
        public void WorkWithCalculationType()
        {
            // ExStart
            // ExFor: CalculationType
            // ExSummary: Shows how to work with calculation type of an extended attribute definition.
            var project = new Project();

            var task = project.RootTask.Children.Add("Task");

            task.Set(Tsk.Start, new DateTime(2020, 4, 16, 8, 0, 0));
            task.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day));

            // create attribute definition with 'Calculation' type
            var calculation = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Date5, null);

            calculation.CalculationType = CalculationType.Calculation;
            calculation.Formula         = "[stARt]";
            project.ExtendedAttributes.Add(calculation);

            // create attribute definition with 'Rollup' type
            var lookup = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Cost1, null);

            lookup.CalculationType = CalculationType.Rollup;
            lookup.RollupType      = RollupType.Average;
            project.ExtendedAttributes.Add(lookup);

            // ExEnd
        }
예제 #7
0
        public void ChangeDefinitionOfExtendedAttribute()
        {
            // ExStart:ChangeExtendedAttributeDefinition
            // ExFor: ExtendedAttribute.AttributeDefinition
            // ExFor: ExtendedAttribute.DateValue
            // ExFor: ExtendedAttribute.FieldId
            // ExSummary: Shows how to change attribute definition of the extended attribute.
            var project = new Project();

            // create new task extended attribute definition
            var definition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Cost, ExtendedAttributeTask.Cost1, string.Empty);

            // add a formula to the attribute.
            definition.Alias   = "Difference between Cost and Actual Cost";
            definition.Formula = "[Cost]-[Actual Cost]";

            project.ExtendedAttributes.Add(definition);

            var task = project.RootTask.Children.Add("Task");

            task.Set(Tsk.Start, new DateTime(2020, 4, 21, 8, 0, 0));
            task.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day));
            task.Set(Tsk.Finish, new DateTime(2020, 4, 21, 17, 0, 0));
            task.Set(Tsk.Deadline, new DateTime(2020, 4, 22, 17, 0, 0));
            task.Set(Tsk.Cost, 20);
            task.Set(Tsk.ActualCost, 13);

            // create extended attribute
            var extendedAttribute = definition.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(extendedAttribute);

            Console.WriteLine("Before change:");
            Console.WriteLine("Alias: " + definition.Alias);
            Console.WriteLine("Field Id: " + extendedAttribute.FieldId);
            Console.WriteLine("Value: " + extendedAttribute.NumericValue);

            // create a new date extended attribute definition
            var newDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Date, ExtendedAttributeTask.Date1, string.Empty);

            // add a formula to the attribute.
            newDefinition.Alias   = "Days from finish to deadline";
            newDefinition.Formula = "[Deadline] - [Finish]";
            project.ExtendedAttributes.Add(newDefinition);

            extendedAttribute = newDefinition.CreateExtendedAttribute();

            Console.WriteLine();
            Console.WriteLine("After change:");
            Console.WriteLine("Alias: " + definition.Alias);
            Console.WriteLine("Field Id: " + extendedAttribute.FieldId);
            Console.WriteLine("Value: " + extendedAttribute.DateValue.Day);

            // ExEnd:ChangeExtendedAttributeDefinition
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

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

            // Add new task and resource
            Task     task1 = project.RootTask.Children.Add("Task");
            Resource rsc1  = project.Resources.Add("Rsc");

            // Assign the resource to the desired task
            ResourceAssignment assignment = project.ResourceAssignments.Add(task1, rsc1);

            // Custom attributes which is visible in "Resource Usage" view can be created with ExtendedAttributeDefinition.CreateResourceDefinition method.
            {
                ExtendedAttributeDefinition resCostAttributeDefinition = ExtendedAttributeDefinition.CreateResourceDefinition(
                    CustomFieldType.Cost,
                    ExtendedAttributeResource.Cost5,
                    "My cost");

                project.ExtendedAttributes.Add(resCostAttributeDefinition);

                var value = resCostAttributeDefinition.CreateExtendedAttribute();

                // The type of the attribute is "Cost", so we need to use "NumericValue" property.
                value.NumericValue = 1500;

                assignment.ExtendedAttributes.Add(value);
            }

            // Custom attributes which is visible in "Task Usage" view can be created with ExtendedAttributeDefinition.CreateTaskDefinition method
            {
                ExtendedAttributeDefinition taskCostAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(
                    CustomFieldType.Cost,
                    ExtendedAttributeTask.Cost5,
                    "My cost for task");

                project.ExtendedAttributes.Add(taskCostAttributeDefinition);

                var value = taskCostAttributeDefinition.CreateExtendedAttribute();

                // The type of the attribute is "Cost", so we need to use "NumericValue" property.
                value.NumericValue = 2300;

                assignment.ExtendedAttributes.Add(value);
            }

            project.Save(dataDir + "AddExtendedAttributesToResourceAssignment_out.mpp", SaveFileFormat.MPP);
            //ExEnd: AddExtendedAttributesToResourceAssignment
        }
예제 #9
0
        public void CreateFlagExtendedAttribute()
        {
            // ExStart:CreateFlagExtendedAttribute
            // ExFor: ExtendedAttribute.FlagValue
            // ExSummary: Shows how to create boolean extended attribute.
            var project = new Project();

            // create new task extended attribute definition
            var definition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Flag, ExtendedAttributeTask.Flag1, "Is Finished");

            // add a formula to the attribute.
            definition.Formula = "[% Complete] = 100";

            project.ExtendedAttributes.Add(definition);

            var finished = project.RootTask.Children.Add("Task");

            finished.Set(Tsk.Start, new DateTime(2020, 4, 21, 8, 0, 0));
            finished.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day));
            finished.Set(Tsk.Finish, new DateTime(2020, 4, 21, 17, 0, 0));
            finished.Set(Tsk.ActualStart, new DateTime(2020, 4, 21, 8, 0, 0));
            finished.Set(Tsk.ActualDuration, project.GetDuration(1, TimeUnitType.Day));
            finished.Set(Tsk.ActualFinish, new DateTime(2020, 4, 21, 17, 0, 0));
            finished.Set(Tsk.PercentComplete, 100);

            var running = project.RootTask.Children.Add("Task");

            running.Set(Tsk.Start, new DateTime(2020, 4, 21, 8, 0, 0));
            running.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day));
            running.Set(Tsk.Finish, new DateTime(2020, 4, 21, 17, 0, 0));
            running.Set(Tsk.ActualStart, new DateTime(2020, 4, 21, 8, 0, 0));

            Console.WriteLine(running.Get(Tsk.PercentComplete));
            // create extended attribute
            var runningFlagAttribute  = definition.CreateExtendedAttribute();
            var finishedFlagAttribute = definition.CreateExtendedAttribute();

            running.ExtendedAttributes.Add(runningFlagAttribute);
            finished.ExtendedAttributes.Add(finishedFlagAttribute);

            Console.WriteLine("Alias: {0}\n", definition.Alias);
            Console.WriteLine("(Finished Task) Field Id: " + finishedFlagAttribute.FieldId);
            Console.WriteLine("(Finished Task) Value: {0}\n", finishedFlagAttribute.FlagValue);
            Console.WriteLine("(Running Task) Field Id: " + runningFlagAttribute.FieldId);
            Console.WriteLine("(Running Task) Value: " + runningFlagAttribute.FlagValue);

            // ExEnd:CreateFlagExtendedAttribute
            Assert.IsTrue(finishedFlagAttribute.FlagValue);
            Assert.IsFalse(runningFlagAttribute.FlagValue);
        }
        public static Project CreateTestProjectWithCustomField()
        {
            Project project = new Project();
            ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Number, ExtendedAttributeTask.Number1, "Sine");

            project.ExtendedAttributes.Add(attr);

            Task task = project.RootTask.Children.Add("Task");

            ExtendedAttribute a = attr.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(a);
            return(project);
        }
        private static Project CreateTestProjectWithCustomField()
        {
            Project project = new Project();

            project.Set(Prj.StartDate, new DateTime(2015, 3, 6, 8, 0, 0));
            ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Custom Field");

            project.ExtendedAttributes.Add(attr);

            Task task = project.RootTask.Children.Add("Task");
            ExtendedAttribute extendedAttribute = attr.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(extendedAttribute);
            return(project);
        }
예제 #12
0
        public void WorkWithCustomFieldType()
        {
            // ExStart
            // ExFor: CustomFieldType
            // ExSummary: Shows how to use <see cref="CustomFieldType" /> (CustomFieldType.Text).
            var project    = new Project(DataDir + "Project2.mpp");
            var definition = ExtendedAttributeDefinition.CreateTaskDefinition(
                CustomFieldType.Text,
                ExtendedAttributeTask.Text1,
                "MyText");

            project.ExtendedAttributes.Add(definition);
            // work with definitions...
            // ExEnd
        }
예제 #13
0
        public void WorkWithTableFields()
        {
            try
            {
                // ExStart:WorkWithTableFields
                // ExFor: Table.TableFields
                // ExSummary: Shows how to work project's tables.
                var project = new Project(DataDir + "Project5.mpp");
                var task    = project.RootTask.Children.Add("New Activity");

                // Define new custom attribute
                var definition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, null);
                project.ExtendedAttributes.Add(definition);

                // Add custom text attribute to created task.
                task.ExtendedAttributes.Add(definition.CreateExtendedAttribute("Activity attribute"));

                // Customize table by adding text attribute field
                var field = new TableField();
                field.Field      = Field.TaskText1;
                field.Width      = 20;
                field.Title      = "Custom attribute";
                field.AlignTitle = StringAlignment.Center;
                field.AlignData  = StringAlignment.Center;

                var table = project.Tables.ToList()[0];
                table.TableFields.Insert(3, field);

                project.Save(OutDir + "ConfigureGanttChart_out.mpp", new MPPSaveOptions {
                    WriteViewData = true
                });

                // ExEnd:WorkWithTableFields
            }
            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.");
            }
        }
예제 #14
0
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

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

                // Create a new project task
                Task task = project.RootTask.Children.Add("New Activity");

                // Define new custom attribute
                ExtendedAttributeDefinition text1Definition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, null);
                project.ExtendedAttributes.Add(text1Definition);
                // Add custom text attribute to created task.
                task.ExtendedAttributes.Add(text1Definition.CreateExtendedAttribute("Activity attribute"));

                // Customize table by adding text attribute field
                TableField attrField = new TableField();
                attrField.Field      = Field.TaskText1;
                attrField.Width      = 20;
                attrField.Title      = "Custom attribute";
                attrField.AlignTitle = StringAlignment.Center;
                attrField.AlignData  = StringAlignment.Center;
                Table table = project.Tables.ToList()[0];
                table.TableFields.Insert(3, attrField);

                // Save project as MPP
                project.Save(dataDir + "ConfigureTheGantChartViewShowSelectedColumnFields_out.mpp", new MPPSaveOptions()
                {
                    WriteViewData = true
                });
                // ExEnd:ConfigureTheGantChartViewShowSelectedColumnFields
            }
            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.");
            }
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

                // ExStart:CreateExtendedAttributes
                Project project1 = new Project(dataDir + "Blank2010.mpp");

                ExtendedAttributeDefinition myTextAttributeDefinition = project1.ExtendedAttributes.GetById((int)ExtendedAttributeTask.Text1);

                // If the Custom field doesn't exist in Project, create it
                if (myTextAttributeDefinition == null)
                {
                    myTextAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, "My text field");
                    project1.ExtendedAttributes.Add(myTextAttributeDefinition);
                }

                // Generate Extended Attribute from definition
                ExtendedAttribute text1TaskAttribute = myTextAttributeDefinition.CreateExtendedAttribute();

                text1TaskAttribute.TextValue = "Text attribute value";

                // Add extended attribute to task
                Task tsk = project1.RootTask.Children.Add("Task 1");
                tsk.ExtendedAttributes.Add(text1TaskAttribute);

                project1.Save(dataDir + "CreateExtendedAttributes_out.mpp", SaveFileFormat.MPP);
                // ExEnd:CreateExtendedAttributes
            }
            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.");
            }
        }
        public void WorkWithExtendedAttributeDefinitionCollection()
        {
            // ExStart
            // ExFor: ExtendedAttributeDefinitionCollection
            // ExFor: ExtendedAttributeDefinitionCollection.Add(ExtendedAttributeDefinition)
            // ExFor: ExtendedAttributeDefinitionCollection.Clear
            // ExFor: ExtendedAttributeDefinitionCollection.Contains(ExtendedAttributeDefinition)
            // ExFor: ExtendedAttributeDefinitionCollection.CopyTo(ExtendedAttributeDefinition[],Int32)
            // ExFor: ExtendedAttributeDefinitionCollection.Count
            // ExFor: ExtendedAttributeDefinitionCollection.GetById(Int32)
            // ExFor: ExtendedAttributeDefinitionCollection.GetEnumerator
            // ExFor: ExtendedAttributeDefinitionCollection.IndexOf(ExtendedAttributeDefinition)
            // ExFor: ExtendedAttributeDefinitionCollection.Insert(Int32,ExtendedAttributeDefinition)
            // ExFor: ExtendedAttributeDefinitionCollection.IsReadOnly
            // ExFor: ExtendedAttributeDefinitionCollection.Item(Int32)
            // ExFor: ExtendedAttributeDefinitionCollection.ParentProject
            // ExFor: ExtendedAttributeDefinitionCollection.Remove(ExtendedAttributeDefinition)
            // ExFor: ExtendedAttributeDefinitionCollection.RemoveAt(Int32)
            // ExFor: ExtendedAttributeDefinitionCollection.ToList
            // ExSummary: Shows how to use extended attribute definition collections.
            var project = new Project(DataDir + "ReadTaskExtendedAttributes.mpp");

            if (!project.ExtendedAttributes.IsReadOnly)
            {
                if (project.ExtendedAttributes.Count > 0)
                {
                    // clear extended attribute definitions
                    project.ExtendedAttributes.Clear();
                }
            }

            // create extended attribute definition for a task
            var taskDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Start, ExtendedAttributeTask.Start7, "Start 7");

            project.ExtendedAttributes.Add(taskDefinition);

            Console.WriteLine("Iterate over extended attributes of " + project.ExtendedAttributes.ParentProject.Get(Prj.Name) + " project: ");
            foreach (var attribute in project.ExtendedAttributes)
            {
                Console.WriteLine("Attribute Alias: " + attribute.Alias);
                Console.WriteLine("Attribute CfType: " + attribute.CfType);
                Console.WriteLine();
            }

            Console.WriteLine();

            // work with extended attribute definitions...
            var resourceDefinition = ExtendedAttributeDefinition.CreateResourceDefinition(CustomFieldType.Cost, ExtendedAttributeResource.Cost5, "My cost");

            if (!project.ExtendedAttributes.Contains(resourceDefinition))
            {
                project.ExtendedAttributes.Add(resourceDefinition);
            }

            // work with extended attribute definitions...
            var resourceDefinition2 = ExtendedAttributeDefinition.CreateResourceDefinition(CustomFieldType.Number, ExtendedAttributeResource.Cost1, "My Cost 2");

            if (project.ExtendedAttributes.IndexOf(resourceDefinition2) < 0)
            {
                project.ExtendedAttributes.Insert(0, resourceDefinition2);
            }

            // work with extended attribute definitions...

            // remove extended attribute by index
            project.ExtendedAttributes.RemoveAt(0);

            Assert.AreEqual(2, project.ExtendedAttributes.Count); // ExSkip

            Console.WriteLine("Print project's extended attributes: ");
            Console.WriteLine("Count of project's extended attribute definitions: " + project.ExtendedAttributes.Count);

            // use collection index access
            Console.WriteLine("Attribute 1 Alias: " + project.ExtendedAttributes[0].Alias);
            Console.WriteLine("Attribute 1 CfType: " + project.ExtendedAttributes[0].CfType);
            Console.WriteLine("Attribute 2 Alias: " + project.ExtendedAttributes[1].Alias);
            Console.WriteLine("Attribute 2 CfType: " + project.ExtendedAttributes[1].CfType);

            var otherProject = new Project();

            // copy attributes to other project
            var attributes = new ExtendedAttributeDefinition[project.ExtendedAttributes.Count];

            project.ExtendedAttributes.CopyTo(attributes, 0);

            foreach (var attribute in attributes)
            {
                otherProject.ExtendedAttributes.Add(attribute);
            }

            Console.WriteLine();
            Console.WriteLine("Iterate over other project's extended attributes: ");
            foreach (var attribute in otherProject.ExtendedAttributes)
            {
                Console.WriteLine("Attribute Alias: " + attribute.Alias);
                Console.WriteLine("Attribute CfType: " + attribute.CfType);
                Console.WriteLine();
            }

            // remove all extended attribute definitions
            List <ExtendedAttributeDefinition> definitions = project.ExtendedAttributes.ToList();

            foreach (var definition in definitions)
            {
                project.ExtendedAttributes.Remove(definition);
            }

            // 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.");
            }
        }
예제 #18
0
        public void WorkWithExtendedAttributeCollection()
        {
            // ExStart
            // ExFor: ExtendedAttributeCollection
            // ExFor: ExtendedAttributeCollection.Add(ExtendedAttribute)
            // ExFor: ExtendedAttributeCollection.Clear
            // ExFor: ExtendedAttributeCollection.Contains(ExtendedAttribute)
            // ExFor: ExtendedAttributeCollection.CopyTo(ExtendedAttribute[],Int32)
            // ExFor: ExtendedAttributeCollection.Count
            // ExFor: ExtendedAttributeCollection.GetEnumerator
            // ExFor: ExtendedAttributeCollection.IndexOf(ExtendedAttribute)
            // ExFor: ExtendedAttributeCollection.Insert(Int32,ExtendedAttribute)
            // ExFor: ExtendedAttributeCollection.IsReadOnly
            // ExFor: ExtendedAttributeCollection.Item(Int32)
            // ExFor: ExtendedAttributeCollection.Remove(ExtendedAttribute)
            // ExFor: ExtendedAttributeCollection.RemoveAt(Int32)
            // ExSummary: Shows how to use extended attribute collections.
            var project = new Project(DataDir + "ReadTaskExtendedAttributes.mpp");

            // Get zero index task
            var task = project.RootTask.Children.GetById(1);

            if (!task.ExtendedAttributes.IsReadOnly && task.ExtendedAttributes.Count > 0)
            {
                // clear extended attributes
                task.ExtendedAttributes.Clear();
            }

            // create extended attribute definition for a task
            var taskDefinition1 = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Start, ExtendedAttributeTask.Start7, "Start 7");
            var taskDefinition2 = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Finish, ExtendedAttributeTask.Finish7, "Finish 7");

            project.ExtendedAttributes.Add(taskDefinition1);
            project.ExtendedAttributes.Add(taskDefinition2);

            Console.WriteLine("Iterate over task extended attributes of " + task.Get(Tsk.Name) + " task: ");
            foreach (var attribute in task.ExtendedAttributes)
            {
                Console.WriteLine("Attribute FieldId: " + attribute.FieldId);
                Console.WriteLine("Attribute Value: " + attribute.DateValue);
                Console.WriteLine();
            }

            // Add extended attribute 1
            var extendedAttribute1 = taskDefinition1.CreateExtendedAttribute();

            extendedAttribute1.DateValue = new DateTime(2020, 4, 14, 8, 0, 0);
            if (task.ExtendedAttributes.IndexOf(extendedAttribute1) < 0)
            {
                task.ExtendedAttributes.Insert(0, extendedAttribute1);
            }

            // Add extended attribute 2
            var extendedAttribute2 = taskDefinition2.CreateExtendedAttribute();

            extendedAttribute2.DateValue = new DateTime(2020, 4, 14, 17, 0, 0);
            task.ExtendedAttributes.Add(extendedAttribute2);

            // work with extended attributes...

            // remove extended attribute by index
            task.ExtendedAttributes.RemoveAt(0);

            Assert.AreEqual(1, task.ExtendedAttributes.Count); // ExSkip

            Console.WriteLine("Count of task's extended attributes: " + task.ExtendedAttributes.Count);

            // use collection index access
            Console.WriteLine("Attribute 1 Value: " + task.ExtendedAttributes[0].DateValue);

            var otherProject = new Project();
            var otherTask    = otherProject.RootTask.Children.Add("Other task");

            // copy attributes to other project
            var attributes = new ExtendedAttribute[task.ExtendedAttributes.Count];

            task.ExtendedAttributes.CopyTo(attributes, 0);

            foreach (var attribute in attributes)
            {
                otherTask.ExtendedAttributes.Add(attribute);
            }

            Console.WriteLine();
            Console.WriteLine("Iterate over other task's extended attributes: ");
            foreach (var attribute in otherTask.ExtendedAttributes)
            {
                Console.WriteLine("Other attribute FieldId: " + attribute.FieldId);
                Console.WriteLine("Other attribute Value: " + attribute.DateValue);
                Console.WriteLine();
            }

            if (task.ExtendedAttributes.Contains(extendedAttribute2))
            {
                task.ExtendedAttributes.Remove(extendedAttribute2);
            }

            // remove all extended attribute definitions
            while (otherTask.ExtendedAttributes.Count > 0)
            {
                otherTask.ExtendedAttributes.Remove(otherTask.ExtendedAttributes[0]);
            }

            // ExEnd
        }
예제 #19
0
        public void ReadWriteTaskExtendedAttributes()
        {
            try
            {
                // ExStart:ReadWriteTaskExtendedAttributes
                // ExFor: Task.ExtendedAttributes
                // ExSummary: Shows how to read task extended attributes.
                var project = new Project(DataDir + "ReadTaskExtendedAttributes.mpp");

                // Create extended attribute definition
                var definition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Start, ExtendedAttributeTask.Start7, "Start 7");
                project.ExtendedAttributes.Add(definition);

                // Get zero index task
                var tsk = project.RootTask.Children.GetById(1);

                // Add extended attribute
                var extendedAttribute = definition.CreateExtendedAttribute();
                extendedAttribute.DateValue = DateTime.Now;

                // Also the following short syntax can be used: ExtendedAttribute attribute = attributeDefinition.CreateExtendedAttribute(DateTime.Now);
                tsk.ExtendedAttributes.Add(extendedAttribute);

                // Create an Extended Attribute Definition of Text1 type
                var taskExtendedAttributeText1Definition =
                    ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Task City Name");

                // Add it to the project's Extended Attributes collection
                project.ExtendedAttributes.Add(taskExtendedAttributeText1Definition);

                var newTask = project.RootTask.Children.Add("Task 1");

                // Create an Extended Attribute from the Attribute Definition
                var taskExtendedAttributeText1 = taskExtendedAttributeText1Definition.CreateExtendedAttribute();

                // Assign a value to the generated Extended Attribute. The type of the attribute is "Text", the "TextValue" property should be used.
                taskExtendedAttributeText1.TextValue = "London";

                // Add the Extended Attribute to task
                newTask.ExtendedAttributes.Add(taskExtendedAttributeText1);

                // Create an Extended Attribute Definition of Text2 type
                var taskExtendedAttributeText2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                    CustomFieldType.Text,
                    ExtendedAttributeTask.Text2,
                    "Task Towns Name");

                // Add lookup values for the extended attribute definition
                taskExtendedAttributeText2Definition.AddLookupValue(new Value {
                    Id = 1, StringValue = "Town1", Description = "This is Town1"
                });
                taskExtendedAttributeText2Definition.AddLookupValue(new Value {
                    Id = 2, StringValue = "Town2", Description = "This is Town2"
                });

                // Add it to the project's Extended Attributes collection
                project.ExtendedAttributes.Add(taskExtendedAttributeText2Definition);

                var task2 = project.RootTask.Children.Add("Task 2");

                // Crate an Extended Attribute from the Text2 Lookup Definition for Id 1
                var taskExtendedAttributeText2 = taskExtendedAttributeText2Definition.CreateExtendedAttribute(taskExtendedAttributeText2Definition.ValueList[1]);

                // Add the Extended Attribute to task
                task2.ExtendedAttributes.Add(taskExtendedAttributeText2);

                // Create an Extended Attribute Definition of Duration2 type
                var taskExtendedAttributeDuration2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                    CustomFieldType.Duration,
                    ExtendedAttributeTask.Duration2,
                    "Some duration");

                // Add lookup values for extended attribute definition
                taskExtendedAttributeDuration2Definition.AddLookupValue(
                    new Value {
                    Id = 3, Duration = project.GetDuration(4, TimeUnitType.Hour), Description = "4 hours"
                });
                taskExtendedAttributeDuration2Definition.AddLookupValue(new Value {
                    Id = 4, Duration = project.GetDuration(1, TimeUnitType.Day), Description = "1 day"
                });
                taskExtendedAttributeDuration2Definition.AddLookupValue(
                    new Value {
                    Id = 5, Duration = project.GetDuration(1, TimeUnitType.Hour), Description = "1 hour"
                });
                taskExtendedAttributeDuration2Definition.AddLookupValue(
                    new Value {
                    Id = 6, Duration = project.GetDuration(10, TimeUnitType.Day), Description = "10 days"
                });

                // Add the definition to the project's Extended Attributes collection
                project.ExtendedAttributes.Add(taskExtendedAttributeDuration2Definition);

                var task3 = project.RootTask.Children.Add("Task 3");

                // Create an Extended Attribute from the Duration2 Lookup Definition for Id 3
                var taskExtendedAttributeDuration2 =
                    taskExtendedAttributeDuration2Definition.CreateExtendedAttribute(taskExtendedAttributeDuration2Definition.ValueList[3]);

                // Add the Extended Attribute to task
                task3.ExtendedAttributes.Add(taskExtendedAttributeDuration2);

                // Create an Extended Attribute Definition of Finish2 Type
                var taskExtendedAttributeFinish2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                    CustomFieldType.Finish,
                    ExtendedAttributeTask.Finish2,
                    "Some finish");

                // Add lookup values for extended attribute definition
                taskExtendedAttributeFinish2Definition.AddLookupValue(
                    new Value {
                    Id = 7, DateTimeValue = new DateTime(1984, 01, 01, 00, 00, 01), Description = "This is Value2"
                });
                taskExtendedAttributeFinish2Definition.AddLookupValue(
                    new Value {
                    Id = 8, DateTimeValue = new DateTime(1994, 01, 01, 00, 01, 01), Description = "This is Value3"
                });
                taskExtendedAttributeFinish2Definition.AddLookupValue(
                    new Value {
                    Id = 9, DateTimeValue = new DateTime(2009, 12, 31, 00, 00, 00), Description = "This is Value4"
                });
                taskExtendedAttributeFinish2Definition.AddLookupValue(new Value {
                    Id = 10, DateTimeValue = DateTime.Now, Description = "This is Value6"
                });

                // Add the definition to the project's Extended Attributes collection
                project.ExtendedAttributes.Add(taskExtendedAttributeFinish2Definition);

                var task4 = project.RootTask.Children.Add("Task 4");

                // Create an Extended Attribute from the Finish2 Lookup Definition for Id 3
                var taskExtendedAttributeFinish2 = taskExtendedAttributeFinish2Definition.CreateExtendedAttribute(taskExtendedAttributeFinish2Definition.ValueList[3]);

                // Add the Extended Attribute to task
                task4.ExtendedAttributes.Add(taskExtendedAttributeFinish2);

                var collector = new ChildTasksCollector();
                TaskUtils.Apply(project.RootTask, collector, 0);

                // Read extended attributes for tasks
                foreach (var task in collector.Tasks)
                {
                    foreach (var attribute in task.ExtendedAttributes)
                    {
                        Console.WriteLine(attribute.FieldId);
                        Console.WriteLine(attribute.ValueGuid);

                        switch (attribute.AttributeDefinition.CfType)
                        {
                        case CustomFieldType.Date:
                        case CustomFieldType.Start:
                        case CustomFieldType.Finish:
                            Console.WriteLine(attribute.DateValue);
                            break;

                        case CustomFieldType.Text:
                            Console.WriteLine(attribute.TextValue);
                            break;

                        case CustomFieldType.Duration:
                            Console.WriteLine(attribute.DurationValue.ToString());
                            break;

                        case CustomFieldType.Cost:
                        case CustomFieldType.Number:
                            Console.WriteLine(attribute.NumericValue);
                            break;

                        case CustomFieldType.Flag:
                            Console.WriteLine(attribute.FlagValue);
                            break;

                        case CustomFieldType.Null:
                        case CustomFieldType.RBS:
                        case CustomFieldType.OutlineCode:
                            return;

                        default:
                            return;
                        }
                    }
                }

                project.Save(OutDir + "ReadWriteTaskExtendedAttributes_out.mpp", SaveFileFormat.MPP);

                // ExEnd:ReadWriteTaskExtendedAttributes
            }
            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.");
            }
        }
        public static void Run()
        {
            try
            {
                //ExStart:AddTaskExtendedAttributes
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

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

                //Create an Extended Attribute Definition of Text1 type
                var taskExtendedAttributeText1Definition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Task City Name");

                //Add it to the project's Extended Attributes collection
                project.ExtendedAttributes.Add(taskExtendedAttributeText1Definition);

                //Add a task to the project
                var task = project.RootTask.Children.Add("Task 1");

                //Create an Extended Attribute from the Attribute Definition
                var taskExtendedAttributeText1 = taskExtendedAttributeText1Definition.CreateExtendedAttribute();

                //Assign a value to the generated Extended Attribute. The type of the attribute is "Text", the "TextValue" property should be used.
                taskExtendedAttributeText1.TextValue = "London";

                //Add the Extended Attribute to task
                task.ExtendedAttributes.Add(taskExtendedAttributeText1);

                project.Save(dataDir + "PlainTextExtendedAttribute_out.mpp", SaveFileFormat.MPP);

                Project project1 = new Project(dataDir + "Blank2010.mpp");

                //Create an Extended Attribute Definition of Text2 type
                var taskExtendedAttributeText2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text2, "Task Towns Name");

                //Add lookup values for the extended attribute definition
                taskExtendedAttributeText2Definition.AddLookupValue(new Value {
                    Id = 1, StringValue = "Town1", Description = "This is Town1"
                });
                taskExtendedAttributeText2Definition.AddLookupValue(new Value {
                    Id = 2, StringValue = "Town2", Description = "This is Town2"
                });

                //Add it to the porject's Extended Attributes collection
                project1.ExtendedAttributes.Add(taskExtendedAttributeText2Definition);

                //Add a task to the project
                var task2 = project1.RootTask.Children.Add("Task 2");

                //Crate an Extended Attribute from the Text2 Lookup Definition for Id 1
                var taskExtendedAttributeText2 = taskExtendedAttributeText2Definition.CreateExtendedAttribute(taskExtendedAttributeText2Definition.ValueList[1]);

                //Add the Extended Attribute to task
                task2.ExtendedAttributes.Add(taskExtendedAttributeText2);

                project1.Save(dataDir + "TextExtendedAttributeWithLookup_out.mpp", SaveFileFormat.MPP);

                Project project2 = new Project(dataDir + "Blank2010.mpp");

                //Create an Extended Attribute Definition of Duration2 type
                var taskExtendedAttributeDuration2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Duration, ExtendedAttributeTask.Duration2, "Some duration");

                //Add lookup values for extended attribute definition
                taskExtendedAttributeDuration2Definition.AddLookupValue(new Value {
                    Id = 2, Duration = project2.GetDuration(4, TimeUnitType.Hour), Description = "4 hours"
                });
                taskExtendedAttributeDuration2Definition.AddLookupValue(new Value {
                    Id = 3, Duration = project2.GetDuration(1, TimeUnitType.Day), Description = "1 day"
                });
                taskExtendedAttributeDuration2Definition.AddLookupValue(new Value {
                    Id = 4, Duration = project2.GetDuration(1, TimeUnitType.Hour), Description = "1 hour"
                });
                taskExtendedAttributeDuration2Definition.AddLookupValue(new Value {
                    Id = 7, Duration = project2.GetDuration(10, TimeUnitType.Day), Description = "10 days"
                });

                //Add the definition to the project's Extended Attributes collection
                project2.ExtendedAttributes.Add(taskExtendedAttributeDuration2Definition);

                //Add a task to the project
                var task3 = project2.RootTask.Children.Add("Task 3");

                //Create an Extended Attribute from the Duration2 Lookup Definition for Id 3
                var taskExtendedAttributeDuration2 = taskExtendedAttributeDuration2Definition.CreateExtendedAttribute(taskExtendedAttributeDuration2Definition.ValueList[3]);

                //Add the Extended Attribute to task
                task3.ExtendedAttributes.Add(taskExtendedAttributeDuration2);

                project2.Save(dataDir + "DurationExtendedAttributeWithLookup_out.mpp", SaveFileFormat.MPP);

                Project project3 = new Project(dataDir + "Blank2010.mpp");

                //Create an Extended Attribute Definition of Finish2 Type
                var taskExtendedAttributeFinish2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Finish, ExtendedAttributeTask.Finish2, "Some finish");

                //Add lookup values for extended attribute defintion
                taskExtendedAttributeFinish2Definition.AddLookupValue(new Value {
                    Id = 2, DateTimeValue = new DateTime(1984, 01, 01, 00, 00, 01), Description = "This is Value2"
                });
                taskExtendedAttributeFinish2Definition.AddLookupValue(new Value {
                    Id = 3, DateTimeValue = new DateTime(1994, 01, 01, 00, 01, 01), Description = "This is Value3"
                });
                taskExtendedAttributeFinish2Definition.AddLookupValue(new Value {
                    Id = 4, DateTimeValue = new DateTime(2009, 12, 31, 00, 00, 00), Description = "This is Value4"
                });
                taskExtendedAttributeFinish2Definition.AddLookupValue(new Value {
                    Id = 7, DateTimeValue = DateTime.Now, Description = "This is Value6"
                });

                //Add the definition to the project's Extended Attributes collection
                project3.ExtendedAttributes.Add(taskExtendedAttributeFinish2Definition);

                //Add a task to the project
                var task4 = project3.RootTask.Children.Add("Task 4");

                //Create an Extneded Attribute from the Finish2 Lookup Definition for Id 3
                var taskExtendedAttributeFinish2 = taskExtendedAttributeFinish2Definition.CreateExtendedAttribute(taskExtendedAttributeFinish2Definition.ValueList[3]);

                //Add the Extended Attribute to task
                task4.ExtendedAttributes.Add(taskExtendedAttributeFinish2);

                // Save the Project
                project3.Save(dataDir + "FinishExtendedAttributeWithLookup_out.mpp", SaveFileFormat.MPP);

                //ExEnd:AddTaskExtendedAttributes
            }
            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.");
            }
        }
예제 #21
0
        public static void Run()
        {
            //ExStart:CalculateDateTimeFunctions
            Project project = CreateTestProject();
            Task    task    = project.RootTask.Children.GetById(1);

            ExtendedAttributeDefinition numberDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Number1, null);

            project.ExtendedAttributes.Add(numberDefinition);

            ExtendedAttribute numberAttribute = numberDefinition.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(numberAttribute);

            // Set ProjDateDiff formula and print extended attribute value
            numberDefinition.Formula = "ProjDateDiff(\"03/23/2015\",\"03/18/2015\")";
            Console.WriteLine(numberAttribute.NumericValue);
            numberDefinition.Formula = "ProjDateDiff(\"03/23/2015\",\"03/25/2015\")";
            Console.WriteLine(numberAttribute.NumericValue);

            ExtendedAttributeDefinition dateDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Date1, null);

            project.ExtendedAttributes.Add(dateDefinition);
            ExtendedAttribute dateAttribute = dateDefinition.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(dateAttribute);

            ExtendedAttributeDefinition durationDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Duration4, "Custom duration field");

            project.ExtendedAttributes.Add(durationDefinition);
            ExtendedAttribute durationAttribute = durationDefinition.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(durationAttribute);

            ExtendedAttributeDefinition textDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text5, "Custom text field");

            project.ExtendedAttributes.Add(textDefinition);
            ExtendedAttribute textAttribute = textDefinition.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(textAttribute);

            // Set ProjDateSub formula and print extended attribute value
            dateDefinition.Formula = "ProjDateSub(\"3/19/2015\", \"1d\")";
            Console.WriteLine(dateAttribute.DateValue);

            // We can set ProjDurConv formula to duration-valued attribute as well as to text-valued attribute.

            // Set ProjDurConv formula to duration-valued extended attribute and print its value.
            durationDefinition.Formula = "ProjDurConv([Duration], pjHours)";
            Console.WriteLine(durationAttribute.DurationValue);

            // Set ProjDurConv formula to text-valued extended attribute and print its value.
            textDefinition.Formula = "ProjDurConv([Duration], pjHours)";
            Console.WriteLine(textAttribute.TextValue);

            textDefinition.Formula = "ProjDurConv([Duration], pjWeeks)";
            Console.WriteLine(textAttribute.TextValue);

            // Set Second formula and print entended attribute value
            numberDefinition.Formula = "Second(\"4/21/2015 2:53:41 AM\")";
            Console.WriteLine(numberAttribute.NumericValue);

            // Set Weekday formula and print entended attribute value
            numberDefinition.Formula = "Weekday(\"24/3/2015\", 1)";
            Console.WriteLine(numberAttribute.NumericValue);
            numberDefinition.Formula = "Weekday(\"24/3/2015\", 2)";
            Console.WriteLine(numberAttribute.NumericValue);
            numberDefinition.Formula = "Weekday(\"24/3/2015\", 3)";
            Console.WriteLine(numberAttribute.NumericValue);
            //ExEnd:CalculateDateTimeFunctions
        }
예제 #22
0
        public void CalculateDateTimeFunctions()
        {
            // ExStart:CalculateDateTimeFunctions
            // ExFor: ExtendedAttribute.TextValue
            // ExFor: ExtendedAttribute.DurationValue
            // ExSummary: Shows how to add extended attributes that uses MS Project date/time formulas.
            var project = new Project();
            var task    = project.RootTask.Children.Add("Task");

            var numberDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Number1, null);

            project.ExtendedAttributes.Add(numberDefinition);

            var numberAttribute = numberDefinition.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(numberAttribute);

            // Set ProjDateDiff formula and print extended attribute value
            numberDefinition.Formula = "ProjDateDiff(\"03/23/2015\",\"03/18/2015\")";
            Console.WriteLine(numberAttribute.NumericValue);
            numberDefinition.Formula = "ProjDateDiff(\"03/23/2015\",\"03/25/2015\")";
            Console.WriteLine(numberAttribute.NumericValue);

            var dateDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Date1, null);

            project.ExtendedAttributes.Add(dateDefinition);
            var dateAttribute = dateDefinition.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(dateAttribute);

            var durationDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Duration4, "Custom duration field");

            project.ExtendedAttributes.Add(durationDefinition);
            var durationAttribute = durationDefinition.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(durationAttribute);

            var textDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text5, "Custom text field");

            project.ExtendedAttributes.Add(textDefinition);
            var textAttribute = textDefinition.CreateExtendedAttribute();

            task.ExtendedAttributes.Add(textAttribute);

            // Set ProjDateSub formula and print extended attribute value
            dateDefinition.Formula = "ProjDateSub(\"3/19/2015\", \"1d\")";
            Console.WriteLine(dateAttribute.DateValue);

            // We can set ProjDurConv formula to duration-valued attribute as well as to text-valued attribute.
            // Set ProjDurConv formula to duration-valued extended attribute and print its value.
            durationDefinition.Formula = "ProjDurConv([Duration], pjHours)";
            Console.WriteLine(durationAttribute.DurationValue);

            // Set ProjDurConv formula to text-valued extended attribute and print its value.
            textDefinition.Formula = "ProjDurConv([Duration], pjWeeks)";
            Console.WriteLine(textAttribute.TextValue);

            // Set Second formula and print extended attribute value
            numberDefinition.Formula = "Second(\"4/21/2015 2:53:41 AM\")";
            Console.WriteLine(numberAttribute.NumericValue);

            // Set Weekday formula and print extended attribute value
            numberDefinition.Formula = "Weekday(\"24/3/2015\", 1)";
            Console.WriteLine(numberAttribute.NumericValue);
            numberDefinition.Formula = "Weekday(\"24/3/2015\", 2)";
            Console.WriteLine(numberAttribute.NumericValue);
            numberDefinition.Formula = "Weekday(\"24/3/2015\", 3)";
            Console.WriteLine(numberAttribute.NumericValue);

            // ExEnd:CalculateDateTimeFunctions
        }
예제 #23
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.");
            }
        }