public usrEntriesCalendarView() { InitializeComponent(); monthCalendar1.Theme = Themes.OfficeSilver.ToString(); ShowTrainingDaySummary = true; filter = (CalendarFilter)GuiState.Default.CalendarViewMode; }
/// <summary> /// Gets all events for a calendar within the specified time range. /// </summary> /// <param name="calendar">Calendar containing events</param> /// <param name="start">Start of event range</param> /// <param name="end">End of event range</param> /// <returns>Calendar events</returns> /// <exception cref="System.ArgumentException">Calendar does not exist on device</exception> /// <exception cref="System.UnauthorizedAccessException">Calendar access denied</exception> /// <exception cref="Plugin.Calendars.Abstractions.PlatformException">Unexpected platform-specific error</exception> public Task <IList <CalendarEvent> > GetEventsAsync(Calendar calendar, DateTime start, DateTime end) { var calEvent = new List <CalendarEvent>(); CalendarManager calManager = null; CalendarQuery calQuery = null; CalendarList calList = null; CalendarRecord calRecord = null; CalendarFilter calFilter = null; try { calManager = new CalendarManager(); calFilter.AddCondition(CalendarFilter.LogicalOperator.And, Event.Start, CalendarFilter.IntegerMatchType.GreaterThanOrEqual, ConvertIntPtrToCalendarTime(start)); calFilter.AddCondition(CalendarFilter.LogicalOperator.And, Event.End, CalendarFilter.IntegerMatchType.LessThanOrEqual, ConvertIntPtrToCalendarTime(end)); calQuery = new CalendarQuery(Event.Uri); calQuery.SetFilter(calFilter); calList = calManager.Database.GetRecordsWithQuery(calQuery, 0, 0); if (calList.Count == 0) { return(Task.FromResult <IList <CalendarEvent> >(calEvent)); } calList.MoveFirst(); do { calRecord = calList.GetCurrentRecord(); string summary = calRecord.Get <string>(Event.Summary); CalendarTime startTime = calRecord.Get <CalendarTime>(Event.Start); CalendarTime endTime = calRecord.Get <CalendarTime>(Event.End); string location = calRecord.Get <string>(Event.Location); string description = calRecord.Get <string>(Event.Description); int IsAllday = calRecord.Get <int>(Event.IsAllday); int Id = calRecord.Get <int>(Event.Id); calEvent.Add( new CalendarEvent { Name = summary, Start = startTime.UtcTime, End = endTime.UtcTime, Location = location, Description = description, AllDay = Convert.ToBoolean(IsAllday), ExternalID = Id.ToString(), } ); } while (calList.MoveNext()); } finally { calRecord?.Dispose(); calRecord = null; calFilter?.Dispose(); calFilter = null; calQuery?.Dispose(); calQuery = null; calList?.Dispose(); calList = null; calManager?.Dispose(); calManager = null; } return(Task.FromResult <IList <CalendarEvent> >(calEvent)); }
public async Task DoLoadCalendarEventsListed(DateTime dStart, DateTime dEnd, int iMax = 0, int iError = 0) { xLog.Debug("DoLoadCalendarEventsListed: Start: " + bIsLoadingCalendarEventsListed.ToString()); if (bIsLoadingCalendarEventsListed) { xLog.Debug("xxxxxxxxxxxxxxxDoLoadCalendarEventsListed: Start: " + bIsLoadingCalendarEventsListed.ToString()); } if (false) { while (bIsLoadingCalendarEventsListed) { Task.Delay(25).Wait(); } bIsLoadingCalendarEventsListed = true; xLog.Debug("DoLoadCalendarEventsListed: Start Now"); } bIsLoadingCalendarEventsListed = true; try { int iMs = 0; var newEvents = new SortedDictionary <DateTime, CalendarEvent>(); LocationTimeHolder lthCheck = LocationTimeHolder.LocalInstanceClone; DateTime swStart = DateTime.Now; if (sys.isWindows) { var rnd = new Random(DateTime.Now.Second); for (int i = 0; i < rnd.Next(5) * 2; i++) { string name = "win"; var calEvent = new CalendarEvent(); calEvent.Title = $"{name} event {i}"; calEvent.Description = $"This is {name} event{i}'s description!"; calEvent.Start = dStart.AddHours(new Random().Next(8) + 10).AddMinutes(new Random().Next(50)); calEvent.End = calEvent.Start.AddHours(new Random().Next(5) + 1); calEvent.EventColor = xColor.FromRgb(rnd.Next(200), rnd.Next(200), rnd.Next(200)); calEvent.DisplayColorString = calEvent.EventColorString; //CheckEventLocationTime(lthCheck, calendar, calEvent); newEvents.Add(calEvent.SortTime.AddMilliseconds(iMs++), calEvent); } } else { var calendars = new List <DeviceCalendar.Calendar>(await DeviceCalendar.DeviceCalendar.GetCalendarsAsync()); foreach (DeviceCalendar.Calendar calendar in calendars) { if (string.IsNullOrEmpty(CalendarFilter) || !CalendarFilter.Contains("|" + calendar.ExternalID + "|")) { var calEvents = await DeviceCalendar.DeviceCalendar.GetEventsAsync(calendar, dStart, dEnd); foreach (CalendarEvent calEvent in calEvents) { CheckEventLocationTime(lthCheck, calendar, calEvent); newEvents.Add(calEvent.SortTime.AddMilliseconds(iMs++), calEvent); if (iMax > 0 && iMs >= iMax) { break; } iMs++; } } } } xLog.Debug("LoadAndCheckEvents took " + (DateTime.Now - swStart).TotalMilliseconds.ToString() + "ms for " + iMs.ToString() + " Events"); lock (ListedDates) { ListedDates.Clear(); ListedDates.AddRange(newEvents.Values); } } catch (Exception ex) { base.Clear(); xLog.Debug("Error reading Calendar Events: " + ex.GetType().Name + ": " + ex.Message); } finally { bIsLoadingCalendarEventsListed = false; } xLog.Debug("DoLoadCalendarEventsListed: Stop"); }