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

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

                project.RootTask.Children.Add("Task1");
                PageInfo pageInfo = project.DefaultView.PageInfo;

                using (Image image = Image.FromFile(dataDir + "Image1.png"))
                {
                    pageInfo.Header.CenteredImage = image;
                    pageInfo.Legend.LeftImage     = image;
                    pageInfo.Legend.LeftText      = string.Empty;
                    MPPSaveOptions saveOptions = new MPPSaveOptions();
                    saveOptions.WriteViewData = true;
                    project.Save(dataDir + "AddImageToPageHeaderFooter_out.mpp", saveOptions);
                }
                // ExEnd:AddImageToPageHeaderFooter
            }
            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.");
            }
        }
        // ExStart:ImplementCustomBarStyleWriting
        static void ImplementCustomBarSytle()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

                Project project = new Project(dataDir + "Blank2010.mpp");
                project.RootTask.Children.Add("Task");

                GanttChartView view = project.DefaultView as GanttChartView;
                GanttBarStyle custom = GetCustomBarStyle();

                // Add the custom bar style to the custom bar collection of the project view
                view.CustomBarStyles.Add(custom);

                string file = "ImplementCustomBarStyleWriting_out.mpp";

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

                project.Save(dataDir + file, options);
            }
            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.");
            }
        }
        [Test] // ExSkip
        public void ImplementCustomBarStyle()
        {
            try
            {
                var project = new Project(DataDir + "Blank2010.mpp");
                project.RootTask.Children.Add("Task");

                var view   = (GanttChartView)project.DefaultView;
                var custom = GetCustomBarStyle();

                // Add the custom bar style to the custom bar collection of the project view
                view.CustomBarStyles.Add(custom);

                var options = new MPPSaveOptions
                {
                    WriteViewData = true
                };

                project.Save(OutDir + "ImplementCustomBarStyleWriting_out.mpp", options);
            }
            catch (NotSupportedException ex)
            {
                Console.WriteLine(
                    ex.Message
                    + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
Beispiel #4
0
 public static void Run()
 {
     // ExStart:AddImageToPageHeaderFooter
     try
     {
         // The path to the documents directory.
         string  dataDir = RunExamples.GetDataDir_ManipulatingMPPFile();
         Project project = new Project(dataDir + "Project1.mpp");
         project.RootTask.Children.Add("Task1");
         PageInfo pageInfo = project.DefaultView.PageInfo;
         using (Image image = Image.FromFile(dataDir + "Image1.png"))
         {
             pageInfo.Header.CenteredImage = image;
             pageInfo.Legend.LeftImage     = image;
             pageInfo.Legend.LeftText      = string.Empty;
             MPPSaveOptions saveOptions = new MPPSaveOptions();
             saveOptions.WriteViewData = true;
             // see the result in the attached screenshot
             project.Save(dataDir + "ReadHeaderAndFooterInformationFromMPPFile1_out.mpp", saveOptions);
         }
     }
     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.");
     }
     // ExEnd:AddImageToPageHeaderFooter
 }
        // ExStart:ImplementCustomBarStyleWriting
        static void ImplementCustomBarSytle()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

                Project project = new Project(dataDir + "Blank2010.mpp");
                project.RootTask.Children.Add("Task");

                GanttChartView view   = project.DefaultView as GanttChartView;
                GanttBarStyle  custom = GetCustomBarStyle();

                // Add the custom bar style to the custom bar collection of the project view
                view.CustomBarStyles.Add(custom);

                string file = "ImplementCustomBarStyleWriting_out.mpp";

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

                project.Save(dataDir + file, options);
            }
            catch (NotSupportedException ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
        public void CreateEmptyProjectToSaveToStreamOptions()
        {
            try
            {
                // ExStart:CreateEmptyProjectToSaveToStreamWithMPPSaveOptions
                // ExFor: MPPSaveOptions
                // ExFor: MPPSaveOptions.RemoveInvalidAssignments
                // ExFor: MPPSaveOptions.WriteViewData
                // ExSummary: Shows how to save project into a stream as an MPP file.
                using (var stream = new FileStream(OutDir + "EmptyProjectSaveStream_out.xml", FileMode.Create, FileAccess.Write))
                {
                    var project = new Project(DataDir + "EstimatedMilestoneTasks.mpp");

                    // create save options
                    var options = new MPPSaveOptions
                    {
                        // sets a value indicating whether to remove invalid resource assignments when saving to MPP
                        RemoveInvalidAssignments = true
                    };

                    // save MPP with options
                    project.Save(stream, options);
                }

                // ExEnd:CreateEmptyProjectToSaveToStreamWithMPPSaveOptions
            }
            catch (NotSupportedException ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

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

                project.RootTask.Children.Add("Task1");
                PageInfo pageInfo = project.DefaultView.PageInfo;
                
                using (Image image = Image.FromFile(dataDir + "Image1.png"))
                {
                    pageInfo.Header.CenteredImage = image;
                    pageInfo.Legend.LeftImage = image;
                    pageInfo.Legend.LeftText = string.Empty;
                    MPPSaveOptions saveOptions = new MPPSaveOptions();
                    saveOptions.WriteViewData = true;
                    project.Save(dataDir + "AddImageToPageHeaderFooter_out.mpp", saveOptions);
                }
                // ExEnd:AddImageToPageHeaderFooter
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
Beispiel #8
0
        public void WorkWithTableTextStyle()
        {
            try
            {
                // ExStart:WorkWithTableTextStyle
                // ExFor: TableTextStyle
                // ExFor: TableTextStyle.#ctor(Int32)
                // ExFor: TableTextStyle.Field
                // ExFor: TableTextStyle.ItemType
                // ExFor: TableTextStyle.RowUid
                // ExFor: Field
                // ExSummary: Shows how to customize table text styles which are used to style different text items in a project.
                var project = new Project(DataDir + "Project2.mpp");
                project.Set(Prj.NewTasksAreManual, false);

                var view = (GanttChartView)project.Views.ToList()[0];

                // set first task name text style
                var style1 = new TableTextStyle(1);
                // set a field the style is to be applied to.
                style1.Field = Field.TaskName;
                // set <see cref="P:Aspose.Tasks.Visualization.TextStyle.FontStyle" /> of the text style font.
                style1.FontStyle = FontStyle.Bold | FontStyle.Italic;
                // set <see cref="P:Aspose.Tasks.Visualization.TextStyle.FontFamily" /> of the text style.
                style1.FontFamily = new FontFamily("Impact");
                // set size in points of the text style font.
                style1.SizeInPoints = 12;

                // set second task duration text style
                var style2 = new TableTextStyle(2);
                style2.Field        = Field.TaskDurationText;
                style2.FontStyle    = FontStyle.Underline;
                style2.FontFamily   = new FontFamily("Impact");
                style2.SizeInPoints = 16;

                view.TableTextStyles.Add(style1);
                view.TableTextStyles.Add(style2);

                var options = new MPPSaveOptions
                {
                    // set a flag indicating that view data must be written
                    WriteViewData = true
                };
                project.Save(OutDir + "WorkWithTableTextStyle_out.mpp", options);

                // ExEnd:WorkWithTableTextStyle
            }
            catch (NotSupportedException ex)
            {
                Console.WriteLine(
                    ex.Message
                    + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
Beispiel #9
0
        public void WorkWithPageSetting()
        {
            try
            {
                // ExStart
                // ExFor: Aspose.Tasks.Visualization.PageSettings
                // ExFor: Aspose.Tasks.Visualization.PageSettings.#ctor
                // ExFor: Aspose.Tasks.Visualization.PageSettings.AdjustToPercentOfNormalSize
                // ExFor: Aspose.Tasks.Visualization.PageSettings.FirstPageNumber
                // ExFor: Aspose.Tasks.Visualization.PageSettings.IsPortrait
                // ExFor: Aspose.Tasks.Visualization.PageSettings.PagesInHeight
                // ExFor: Aspose.Tasks.Visualization.PageSettings.PagesInWidth
                // ExFor: Aspose.Tasks.Visualization.PageSettings.PaperSize
                // ExFor: Aspose.Tasks.Visualization.PageSettings.PercentOfNormalSize
                // ExSummary: Shows how to work with <see cref="Aspose.Tasks.Visualization.PageSettings" />.
                var project = new Project(DataDir + "Project2.mpp");

                // get the settings
                var settings = project.DefaultView.PageInfo.PageSettings;
                // lets tune some properties
                // set a value indicating whether the page orientation is portrait; returns false if the page orientation is landscape.
                settings.IsPortrait = true;
                // set a number of pages in width to be printed.
                settings.PagesInWidth = 5;
                // set a number of pages in height to be printed.
                settings.PagesInHeight = 7;
                // set a percentage of normal size to adjust printing to.
                settings.PercentOfNormalSize = 200;
                // set a value indicating whether to adjust printing to the specified percentage of normal size.
                settings.AdjustToPercentOfNormalSize = false;
                // set a paper size. Can be one of the values of the <see cref="T:Aspose.Tasks.Visualization.PrinterPaperSize" /> enumeration.
                settings.PaperSize = PrinterPaperSize.PaperB4;
                // set a first page number for printing.
                settings.FirstPageNumber = 3;

                var options = new MPPSaveOptions
                {
                    WriteViewData = true
                };

                project.Save(OutDir + "TestCanWritePageSettings.mpp", options);
                // ExEnd
            }
            catch (NotSupportedException ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
        public static void Run()
        {
            // 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()
        {
            // 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.");
            }
        }
Beispiel #12
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);
        }
        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.");
            }

        }