Microsoft.Protocols.TestSuites.MS_ASEMAIL.TestSuiteHelper.CreateiCalendarFormatContent C# (CSharp) Method

CreateiCalendarFormatContent() static private method

Create iCalendar format string from one calendar instance
static private CreateiCalendarFormatContent ( Calendar calendar ) : string
calendar Calendar Calendar information
return string
        internal static string CreateiCalendarFormatContent(Calendar calendar)
        {
            StringBuilder ical = new StringBuilder();
            ical.AppendLine("BEGIN: VCALENDAR");
            ical.AppendLine("PRODID:-//Microosft Protocols TestSuites");
            ical.AppendLine("VERSION:2.0");
            ical.AppendLine("METHOD:REQUEST");

            ical.AppendLine("X-MS-OLK-FORCEINSPECTOROPEN:TRUE");
            ical.AppendLine("BEGIN:VTIMEZONE");
            ical.AppendLine("TZID:UTC");
            ical.AppendLine("BEGIN:STANDARD");
            ical.AppendLine("DTSTART:16010101T000000");
            ical.AppendLine("TZOFFSETFROM:-0000");
            ical.AppendLine("TZOFFSETTO:-0000");
            ical.AppendLine("END:STANDARD");
            ical.AppendLine("END:VTIMEZONE");

            ical.AppendLine("BEGIN:VEVENT");
            ical.AppendLine("UID:" + calendar.UID);

            ical.AppendLine("DTSTAMP:" + ((DateTime)calendar.DtStamp).ToString("yyyyMMddTHHmmss"));
            ical.AppendLine("DESCRIPTION:" + calendar.Subject);
            ical.AppendLine("SUMMARY:" + calendar.Subject);
            ical.AppendLine("ATTENDEE;CN=\"\";RSVP=" + (calendar.ResponseRequested == true ? "TRUE" : "FALSE") + ":mailto:" + calendar.Attendees.Attendee[0].Email);
            ical.AppendLine("ORGANIZER:MAILTO:" + calendar.OrganizerEmail);
            ical.AppendLine("LOCATION:" + (calendar.Location ?? "My Office"));

            if (calendar.AllDayEvent == 1)
            {
                ical.AppendLine("DTSTART;VALUE=DATE:" + ((DateTime)calendar.StartTime).Date.ToString("yyyyMMdd"));
                ical.AppendLine("DTEND;VALUE=DATE:" + ((DateTime)calendar.EndTime).Date.ToString("yyyyMMdd"));
                ical.AppendLine("X-MICROSOFT-CDO-ALLDAYEVENT:TRUE");
            }
            else
            {
                ical.AppendLine("DTSTART;TZID=\"UTC\":" + ((DateTime)calendar.StartTime).ToString("yyyyMMddTHHmmss"));
                ical.AppendLine("DTEND;TZID=\"UTC\":" + ((DateTime)calendar.EndTime).ToString("yyyyMMddTHHmmss"));
            }

            if (calendar.Recurrence != null)
            {
                switch (calendar.Recurrence.Type)
                {
                    case 1:
                        ical.AppendLine("RRULE:FREQ=WEEKLY;BYDAY=MO;UNTIL=" + calendar.Recurrence.Until);
                        break;
                    case 2:
                        ical.AppendLine("RRULE:FREQ=MONTHLY;COUNT=3;BYMONTHDAY=1");
                        break;
                    case 3:
                        ical.AppendLine("RRULE:FREQ=MONTHLY;COUNT=3;BYDAY=1MO");
                        break;
                    case 5:
                        ical.AppendLine("RRULE:FREQ=YEARLY;COUNT=3;BYMONTHDAY=1;BYMONTH=1");
                        break;
                    case 6:
                        ical.AppendLine("RRULE:FREQ=YEARLY;COUNT=3;BYDAY=2MO;BYMONTH=1");
                        break;
                }
            }

            if (calendar.Exceptions != null)
            {
                ical.AppendLine("EXDATE;TZID=\"UTC\":" + ((DateTime)calendar.StartTime).AddDays(7).ToString("yyyyMMddTHHmmss"));
                ical.AppendLine("RECURRENCE-ID;TZID=\"UTC\":" + ((DateTime)calendar.StartTime).ToString("yyyyMMddTHHmmss"));
            }

            switch (calendar.BusyStatus)
            {
                case 0:
                    ical.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:FREE");
                    break;
                case 1:
                    ical.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE");
                    break;
                case 2:
                    ical.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:BUSY");
                    break;
                case 3:
                    ical.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:OOF");
                    break;
            }

            if (calendar.DisallowNewTimeProposal == true)
            {
                ical.AppendLine("X-MICROSOFT-DISALLOW-COUNTER:TRUE");
            }

            if (!string.IsNullOrEmpty(calendar.Reminder))
            {
                ical.AppendLine("BEGIN:VALARM");
                ical.AppendLine("TRIGGER:-PT" + calendar.Reminder + "M");
                ical.AppendLine("ACTION:DISPLAY");
                ical.AppendLine("END:VALARM");
            }

            ical.AppendLine("END:VEVENT");
            ical.AppendLine("END:VCALENDAR");
            return ical.ToString();
        }