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

            // ExStart:ExtendedAttributes
            Project prj = new Project(dataDir + "ExtendedAttributes.mpp");
            ExtendedAttributeDefinitionCollection eads = prj.ExtendedAttributes;

            // Create extended attribute definition
            ExtendedAttributeDefinition ead = new ExtendedAttributeDefinition();
            ead.FieldId = ((int)ExtendedAttributeTask.Start7).ToString();
            ead.FieldName = "Start7";
            eads.Add(ead);

            // Get zero index task
            Task tsk = prj.RootTask.Children.GetById(1);
            ExtendedAttributeCollection eas = tsk.ExtendedAttributes;

            // Add extended attribute
            string dateTimeFormat = "yyyy-MM-ddTHH:mm:ss";
            ExtendedAttribute ea = new ExtendedAttribute();
            ea.FieldId = ead.FieldId;
            ea.Value = XmlConvert.ToString(DateTime.Now, dateTimeFormat);
            eas.Add(ea);
            // 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 = new ExtendedAttributeDefinition();                
                attr.FieldId = ExtendedAttributeTask.Text1.ToString("D");
                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 = new ExtendedAttributeDefinition
            {
                FieldId = ((int) ExtendedAttributeTask.Text1).ToString(),
                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 == true ? "Value is Read only" : "Value is not read only");
            extendedAttribute.Value = "Invalid";
            Console.WriteLine(extendedAttribute.Value == string.Empty ? "Formula values are read-only" : "Values are not read-only");
            // ExEnd:AccessReadOnlyCustomFieldValuesUsingFormulas
        }
 static Project CreateTestProjectWithCustomFieldWithoutResource()
 {
     Project project = new Project();
     project.Set(Prj.StartDate, new DateTime(2015, 3, 6, 8, 0, 0));
     ExtendedAttributeDefinition attr = new ExtendedAttributeDefinition();
     attr.FieldId = ExtendedAttributeTask.Text1.ToString("D");
     project.ExtendedAttributes.Add(attr);
  
     Task task = project.RootTask.Children.Add("Task");
     ExtendedAttribute a = attr.CreateExtendedAttribute();
     task.ExtendedAttributes.Add(a);
     return project;
 }
        public static Project CreateTestProjectWithCustomField()
        {
            Project project = new Project();
            ExtendedAttributeDefinition attr = new ExtendedAttributeDefinition();          
            attr.FieldId = ExtendedAttributeTask.Text1.ToString("D");
            attr.Alias = "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 = new ExtendedAttributeDefinition();
            attr.FieldId = ExtendedAttributeTask.Text1.ToString("D");
            project.ExtendedAttributes.Add(attr);

            Task task = project.RootTask.Children.Add("Task");
            ExtendedAttribute extendedAttribute = attr.CreateExtendedAttribute();
            task.ExtendedAttributes.Add(extendedAttribute);
            Resource rsc = project.Resources.Add("Rsc");
            ResourceAssignment resourceAssignment = project.ResourceAssignments.Add(task, rsc);
            return project;
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

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

                // Define extended attribute
                ExtendedAttributeDefinition myNumber1 = null;
                if (project1.ExtendedAttributes.GetById(Convert.ToInt32(ExtendedAttributeResource.Number1.ToString("D"))) == null)
                {
                    myNumber1 = new ExtendedAttributeDefinition();
                    myNumber1.Alias = "Age";
                    myNumber1.CfType = CustomFieldType.Number;
                    myNumber1.FieldId = ExtendedAttributeResource.Number1.ToString("D");
                    project1.ExtendedAttributes.Add(myNumber1);
                }
                else
                    myNumber1 = project1.ExtendedAttributes.GetById(Convert.ToInt32(ExtendedAttributeResource.Number1.ToString("D")));

                // Create extended attribute and set its value
                ExtendedAttribute Number1Resource = myNumber1.CreateExtendedAttribute();
                Number1Resource.Value = "30.5345";

                // Add a new resource and its extended attribute   
                Resource rsc = project1.Resources.Add("R1");
                rsc.ExtendedAttributes.Add(Number1Resource);

                // Save project as MPP
                project1.Save(dataDir + "ResourceExtendedAttributes_out.mpp", SaveFileFormat.MPP);
                // ExEnd:SetResourceExtendedAttributes
            }
            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 myText1Def = null;

                // If the Custom field doesn't exist in Project, create it
                if (project1.ExtendedAttributes.GetById(Convert.ToInt32(ExtendedAttributeTask.Text1.ToString("D"))) == null)
                {
                    myText1Def = new ExtendedAttributeDefinition();
                    myText1Def.Alias = "MyValue";
                    myText1Def.CfType = CustomFieldType.Number;
                    myText1Def.FieldId = ExtendedAttributeTask.Text1.ToString("D");
                    project1.ExtendedAttributes.Add(myText1Def);
                }
                else
                    myText1Def = project1.ExtendedAttributes.GetById(Convert.ToInt32(ExtendedAttributeTask.Number1.ToString("D")));

                // Generate Extended Attribute from definition
                ExtendedAttribute text1TaskAttr = myText1Def.CreateExtendedAttribute();
                text1TaskAttr.Value = "20.55";

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

                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.");
            }
        }
        // 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 = new ExtendedAttributeDefinition();
            extendedAttributeDefinition.FieldId = ExtendedAttributeTask.Text1.ToString("D");
            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;
        }
Пример #10
0
        public async Task TestEditTaskExtendedAttributeLookupValue()
        {
            var remoteName = await UploadFileToStorageAsync("NewProductDev.mpp");

            var newExtendedAttribute = new ExtendedAttributeDefinition
            {
                CalculationType = CalculationType.Lookup,
                CfType          = CustomFieldType.Text,
                FieldName       = "Text3",
                ElementType     = ElementType.Task,
                Alias           = "New Field",
                ValueList       = new List <Value>
                {
                    new Value {
                        Description = "descr1", Val = "Internal", Id = 111
                    },
                    new Value {
                        Description = "descr2", Val = "External", Id = 112
                    }
                }
            };

            var putAttributeResponse = await TasksApi.PutExtendedAttributeAsync(new PutExtendedAttributeRequest
            {
                ExtendedAttribute = newExtendedAttribute,
                Name   = remoteName,
                Folder = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, putAttributeResponse.Code);
            var taskResponse = await TasksApi.GetTaskAsync(new GetTaskRequest
            {
                TaskUid = 27,
                Name    = remoteName,
                Folder  = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, taskResponse.Code);
            Assert.IsNotNull(taskResponse.Task);

            taskResponse.Task.ExtendedAttributes.Add(
                new ExtendedAttribute {
                LookupValueId = 112, FieldId = putAttributeResponse.ExtendedAttribute.FieldId
            });

            var putTaskResponse = await TasksApi.PutTaskAsync(new PutTaskRequest
            {
                TaskUid = 27,
                Task    = taskResponse.Task,
                Name    = remoteName,
                Folder  = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, putTaskResponse.Code);

            taskResponse = await TasksApi.GetTaskAsync(new GetTaskRequest
            {
                TaskUid = 27,
                Name    = remoteName,
                Folder  = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, taskResponse.Code);
            Assert.IsNotNull(taskResponse.Task);
            Assert.AreEqual(1, taskResponse.Task.ExtendedAttributes.Count);
            Assert.AreEqual("188743737", taskResponse.Task.ExtendedAttributes[0].FieldId);
            Assert.AreEqual(112, taskResponse.Task.ExtendedAttributes[0].LookupValueId);
        }
Пример #11
0
        public async Task TestEditTaskExtendedAttributeTextValue()
        {
            var remoteName = await UploadFileToStorageAsync("NewProductDev.mpp");

            var newExtendedAttribute = new ExtendedAttributeDefinition
            {
                CalculationType = CalculationType.None,
                CfType          = CustomFieldType.Text,
                FieldName       = "Text1",
                ElementType     = ElementType.Task,
                Alias           = "Custom Text Field"
            };

            var putAttributeResponse = await TasksApi.PutExtendedAttributeAsync(new PutExtendedAttributeRequest
            {
                ExtendedAttribute = newExtendedAttribute,
                Name   = remoteName,
                Folder = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, putAttributeResponse.Code);
            var taskResponse = await TasksApi.GetTaskAsync(new GetTaskRequest
            {
                TaskUid = 27,
                Name    = remoteName,
                Folder  = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, taskResponse.Code);
            Assert.IsNotNull(taskResponse.Task);

            taskResponse.Task.ExtendedAttributes.Add(
                new ExtendedAttribute
            {
                TextValue = "Test value",
                FieldId   = "188743731"
            });

            var putTaskResponse = await TasksApi.PutTaskAsync(new PutTaskRequest
            {
                TaskUid = 27,
                Task    = taskResponse.Task,
                Name    = remoteName,
                Folder  = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, putTaskResponse.Code);

            taskResponse = await TasksApi.GetTaskAsync(new GetTaskRequest
            {
                TaskUid = 27,
                Name    = remoteName,
                Folder  = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, taskResponse.Code);
            Assert.IsNotNull(taskResponse.Task);
            Assert.AreEqual(1, taskResponse.Task.ExtendedAttributes.Count);
            Assert.AreEqual("188743731", taskResponse.Task.ExtendedAttributes[0].FieldId);
            Assert.AreEqual("Test value", taskResponse.Task.ExtendedAttributes[0].TextValue);
        }
Пример #12
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.");
            }
        }
Пример #13
0
        public async Task TestEditTaskExtendedAttributeDurationValue()
        {
            var remoteName = await UploadFileToStorageAsync("NewProductDev.mpp");

            var newExtendedAttribute = new ExtendedAttributeDefinition
            {
                CalculationType = CalculationType.None,
                CfType          = CustomFieldType.Duration,
                FieldName       = "Duration3",
                ElementType     = ElementType.Task,
                Alias           = "Custom Duration Field"
            };

            var putAttributeResponse = await TasksApi.PutExtendedAttributeAsync(new PutExtendedAttributeRequest
            {
                ExtendedAttribute = newExtendedAttribute,
                Name   = remoteName,
                Folder = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, putAttributeResponse.Code);
            var taskResponse = await TasksApi.GetTaskAsync(new GetTaskRequest
            {
                TaskUid = 27,
                Name    = remoteName,
                Folder  = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, taskResponse.Code);
            Assert.IsNotNull(taskResponse.Task);

            taskResponse.Task.ExtendedAttributes.Add(
                new ExtendedAttribute
            {
                DurationValue = new Duration {
                    TimeSpan = TimeSpan.FromHours(4), TimeUnit = TimeUnitType.Minute
                },
                FieldId = "188743785"
            });

            var putTaskResponse = await TasksApi.PutTaskAsync(new PutTaskRequest
            {
                TaskUid = 27,
                Task    = taskResponse.Task,
                Name    = remoteName,
                Folder  = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, putTaskResponse.Code);

            taskResponse = await TasksApi.GetTaskAsync(new GetTaskRequest
            {
                TaskUid = 27,
                Name    = remoteName,
                Folder  = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, taskResponse.Code);
            Assert.IsNotNull(taskResponse.Task);
            Assert.AreEqual(1, taskResponse.Task.ExtendedAttributes.Count);
            Assert.AreEqual("188743785", taskResponse.Task.ExtendedAttributes[0].FieldId);
            Assert.IsNotNull(taskResponse.Task.ExtendedAttributes[0].DurationValue);
            Assert.AreEqual(TimeSpan.FromHours(4), taskResponse.Task.ExtendedAttributes[0].DurationValue.TimeSpan);
        }
        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 = new ExtendedAttributeDefinition();
                attr.FieldId = ((int)ExtendedAttributeTask.Flag1).ToString();
                attr.Alias = "Labeled";
                project.ExtendedAttributes.Add(attr);
                ExtendedAttribute taskAttr = new ExtendedAttribute();
                taskAttr.Value = "1";
                taskAttr.FieldId = attr.FieldId;
                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.");
            }
        }
Пример #15
0
        public static void Main(string[] args)
        {
            var project = new Project("Data/Project1.mpp");

            ExtendedAttributeDefinitionCollection attributeCollection = project.ExtendedAttributes;

            foreach (ExtendedAttributeDefinition extendedAttributeDefinition in attributeCollection)
            {
                Console.WriteLine($"Extended Attribute {extendedAttributeDefinition.FieldName} with alias {extendedAttributeDefinition.Alias} and type {extendedAttributeDefinition.ElementType.ToString()}");
            }

            ExtendedAttributeDefinition extendedAttribute = project.ExtendedAttributes.GetById((int)ExtendedAttributeTask.Number1);

            if (extendedAttribute.ValueList != null && extendedAttribute.ValueList.Count != 0)
            {
                foreach (Value value in extendedAttribute.ValueList)
                {
                    Console.WriteLine($"Value can be {value.StringValue} with description {value.Description}");
                }
            }

            ExtendedAttributeDefinition extendedAttributeDate = project.ExtendedAttributes.GetById((int)ExtendedAttributeTask.Date1);

            string stringFormula = extendedAttributeDate.Formula;

            Console.WriteLine($"Date Formula is {stringFormula}");

            List <Task> taskList = project.SelectAllChildTasks().ToList();

            var valueRetrivalDictionary = new Dictionary <string, Func <ExtendedAttribute, string> >
            {
                { "Text", s => s.TextValue },
                { "Cost", s => s.NumericValue.ToString() },
                { "Number", s => s.NumericValue.ToString() },
                { "Date", s => s.DateValue.ToString() }
            };

            foreach (Task task in taskList)
            {
                foreach (ExtendedAttribute taskExtendedAttribute in task.ExtendedAttributes)
                {
                    string taskValue = string.Empty;

                    string fieldStringType =
                        taskExtendedAttribute.AttributeDefinition.FieldName.Substring(0,
                                                                                      taskExtendedAttribute.AttributeDefinition.FieldName
                                                                                      .Length - 1);
                    valueRetrivalDictionary.TryGetValue(fieldStringType, out Func <ExtendedAttribute, string> valueGetter);

                    if (valueGetter != null)
                    {
                        taskValue = valueGetter(taskExtendedAttribute);
                    }

                    Console.WriteLine($"Task {task} extended attribute {taskExtendedAttribute.AttributeDefinition.Alias} value set to {taskValue}");
                }
            }

            foreach (Resource projectResource in project.Resources)
            {
                foreach (ExtendedAttribute projectResourceExtendedAttribute in projectResource.ExtendedAttributes)
                {
                    string taskValue = string.Empty;

                    string fieldStringType =
                        projectResourceExtendedAttribute.AttributeDefinition.FieldName.Substring(0,
                                                                                                 projectResourceExtendedAttribute
                                                                                                 .AttributeDefinition.FieldName.Length
                                                                                                 - 1);
                    valueRetrivalDictionary.TryGetValue(fieldStringType, out Func <ExtendedAttribute, string> valueGetter);

                    if (valueGetter != null)
                    {
                        taskValue = valueGetter(projectResourceExtendedAttribute);
                    }

                    Console.WriteLine($"Resource {projectResource} extended attribute {projectResourceExtendedAttribute.AttributeDefinition.Alias} value set to {taskValue}");
                }
            }
        }
Пример #16
0
        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

            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManipulatingMPPFile();

            Project project = new Project(dataDir + "Project1.mpp");

            //// Apply Aspose.Task API License
            //License license = new License();

            //// Place license file in Bin/Debug/Folder
            //license.SetLicense("Aspose.Tasks.lic");

            #region task attributes
            // Add new text3 extended attribute and one text value
            ExtendedAttributeDefinition taskTextAttr = new ExtendedAttributeDefinition();
            taskTextAttr.Alias       = "New text3 attribute";
            taskTextAttr.FieldName   = "Text3";
            taskTextAttr.ElementType = ElementType.Task;
            taskTextAttr.CfType      = CustomFieldType.Text;
            taskTextAttr.FieldId     = Convert.ToInt32(ExtendedAttributeTask.Text3).ToString();
            taskTextAttr.LookupUid   = Guid.NewGuid().ToString();
            project.ExtendedAttributes.Add(taskTextAttr);

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

            // Add new cost1 extended attribute and two cost values
            ExtendedAttributeDefinition taskCostAttr = new ExtendedAttributeDefinition();
            taskCostAttr.Alias       = "New cost1 attribute";
            taskCostAttr.FieldName   = "Cost1";
            taskCostAttr.ElementType = ElementType.Task;
            taskCostAttr.CfType      = CustomFieldType.Cost;
            taskCostAttr.FieldId     = Convert.ToInt32(ExtendedAttributeTask.Cost1).ToString();
            taskCostAttr.LookupUid   = Guid.NewGuid().ToString();
            project.ExtendedAttributes.Add(taskCostAttr);

            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";

            taskCostAttr.ValueList.Add(costVal1);
            taskCostAttr.ValueList.Add(costVal2);

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

            ExtendedAttribute taskAttr = new ExtendedAttribute();
            taskAttr.AttributeDefinition = taskCostAttr;
            taskAttr.Value   = "99900";
            taskAttr.FieldId = taskCostAttr.FieldId;
            task.ExtendedAttributes.Add(taskAttr);

            ExtendedAttributeDefinition taskStartAttr = new ExtendedAttributeDefinition();
            taskStartAttr.Alias       = "New start 7 attribute";
            taskStartAttr.CfType      = CustomFieldType.Start;
            taskStartAttr.ElementType = ElementType.Task;
            taskStartAttr.FieldName   = "Start7";
            taskStartAttr.FieldId     = Convert.ToInt32(ExtendedAttributeTask.Start7).ToString();
            taskStartAttr.LookupUid   = Guid.NewGuid().ToString();
            Value startVal = new Value();
            startVal.Val         = DateTime.Now.ToString();
            startVal.Description = "Start 7 value description";

            taskStartAttr.ValueList.Add(startVal);

            project.ExtendedAttributes.Add(taskStartAttr);

            ExtendedAttributeDefinition taskFinishAttr = new ExtendedAttributeDefinition();
            taskFinishAttr.Alias       = "New finish 4 attribute";
            taskFinishAttr.CfType      = CustomFieldType.Finish;
            taskFinishAttr.ElementType = ElementType.Task;
            taskFinishAttr.FieldName   = "Finish4";
            taskFinishAttr.FieldId     = Convert.ToInt32(ExtendedAttributeTask.Finish4).ToString();
            taskFinishAttr.LookupUid   = Guid.NewGuid().ToString();
            Value finishVal = new Value();
            finishVal.Val         = DateTime.Now.ToString();
            finishVal.Description = "Finish 4 value description";

            taskFinishAttr.ValueList.Add(finishVal);

            project.ExtendedAttributes.Add(taskFinishAttr);

            ExtendedAttributeDefinition numberAttr = new ExtendedAttributeDefinition();
            numberAttr.Alias       = "New number attribute";
            numberAttr.FieldName   = "Number20";
            numberAttr.CfType      = CustomFieldType.Number;
            numberAttr.ElementType = ElementType.Task;
            numberAttr.FieldId     = Convert.ToInt32(ExtendedAttributeTask.Number20).ToString();
            numberAttr.LookupUid   = Guid.NewGuid().ToString();
            Value val1 = new Value();
            val1.Val         = "1";
            val1.Description = "Number 1 value";
            Value val2 = new Value();
            val2.Val         = "2";
            val2.Description = "Number 2 value";
            Value val3 = new Value();
            val3.Val         = "3";
            val3.Description = "Number 3 value";

            numberAttr.ValueList.Add(val1);
            numberAttr.ValueList.Add(val2);
            numberAttr.ValueList.Add(val3);

            project.ExtendedAttributes.Add(numberAttr);

            #endregion

            ExtendedAttributeDefinition rscStartAttr = new ExtendedAttributeDefinition();
            rscStartAttr.Alias           = "New start5 attribute";
            rscStartAttr.FieldName       = "Start5";
            rscStartAttr.ElementType     = ElementType.Resource;
            rscStartAttr.CfType          = CustomFieldType.Start;
            rscStartAttr.CalculationType = CalculationType.Rollup;
            rscStartAttr.RollupType      = RollupType.Sum;

            rscStartAttr.FieldId   = Convert.ToInt32(ExtendedAttributeTask.Start5).ToString();;
            rscStartAttr.LookupUid = Guid.NewGuid().ToString();
            Value startVal2 = new Value();
            startVal2.Id          = 4;
            startVal2.Val         = DateTime.Now.ToString();
            startVal2.Description = "this is start5 value descr";

            rscStartAttr.ValueList.Add(startVal2);

            project.ExtendedAttributes.Add(rscStartAttr);

            ExtendedAttributeDefinition myTaskDurattr = new ExtendedAttributeDefinition();
            myTaskDurattr.Alias           = "New Duration";
            myTaskDurattr.CfType          = CustomFieldType.Duration;
            myTaskDurattr.FieldId         = ExtendedAttributeTask.Duration1.ToString("D");
            myTaskDurattr.CalculationType = CalculationType.Rollup;
            myTaskDurattr.RollupType      = RollupType.Sum;
            myTaskDurattr.ElementType     = ElementType.Task;
            project.ExtendedAttributes.Add(myTaskDurattr);

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

            ExtendedAttribute timeexExtendedAttribute = myTaskDurattr.CreateExtendedAttribute();

            timeexExtendedAttribute.DurationFormat = TimeUnitType.Hour;
            timeexExtendedAttribute.Value          = "PT3H0M0S";
            timeTask.ExtendedAttributes.Add(timeexExtendedAttribute);

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

            // Save the project as MPP project file
            project.Save(dataDir + "ExtendedAttribute_out.mpp", mppSaveOptions);
        }
Пример #17
0
        public void WorkWithValue()
        {
            // ExStart
            // ExFor: Value
            // ExFor: Value.#ctor
            // ExFor: Value.Id
            // ExFor: Value.Val
            // ExFor: Value.ValueGuid
            // ExFor: Value.Description
            // ExFor: Value.StringValue
            // ExFor: Value.Phonetic
            // ExFor: Value.Duration
            // ExFor: Value.DateTimeValue
            // ExFor: Value.NumericValue
            // ExSummary: Shows how to read work with lookup values.
            var project = new Project(DataDir + "ReadTaskExtendedAttributes.mpp");

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

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

            Console.WriteLine("Iterate over text lookup values:");
            foreach (var value in textLookup.ValueList)
            {
                Console.WriteLine("Id: " + value.Id);
                Console.WriteLine("GUID: " + value.ValueGuid);
                Console.WriteLine("Value: " + value.Val);
                Console.WriteLine("String Value: " + value.StringValue);
                Console.WriteLine("Description: " + value.Description);
                Console.WriteLine("Phonetic: " + value.Phonetic);
                Console.WriteLine();
            }

            // Create an Extended Attribute Definition of Duration type
            var durationLookup = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                CustomFieldType.Duration,
                ExtendedAttributeTask.Duration1,
                "Custom Durations");

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

            Console.WriteLine("Iterate over duration lookup values:");
            foreach (var value in durationLookup.ValueList)
            {
                Console.WriteLine("Id: " + value.Id);
                Console.WriteLine("GUID: " + value.ValueGuid);
                Console.WriteLine("Value: " + value.Val);
                Console.WriteLine("Duration: " + value.Duration);
                Console.WriteLine("Description: " + value.Description);
                Console.WriteLine("Phonetic: " + value.Phonetic);
                Console.WriteLine();
            }

            // Create an Extended Attribute Definition of Date type
            var dateLookup = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                CustomFieldType.Date,
                ExtendedAttributeTask.Date1,
                "Custom Date");

            dateLookup.AddLookupValue(new Value {
                Id = 7, DateTimeValue = new DateTime(2020, 4, 27, 8, 0, 0), Description = "Start Date", Phonetic = "Start Date"
            });

            Console.WriteLine("Iterate over date lookup values:");
            foreach (var value in dateLookup.ValueList)
            {
                Console.WriteLine("Id: " + value.Id);
                Console.WriteLine("GUID: " + value.ValueGuid);
                Console.WriteLine("Value: " + value.Val);
                Console.WriteLine("DateTime Value: " + value.DateTimeValue);
                Console.WriteLine("Description: " + value.Description);
                Console.WriteLine("Phonetic: " + value.Phonetic);
                Console.WriteLine();
            }

            // Create an Extended Attribute Definition of Number type
            var numericLookup = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                CustomFieldType.Number,
                ExtendedAttributeTask.Number1,
                "Number of tons");

            numericLookup.AddLookupValue(new Value {
                Id = 8, NumericValue = 10, Description = "10 tons", Phonetic = "Ten tons"
            });
            numericLookup.AddLookupValue(new Value {
                Id = 9, NumericValue = 20, Description = "20 tons", Phonetic = "Twenty tons"
            });
            numericLookup.AddLookupValue(new Value {
                Id = 10, NumericValue = 30, Description = "30 tons", Phonetic = "Thirty tons"
            });

            Console.WriteLine("Iterate over numeric lookup values:");
            foreach (var value in numericLookup.ValueList)
            {
                Console.WriteLine("Id: " + value.Id);
                Console.WriteLine("GUID: " + value.ValueGuid);
                Console.WriteLine("Value: " + value.Val);
                Console.WriteLine("Numeric Value: " + value.NumericValue);
                Console.WriteLine("Description: " + value.Description);
                Console.WriteLine("Phonetic: " + value.Phonetic);
                Console.WriteLine();
            }

            project.ExtendedAttributes.Add(textLookup);
            project.ExtendedAttributes.Add(durationLookup);
            project.ExtendedAttributes.Add(dateLookup);
            project.ExtendedAttributes.Add(numericLookup);
            // 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");

                #region task attributes
                // Add new text3 extended attribute and one text value
                ExtendedAttributeDefinition taskTextAttr = new ExtendedAttributeDefinition();
                taskTextAttr.Alias = "New text3 attribute";
                taskTextAttr.FieldName = "Text3";
                taskTextAttr.ElementType = ElementType.Task;
                taskTextAttr.CfType = CustomFieldType.Text;
                taskTextAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Text3).ToString();
                taskTextAttr.LookupUid = Guid.NewGuid().ToString();
                project.ExtendedAttributes.Add(taskTextAttr);

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

                // Add new cost1 extended attribute and two cost values
                ExtendedAttributeDefinition taskCostAttr = new ExtendedAttributeDefinition();
                taskCostAttr.Alias = "New cost1 attribute";
                taskCostAttr.FieldName = "Cost1";
                taskCostAttr.ElementType = ElementType.Task;
                taskCostAttr.CfType = CustomFieldType.Cost;
                taskCostAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Cost1).ToString();
                taskCostAttr.LookupUid = Guid.NewGuid().ToString();
                project.ExtendedAttributes.Add(taskCostAttr);

                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";

                taskCostAttr.ValueList.Add(costVal1);
                taskCostAttr.ValueList.Add(costVal2);

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

                ExtendedAttribute taskAttr = new ExtendedAttribute();
                taskAttr.AttributeDefinition = taskCostAttr;
                taskAttr.Value = "99900";
                taskAttr.FieldId = taskCostAttr.FieldId;
                task.ExtendedAttributes.Add(taskAttr);

                ExtendedAttributeDefinition taskStartAttr = new ExtendedAttributeDefinition();
                taskStartAttr.Alias = "New start 7 attribute";
                taskStartAttr.CfType = CustomFieldType.Start;
                taskStartAttr.ElementType = ElementType.Task;
                taskStartAttr.FieldName = "Start7";
                taskStartAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Start7).ToString();
                taskStartAttr.LookupUid = Guid.NewGuid().ToString();
                Value startVal = new Value();
                startVal.Val = DateTime.Now.ToString();
                startVal.Description = "Start 7 value description";

                taskStartAttr.ValueList.Add(startVal);

                project.ExtendedAttributes.Add(taskStartAttr);

                ExtendedAttributeDefinition taskFinishAttr = new ExtendedAttributeDefinition();
                taskFinishAttr.Alias = "New finish 4 attribute";
                taskFinishAttr.CfType = CustomFieldType.Finish;
                taskFinishAttr.ElementType = ElementType.Task;
                taskFinishAttr.FieldName = "Finish4";
                taskFinishAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Finish4).ToString();
                taskFinishAttr.LookupUid = Guid.NewGuid().ToString();
                Value finishVal = new Value();
                finishVal.Val = DateTime.Now.ToString();
                finishVal.Description = "Finish 4 value description";

                taskFinishAttr.ValueList.Add(finishVal);

                project.ExtendedAttributes.Add(taskFinishAttr);

                ExtendedAttributeDefinition numberAttr = new ExtendedAttributeDefinition();
                numberAttr.Alias = "New number attribute";
                numberAttr.FieldName = "Number20";
                numberAttr.CfType = CustomFieldType.Number;
                numberAttr.ElementType = ElementType.Task;
                numberAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Number20).ToString();
                numberAttr.LookupUid = Guid.NewGuid().ToString();
                Value val1 = new Value();
                val1.Val = "1";
                val1.Description = "Number 1 value";
                Value val2 = new Value();
                val2.Val = "2";
                val2.Description = "Number 2 value";
                Value val3 = new Value();
                val3.Val = "3";
                val3.Description = "Number 3 value";

                numberAttr.ValueList.Add(val1);
                numberAttr.ValueList.Add(val2);
                numberAttr.ValueList.Add(val3);

                project.ExtendedAttributes.Add(numberAttr);

                #endregion

                ExtendedAttributeDefinition rscStartAttr = new ExtendedAttributeDefinition();
                rscStartAttr.Alias = "New start5 attribute";
                rscStartAttr.FieldName = "Start5";
                rscStartAttr.ElementType = ElementType.Resource;
                rscStartAttr.CfType = CustomFieldType.Start;
                rscStartAttr.CalculationType = CalculationType.Rollup;
                rscStartAttr.RollupType = RollupType.Sum;

                rscStartAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Start5).ToString(); ;
                rscStartAttr.LookupUid = Guid.NewGuid().ToString();
                Value startVal2 = new Value();
                startVal2.Id = 4;
                startVal2.Val = DateTime.Now.ToString();
                startVal2.Description = "this is start5 value descr";

                rscStartAttr.ValueList.Add(startVal2);

                project.ExtendedAttributes.Add(rscStartAttr);

                ExtendedAttributeDefinition myTaskDurattr = new ExtendedAttributeDefinition();
                myTaskDurattr.Alias = "New Duration";
                myTaskDurattr.CfType = CustomFieldType.Duration;
                myTaskDurattr.FieldId = ExtendedAttributeTask.Duration1.ToString("D");
                myTaskDurattr.CalculationType = CalculationType.Rollup;
                myTaskDurattr.RollupType = RollupType.Sum;
                myTaskDurattr.ElementType = ElementType.Task;
                project.ExtendedAttributes.Add(myTaskDurattr);

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

                ExtendedAttribute timeexExtendedAttribute = myTaskDurattr.CreateExtendedAttribute();

                timeexExtendedAttribute.DurationFormat = TimeUnitType.Hour;
                timeexExtendedAttribute.Value = "PT3H0M0S";
                timeTask.ExtendedAttributes.Add(timeexExtendedAttribute);

                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.");
            }

        }
Пример #19
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()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

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

                // Create the Extended Attribute Definition of Text Type
                ExtendedAttributeDefinition taskExtendedAttributeText9Definition;
                taskExtendedAttributeText9Definition = new ExtendedAttributeDefinition();
                taskExtendedAttributeText9Definition.Alias = "Task City Name";      
                taskExtendedAttributeText9Definition.FieldName = "Text9";
                taskExtendedAttributeText9Definition.ElementType = ElementType.Task;
                taskExtendedAttributeText9Definition.CfType = CustomFieldType.Text;
                taskExtendedAttributeText9Definition.FieldId = Convert.ToInt32(ExtendedAttributeTask.Text9).ToString(System.Globalization.CultureInfo.InvariantCulture);

                // Create an Extended Attribute Definition of Flag Type
                ExtendedAttributeDefinition taskExtendedAttributeFlag1Definition;
                taskExtendedAttributeFlag1Definition = new ExtendedAttributeDefinition();
                taskExtendedAttributeFlag1Definition.Alias = "Is Billable";
                taskExtendedAttributeFlag1Definition.FieldName = "Flag1";
                taskExtendedAttributeFlag1Definition.ElementType = ElementType.Task;
                taskExtendedAttributeFlag1Definition.CfType = CustomFieldType.Flag;
                taskExtendedAttributeFlag1Definition.FieldId = Convert.ToInt32(ExtendedAttributeTask.Flag1).ToString(System.Globalization.CultureInfo.InvariantCulture);

                // Add the Extended Attribute Definitions to the Project's Extended Attribute Collection
                project1.ExtendedAttributes.Add(taskExtendedAttributeText9Definition);
                project1.ExtendedAttributes.Add(taskExtendedAttributeFlag1Definition);

                // Add a task to project and set its properties
                Task task = project1.RootTask.Children.Add("Task 1");
                task.Set(Tsk.Start, new DateTime(2016, 7, 27, 8, 0, 0));
                task.Set(Tsk.Duration, project1.GetDuration(8, TimeUnitType.Hour));

                // Create Extended Attribute and set it's values
                ExtendedAttribute taskExtendedAttributeText9 = new ExtendedAttribute();
                taskExtendedAttributeText9.FieldId = taskExtendedAttributeText9Definition.FieldId;
                taskExtendedAttributeText9.Value = "London";               
                
                // Create Extended Attribute of Flag type and set it's values
                ExtendedAttribute taskExtendedAttributeFlag1 = new ExtendedAttribute();
                taskExtendedAttributeFlag1.FieldId = taskExtendedAttributeFlag1Definition.FieldId;
                taskExtendedAttributeFlag1.Value = "1";

                // Add the Extended Attributes to Task
                task.ExtendedAttributes.Add(taskExtendedAttributeText9);
                task.ExtendedAttributes.Add(taskExtendedAttributeFlag1);

                // Save the Project               
                project1.Save(dataDir + "AddTaskExtendedAttributes_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()
        {
            // 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");

                #region task attributes

                // 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);

                #endregion

                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.");
            }
        }
Пример #22
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.");
            }
        }
Пример #23
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
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Projects();

            string newFile = dataDir+ "WriteUpdatedExtendedAttributeDefinitions.mpp";
            string resultFile = dataDir+ "Output.mpp";

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

            #region task attributes
            // Add new text3 extended attribute and one text value
            ExtendedAttributeDefinition taskTextAttr = new ExtendedAttributeDefinition();
            taskTextAttr.Alias = "New text3 attribute";
            taskTextAttr.FieldName = "Text3";
            taskTextAttr.ElementType = ElementType.Task;
            taskTextAttr.CfType = CustomFieldType.Text;

            project.ExtendedAttributes.Add(taskTextAttr);

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

            taskTextAttr.ValueList.Add(textVal);

            // Add new cost1 extended attribute and two cost values
            ExtendedAttributeDefinition taskCostAttr = new ExtendedAttributeDefinition();
            taskCostAttr.Alias = "New cost1 attribute";
            taskCostAttr.FieldName = "Cost1";
            taskCostAttr.ElementType = ElementType.Task;
            taskCostAttr.CfType = CustomFieldType.Cost;

            project.ExtendedAttributes.Add(taskCostAttr);

            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";

            taskCostAttr.ValueList.Add(costVal1);
            taskCostAttr.ValueList.Add(costVal2);

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

            ExtendedAttribute taskAttr = new ExtendedAttribute();
            taskAttr.AttributeDefinition = taskCostAttr;
            taskAttr.Value = "99900";
            taskAttr.FieldId = taskCostAttr.FieldId;
            task.ExtendedAttributes.Add(taskAttr);

            ExtendedAttributeDefinition taskStartAttr = new ExtendedAttributeDefinition();
            taskStartAttr.Alias = "New start 7 attribute";
            taskStartAttr.CfType = CustomFieldType.Start;
            taskStartAttr.ElementType = ElementType.Task;
            taskStartAttr.FieldName = "Start7";

            Value startVal = new Value();
            startVal.Val = DateTime.Now.ToString();
            startVal.Description = "Start 7 value description";

            taskStartAttr.ValueList.Add(startVal);

            project.ExtendedAttributes.Add(taskStartAttr);

            ExtendedAttributeDefinition taskFinishAttr = new ExtendedAttributeDefinition();
            taskFinishAttr.Alias = "New finish 4 attribute";
            taskFinishAttr.CfType = CustomFieldType.Finish;
            taskFinishAttr.ElementType = ElementType.Task;
            taskFinishAttr.FieldName = "Finish4";

            Value finishVal = new Value();
            finishVal.Val = DateTime.Now.ToString();
            finishVal.Description = "Finish 4 value description";

            taskFinishAttr.ValueList.Add(finishVal);

            project.ExtendedAttributes.Add(taskFinishAttr);

            ExtendedAttributeDefinition numberAttr = new ExtendedAttributeDefinition();
            numberAttr.Alias = "New number attribute";
            numberAttr.FieldName = "Number20";
            numberAttr.CfType = CustomFieldType.Number;
            numberAttr.ElementType = ElementType.Task;

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

            numberAttr.ValueList.Add(val1);
            numberAttr.ValueList.Add(val2);
            numberAttr.ValueList.Add(val3);

            project.ExtendedAttributes.Add(numberAttr);

            #endregion

            ExtendedAttributeDefinition rscStartAttr = new ExtendedAttributeDefinition();
            rscStartAttr.Alias = "New start5 attribute";
            rscStartAttr.FieldName = "Start5";
            rscStartAttr.ElementType = ElementType.Resource;
            rscStartAttr.CfType = CustomFieldType.Start;

            Value startVal2 = new Value();
            startVal2.Id = 4;
            startVal2.Val = DateTime.Now.ToString();
            startVal2.Description = "this is start5 value descr";

            rscStartAttr.ValueList.Add(startVal2);

            project.ExtendedAttributes.Add(rscStartAttr);


            //Save the project as MPP project file
            project.Save(resultFile, Aspose.Tasks.Saving.SaveFileFormat.MPP);
        }
Пример #25
0
        public async Task TestAddExtendedAttributeDefinition()
        {
            var remoteName = await UploadFileToStorageAsync("NewProductDev.mpp");

            var newExtendedAttribute = new ExtendedAttributeDefinition
            {
                CalculationType = CalculationType.Lookup,
                CfType          = CustomFieldType.Text,
                FieldName       = "Text3",
                ElementType     = ElementType.Task,
                Alias           = "New Field",
                ValueList       = new List <Value>
                {
                    new Value {
                        Description = "descr1", Val = "Internal", Id = 111
                    },
                    new Value {
                        Description = "descr2", Val = "External", Id = 112
                    }
                }
            };

            var response = await TasksApi.PutExtendedAttributeAsync(new PutExtendedAttributeRequest
            {
                ExtendedAttribute = newExtendedAttribute,
                Name   = remoteName,
                Folder = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, response.Code);
            Assert.IsNotNull(response.ExtendedAttribute);

            Assert.AreEqual("Text3", response.ExtendedAttribute.FieldName);
            Assert.AreEqual("New Field", response.ExtendedAttribute.Alias);
            Assert.AreEqual("188743737", response.ExtendedAttribute.FieldId);

            var addedAttributeIndex = response.ExtendedAttribute.Index;


            var getResponse = await TasksApi.GetExtendedAttributeByIndexAsync(new GetExtendedAttributeByIndexRequest
            {
                Index  = addedAttributeIndex,
                Name   = remoteName,
                Folder = this.DataFolder
            });

            Assert.AreEqual((int)HttpStatusCode.OK, getResponse.Code);
            Assert.IsNotNull(getResponse.ExtendedAttribute);

            var extendedAttribute = getResponse.ExtendedAttribute;


            Assert.AreEqual("188743737", extendedAttribute.FieldId);
            Assert.AreEqual("Text3", extendedAttribute.FieldName);
            Assert.AreEqual(CustomFieldType.Text, extendedAttribute.CfType);
            Assert.AreEqual("New Field", extendedAttribute.Alias);
            var valueList = extendedAttribute.ValueList;

            Assert.AreEqual(2, valueList.Count);

            Assert.AreEqual(111, valueList[0].Id);
            Assert.AreEqual("Internal", valueList[0].Val);
            Assert.AreEqual("descr1", valueList[0].Description);

            Assert.AreEqual(112, valueList[1].Id);
            Assert.AreEqual("External", valueList[1].Val);
            Assert.AreEqual("descr2", valueList[1].Description);
        }
        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.");
            }
        }
Пример #27
0
        static void Main(string[] args)
        {
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data", "TestProject.mpp");

            Project myProject = new Project(filePath);


            ExtendedAttributeDefinition attribute = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Test Attribute");

            Value value1 = new Value
            {
                Id          = 1,
                StringValue = "Server/Database",
                Description = "DataBase of Server Side"
            };

            Value value2 = new Value
            {
                Id          = 2,
                StringValue = "Server/Api",
                Description = "Api of Server Side"
            };

            Value value3 = new Value
            {
                Id          = 3,
                StringValue = "Client/WebUI",
                Description = "WebUI of Client Side"
            };

            attribute.AddLookupValue(value1);

            attribute.AddLookupValue(value2);

            attribute.AddLookupValue(value3);

            myProject.ExtendedAttributes.Add(attribute);


            ExtendedAttribute serverDatabaseAttribute = attribute.CreateExtendedAttribute(value1);

            ExtendedAttribute serverApiAttribute = attribute.CreateExtendedAttribute(value2);

            ExtendedAttribute clientUIAttribute = attribute.CreateExtendedAttribute(value3);


            Task task1 = myProject.RootTask.Children.Add("Task 1");

            task1.ExtendedAttributes.Add(serverDatabaseAttribute);


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

            task2.ExtendedAttributes.Add(serverDatabaseAttribute);


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

            task3.ExtendedAttributes.Add(serverApiAttribute);


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

            task4.ExtendedAttributes.Add(clientUIAttribute);

            myProject.Save(filePath, SaveFileFormat.MPP);
        }
Пример #28
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Projects();

            string newFile    = dataDir + "WriteUpdatedExtendedAttributeDefinitions.mpp";
            string resultFile = dataDir + "Output.mpp";

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

            #region task attributes
            // Add new text3 extended attribute and one text value
            ExtendedAttributeDefinition taskTextAttr = new ExtendedAttributeDefinition();
            taskTextAttr.Alias       = "New text3 attribute";
            taskTextAttr.FieldName   = "Text3";
            taskTextAttr.ElementType = ElementType.Task;
            taskTextAttr.CfType      = CustomFieldType.Text;

            project.ExtendedAttributes.Add(taskTextAttr);

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

            taskTextAttr.ValueList.Add(textVal);

            // Add new cost1 extended attribute and two cost values
            ExtendedAttributeDefinition taskCostAttr = new ExtendedAttributeDefinition();
            taskCostAttr.Alias       = "New cost1 attribute";
            taskCostAttr.FieldName   = "Cost1";
            taskCostAttr.ElementType = ElementType.Task;
            taskCostAttr.CfType      = CustomFieldType.Cost;

            project.ExtendedAttributes.Add(taskCostAttr);

            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";

            taskCostAttr.ValueList.Add(costVal1);
            taskCostAttr.ValueList.Add(costVal2);

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

            ExtendedAttribute taskAttr = new ExtendedAttribute();
            taskAttr.AttributeDefinition = taskCostAttr;
            taskAttr.Value   = "99900";
            taskAttr.FieldId = taskCostAttr.FieldId;
            task.ExtendedAttributes.Add(taskAttr);

            ExtendedAttributeDefinition taskStartAttr = new ExtendedAttributeDefinition();
            taskStartAttr.Alias       = "New start 7 attribute";
            taskStartAttr.CfType      = CustomFieldType.Start;
            taskStartAttr.ElementType = ElementType.Task;
            taskStartAttr.FieldName   = "Start7";

            Value startVal = new Value();
            startVal.Val         = DateTime.Now.ToString();
            startVal.Description = "Start 7 value description";

            taskStartAttr.ValueList.Add(startVal);

            project.ExtendedAttributes.Add(taskStartAttr);

            ExtendedAttributeDefinition taskFinishAttr = new ExtendedAttributeDefinition();
            taskFinishAttr.Alias       = "New finish 4 attribute";
            taskFinishAttr.CfType      = CustomFieldType.Finish;
            taskFinishAttr.ElementType = ElementType.Task;
            taskFinishAttr.FieldName   = "Finish4";

            Value finishVal = new Value();
            finishVal.Val         = DateTime.Now.ToString();
            finishVal.Description = "Finish 4 value description";

            taskFinishAttr.ValueList.Add(finishVal);

            project.ExtendedAttributes.Add(taskFinishAttr);

            ExtendedAttributeDefinition numberAttr = new ExtendedAttributeDefinition();
            numberAttr.Alias       = "New number attribute";
            numberAttr.FieldName   = "Number20";
            numberAttr.CfType      = CustomFieldType.Number;
            numberAttr.ElementType = ElementType.Task;

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

            numberAttr.ValueList.Add(val1);
            numberAttr.ValueList.Add(val2);
            numberAttr.ValueList.Add(val3);

            project.ExtendedAttributes.Add(numberAttr);

            #endregion

            ExtendedAttributeDefinition rscStartAttr = new ExtendedAttributeDefinition();
            rscStartAttr.Alias       = "New start5 attribute";
            rscStartAttr.FieldName   = "Start5";
            rscStartAttr.ElementType = ElementType.Resource;
            rscStartAttr.CfType      = CustomFieldType.Start;

            Value startVal2 = new Value();
            startVal2.Id          = 4;
            startVal2.Val         = DateTime.Now.ToString();
            startVal2.Description = "this is start5 value descr";

            rscStartAttr.ValueList.Add(startVal2);

            project.ExtendedAttributes.Add(rscStartAttr);


            //Save the project as MPP project file
            project.Save(resultFile, Aspose.Tasks.Saving.SaveFileFormat.MPP);
        }
Пример #29
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
        }
Пример #30
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
        }