Exemple #1
0
        public void AddEvent(string Titulo, string Lugar, DateTime Inicio, DateTime Termina, string Descripcion)
        {
            try
            {
                EKEventStore evStore = new EKEventStore();
                evStore.RequestAccess(EKEntityType.Event, (bool granted, NSError e) => {
                    if (!granted)
                    {
                        new UIAlertView("Acceso denegado", "El usuario no permite acceso al calendario", null, "ok", null).Show();
                    }
                });
                EKCalendar  calendar    = evStore.DefaultCalendarForNewEvents;
                NSPredicate evPredicate = evStore.PredicateForEvents(Inicio, Termina, evStore.GetCalendars(EKEntityType.Event));
                bool        encontrado  = false;

                evStore.EnumerateEvents(evPredicate, delegate(EKEvent calEvent, ref bool stop) {
                    if (calEvent.Title == Titulo)
                    {
                        encontrado = true;
                    }
                });
                if (encontrado)
                {
                    new UIAlertView("Evento", "El evento ya existe en el calendario", null, "ok", null).Show();
                }
                else
                {
                    EKEvent newEvent = EKEvent.FromStore(evStore);
                    newEvent.Title     = Titulo;
                    newEvent.Notes     = Descripcion;
                    newEvent.Calendar  = calendar;
                    newEvent.StartDate = Inicio;
                    newEvent.EndDate   = Termina;
                    newEvent.Location  = Lugar;
                    var error = new NSError(new NSString(""), 0);
                    evStore.SaveEvent(newEvent, EKSpan.ThisEvent, out error);
                    if (error.LocalizedDescription != "")
                    {
                        new UIAlertView("Evento", "Hubo un problema al agregar el evento " + error.LocalizedDescription, null, "ok", null).Show();
                    }
                    else
                    {
                        new UIAlertView("Evento", "El evento se agregó a su calendario", null, "ok", null).Show();
                    }
                }
            }
            catch (Exception) {
                new UIAlertView("Evento", "Hubo un problema al agregar el evento", null, "ok", null).Show();
            }
        }
        public void AddEvent(string Titulo, string Lugar, DateTime Inicio, DateTime Termina, string Descripcion)
        {
            try
            {
                EKEventStore evStore = new EKEventStore();
                evStore.RequestAccess(EKEntityType.Event, (bool granted, NSError e) => {
                    if (!granted)
                        new UIAlertView("Acceso denegado", "El usuario no permite acceso al calendario", null, "ok", null).Show();
                });
                EKCalendar calendar = evStore.DefaultCalendarForNewEvents;
                NSPredicate evPredicate = evStore.PredicateForEvents(Inicio, Termina, evStore.GetCalendars(EKEntityType.Event));
                bool encontrado = false;

                evStore.EnumerateEvents(evPredicate, delegate(EKEvent calEvent, ref bool stop) {
                    if (calEvent.Title == Titulo)
                        encontrado = true;
                });
                if (encontrado)
                {
                    new UIAlertView("Evento", "El evento ya existe en el calendario", null, "ok", null).Show();
                }
                else
                {
                    EKEvent newEvent = EKEvent.FromStore(evStore);
                    newEvent.Title = Titulo;
                    newEvent.Notes = Descripcion;
                    newEvent.Calendar = calendar;
                    newEvent.StartDate = Inicio;
                    newEvent.EndDate = Termina;
                    newEvent.Location = Lugar;
                    var error = new NSError(new NSString(""), 0);
                    evStore.SaveEvent(newEvent, EKSpan.ThisEvent, out error);
                    if(error.LocalizedDescription!="")
                        new UIAlertView("Evento", "Hubo un problema al agregar el evento " + error.LocalizedDescription, null, "ok", null).Show();
                    else
                        new UIAlertView("Evento", "El evento se agregó a su calendario", null, "ok", null).Show();
                }
            }
            catch (Exception) {
                new UIAlertView("Evento", "Hubo un problema al agregar el evento", null, "ok", null).Show();
            }
            
        }
Exemple #3
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);
            });
        }
Exemple #4
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();
        }