Пример #1
0
        private static RecurrencePattern parseEndType(RecurrencePattern recurrencePattern, byte[] recurrence)
        {
            int n = 4;
            if (recurrence[6] == 0)
            {
                n = 0;
            }
            else if (recurrence[6] == 3)
            {
                n = 8;
            }


            if (recurrence[22 + n] == 35 && recurrence[23 + n] == 32)
            {
                //no end
                recurrencePattern.hasEnd = false;
            }
            if (recurrence[22 + n] == 34 && recurrence[23 + n] == 32)
            {
                //end after n occurence
                string _a = System.Convert.ToString(recurrence[23 + n + 4], 16);
                string _b = System.Convert.ToString(recurrence[23 + n + 3], 16);
                int _c = System.Convert.ToInt32(_a + _b, 16);
                recurrencePattern.hasEnd = true;
                recurrencePattern.numberOfOccurrences = _c;
            }
            if (recurrence[22 + n] == 33 && recurrence[23 + n] == 32)
            {
                //end after date
                string _a = System.Convert.ToString(recurrence[23 + n + 4], 16);
                string _b = System.Convert.ToString(recurrence[23 + n + 3], 16);
                int _c = System.Convert.ToInt32(_a + _b, 16);
                recurrencePattern.hasEnd = true;
                recurrencePattern.numberOfOccurrences = _c;
            }

            return recurrencePattern;
        }
Пример #2
0
        private static RecurrencePattern parseRecurrenceMeeting(byte[] recurrence)
        {

            RecurrencePattern recurrencePattern = new RecurrencePattern();

            int startMinutes = 0;
            int endMinutes = 0;
            for (int i = 40; i < recurrence.Length; i++)
            {
                if (recurrence[i] == 6 && recurrence[i + 1] == 48 && recurrence[i + 2] == 0 && recurrence[i + 3] == 0)
                {
                    string a = System.Convert.ToString(recurrence[i - 1], 16);
                    string b = System.Convert.ToString(recurrence[i - 2], 16);
                    String c = System.Convert.ToString(recurrence[i - 3], 16);
                    String d = System.Convert.ToString(recurrence[i - 4], 16);
                    endMinutes = System.Convert.ToInt32(a + b + c + d, 16);

                    a = System.Convert.ToString(recurrence[i - 5], 16);
                    b = System.Convert.ToString(recurrence[i - 6], 16);
                    c = System.Convert.ToString(recurrence[i - 7], 16);
                    d = System.Convert.ToString(recurrence[i - 8], 16);
                    startMinutes = System.Convert.ToInt32(a + b + c + d, 16);

                    break;
                }
            }
            DateTime startDate = Convert.ToDateTime("1601-1-1");
            startDate = startDate.AddMinutes(startMinutes);
            DateTime endDate = Convert.ToDateTime("1601-1-1");
            endDate = endDate.AddMinutes(endMinutes);


            recurrencePattern.startDate = startDate;
            recurrencePattern.endDate = endDate;

            if (recurrence[4] == 10 && recurrence[5] == 32)
            {
                //its a daily meeting
                recurrencePattern.patternType = PatternType.DAILY;

                string a = System.Convert.ToString(recurrence[15], 16);
                string b = System.Convert.ToString(recurrence[14], 16);
                int c = System.Convert.ToInt32(a + b, 16);
                c = c / 60 / 24;//its recurrence number. for example c=1 means every 1 day

                recurrencePattern.dailyInterval = c;

                if (recurrence[6] == 1)
                {
                    //weekday meeting.
                    recurrencePattern.dailyInterval = -1;//-1 means weekday.                   
                }
                recurrencePattern = parseEndType(recurrencePattern, recurrence);
            }
            else if (recurrence[4] == 11 && recurrence[5] == 32)
            {
                //weekly meeting
                recurrencePattern.patternType = PatternType.WEEKLY;

                string a = System.Convert.ToString(recurrence[15], 16);
                string b = System.Convert.ToString(recurrence[14], 16);
                int c = System.Convert.ToInt32(a + b, 16);//for example, c=1 means every 1 week
                recurrencePattern.weeklyInterval = c;

                if (recurrence[6] == 1)
                {
                    int weeks = recurrence[22];
                    byte[] list = BitConverter.GetBytes(weeks);
                    System.Collections.BitArray arr = new System.Collections.BitArray(list);
                    bool sbit = arr[0];//Sunday
                    bool mbit = arr[1];//Monday
                    bool tubit = arr[2];//Tuesday
                    bool wbit = arr[3];//Wednesday
                    bool thbit = arr[4];//Thursday
                    bool fbit = arr[5];//Friday
                    bool sabit = arr[6];//Saturday

                    List<dayOfWeekType> daysOfWeeklist = new List<dayOfWeekType>();
                    if (sbit)
                    {
                        daysOfWeeklist.Add(dayOfWeekType.SUN);
                    }
                    if (mbit)
                    {
                        daysOfWeeklist.Add(dayOfWeekType.MON);
                    }
                    if (tubit)
                    {
                        daysOfWeeklist.Add(dayOfWeekType.TUE);
                    }
                    if (wbit)
                    {
                        daysOfWeeklist.Add(dayOfWeekType.WED);
                    }
                    if (thbit)
                    {
                        daysOfWeeklist.Add(dayOfWeekType.THU);
                    }
                    if (fbit)
                    {
                        daysOfWeeklist.Add(dayOfWeekType.FRI);
                    }
                    if (sabit)
                    {
                        daysOfWeeklist.Add(dayOfWeekType.SAT);
                    }
                    dayOfWeekType[] daysOfWeek = daysOfWeeklist.ToArray();
                    recurrencePattern.daysOfWeek = daysOfWeek;
                }
                recurrencePattern = parseEndType(recurrencePattern, recurrence);
            }
            else if (recurrence[4] == 12 && recurrence[5] == 32)
            {
                //monthly meeting                

                string a = System.Convert.ToString(recurrence[15], 16);
                string b = System.Convert.ToString(recurrence[14], 16);
                int c = System.Convert.ToInt32(a + b, 10);//for example, c=1 means every 1 month

                recurrencePattern.monthlyInterval = c;

                if (recurrence[6] == 2)// the first radio box
                {
                    recurrencePattern.patternType = PatternType.MONTHLY;

                    int dayth = recurrence[22];//fox example, dayth=2 means the second day every month
                    recurrencePattern.dayOfMonth = dayth;
                }
                else if (recurrence[6] == 3)// the second radio box
                {
                    recurrencePattern.patternType = PatternType.RELATIVE_MONTHLY;

                    int ordernumber = recurrence[26];//the first/second/third/fourth/last weeks

                    switch (ordernumber)
                    {
                        case 1:
                            recurrencePattern.weekOfMonth = WeekOfMonthType.FIRST;
                            break;
                        case 2:
                            recurrencePattern.weekOfMonth = WeekOfMonthType.SECOND;
                            break;
                        case 3:
                            recurrencePattern.weekOfMonth = WeekOfMonthType.THIRD;
                            break;
                        case 4:
                            recurrencePattern.weekOfMonth = WeekOfMonthType.FOURTH;
                            break;
                        case 5:
                            recurrencePattern.weekOfMonth = WeekOfMonthType.LAST;
                            break;
                    }


                    int weekth = recurrence[22];//
                    switch (weekth)
                    {
                        case 1:
                            recurrencePattern.dayOfWeekOfMonthly = dayRecurrenceType.SUN;
                            break;
                        case 2:
                            recurrencePattern.dayOfWeekOfMonthly = dayRecurrenceType.MON;
                            break;
                        case 4:
                            recurrencePattern.dayOfWeekOfMonthly = dayRecurrenceType.TUE;
                            break;
                        case 8:
                            recurrencePattern.dayOfWeekOfMonthly = dayRecurrenceType.WED;
                            break;
                        case 16:
                            recurrencePattern.dayOfWeekOfMonthly = dayRecurrenceType.THU;
                            break;
                        case 64:
                            recurrencePattern.dayOfWeekOfMonthly = dayRecurrenceType.SAT;
                            break;
                        case 127:
                            recurrencePattern.dayOfWeekOfMonthly = dayRecurrenceType.ANYDAY;
                            break;
                        case 62:
                            recurrencePattern.dayOfWeekOfMonthly = dayRecurrenceType.WEEKDAY;
                            break;
                        case 65:
                            recurrencePattern.dayOfWeekOfMonthly = dayRecurrenceType.WEEKENDDAY;
                            break;
                    }
                }
                recurrencePattern = parseEndType(recurrencePattern, recurrence);
            }
            else if (recurrence[4] == 13 && recurrence[5] == 32)
            {
                //yearly meeting
                recurrencePattern.patternType = PatternType.YEARLY;
                recurrencePattern = parseEndType(recurrencePattern, recurrence);
            }

            return recurrencePattern;

        }