Exemple #1
0
        public void HandleValidationException()
        {
            // ExStart:ExValidationException
            // ExFor: ValidationException
            // ExFor: ValidationException.#ctor(SerializationInfo,StreamingContext)
            // ExSummary: Shows how to handle <see cref="ValidationException"/> while working with recurrence tasks.
            try
            {
                var project    = new Project();
                var parameters = new RecurringTaskParameters {
                    TaskName = "t1", Duration = project.GetDuration(1, TimeUnitType.Day), RecurrencePattern = null
                };
                project.RootTask.Children.Add(parameters);
            }
            catch (ValidationException ex)
            {
                Console.WriteLine("Message: ");
                Console.WriteLine(ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine("Inner exception message: ");
                    Console.WriteLine(ex.InnerException.Message);
                }
            }

            // ExEnd:ExValidationException
        }
        public void CreateRecurringTask()
        {
            try
            {
                // ExStart:CreateRecurringTask
                // ExFor: RecurringTaskParameters
                // ExFor: RecurringTaskParameters.#ctor
                // ExFor: RecurringTaskParameters.Duration
                // ExFor: RecurringTaskParameters.RecurrencePattern
                // ExFor: RecurringTaskParameters.IgnoreResourceCalendar
                // ExFor: RecurringTaskParameters.TaskName
                // ExFor: RecurringTaskParameters.SetCalendar(Project,String)
                // ExFor: WeeklyRecurrencePattern
                // ExFor: WeeklyRecurrencePattern.#ctor
                // ExFor: WeeklyRecurrencePattern.Repetition
                // ExFor: EndByRecurrenceRange
                // ExFor: EndByRecurrenceRange.#ctor
                // ExFor: EndByRecurrenceRange.Finish
                // ExFor: WeeklyRepetition
                // ExFor: WeeklyRepetition.#ctor
                // ExFor: WeeklyRepetition.WeekDays
                // ExFor: WeeklyRepetitionBase
                // ExFor: WeeklyRepetitionBase.#ctor
                // ExFor: WeeklyRepetitionBase.RepetitionInterval
                // ExFor: WeekdayType
                // ExFor: RecurrencePattern
                // ExSummary: Shows how to create a recurring task.
                var project    = new Project(DataDir + "Blank2010.mpp");
                var parameters = new RecurringTaskParameters
                {
                    TaskName          = "Recurring task",
                    Duration          = project.GetDuration(1, TimeUnitType.Day),
                    RecurrencePattern = new WeeklyRecurrencePattern
                    {
                        Repetition = new WeeklyRepetition
                        {
                            RepetitionInterval = 2,
                            WeekDays           = WeekdayType.Sunday | WeekdayType.Monday | WeekdayType.Friday
                        },
                        RecurrenceRange = new EndByRecurrenceRange
                        {
                            Start  = new DateTime(2018, 7, 1, 8, 0, 0),
                            Finish = new DateTime(2018, 7, 20, 17, 0, 0)
                        }
                    },
                    IgnoreResourceCalendar = false
                };

                parameters.SetCalendar(project, "Standard");

                project.RootTask.Children.Add(parameters);

                // ExEnd:CreateRecurringTask
            }
            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 WorkWithDailyWorkRepetition()
        {
            // ExStart
            // ExFor: DailyWorkRepetition
            // ExFor: DailyWorkRepetition.#ctor
            // ExFor: DailyRepetitionBase
            // ExFor: DailyRepetitionBase.#ctor
            // ExFor: DailyRepetitionBase.RepetitionInterval
            // ExFor: DailyRecurrencePattern
            // ExFor: DailyRecurrencePattern.#ctor
            // ExFor: DailyRecurrencePattern.Repetition
            // ExFor: EndAfterRecurrenceRange
            // ExFor: EndAfterRecurrenceRange.#ctor
            // ExFor: EndAfterRecurrenceRange.OccurrenceNumber
            // ExFor: RecurrenceRangeBase
            // ExFor: RecurrenceRangeBase.#ctor
            // ExFor: RecurrenceRangeBase.Start
            // ExFor: RecurrencePatternBase
            // ExFor: RecurrencePatternBase.#ctor
            // ExFor: RecurrencePatternBase.RecurrenceRange
            // ExSummary: Shows how to work with daily work repetition pattern repetitions while create recurring tasks.
            var project    = new Project(DataDir + "Project1.mpp");
            var parameters = new RecurringTaskParameters
            {
                TaskName          = "New recurrent task",
                RecurrencePattern = new DailyRecurrencePattern
                {
                    RecurrenceRange = new EndAfterRecurrenceRange
                    {
                        Start = new DateTime(2018, 1, 1, 8, 0, 0), OccurrenceNumber = 9
                    },
                    Repetition = new DailyWorkRepetition {
                        RepetitionInterval = 1
                    }
                },
                Duration = project.GetDuration(1, TimeUnitType.Hour)
            };

            parameters.SetCalendar(project, "Standard");

            var task = project.RootTask.Children.Add(parameters);

            task.Set(Tsk.Start, new DateTime(2020, 4, 27, 8, 0, 0));

            // work with the project further...
            // ...
            // ExEnd
        }
Exemple #4
0
        public void WorkWithDailyWorkRepetition()
        {
            try
            {
// ExStart
                // ExFor: DailyCalendarRepetition
                // ExFor: DailyCalendarRepetition.#ctor
                // ExSummary: Shows how to work with daily work repetition pattern repetitions and a '24 Hours' while create recurring tasks.
                var project  = new Project(DataDir + "Project1.mpp");
                var calendar = project.Calendars.Add("24 Hours");
                Calendar.Make24HourCalendar(calendar);
                var parameters = new RecurringTaskParameters
                {
                    TaskName          = "t1",
                    Duration          = project.GetDuration(1, TimeUnitType.Day),
                    RecurrencePattern = new DailyRecurrencePattern
                    {
                        Repetition = new DailyCalendarRepetition {
                            RepetitionInterval = 1
                        },
                        RecurrenceRange = new EndByRecurrenceRange
                        {
                            Start  = new DateTime(2018, 7, 2, 0, 0, 0),
                            Finish = new DateTime(2018, 7, 8, 16, 0, 0)
                        }
                    }
                };
                parameters.SetCalendar(project, "24 Hours");
                project.RootTask.Children.Add(parameters);

                // work with the project further...
                project.Save(OutDir + "CanAddRecurringTask_Days_CalendarDays_24h_Test_out.mpp", SaveFileFormat.MPP);

                // 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 void WorkWithByYearDayRepetition()
        {
            try
            {
                // ExStart
                // ExFor: ByYearDayRepetition
                // ExFor: ByYearDayRepetition.#ctor
                // ExFor: ByYearDayRepetition.DayPosition
                // ExFor: ByYearDayRepetition.Month
                // ExFor: YearlyRepetitionBase
                // ExFor: YearlyRepetitionBase.#ctor
                // ExFor: Month
                // ExSummary: Shows how to work with year day repetitions while create a new recurring tasks.
                var project    = new Project(DataDir + "Project1.mpp");
                var parameters = new RecurringTaskParameters
                {
                    TaskName          = "t1",
                    Duration          = project.GetDuration(1, TimeUnitType.Day),
                    RecurrencePattern = new YearlyRecurrencePattern
                    {
                        Repetition = new ByYearDayRepetition {
                            DayPosition = 1, Month = Month.July
                        },
                        RecurrenceRange = new EndByRecurrenceRange
                        {
                            Start  = new DateTime(2018, 7, 1, 8, 0, 0),
                            Finish = new DateTime(2019, 7, 1, 17, 0, 0)
                        }
                    }
                };
                project.RootTask.Children.Add(parameters);

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

                // 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 void WorkWithByMonthDayRepetition()
        {
            try
            {
                // ExStart
                // ExFor: ByMonthWeekDayRepetition
                // ExFor: ByMonthWeekDayRepetition.#ctor
                // ExFor: ByMonthWeekDayRepetition.Position
                // ExFor: ByMonthWeekDayRepetition.WeekDay
                // ExSummary: Shows how to work with month weekday repetitions while create a new recurring tasks.
                var project    = new Project(DataDir + "Project1.mpp");
                var parameters = new RecurringTaskParameters
                {
                    TaskName          = "t1",
                    Duration          = project.GetDuration(1, TimeUnitType.Day),
                    RecurrencePattern = new MonthlyRecurrencePattern
                    {
                        Repetition = new ByMonthWeekDayRepetition
                        {
                            Position           = OrdinalNumber.First,
                            WeekDay            = DayOfWeek.Sunday,
                            RepetitionInterval = 2
                        },
                        RecurrenceRange = new EndByRecurrenceRange
                        {
                            Start  = new DateTime(2018, 7, 1, 8, 0, 0),
                            Finish = new DateTime(2018, 9, 2, 17, 0, 0)
                        }
                    }
                };
                project.RootTask.Children.Add(parameters);
                project.Save(OutDir + "CanAddRecurringTask_Months_WeekDay_EndByRecurrenceRange_Test_out.mpp", SaveFileFormat.MPP);

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

                // ExStart:CreateRecurringTask
                // Create project instance
                var project    = new Project(dataDir + "Blank2010.mpp");
                var parameters = new RecurringTaskParameters
                {
                    TaskName          = "Recurring task",
                    Duration          = project.GetDuration(1, TimeUnitType.Day),
                    RecurrencePattern =
                        new WeeklyRecurrencePattern
                    {
                        Repetition = new WeeklyRepetition
                        {
                            RepetitionInterval = 2,
                            WeekDays           =
                                WeekdayType.Sunday | WeekdayType.Monday
                                | WeekdayType.Friday,
                        },
                        RecurrenceRange =
                            new EndByRecurrenceRange
                        {
                            Start  = new DateTime(2018, 7, 1, 8, 0, 0),
                            Finish = new DateTime(2018, 7, 20, 17, 0, 0),
                        }
                    }
                };
                project.RootTask.Children.Add(parameters);
                // ExEnd:CreateRecurringTask
            }
            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 void WorkWithTaskCollection()
        {
            // ExStart:WorkWithTaskCollection
            // ExFor: TaskCollection
            // ExFor: TaskCollection.Add
            // ExFor: TaskCollection.Add(String)
            // ExFor: TaskCollection.Add(RecurringTaskParameters)
            // ExFor: TaskCollection.Add(String,Int32)
            // ExFor: TaskCollection.Count
            // ExFor: TaskCollection.GetById(Int32)
            // ExFor: TaskCollection.GetByUid(Int32)
            // ExFor: TaskCollection.GetEnumerator
            // ExFor: TaskCollection.IsReadOnly
            // ExFor: TaskCollection.ParentProject
            // ExFor: TaskCollection.ToList
            // ExSummary: Shows how to work with task collections.
            var project = new Project();

            // the task collection is not read-only and can be extended
            Console.WriteLine("Is task collection read - only: " + project.RootTask.Children.IsReadOnly);

            // create tasks
            var task1 = project.RootTask.Children.Add();

            task1.Set(Tsk.Name, "Task 1");
            task1.Set(Tsk.Start, new DateTime(2020, 4, 15, 8, 0, 0));
            task1.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day));
            task1.Set(Tsk.Finish, new DateTime(2020, 4, 15, 17, 0, 0));
            var task3 = project.RootTask.Children.Add("Task 3");

            task3.Set(Tsk.Start, new DateTime(2020, 4, 15, 8, 0, 0));
            task3.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day));
            task3.Set(Tsk.Finish, new DateTime(2020, 4, 15, 17, 0, 0));
            var task2 = project.RootTask.Children.Add("Task 2", 2);

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

            // print project tasks
            Console.WriteLine("Count of tasks: " + project.RootTask.Children.Count);
            foreach (var child in project.RootTask.Children)
            {
                Console.WriteLine("Parent Project: " + project.RootTask.ParentProject.Get(Prj.Name));
                Console.WriteLine("Task name: " + child.Get(Tsk.Name));
                Console.WriteLine("Task start: " + child.Get(Tsk.Start));
                Console.WriteLine("Task duration: " + child.Get(Tsk.Duration));
                Console.WriteLine("Task finish: " + child.Get(Tsk.Finish));
                Console.WriteLine();
            }

            // a task can be taken from the collection by ID
            var task1ToEdit = project.RootTask.Children.GetById(1);

            task1ToEdit.Set(Tsk.Name, "Task 1 (Edited)");

            // or by UID
            var taskToEdit2 = project.RootTask.Children.GetByUid(2);

            taskToEdit2.Set(Tsk.Name, "Task 2 (Edited)");

            // also one can add a recurring task
            var parameters = new RecurringTaskParameters
            {
                TaskName          = "t1",
                Duration          = project.GetDuration(1, TimeUnitType.Day),
                RecurrencePattern = new DailyRecurrencePattern
                {
                    Repetition = new DailyCalendarRepetition {
                        RepetitionInterval = 1
                    },
                    RecurrenceRange = new EndByRecurrenceRange
                    {
                        Start  = new DateTime(2020, 4, 13, 8, 0, 0),
                        Finish = new DateTime(2021, 4, 13, 17, 0, 0)
                    }
                }
            };

            // the first task in a sequence is returned
            var recurring = project.RootTask.Children.Add(parameters);

            Console.WriteLine("Task name: " + recurring.Get(Tsk.Name));

            // the collection can be converted into a plain list
            List <Task> tasks = project.RootTask.Children.ToList();

            foreach (var task in tasks)
            {
                task.Delete();
            }

            // ExEnd:WorkWithTaskCollection
        }