예제 #1
0
        /// <summary>
        /// This method retrieves all the events for the past week via a query and displays them
        /// on the EventList Screen.
        /// </summary>
        protected void GetEventsViaQuery(DateTime startDate, DateTime endDate)
        {
            List<CalendarEntry> eventsList = new List<CalendarEntry>();
            try {
                EKEventStore store = new EKEventStore();
                EKCalendar calendar = store.DefaultCalendarForNewEvents;

                // Query the event
                if (calendar != null)
                {
                    // Searches for every event in the range of given dates
                    NSPredicate predicate = store.PredicateForEvents(IPhoneUtils.DateTimeToNSDate(startDate),IPhoneUtils.DateTimeToNSDate(endDate),new EKCalendar[] {calendar});
                    store.EnumerateEvents(predicate, delegate(EKEvent currentEvent, ref bool stop)
                                          {
                        // Perform your check for an event type
                        CalendarEntry entry = new CalendarEntry();
                        entry.Uid = currentEvent.EventIdentifier;
                        entry.Title = currentEvent.Title;
                        entry.Notes = currentEvent.Notes;
                        entry.Location = currentEvent.Location;
                        entry.IsAllDayEvent = currentEvent.AllDay;
                        entry.StartDate = IPhoneUtils.NSDateToDateTime(currentEvent.StartDate);
                        entry.EndDate = IPhoneUtils.NSDateToDateTime(currentEvent.EndDate);

                        try {

                            // TODO: locate how to translate this features
                            // entry.Type (birthday, exchange, etc)
                            //calendarEvent.  = entry.IsEditable

                            // Attendees
                            if(currentEvent.Attendees != null && currentEvent.Attendees.Length>0) {
                                int attendeesNum = currentEvent.Attendees.Length;
                                entry.Attendees = new CalendarAttendee[attendeesNum];
                                int index = 0;
                                foreach(EKParticipant participant in currentEvent.Attendees) {
                                    CalendarAttendee attendee = new CalendarAttendee();
                                    attendee.Name = participant.Name;
                                    attendee.Address = participant.Url.AbsoluteString;
                                    if(participant.ParticipantStatus == EKParticipantStatus.Unknown || participant.ParticipantStatus == EKParticipantStatus.Pending) {
                                        attendee.Status = AttendeeStatus.NeedsAction;
                                    }
                                    entry.Attendees[index] = attendee;
                                    index++;
                                }
                            }

                            // Alarms
                            if(currentEvent.HasAlarms && currentEvent.Alarms != null && currentEvent.Alarms.Length >0) {
                                int alarmsNum = currentEvent.Alarms.Length;
                                entry.Alarms = new CalendarAlarm[alarmsNum];
                                int index = 0;
                                foreach(EKAlarm alarm in currentEvent.Alarms) {
                                    CalendarAlarm eventAlarm = new CalendarAlarm();
                                    eventAlarm.Trigger = IPhoneUtils.NSDateToDateTime(alarm.AbsoluteDate);
                                    // TODO: how to manage "action", "sound" and "emailaddress"
                                    entry.Alarms[index] = eventAlarm;
                                    index++;
                                }
                            }

                            // Recurrence Rules (pick only the first one)
                            if(currentEvent.HasRecurrenceRules && currentEvent.RecurrenceRules != null && currentEvent.RecurrenceRules.Length >0) {
                                entry.IsRecurrentEvent = true;
                                EKRecurrenceRule rule = currentEvent.RecurrenceRules[0];
                                if(rule != null) {
                                    entry.Recurrence = new CalendarRecurrence();
                                    if(rule.Frequency == EKRecurrenceFrequency.Weekly) {
                                        entry.Recurrence.Type = RecurrenceType.Weekly;
                                    } else if(rule.Frequency == EKRecurrenceFrequency.Monthly) {
                                        entry.Recurrence.Type = RecurrenceType.Montly;
                                    } else if(rule.Frequency == EKRecurrenceFrequency.Yearly) {
                                        entry.Recurrence.Type = RecurrenceType.Yearly;
                                    }
                                    if(rule.RecurrenceEnd != null) {
                                        entry.Recurrence.EndDate = IPhoneUtils.NSDateToDateTime(rule.RecurrenceEnd.EndDate);
                                        entry.Recurrence.Interval = (int)rule.Interval;
                                        entry.RecurrenceNumber = rule.RecurrenceEnd.OccurrenceCount;
                                    }
                                }
                            }

                        } catch (Exception ex) {
                                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Unhandled exception while getting calendar entry information (event_id=" + entry.Uid +"). Exception message: " + ex.Message);
                        }

                        eventsList.Add(entry);
                    });

                }
            } catch (Exception ex) {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Unhandled exception while getting calendar entries. Exception message: " + ex.Message);
            }

            SystemLogger.Log(SystemLogger.Module.PLATFORM, "eventsList: " + eventsList.Count);
            UIApplication.SharedApplication.InvokeOnMainThread (delegate {
                IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.Pim.onListCalendarEntriesEnd", eventsList);
            });
        }
예제 #2
0
        /// <summary>
        /// This method retrieves all the events for the past week via a query and displays them
        /// on the EventList Screen.
        /// </summary>
        protected void GetEventsViaQuery(DateTime startDate, DateTime endDate)
        {
            List<CalendarEntry> eventsList = new List<CalendarEntry>();
            EKEventStore store = new EKEventStore();
            EKCalendar calendar = store.DefaultCalendarForNewEvents;

            // Query the event
            if (calendar != null)
            {
                // Searches for every event in the range of given dates
                NSPredicate predicate = store.PredicateForEvents(startDate,endDate,new EKCalendar[] {calendar});
                store.EnumerateEvents(predicate, delegate(EKEvent currentEvent, ref bool stop)
                                      {
                    // Perform your check for an event type
                    CalendarEntry entry = new CalendarEntry();
                    entry.Uid = currentEvent.EventIdentifier;
                    entry.Title = currentEvent.Title;
                    entry.Notes = currentEvent.Notes;
                    entry.Location = currentEvent.Location;
                    entry.IsAllDayEvent = currentEvent.AllDay;
                    entry.StartDate = currentEvent.StartDate;
                    entry.EndDate = currentEvent.EndDate;

                    // TODO: locate how to translate this features
                    // entry.Type (birthday, exchange, etc)
                    //calendarEvent.  = entry.IsEditable

                    // Attendees
                    if(currentEvent.Attendees != null && currentEvent.Attendees.Length>0) {
                        int attendeesNum = currentEvent.Attendees.Length;
                        entry.Attendees = new CalendarAttendee[attendeesNum];
                        int index = 0;
                        foreach(EKParticipant participant in currentEvent.Attendees) {
                            CalendarAttendee attendee = new CalendarAttendee();
                            attendee.Name = participant.Name;
                            attendee.Address = participant.Url.AbsoluteString;
                            if(participant.ParticipantStatus == EKParticipantStatus.Unknown || participant.ParticipantStatus == EKParticipantStatus.Pending) {
                                attendee.Status = AttendeeStatus.NeedsAction;
                            }
                            entry.Attendees[index] = attendee;
                            index++;
                        }
                    }

                    // Alarms
                    if(currentEvent.HasAlarms && currentEvent.Alarms != null && currentEvent.Alarms.Length >0) {
                        int alarmsNum = currentEvent.Alarms.Length;
                        entry.Alarms = new CalendarAlarm[alarmsNum];
                        int index = 0;
                        foreach(EKAlarm alarm in currentEvent.Alarms) {
                            CalendarAlarm eventAlarm = new CalendarAlarm();
                            eventAlarm.Trigger = alarm.AbsoluteDate;
                            // TODO: how to manage "action", "sound" and "emailaddress"
                            entry.Alarms[index] = eventAlarm;
                            index++;
                        }
                    }

                    // Recurrence Rules (pick only the first one)
                    if(currentEvent.HasRecurrenceRules && currentEvent.RecurrenceRules != null && currentEvent.RecurrenceRules.Length >0) {
                        entry.IsRecurrentEvent = true;
                        EKRecurrenceRule rule = currentEvent.RecurrenceRules[0];
                        if(rule != null) {
                            entry.Recurrence = new CalendarRecurrence();
                            if(rule.Frequency == EKRecurrenceFrequency.Weekly) {
                                entry.Recurrence.Type = RecurrenceType.Weekly;
                            } else if(rule.Frequency == EKRecurrenceFrequency.Monthly) {
                                entry.Recurrence.Type = RecurrenceType.Montly;
                            } else if(rule.Frequency == EKRecurrenceFrequency.Yearly) {
                                entry.Recurrence.Type = RecurrenceType.Yearly;
                            }
                            if(rule.RecurrenceEnd != null) {
                                entry.Recurrence.EndDate = rule.RecurrenceEnd.EndDate;
                                entry.Recurrence.Interval = rule.Interval;
                                entry.RecurrenceNumber = rule.RecurrenceEnd.OccurrenceCount;
                            }
                        }
                    }

                    eventsList.Add(entry);
                });

            }

            // TODO :: this API could no longer be invoked in this way.
            // the list of entries must be queried after checking access --> so, process has to send data via callback

            // return eventsList.ToArray();
        }