public static void Run() { //ExStart:AddRemoveCalendarExceptions string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); using (FileStream fs = new FileStream(dataDir + "project_test.mpp", FileMode.Open)) { // Create project instance Project prj = new Project(fs); // Remove an exception Aspose.Tasks.Calendar cal = prj.Calendars.ToList()[0]; if (cal.Exceptions.Count > 1) { CalendarException exc = cal.Exceptions.ToList()[0]; cal.Exceptions.Remove(exc); } // Add an exception CalendarException calExc = new CalendarException(); calExc.FromDate = new System.DateTime(2009, 1, 1); calExc.ToDate = new System.DateTime(2009, 1, 3); cal.Exceptions.Add(calExc); // Display exceptions foreach (CalendarException calExc1 in cal.Exceptions) { Console.WriteLine("From" + calExc1.FromDate.ToShortDateString()); Console.WriteLine("To" + calExc1.ToDate.ToShortDateString()); } } //ExEnd:AddRemoveCalendarExceptions }
public void TestPutCalendarException() { TasksApi target = new TasksApi(APIKEY, APPSID, BASEPATH); StorageApi storageApi = new StorageApi(APIKEY, APPSID, BASEPATH); string name = "sample-project.mpp"; int? calendarUid = 1; int? index = 1; string fileName = null; string storage = null; string folder = null; CalendarException body = new CalendarException(); body.Name = "NewTask"; body.FromDate = new DateTime(2016, 2, 18); body.ToDate = new DateTime(2016, 2, 22); storageApi.PutCreate(name, null, null, System.IO.File.ReadAllBytes("\\temp\\tasks\\resources\\" + name)); SaaSposeResponse actual; actual = target.PutCalendarException(name, calendarUid, index, fileName, storage, folder, body); Assert.AreEqual("200", actual.Code); Assert.IsInstanceOfType(new SaaSposeResponse(), actual.GetType()); }
public static void Run() { // ExStart:DefineWeekdayExceptions string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); // Create a project instance Project prj = new Project(); // Define Calendar Aspose.Tasks.Calendar cal = prj.Calendars.Add("Calendar1"); // Define week days exception for a holiday CalendarException except = new CalendarException(); except.EnteredByOccurrences = false; except.FromDate = new DateTime(2009, 12, 24, 0, 0, 0); except.ToDate = new DateTime(2009, 12, 31, 23, 59, 0); except.Type = CalendarExceptionType.Daily; except.DayWorking = false; cal.Exceptions.Add(except); // Save the Project prj.Save(dataDir + "Project_DefineWeekDayException_out.xml", Aspose.Tasks.Saving.SaveFileFormat.XML); // ExEnd:DefineWeekdayExceptions }
public void HandleExceptionOccurrences() { // ExStart:HandleExceptionOccurrences // ExFor: CalendarExceptionType // ExFor: CalendarException.EnteredByOccurrences // ExFor: CalendarException.Occurrences // ExSummary: Shows how to define a calendar exception by occurrences. var project = new Project(); // Define a calendar var calendar = project.Calendars.Add("Calendar1"); // Define exception and specify occurrences var exception = new CalendarException(); exception.EnteredByOccurrences = true; exception.Occurrences = 5; exception.Type = CalendarExceptionType.YearlyByDay; exception.MonthDay = 22; exception.Month = Month.April; // Add exception to calendar calendar.Exceptions.Add(exception); // ExEnd:HandleExceptionOccurrences }
private void AssertCalendarExceptionsAreEqual(CalendarException c1, CalendarException c2) { Assert.AreEqual(c1.Name, c2.Name); Assert.AreEqual(c1.DayWorking, c2.DayWorking); Assert.AreEqual(c1.EnteredByOccurrences, c2.EnteredByOccurrences); Assert.AreEqual(c1.FromDate, c2.FromDate); Assert.AreEqual(c1.MonthDay, c2.MonthDay); Assert.AreEqual(c1.Occurrences, c2.Occurrences); Assert.AreEqual(c1.Period, c2.Period); Assert.AreEqual(c1.ToDate.GetValueOrDefault().Date, c2.ToDate.GetValueOrDefault().Date); Assert.AreEqual(c1.Type, c2.Type); Assert.AreEqual((c1.WorkingTimes?.Count).GetValueOrDefault(), (c2.WorkingTimes?.Count).GetValueOrDefault()); for (int i = 0; i < (c1.WorkingTimes?.Count).GetValueOrDefault(); i++) { Assert.AreEqual(c1.WorkingTimes[i].FromTime.Value.TimeOfDay, c2.WorkingTimes[i].FromTime.Value.TimeOfDay); Assert.AreEqual(c1.WorkingTimes[i].ToTime.Value.TimeOfDay, c2.WorkingTimes[i].ToTime.Value.TimeOfDay); } Assert.AreEqual((c1.DaysOfWeek?.Count).GetValueOrDefault(), (c2.DaysOfWeek?.Count).GetValueOrDefault()); for (int i = 0; i < (c1.DaysOfWeek?.Count).GetValueOrDefault(); i++) { Assert.AreEqual(c1.DaysOfWeek[i], c2.DaysOfWeek[i]); } }
public void ExceptionByDayType() { // ExStart // ExFor: CalendarException.DaysOfWeek // ExFor: CalendarException.ParentCalendar // ExSummary: Shows how to define calendar exception by week day. var project = new Project(DataDir + "project_test.mpp"); // create a calendar var calendar = project.Calendars.Add("Calendar1"); // create calendar exception for every friday var exception = new CalendarException(); exception.Type = CalendarExceptionType.Weekly; exception.FromDate = new DateTime(2020, 4, 6); exception.ToDate = new DateTime(2020, 4, 12); exception.DaysOfWeek.Add(DayType.Friday); // check that aa friday is exceptional Console.WriteLine("Is date an exception date: " + exception.CheckException(new DateTime(2020, 4, 10))); // add the exception to the calendar calendar.Exceptions.Add(exception); Console.WriteLine("Parent calendar name: " + exception.ParentCalendar.Name); // ExEnd Assert.IsTrue(exception.CheckException(new DateTime(2020, 4, 10))); }
public static void Run() { // ExStart:AddRemoveCalendarExceptions string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); using (FileStream fs = new FileStream(dataDir + "project_test.mpp", FileMode.Open)) { // Create project instance Project prj = new Project(fs); // Remove an exception Aspose.Tasks.Calendar cal = prj.Calendars.ToList()[0]; if (cal.Exceptions.Count > 1) { CalendarException exc = cal.Exceptions.ToList()[0]; cal.Exceptions.Remove(exc); } // Add an exception CalendarException calExc = new CalendarException(); calExc.FromDate = new System.DateTime(2009, 1, 1); calExc.ToDate = new System.DateTime(2009, 1, 3); cal.Exceptions.Add(calExc); // Display exceptions foreach (CalendarException calExc1 in cal.Exceptions) { Console.WriteLine("From" + calExc1.FromDate.ToShortDateString()); Console.WriteLine("To" + calExc1.ToDate.ToShortDateString()); } } // ExEnd:AddRemoveCalendarExceptions }
public static void Run() { // ExStart:DefineWeekdayExceptions string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); // Create a project instance Project prj = new Project(); // Define Calendar Aspose.Tasks.Calendar cal = prj.Calendars.Add("Calendar1"); // Define week days exception for a holiday CalendarException except = new CalendarException(); except.EnteredByOccurrences = false; except.FromDate = new DateTime(2009, 12, 24, 0, 0, 0); except.ToDate = new DateTime(2009, 12, 31, 23, 59, 0); except.Type = CalendarExceptionType.Daily; except.DayWorking = false; cal.Exceptions.Add(except); // Save the Project prj.Save(dataDir + "Project_DefineWeekDayException_out.xml", Aspose.Tasks.Saving.SaveFileFormat.XML); // ExEnd:DefineWeekdayExceptions }
public static void Run() { // ExStart:WriteUpdatedCalendarDataToMPP string resultFile = "result_WriteUpdatedCalendarDataToMPP_out.mpp"; string newFile = "project_update_test.mpp"; string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); try { // Create project instance and access calendar Project project = new Project(dataDir + newFile); Calendar cal = project.Calendars.GetByUid(3); // Update the calendar information Calendar.MakeStandardCalendar(cal); cal.Name = "Test calendar"; CalendarException exc = new CalendarException(); exc.FromDate = DateTime.Now; exc.ToDate = DateTime.Now.AddDays(2); exc.DayWorking = true; WorkingTime wt1 = new WorkingTime(); wt1.FromTime = new DateTime(10, 1, 1, 9, 0, 0); wt1.ToTime = new DateTime(10, 1, 1, 13, 0, 0); WorkingTime wt2 = new WorkingTime(); wt2.FromTime = new DateTime(10, 1, 1, 14, 0, 0); wt2.ToTime = new DateTime(10, 1, 1, 19, 0, 0); WorkingTime wt3 = new WorkingTime(); wt3.FromTime = new DateTime(10, 1, 1, 20, 0, 0); wt3.ToTime = new DateTime(10, 1, 1, 21, 0, 0); exc.WorkingTimes.Add(wt1); exc.WorkingTimes.Add(wt2); exc.WorkingTimes.Add(wt3); cal.Exceptions.Add(exc); CalendarException exc2 = new CalendarException(); exc2.FromDate = DateTime.Now.AddDays(7); exc2.ToDate = exc2.FromDate; exc2.DayWorking = false; cal.Exceptions.Add(exc2); project.Set(Prj.Calendar, cal); // Save project project.Save(dataDir + resultFile, SaveFileFormat.MPP); } 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:WriteUpdatedCalendarDataToMPP }
public static void Run() { // ExStart:WriteUpdatedCalendarDataToMPP string resultFile = "result_WriteUpdatedCalendarDataToMPP_out.mpp"; string newFile = "project_update_test.mpp"; string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); try { // Create project instance and access calendar Project project = new Project(dataDir + newFile); Calendar cal = project.Calendars.GetByUid(3); // Update the calendar information Calendar.MakeStandardCalendar(cal); cal.Name = "Test calendar"; CalendarException exc = new CalendarException(); exc.FromDate = DateTime.Now; exc.ToDate = DateTime.Now.AddDays(2); exc.DayWorking = true; WorkingTime wt1 = new WorkingTime(); wt1.FromTime = new DateTime(10, 1, 1, 9, 0, 0); wt1.ToTime = new DateTime(10, 1, 1, 13, 0, 0); WorkingTime wt2 = new WorkingTime(); wt2.FromTime = new DateTime(10, 1, 1, 14, 0, 0); wt2.ToTime = new DateTime(10, 1, 1, 19, 0, 0); WorkingTime wt3 = new WorkingTime(); wt3.FromTime = new DateTime(10, 1, 1, 20, 0, 0); wt3.ToTime = new DateTime(10, 1, 1, 21, 0, 0); exc.WorkingTimes.Add(wt1); exc.WorkingTimes.Add(wt2); exc.WorkingTimes.Add(wt3); cal.Exceptions.Add(exc); CalendarException exc2 = new CalendarException(); exc2.FromDate = DateTime.Now.AddDays(7); exc2.ToDate = exc2.FromDate; exc2.DayWorking = false; cal.Exceptions.Add(exc2); project.Set(Prj.Calendar, cal); // Save project project.Save(dataDir + resultFile, SaveFileFormat.MPP); } 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:WriteUpdatedCalendarDataToMPP }
private void convertCalendarTable() { using (var table = gtfs.GetTable("calendar")) { foreach (var record in table.Records) { bool[] days = new bool[7]; days[0] = record["sunday"] == "1"; days[1] = record["monday"] == "1"; days[2] = record["tuesday"] == "1"; days[3] = record["wednesday"] == "1"; days[4] = record["thursday"] == "1"; days[5] = record["friday"] == "1"; days[6] = record["saturday"] == "1"; Service entity = new Service { Days = days, startDate = new DateTime(Int32.Parse(record["start_date"].Substring(0, 4)), Int32.Parse(record["start_date"].Substring(4, 2)), Int32.Parse(record["start_date"].Substring(6, 2))), endDate = new DateTime(Int32.Parse(record["end_date"].Substring(0, 4)), Int32.Parse(record["end_date"].Substring(4, 2)), Int32.Parse(record["end_date"].Substring(6, 2))) }; sdb.AddEntity(entity); getService.Add(record["service_id"], entity); calculatePercent(table); } } using (var table = gtfs.GetTable("calendar_dates")) { foreach (var record in table.Records) { Service serviceEntity = null; if (!getService.ContainsKey(record["service_id"])) { serviceEntity = Service.CreateEmptyService(); sdb.AddEntity(serviceEntity); getService.Add(record["service_id"], serviceEntity); } CalendarException entity = new CalendarException { Date = new DateTime(Int32.Parse(record["date"].Substring(0, 4)), Int32.Parse(record["date"].Substring(4, 2)), Int32.Parse(record["date"].Substring(6, 2))), Type = Int32.Parse(record["exception_type"]), Service = getService[record["service_id"]] ?? serviceEntity }; sdb.AddEntity(entity); calculatePercent(table); } } }
public void WriteUpdatedCalendarDataToMPP() { try { // ExStart:WriteUpdatedCalendarDataToMPP // ExFor: Calendar.MakeStandardCalendar(Calendar) // ExSummary: Shows how to create a calendar with exception days. var project = new Project(DataDir + "project_update_test.mpp"); var calendar = project.Calendars.GetByUid(3); // Update the calendar information Calendar.MakeStandardCalendar(calendar); calendar.Name = "Test calendar"; var exception = new CalendarException(); exception.FromDate = DateTime.Now; exception.ToDate = DateTime.Now.AddDays(2); exception.DayWorking = true; var wt1 = new WorkingTime(); wt1.FromTime = new DateTime(10, 1, 1, 9, 0, 0); wt1.ToTime = new DateTime(10, 1, 1, 13, 0, 0); var wt2 = new WorkingTime(); wt2.FromTime = new DateTime(10, 1, 1, 14, 0, 0); wt2.ToTime = new DateTime(10, 1, 1, 19, 0, 0); var wt3 = new WorkingTime(); wt3.FromTime = new DateTime(10, 1, 1, 20, 0, 0); wt3.ToTime = new DateTime(10, 1, 1, 21, 0, 0); exception.WorkingTimes.Add(wt1); exception.WorkingTimes.Add(wt2); exception.WorkingTimes.Add(wt3); calendar.Exceptions.Add(exception); var exception2 = new CalendarException(); exception2.FromDate = DateTime.Now.AddDays(7); exception2.ToDate = exception2.FromDate; exception2.DayWorking = false; calendar.Exceptions.Add(exception2); project.Set(Prj.Calendar, calendar); project.Save(OutDir + "WriteUpdatedCalendarDataToMPP_out.mpp", SaveFileFormat.MPP); // ExEnd:WriteUpdatedCalendarDataToMPP } 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 GetExceptionDates() { // ExStart:GetExceptionDates // ExFor: CalendarException.GetExceptionDates // ExSummary: Shows how to get dates for which a specific calendar exception is effective. Project project = new Project(DataDir + "CalendarExceptions.mpp"); Calendar calendar = project.Calendars.GetByUid(1); CalendarException calendarException = calendar.Exceptions[0]; foreach (var date in calendarException.GetExceptionDates()) { Console.WriteLine(date); } // ExEnd:GetExceptionDates }
public async Task TestAddCalendarException() { var remoteName = await UploadFileToStorageAsync("New project 2013.mpp"); var calendarException = new CalendarException { Name = "Non-working day exception", DayWorking = false, FromDate = new DateTime(2014, 10, 28), ToDate = new DateTime(2015, 08, 5), Occurrences = 10, Type = CalendarExceptionType.MonthlyByDay, EnteredByOccurrences = true, MonthDay = 5, Period = 1 }; var response = await TasksApi.PostCalendarExceptionAsync(new PostCalendarExceptionRequest { CalendarUid = 1, CalendarException = calendarException, Name = remoteName, Folder = this.DataFolder }); Assert.AreEqual((int)HttpStatusCode.Created, response.Code); var getResponse = await TasksApi.GetCalendarExceptionsAsync(new GetCalendarExceptionsRequest { Name = remoteName, Folder = this.DataFolder, CalendarUid = 1 }); Assert.AreEqual((int)HttpStatusCode.OK, getResponse.Code); Assert.IsNotNull(getResponse.CalendarExceptions); Assert.AreEqual(1, getResponse.CalendarExceptions.Count); AssertCalendarExceptionsAreEqual(calendarException, getResponse.CalendarExceptions[0]); }
public static void Run() { string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); // Create a project instance Project project1 = new Project(); // Define Calendar Aspose.Tasks.Calendar cal = project1.Calendars.Add("Calendar1"); // ExStart:HandleExceptionOccurences // Define exception and specify occurences CalendarException except = new CalendarException(); except.EnteredByOccurrences = true; except.Occurrences = 5; except.Type = CalendarExceptionType.YearlyByDay; // ExEnd:HandleExceptionOccurences // Add exception to calendar and save the Project cal.Exceptions.Add(except); project1.Save(dataDir + "Project_HandleExceptionOccurences_out.xml", Aspose.Tasks.Saving.SaveFileFormat.XML); }
public static void Run() { string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); // Create a project instance Project project1 = new Project(); // Define Calendar Aspose.Tasks.Calendar cal = project1.Calendars.Add("Calendar1"); // ExStart:HandleExceptionOccurences // Define exception and specify occurences CalendarException except = new CalendarException(); except.EnteredByOccurrences = true; except.Occurrences = 5; except.Type = CalendarExceptionType.YearlyByDay; // ExEnd:HandleExceptionOccurences // Add exception to calendar and save the Project cal.Exceptions.Add(except); project1.Save(dataDir + "Project_HandleExceptionOccurences_out.xml", Aspose.Tasks.Saving.SaveFileFormat.XML); }
public void ExceptionByMonth() { // ExStart // ExFor: CalendarException.Month // ExFor: CalendarException.MonthDay // ExFor: CalendarException.MonthItem // ExFor: CalendarException.MonthPosition // ExFor: CalendarException.Period // ExFor: MonthItemType // ExFor: MonthPosition // ExSummary: Shows how to define calendar exception by month day. var project = new Project(DataDir + "project_test.mpp"); // create a calendar var calendar = project.Calendars.Add("Calendar1"); // create calendar exception for every friday var exception = new CalendarException(); exception.Type = CalendarExceptionType.MonthlyByDay; exception.FromDate = new DateTime(2010, 1, 1); exception.ToDate = new DateTime(2020, 12, 31); exception.Month = Month.December; exception.MonthDay = 1; exception.MonthItem = MonthItemType.Undefined; exception.MonthPosition = MonthPosition.Last; exception.Period = 5; // check that aa friday is exceptional Console.WriteLine("Is date an exception date: " + exception.CheckException(new DateTime(2012, 12, 1))); // add the exception to the calendar calendar.Exceptions.Add(exception); // ExEnd Assert.IsTrue(exception.CheckException(new DateTime(2012, 12, 1))); }
public void DefineCalendarExceptions() { // ExStart:DefineCalendarExceptions // ExFor: CalendarException // ExFor: CalendarException.#ctor // ExFor: CalendarException.FromDate // ExFor: CalendarException.ToDate // ExFor: CalendarException.Type // ExFor: CalendarException.DayWorking // ExFor: CalendarException.Name // ExFor: CalendarException.CheckException(DateTime) // ExSummary: Shows how to add/remove calendar exceptions. var project = new Project(DataDir + "project_test.mpp"); // create a calendar var calendar = project.Calendars.Add("Calendar1"); // create week days exception for a holiday var exception = new CalendarException(); exception.Name = "New Calendar Exception"; exception.EnteredByOccurrences = false; exception.FromDate = new DateTime(2009, 12, 24, 0, 0, 0); exception.ToDate = new DateTime(2009, 12, 31, 23, 59, 0); exception.Type = CalendarExceptionType.Daily; exception.Month = Month.December; exception.DayWorking = false; // check that date is exceptional Console.WriteLine("Is date an exception date: " + exception.CheckException(new DateTime(2009, 12, 26, 8, 0, 0))); calendar.Exceptions.Add(exception); // remove an exception var cal = project.Calendars.ToList()[0]; if (cal.Exceptions.Count > 1) { var excToRemove = cal.Exceptions.ToList()[0]; cal.Exceptions.Remove(excToRemove); } // add an exception var exception2 = new CalendarException(); exception2.FromDate = new System.DateTime(2009, 1, 1); exception2.ToDate = new System.DateTime(2009, 1, 3); cal.Exceptions.Add(exception2); // print exceptions foreach (var exc in cal.Exceptions) { Console.WriteLine("Name: " + exc.Name); Console.WriteLine("From: " + exc.FromDate.ToShortDateString()); Console.WriteLine("To: " + exc.ToDate.ToShortDateString()); Console.WriteLine("Parent Calendar Name: " + exc.ParentCalendar.Name); } // ExEnd:DefineCalendarExceptions }
public void WorkWithDayTypeCollection() { // ExStart // ExFor: DayTypeCollection // ExFor: DayTypeCollection.Add(DayType) // ExFor: DayTypeCollection.Clear // ExFor: DayTypeCollection.Contains(DayType) // ExFor: DayTypeCollection.CopyTo(DayType[],Int32) // ExFor: DayTypeCollection.Count // ExFor: DayTypeCollection.GetEnumerator // ExFor: DayTypeCollection.IndexOf(DayType) // ExFor: DayTypeCollection.Insert(Int32,DayType) // ExFor: DayTypeCollection.IsReadOnly // ExFor: DayTypeCollection.Item(Int32) // ExFor: DayTypeCollection.Remove(DayType) // ExFor: DayTypeCollection.RemoveAt(Int32) // ExSummary: Shows how to use a week day collection to define weekly calendar exception. var project = new Project(DataDir + "WeeklyDayTypeException.mpp"); var calendar = project.Calendars.GetByUid(1); foreach (var calendarException in calendar.Exceptions) { Console.WriteLine("Exception Name: " + calendarException.Name); Console.WriteLine("Days of week count: " + calendarException.DaysOfWeek.Count); foreach (var dayType in calendarException.DaysOfWeek) { Console.WriteLine("Day type: " + dayType); } Console.WriteLine(); } var exc1 = calendar.Exceptions.ToList()[0]; if (!exc1.DaysOfWeek.IsReadOnly && exc1.DaysOfWeek.IndexOf(DayType.Monday) < 0) { exc1.DaysOfWeek.Insert(0, DayType.Wednesday); } var exc2 = calendar.Exceptions.ToList()[1]; if (exc2.DaysOfWeek.Contains(DayType.Sunday)) { // delete a day type from "Exception 2" by day type exc2.DaysOfWeek.Remove(DayType.Sunday); } // delete a day type from "Exception 2" by index Console.WriteLine("Remove " + exc2.DaysOfWeek[0] + " day type from exception by index..."); exc2.DaysOfWeek.RemoveAt(0); // Change exceptions (there is no exceptions in initial project data) var exc4 = new CalendarException { Name = "Weekly Exception 2", FromDate = new DateTime(2020, 4, 13), ToDate = new DateTime(2020, 4, 18), Occurrences = 3, Type = CalendarExceptionType.Weekly }; exc4.DaysOfWeek.Add(DayType.Monday); exc4.DaysOfWeek.Add(DayType.Thursday); calendar.Exceptions.Add(exc4); var exc3 = calendar.Exceptions.ToList()[2]; // remove all days of week for "Exception 3" exc3.DaysOfWeek.Clear(); var dayTypes = new DayType[exc4.DaysOfWeek.Count]; exc4.DaysOfWeek.CopyTo(dayTypes, 0); foreach (var dayType in dayTypes) { exc3.DaysOfWeek.Add(dayType); } Console.WriteLine("Days of week for exception: " + exc3.Name); foreach (var dayType in exc3.DaysOfWeek) { Console.WriteLine("Day type: " + dayType); } // ExEnd }
public void WorkWithCalendarExceptionCollection() { // ExStart:UseCalendarExceptionCollection // ExFor: CalendarExceptionCollection // ExFor: CalendarExceptionCollection.Add(CalendarException) // ExFor: CalendarExceptionCollection.AddRange(IEnumerable{Aspose.Tasks.CalendarException}) // ExFor: CalendarExceptionCollection.Clear // ExFor: CalendarExceptionCollection.Count // ExFor: CalendarExceptionCollection.GetEnumerator // ExFor: CalendarExceptionCollection.ParentCalendar // ExFor: CalendarExceptionCollection.Remove(CalendarException) // ExFor: CalendarExceptionCollection.ToList // ExSummary: Shows how to use calendar exception collection to define calendar exceptions. var project = new Project(DataDir + "project_update_test.mpp"); var calendar = project.Calendars.GetByUid(3); calendar.Exceptions.Clear(); Calendar.MakeStandardCalendar(calendar); var exception = new CalendarException(); exception.FromDate = new DateTime(2020, 3, 30, 8, 0, 0); exception.ToDate = new DateTime(2020, 4, 3, 17, 0, 0); exception.DayWorking = true; exception.Name = "Exception 1"; var wt1 = new WorkingTime(); wt1.FromTime = new DateTime(10, 1, 1, 9, 0, 0); wt1.ToTime = new DateTime(10, 1, 1, 13, 0, 0); var wt2 = new WorkingTime(); wt2.FromTime = new DateTime(10, 1, 1, 14, 0, 0); wt2.ToTime = new DateTime(10, 1, 1, 19, 0, 0); exception.WorkingTimes.Add(wt1); exception.WorkingTimes.Add(wt2); calendar.Exceptions.Add(exception); var nonWorkingExceptions = new CalendarException[2]; nonWorkingExceptions[0] = new CalendarException(); nonWorkingExceptions[0].FromDate = new DateTime(2020, 4, 13, 8, 0, 0); nonWorkingExceptions[0].ToDate = new DateTime(2020, 4, 18, 17, 0, 0); nonWorkingExceptions[0].DayWorking = false; nonWorkingExceptions[0].Name = "Exception 2"; nonWorkingExceptions[1] = new CalendarException(); nonWorkingExceptions[1].FromDate = new DateTime(2020, 4, 6, 8, 0, 0); nonWorkingExceptions[1].ToDate = new DateTime(2020, 4, 10, 17, 0, 0); nonWorkingExceptions[1].DayWorking = false; nonWorkingExceptions[1].Name = "Exception 3"; calendar.Exceptions.AddRange(nonWorkingExceptions); Console.WriteLine("Exceptions of calendar {0}: ", calendar.Exceptions.ParentCalendar.Name); Console.WriteLine("Exceptions count: {0}", calendar.Exceptions.Count); Console.WriteLine(); foreach (var calendarException in calendar.Exceptions) { Console.WriteLine("Name: " + calendarException.Name); Console.WriteLine("From Date: " + calendarException.FromDate); Console.WriteLine("To Date: " + calendarException.ToDate); Console.WriteLine("Is day working: " + calendarException.DayWorking); Console.WriteLine(); } // remove all exceptions Console.WriteLine("Remove calendar exceptions..."); List <CalendarException> exceptions = calendar.Exceptions.ToList(); foreach (var calendarException in exceptions) { Console.WriteLine("Remove exception: " + calendarException.Name); Console.WriteLine(); calendar.Exceptions.Remove(calendarException); } // ExEnd:UseCalendarExceptionCollection }