예제 #1
0
파일: Event.cs 프로젝트: CherifSy/PnP
        public string ToString(List<Event> Events)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("BEGIN:VEVENT");
            builder.AppendLine("SUMMARY:" + CleanText(Title));
            builder.AppendLine("DTSTAMP:" + Created.ToString("yyyyMMddTHHmmssZ"));
            builder.AppendLine("DESCRIPTION:" + CleanText(Description));
            builder.AppendLine("LOCATION:" + CleanText(Location));
            builder.AppendLine("CATEGORIES:" + CleanText(Category));
            builder.AppendLine("UID:" + UID);
            builder.AppendLine("STATUS:CONFIRMED");
            builder.AppendLine("LAST-MODIFIED:" + LastModified.ToString("yyyyMMddTHHmmssZ"));

            if(AllDayEvent)
            {
                builder.AppendLine("DTSTART;VALUE=DATE:" + EventDate.ToString("yyyyMMdd"));

                double days = Math.Round(((Double)Duration / (double)(60 * 60 * 24)));
                builder.AppendLine("DTEND;VALUE=DATE:" + EventDate.AddDays(days).ToString("yyyyMMdd"));
            }
            else
            {
                builder.AppendLine("DTSTART:" + EventDate.ToString("yyyyMMddTHHmmssZ"));
                builder.AppendLine("DTEND:" + EventDate.AddSeconds(Duration).ToString("yyyyMMddTHHmmssZ"));
            }

            IEnumerable<Event> deletedEvents = Events.Where(e => e.MasterSeriesItemID == ID && e.EventType == EventType.Deleted);
            foreach(Event deletedEvent in deletedEvents)
            {
                if(AllDayEvent)
                    builder.AppendLine("EXDATE;VALUE=DATE:" + deletedEvent.RecurrenceID.ToString("yyyyMMdd"));
                else
                    builder.AppendLine("EXDATE:" + deletedEvent.RecurrenceID.ToString("yyyyMMddTHHmmssZ"));
            }

            if(RecurrenceID != DateTime.MinValue && EventType == EventType.Exception) //  Event is exception to recurring item
            {
                if(AllDayEvent)
                    builder.AppendLine("RECURRENCE-ID;VALUE=DATE:" + RecurrenceID.ToString("yyyyMMdd"));
                else
                    builder.AppendLine("RECURRENCE-ID:" + RecurrenceID.ToString("yyyyMMddTHHmmssZ"));
            }
            else if (Recurrence && !RecurrenceData.Contains("V3RecurrencePattern"))
            {
                RecurrenceHelper recurrenceHelper = new RecurrenceHelper();
                builder.AppendLine(recurrenceHelper.BuildRecurrence(RecurrenceData, EndDate));
            }

            if(EventType == CalendarModel.EventType.Exception)
            {
                List<Event> exceptions = Events.Where(e => e.MasterSeriesItemID == MasterSeriesItemID).OrderBy(e => e.Created).ToList<Event>();
                builder.AppendLine("SEQUENCE:" + (exceptions.IndexOf(this) + 1));
            }
            else
                builder.AppendLine("SEQUENCE:0");

            builder.AppendLine("BEGIN:VALARM");
            builder.AppendLine("ACTION:DISPLAY");
            builder.AppendLine("TRIGGER:-PT10M");
            builder.AppendLine("DESCRIPTION:Reminder");
            builder.AppendLine("END:VALARM");

            builder.AppendLine("END:VEVENT");

            return builder.ToString();
        }
예제 #2
0
        public string ToString(List <Event> Events)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("BEGIN:VEVENT");
            builder.AppendLine("SUMMARY:" + CleanText(Title));
            builder.AppendLine("DTSTAMP:" + Created.ToString("yyyyMMddTHHmmssZ"));
            builder.AppendLine("DESCRIPTION:" + CleanText(Description));
            builder.AppendLine("LOCATION:" + CleanText(Location));
            builder.AppendLine("CATEGORIES:" + CleanText(Category));
            builder.AppendLine("UID:" + UID);
            builder.AppendLine("STATUS:CONFIRMED");
            builder.AppendLine("LAST-MODIFIED:" + LastModified.ToString("yyyyMMddTHHmmssZ"));

            if (AllDayEvent)
            {
                builder.AppendLine("DTSTART;VALUE=DATE:" + EventDate.ToString("yyyyMMdd"));

                double days = Math.Round(((Double)Duration / (double)(60 * 60 * 24)));
                builder.AppendLine("DTEND;VALUE=DATE:" + EventDate.AddDays(days).ToString("yyyyMMdd"));
            }
            else
            {
                builder.AppendLine("DTSTART:" + EventDate.ToString("yyyyMMddTHHmmssZ"));
                builder.AppendLine("DTEND:" + EventDate.AddSeconds(Duration).ToString("yyyyMMddTHHmmssZ"));
            }

            IEnumerable <Event> deletedEvents = Events.Where(e => e.MasterSeriesItemID == ID && e.EventType == EventType.Deleted);

            foreach (Event deletedEvent in deletedEvents)
            {
                if (AllDayEvent)
                {
                    builder.AppendLine("EXDATE;VALUE=DATE:" + deletedEvent.RecurrenceID.ToString("yyyyMMdd"));
                }
                else
                {
                    builder.AppendLine("EXDATE:" + deletedEvent.RecurrenceID.ToString("yyyyMMddTHHmmssZ"));
                }
            }

            if (RecurrenceID != DateTime.MinValue && EventType == EventType.Exception) //  Event is exception to recurring item
            {
                if (AllDayEvent)
                {
                    builder.AppendLine("RECURRENCE-ID;VALUE=DATE:" + RecurrenceID.ToString("yyyyMMdd"));
                }
                else
                {
                    builder.AppendLine("RECURRENCE-ID:" + RecurrenceID.ToString("yyyyMMddTHHmmssZ"));
                }
            }
            else if (Recurrence && !RecurrenceData.Contains("V3RecurrencePattern"))
            {
                RecurrenceHelper recurrenceHelper = new RecurrenceHelper();
                builder.AppendLine(recurrenceHelper.BuildRecurrence(RecurrenceData, EndDate));
            }

            if (EventType == CalendarModel.EventType.Exception)
            {
                List <Event> exceptions = Events.Where(e => e.MasterSeriesItemID == MasterSeriesItemID).OrderBy(e => e.Created).ToList <Event>();
                builder.AppendLine("SEQUENCE:" + (exceptions.IndexOf(this) + 1));
            }
            else
            {
                builder.AppendLine("SEQUENCE:0");
            }

            builder.AppendLine("BEGIN:VALARM");
            builder.AppendLine("ACTION:DISPLAY");
            builder.AppendLine("TRIGGER:-PT10M");
            builder.AppendLine("DESCRIPTION:Reminder");
            builder.AppendLine("END:VALARM");

            builder.AppendLine("END:VEVENT");

            return(builder.ToString());
        }