Exemplo n.º 1
0
        public virtual ICalendarComponent Build(string objectName)
        {
            ICalendarComponent c;
            var name = objectName.ToUpper();

            switch (name)
            {
            case Components.Alarm:
                c = new Alarm();
                break;

            case EventStatus.Name:
                c = new CalendarEvent();
                break;

            case Components.Freebusy:
                c = new FreeBusy();
                break;

            case JournalStatus.Name:
                c = new Journal();
                break;

            case Components.Timezone:
                c = new VTimeZone();
                break;

            case TodoStatus.Name:
                c = new Todo();
                break;

            case Components.Calendar:
                c = new Calendar();
                break;

            case Components.Daylight:
            case Components.Standard:
                c = new VTimeZoneInfo();
                break;

            default:
                c = new CalendarComponent();
                break;
            }
            c.Name = name;
            return(c);
        }
Exemplo n.º 2
0
        private static void PopulateTimeZoneInfoRecurrenceDates(VTimeZoneInfo tzi, List <ZoneInterval> intervals, TimeSpan delta)
        {
            foreach (var interval in intervals)
            {
                var periodList = new PeriodList();
                var time       = interval.IsoLocalStart.ToDateTimeUnspecified();
                var date       = new CalDateTime(time).Add(delta) as CalDateTime;
                if (date == null)
                {
                    continue;
                }

                date.HasTime = true;
                periodList.Add(date);
                tzi.RecurrenceDates.Add(periodList);
            }
        }
Exemplo n.º 3
0
        private static void PopulateTimeZoneInfoRecurrenceRules(VTimeZoneInfo tzi, ZoneInterval interval)
        {
            var recurrence = new IntervalRecurrencePattern(interval);

            tzi.RecurrenceRules.Add(recurrence);
        }
Exemplo n.º 4
0
        private static VTimeZoneInfo CreateTimeZoneInfo(List <ZoneInterval> matchedIntervals, List <ZoneInterval> intervals, bool isRRule = true,
                                                        bool isOnlyInterval = false, bool isDaylight = false)
        {
            if (matchedIntervals == null || !matchedIntervals.Any())
            {
                throw new ArgumentException("No intervals found in matchedIntervals");
            }

            var oldestInterval = matchedIntervals.OrderBy(x => x.Start).FirstOrDefault();

            if (oldestInterval == null)
            {
                throw new InvalidOperationException("oldestInterval was not found");
            }

            var previousInterval = intervals.SingleOrDefault(x => (x.HasEnd ? x.End : Instant.MaxValue) == oldestInterval.Start);

            var delta = new TimeSpan(1, 0, 0);

            if (previousInterval != null)
            {
                delta = (previousInterval.WallOffset - oldestInterval.WallOffset).ToTimeSpan();
            }
            else if (isOnlyInterval)
            {
                delta = new TimeSpan();
            }

            var utcOffset = oldestInterval.StandardOffset.ToTimeSpan();

            var timeZoneInfo = new VTimeZoneInfo();


            if (isDaylight)
            {
                timeZoneInfo.Name       = "DAYLIGHT";
                timeZoneInfo.OffsetFrom = new UtcOffset(utcOffset);
                timeZoneInfo.OffsetTo   = new UtcOffset(utcOffset - delta);
            }
            else
            {
                timeZoneInfo.Name       = "STANDARD";
                timeZoneInfo.OffsetFrom = new UtcOffset(utcOffset + delta);
                timeZoneInfo.OffsetTo   = new UtcOffset(utcOffset);
            }

            // timeZoneInfo.TimeZoneName = oldestInterval.Name;

            var start = oldestInterval.IsoLocalStart.ToDateTimeUnspecified() + delta;

            timeZoneInfo.Start = new CalDateTime(start)
            {
                HasTime = true
            };

            if (isRRule)
            {
                PopulateTimeZoneInfoRecurrenceRules(timeZoneInfo, oldestInterval);
            }
            // fixing the case that outlook 2010 cannot process the timezone with RDate
            // reference https://support.microsoft.com/en-hk/help/4456241/you-receive-a-meeting-request-that-has-not-supported-calendar-message
            else if (!isOnlyInterval)
            {
                PopulateTimeZoneInfoRecurrenceDates(timeZoneInfo, matchedIntervals, delta);
            }

            return(timeZoneInfo);
        }
Exemplo n.º 5
0
        private static VTimeZoneInfo CreateTimeZoneInfo(List <ZoneInterval> matchedIntervals, List <ZoneInterval> intervals, bool isRRule = true,
                                                        bool isOnlyInterval = false)
        {
            if (matchedIntervals == null || !matchedIntervals.Any())
            {
                throw new ArgumentException("No intervals found in matchedIntervals");
            }

            var oldestInterval = matchedIntervals.OrderBy(x => x.Start).FirstOrDefault();

            if (oldestInterval == null)
            {
                throw new InvalidOperationException("oldestInterval was not found");
            }

            var previousInterval = intervals.SingleOrDefault(x => (x.HasEnd ? x.End : Instant.MaxValue) == oldestInterval.Start);

            var delta = new TimeSpan(1, 0, 0);

            if (previousInterval != null)
            {
                delta = new TimeSpan(0, 0, previousInterval.WallOffset.Seconds - oldestInterval.WallOffset.Seconds);
            }
            else if (isOnlyInterval)
            {
                delta = new TimeSpan();
            }

            var utcOffset = oldestInterval.StandardOffset.ToTimeSpan();

            var timeZoneInfo = new VTimeZoneInfo();

            var isDaylight = oldestInterval.Savings.Ticks > 0;

            if (isDaylight)
            {
                timeZoneInfo.Name       = Components.Daylight;
                timeZoneInfo.OffsetFrom = new UtcOffset(utcOffset);
                timeZoneInfo.OffsetTo   = new UtcOffset(utcOffset - delta);
            }
            else
            {
                timeZoneInfo.Name       = Components.Standard;
                timeZoneInfo.OffsetFrom = new UtcOffset(utcOffset + delta);
                timeZoneInfo.OffsetTo   = new UtcOffset(utcOffset);
            }

            timeZoneInfo.TimeZoneName = oldestInterval.Name;

            var start = oldestInterval.IsoLocalStart.ToDateTimeUnspecified() + delta;

            timeZoneInfo.Start = new CalDateTime(start)
            {
                HasTime = true
            };

            if (isRRule)
            {
                PopulateTimeZoneInfoRecurrenceRules(timeZoneInfo, oldestInterval);
            }
            else
            {
                PopulateTimeZoneInfoRecurrenceDates(timeZoneInfo, matchedIntervals, delta);
            }

            return(timeZoneInfo);
        }