/// <summary>
        /// Makes the event info.
        /// </summary>
        /// <param name="dtStart">The dt start.</param>
        /// <param name="calEvent">The cal event.</param>
        /// <returns></returns>
        private CalendarEventInfo MakeEventInfo(DateTime dtStart, CalendarEvent calEvent)
        {
            CalendarEventInfo retVal = new CalendarEventInfo();

            dtStart = new DateTime(dtStart.Year, dtStart.Month, dtStart.Day,
                                   calEvent.DtStart.Hour, calEvent.DtStart.Minute,
                                   calEvent.DtStart.Second);

            ulong eventId = EncryptId(calEvent, dtStart);

            //TODO: Use Clone
            CalendarEvent virtualEvent = (CalendarEvent)calEvent.Clone();

            TimeSpan eventDuration = calEvent.DtEnd - calEvent.DtStart;

            virtualEvent.DtStart = dtStart;
            virtualEvent.DtEnd   = virtualEvent.DtStart + eventDuration;

            retVal.EventProvider = this;
            retVal.CalendarEvent = virtualEvent;

            retVal.SetEventId(EventProviderHelper.MakeEventId(GetEventType(), eventId));

            return(retVal);
        }
        /// <summary>
        /// Deletes the event.
        /// </summary>
        /// <remarks>Add except date in recurrence for this event</remarks>
        /// <param name="eventInfo"></param>
        public void DeleteEvent(ulong eventId)
        {
            if (EventProviderHelper.CheckEventBelong(GetEventType(), eventId))
            {
                DateTime      recurDate;
                CalendarEvent calEvent;

                ulong eventKey = EventProviderHelper.GetEventKey(eventId);

                if (DecryptId(eventKey, out recurDate, out calEvent))
                {
                    CalendarEventRecurrence[] eventRecurrs = CalendarEventRecurrence.List(new FilterElement("EventId",
                                                                                                            FilterElementType.Equal, calEvent.PrimaryKeyId.Value));

                    foreach (CalendarEventRecurrence eventRecurr in eventRecurrs)
                    {
                        // Add exception date
                        if (recurDate <= eventRecurr.DtEnd &&
                            recurDate >= eventRecurr.DtStart)
                        {
                            eventRecurr.Exdate = eventRecurr.Exdate + ";" + recurDate.ToString();
                            eventRecurr.Save();
                            break;
                        }
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates the event.
        /// </summary>
        /// <param name="eventInfo"></param>
        /// <returns></returns>
        public CalendarEventInfo CreateEvent(ulong eventId)
        {
            //Is create primary event only
            if (eventId != 0)
            {
                return(null);
            }

            CalendarEventInfo retVal = null;

            if (_calendar != null)
            {
                retVal = new CalendarEventInfo();
                CalendarEvent calEvent = new CalendarEvent();

                calEvent.PrimaryCalendarId = _calendar.PrimaryKeyId.Value;

                //Raise event
                CalendarEvent.RaiseCreateEvent(calEvent);

                calEvent.Save();

                retVal.CalendarEvent = calEvent;
                retVal.EventProvider = this;
                retVal.SetEventId(EventProviderHelper.MakeEventId(GetEventType(),
                                                                  (ulong)(int)calEvent.PrimaryKeyId.Value));
            }

            return(retVal);
        }
Exemple #4
0
        /// <summary>
        /// Gets the event info collection.
        /// </summary>
        /// <param name="dtStart">The dt start.</param>
        /// <param name="dtEnd">The dt end.</param>
        /// <returns></returns>
        public EventInfoCollections GetEventInfoCollection(DateTime dtStart,
                                                           DateTime dtEnd)
        {
            EventInfoCollections retVal = new EventInfoCollections();

            if (_calendarId == -1)
            {
                throw new NullReferenceException("calendarId");
            }

            CalendarEventLink[] eventLinks = CalendarEventLink.List(new FilterElement("CalendarId",
                                                                                      FilterElementType.Equal, _calendarId));

            foreach (CalendarEventLink eventLink in eventLinks)
            {
                try
                {
                    CalendarEvent calEvent = new CalendarEvent(eventLink.EventId);

                    if ((calEvent.DtStart >= dtStart) && (calEvent.DtEnd <= dtEnd))
                    {
                        CalendarEventInfo eventInfo = new CalendarEventInfo(this, calEvent);
                        eventInfo.SetEventId(EventProviderHelper.MakeEventId(GetEventType(),
                                                                             (ulong)(int)eventLink.PrimaryKeyId.Value));
                        retVal.Add(eventInfo);
                    }
                }
                catch (ObjectNotFoundException)
                {
                    throw;
                }
            }

            return(retVal);
        }
        /// <summary>
        /// Gets the event info.
        /// </summary>
        /// <param name="eventId">The event id.</param>
        /// <returns></returns>
        public CalendarEventInfo GetEventInfo(ulong eventId)
        {
            CalendarEventInfo retVal = null;

            if (EventProviderHelper.CheckEventBelong(GetEventType(), eventId))
            {
                DateTime      recurDate;
                CalendarEvent calEvent;

                ulong eventKey = EventProviderHelper.GetEventKey(eventId);

                if (DecryptId(eventKey, out recurDate, out calEvent))
                {
                    retVal = MakeEventInfo(recurDate, calEvent);
                }
            }
            return(retVal);
        }
Exemple #6
0
        /// <summary>
        /// Gets the event info.
        /// </summary>
        /// <param name="eventId">The event id.</param>
        /// <returns></returns>
        public CalendarEventInfo GetEventInfo(ulong eventId)
        {
            CalendarEventInfo retVal = null;

            if (EventProviderHelper.CheckEventBelong(GetEventType(), eventId))
            {
                int eventKey = (int)EventProviderHelper.GetEventKey(eventId);
                try
                {
                    CalendarEvent calEvent = new CalendarEvent(eventKey);
                    retVal = new CalendarEventInfo(this, calEvent);
                    retVal.SetEventId(eventId);
                }
                catch (ObjectNotFoundException)
                {
                    throw;
                }
            }

            return(retVal);
        }
Exemple #7
0
        /// <summary>
        /// Deletes the event.
        /// </summary>
        /// <param name="eventId">The event id.</param>
        public void DeleteEvent(ulong eventId)
        {
            if (EventProviderHelper.CheckEventBelong(GetEventType(), eventId))
            {
                if (_calendar == null)
                {
                    throw new NullReferenceException("calendar");
                }
                try
                {
                    int           eventKey = (int)EventProviderHelper.GetEventKey(eventId);
                    CalendarEvent calEvent = new CalendarEvent(eventKey);

                    //Raise event
                    CalendarEvent.RaiseDeleteEvent(calEvent);
                    calEvent.Delete();
                }
                catch (ObjectNotFoundException)
                {
                    throw;
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Deletes the event.
        /// </summary>
        /// <param name="eventInfo"></param>
        public void DeleteEvent(ulong eventId)
        {
            if (EventProviderHelper.CheckEventBelong(GetEventType(), eventId))
            {
                if (_calendarId == -1)
                {
                    throw new NullReferenceException("calendarId");
                }

                try
                {
                    int linkKey = (int)EventProviderHelper.GetEventKey(eventId);

                    CalendarEventLink eventLink = new CalendarEventLink(linkKey);

                    eventLink.Delete();
                }
                catch (ObjectNotFoundException)
                {
                    throw;
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Gets the event info collection.
        /// </summary>
        /// <param name="dtStart">The dt start.</param>
        /// <param name="dtEnd">The dt end.</param>
        /// <returns></returns>
        public EventInfoCollections GetEventInfoCollection(DateTime dtStart, DateTime dtEnd)
        {
            EventInfoCollections retVal = new EventInfoCollections();

            if (_calendar == null)
            {
                throw new NullReferenceException("calendar");
            }

            CalendarEvent[] calEvents = CalendarEvent.List(new FilterElement("PrimaryCalendarId",
                                                                             FilterElementType.Equal, _calendar.PrimaryKeyId.Value));
            foreach (CalendarEvent calEvent in calEvents)
            {
                if ((calEvent.DtStart >= dtStart) && (calEvent.DtEnd <= dtEnd))
                {
                    CalendarEventInfo eventInfo = new CalendarEventInfo(this, calEvent);
                    eventInfo.SetEventId(EventProviderHelper.MakeEventId(GetEventType(),
                                                                         (ulong)(int)calEvent.PrimaryKeyId.Value));
                    retVal.Add(eventInfo);
                }
            }

            return(retVal);
        }
Exemple #10
0
        /// <summary>
        /// Creates the event.
        /// </summary>
        /// <param name="eventInfo"></param>
        /// <returns></returns>
        public CalendarEventInfo CreateEvent(ulong eventId)
        {
            CalendarEventInfo retVal = null;

            //Is create link only
            if (eventId == 0)
            {
                return(retVal);
            }

            if (_calendarId != 0)
            {
                try
                {
                    int eventKey = (int)EventProviderHelper.GetEventKey(eventId);

                    CalendarEvent calEvent = new CalendarEvent(eventKey);

                    retVal = new CalendarEventInfo(this, calEvent);

                    CalendarEventLink eventLink = new CalendarEventLink();
                    eventLink.CalendarId = _calendarId;
                    eventLink.EventId    = (int)EventProviderHelper.GetEventKey(eventId);
                    eventLink.Save();

                    //Set event key
                    retVal.SetEventId(EventProviderHelper.MakeEventId(GetEventType(),
                                                                      (ulong)(int)eventLink.PrimaryKeyId.Value));
                }
                catch (ObjectNotFoundException)
                {
                }
            }

            return(retVal);
        }