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; }
private static Project CreateTestProjectWithCustomField() { Project project = new Project(); project.Set(Prj.StartDate, new DateTime(2015, 3, 6, 8, 0, 0)); ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Number, ExtendedAttributeTask.Number1, "Custom"); project.ExtendedAttributes.Add(attr); Task task = project.RootTask.Children.Add("Task"); ExtendedAttribute extendedAttribute = attr.CreateExtendedAttribute(); task.ExtendedAttributes.Add(extendedAttribute); return(project); }
static Project CreateTestProjectWithCustomFieldWithoutResource() { Project project = new Project(); project.Set(Prj.StartDate, new DateTime(2015, 3, 6, 8, 0, 0)); ExtendedAttributeDefinition attr = new ExtendedAttributeDefinition(); project.ExtendedAttributes.Add(attr); attr.FieldId = ExtendedAttributeTask.Text1.ToString("D"); 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 = "Custom Field"; 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(); project.ExtendedAttributes.Add(attr); attr.FieldId = ExtendedAttributeTask.Text1.ToString("D"); Task task = project.RootTask.Children.Add("Task"); ExtendedAttribute extendedAttribute = attr.CreateExtendedAttribute(); task.ExtendedAttributes.Add(extendedAttribute); Resource rsc = project.Resources.Add("Rsc"); ResourceAssignment assn = project.ResourceAssignments.Add(task, rsc); return(project); }
public static void Run() { // ExStart:ReadOnlyAccessToCustomFieldValuesUsingFormulas Project project = new Project(); ExtendedAttributeDefinition attribute = new ExtendedAttributeDefinition { FieldId = ((int)ExtendedAttributeTask.Text1).ToString(), Formula = "[Cost]-[Actual Cost]" }; project.ExtendedAttributes.Add(attribute); Task task = project.RootTask.Children.Add("Task"); ExtendedAttribute extendedAttribute = attribute.CreateExtendedAttribute(); task.ExtendedAttributes.Add(extendedAttribute); 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:ReadOnlyAccessToCustomFieldValuesUsingFormulas }
public static void Run() { try { // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); // ExStart:ConfigureTheGantChartViewShowSelectedColumnFields Project project = new Project(dataDir + "Project5.mpp"); // Create a new project task Task task = project.RootTask.Children.Add("New Activity"); // Define new custom attribute ExtendedAttributeDefinition text1Definition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, null); project.ExtendedAttributes.Add(text1Definition); // Add custom text attribute to created task. task.ExtendedAttributes.Add(text1Definition.CreateExtendedAttribute("Activity attribute")); // Customize table by adding text attribute field TableField attrField = new TableField(); attrField.Field = Field.TaskText1; attrField.Width = 20; attrField.Title = "Custom attribute"; attrField.AlignTitle = StringAlignment.Center; attrField.AlignData = StringAlignment.Center; Table table = project.Tables.ToList()[0]; table.TableFields.Insert(3, attrField); // Save project as MPP project.Save(dataDir + "ConfigureTheGantChartViewShowSelectedColumnFields_out.mpp", new MPPSaveOptions() { WriteViewData = true }); // ExEnd:ConfigureTheGantChartViewShowSelectedColumnFields } catch (Exception ex) { Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); } }
// 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; }
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 = project1.ExtendedAttributes.GetById((int)ExtendedAttributeTask.Number1); if (myNumber1 == null) { myNumber1 = ExtendedAttributeDefinition.CreateResourceDefinition(ExtendedAttributeResource.Number1, "Age"); project1.ExtendedAttributes.Add(myNumber1); } // Create extended attribute and set its value ExtendedAttribute number1Resource = myNumber1.CreateExtendedAttribute(); number1Resource.NumericValue = 30.5345m; // 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 myTextAttributeDefinition = project1.ExtendedAttributes.GetById((int)ExtendedAttributeTask.Text1); // If the Custom field doesn't exist in Project, create it if (myTextAttributeDefinition == null) { myTextAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Text1, "My text field"); project1.ExtendedAttributes.Add(myTextAttributeDefinition); } // Generate Extended Attribute from definition ExtendedAttribute text1TaskAttribute = myTextAttributeDefinition.CreateExtendedAttribute(); text1TaskAttribute.TextValue = "Text attribute value"; // Add extended attribute to task Task tsk = project1.RootTask.Children.Add("Task 1"); tsk.ExtendedAttributes.Add(text1TaskAttribute); project1.Save(dataDir + "CreateExtendedAttributes_out.mpp", SaveFileFormat.MPP); // ExEnd:CreateExtendedAttributes } catch (Exception ex) { Console.Write(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx."); } }
public 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."); } }
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() { // This example requires Aspose.Task for .NET, a trial version can be download from http://www.aspose.com/corporate/purchase/temporary-license.aspx try { // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); //ExStart:WriteUpdatedExtendedAttributeDefinitions Project project = new Project(dataDir + "WriteUpdatedExtendedAttributeDefinitions.mpp"); // Add new text3 extended attribute with lookup and one lookup value ExtendedAttributeDefinition taskTextAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Text3, "New text3 attribute"); taskTextAttributeDefinition.ElementType = ElementType.Task; project.ExtendedAttributes.Add(taskTextAttributeDefinition); Value textVal = new Value(); textVal.Id = 1; textVal.Description = "Text value descr"; textVal.Val = "Text value1"; taskTextAttributeDefinition.AddLookupValue(textVal); // Add new cost1 extended attribute with lookup and two cost values ExtendedAttributeDefinition taskCostAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Cost1, "New cost1 attribute"); project.ExtendedAttributes.Add(taskCostAttributeDefinition); Value costVal1 = new Value(); costVal1.Id = 2; costVal1.Description = "Cost value 1 descr"; costVal1.Val = "99900"; Value costVal2 = new Value(); costVal2.Id = 3; costVal2.Description = "Cost value 2 descr"; costVal2.Val = "11100"; taskCostAttributeDefinition.AddLookupValue(costVal1); taskCostAttributeDefinition.AddLookupValue(costVal2); // Add new task and assign attribute lookup value. Task task = project.RootTask.Children.Add("New task"); ExtendedAttribute taskAttr = taskCostAttributeDefinition.CreateExtendedAttribute(costVal1); task.ExtendedAttributes.Add(taskAttr); ExtendedAttributeDefinition taskStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Start7, "New start 7 attribute"); Value startVal = new Value(); startVal.Id = 4; startVal.DateTimeValue = DateTime.Now; startVal.Description = "Start 7 value description"; taskStartAttributeDefinition.AddLookupValue(startVal); project.ExtendedAttributes.Add(taskStartAttributeDefinition); ExtendedAttributeDefinition taskFinishAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Finish4, "New finish 4 attribute"); Value finishVal = new Value(); finishVal.Id = 5; finishVal.DateTimeValue = DateTime.Now; finishVal.Description = "Finish 4 value description"; taskFinishAttributeDefinition.ValueList.Add(finishVal); project.ExtendedAttributes.Add(taskFinishAttributeDefinition); ExtendedAttributeDefinition numberAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Number20, "New number attribute"); Value val1 = new Value(); val1.Id = 6; val1.Val = "1"; val1.Description = "Number 1 value"; Value val2 = new Value(); val2.Id = 7; val2.Val = "2"; val2.Description = "Number 2 value"; Value val3 = new Value(); val2.Id = 8; val3.Val = "3"; val3.Description = "Number 3 value"; numberAttributeDefinition.AddLookupValue(val1); numberAttributeDefinition.AddLookupValue(val2); numberAttributeDefinition.AddLookupValue(val3); project.ExtendedAttributes.Add(numberAttributeDefinition); ExtendedAttributeDefinition rscStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupResourceDefinition(ExtendedAttributeResource.Start5, "New start5 attribute"); Value startVal2 = new Value(); startVal2.Id = 9; startVal2.DateTimeValue = DateTime.Now; startVal2.Description = "this is start5 value descr"; rscStartAttributeDefinition.AddLookupValue(startVal2); project.ExtendedAttributes.Add(rscStartAttributeDefinition); // Define a duration attribute without lookup. ExtendedAttributeDefinition taskDurationAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Duration1, "New Duration"); project.ExtendedAttributes.Add(taskDurationAttributeDefinition); // Add new task and assign duration value to the previously defined duration attribute. Task timeTask = project.RootTask.Children.Add("New task"); ExtendedAttribute durationExtendedAttribute = taskDurationAttributeDefinition.CreateExtendedAttribute(); durationExtendedAttribute.DurationValue = project.GetDuration(3.0, TimeUnitType.Hour); timeTask.ExtendedAttributes.Add(durationExtendedAttribute); MPPSaveOptions mppSaveOptions = new MPPSaveOptions(); mppSaveOptions.WriteViewData = true; // Save the project as MPP project file project.Save(dataDir + "WriteUpdatedExtendedAttributeDefinitions_out.mpp", mppSaveOptions); //ExEnd:WriteUpdatedExtendedAttributeDefinitions } catch (Exception ex) { Console.Write(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx."); } }
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."); } }
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); }
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 }
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); }
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."); } }