Exemplo n.º 1
0
        protected override void InternalSetValue(PropertyBag.BasicPropertyStore propertyBag, object value)
        {
            PublicFolderFreeBusy publicFolderFreeBusy = value as PublicFolderFreeBusy;

            if (publicFolderFreeBusy == null)
            {
                throw new ArgumentException("value");
            }
            IEnumerable <PublicFolderFreeBusyAppointment> sortedAppointments = from appointment in publicFolderFreeBusy.Appointments
                                                                               orderby appointment.StartTime
                                                                               select appointment;
            ExDateTime startDate      = publicFolderFreeBusy.StartDate;
            int        numberOfMonths = publicFolderFreeBusy.NumberOfMonths;

            int[] array = new int[numberOfMonths];
            for (int i = 0; i < numberOfMonths; i++)
            {
                ExDateTime startMonth = startDate.AddMonths(i);
                array[i] = PublicFolderFreeBusyProperty.PublishMonthPropertyConverter.ToInt(startMonth);
            }
            foreach (PublicFolderFreeBusyProperty.FreeBusyPropertySet freeBusyPropertySet in PublicFolderFreeBusyProperty.FreeBusyPropertySets)
            {
                byte[][] propertyValue = PublicFolderFreeBusyProperty.AppointmentsPropertyConverter.ToBinary(sortedAppointments, freeBusyPropertySet.BusyType, startDate, numberOfMonths);
                propertyBag.SetValue(freeBusyPropertySet.Appointments, propertyValue);
                propertyBag.SetValue(freeBusyPropertySet.PublishMonths, array);
            }
        }
Exemplo n.º 2
0
        // Token: 0x060025FA RID: 9722 RVA: 0x000DBE84 File Offset: 0x000DA084
        public static List <TimeRange> GetTimeRanges(UserContext userContext)
        {
            TimeRange.RangeId rangeId        = TimeRange.RangeId.All;
            ExDateTime        normalizedDate = TimeRange.GetNormalizedDate(DateTimeUtilities.GetLocalTime());
            int        num              = (7 + (normalizedDate.DayOfWeek - userContext.UserOptions.WeekStartDay)) % 7;
            ExDateTime normalizedDate2  = TimeRange.GetNormalizedDate(normalizedDate.IncrementDays(1));
            ExDateTime normalizedDate3  = TimeRange.GetNormalizedDate(normalizedDate.IncrementDays(-1));
            ExDateTime normalizedDate4  = TimeRange.GetNormalizedDate(normalizedDate.IncrementDays(7 - num));
            ExDateTime normalizedDate5  = TimeRange.GetNormalizedDate(normalizedDate4.IncrementDays(7));
            ExDateTime normalizedDate6  = TimeRange.GetNormalizedDate(normalizedDate5.IncrementDays(7));
            ExDateTime normalizedDate7  = TimeRange.GetNormalizedDate(normalizedDate6.IncrementDays(7));
            ExDateTime normalizedDate8  = TimeRange.GetNormalizedDate(normalizedDate.IncrementDays(-1 * (7 + num)));
            ExDateTime normalizedDate9  = TimeRange.GetNormalizedDate(normalizedDate8.IncrementDays(-7));
            ExDateTime normalizedDate10 = TimeRange.GetNormalizedDate(normalizedDate9.IncrementDays(-7));

            if (normalizedDate7.Month != normalizedDate.Month)
            {
                rangeId &= ~TimeRange.RangeId.LaterThisMonth;
            }
            if (num != 6)
            {
                rangeId &= ~TimeRange.RangeId.Tomorrow;
            }
            if (num != 0)
            {
                rangeId &= ~TimeRange.RangeId.Yesterday;
            }
            if (normalizedDate10.Month != normalizedDate.Month || 1 >= normalizedDate10.Day)
            {
                rangeId &= ~TimeRange.RangeId.EarlierThisMonth;
            }
            List <TimeRange> list       = new List <TimeRange>(18);
            ExDateTime       exDateTime = new ExDateTime(userContext.TimeZone, normalizedDate.Year, normalizedDate.Month, 1);

            exDateTime = TimeRange.GetNormalizedDate(exDateTime.AddMonths(2));
            ExDateTime exDateTime2 = ExDateTime.MaxValue;

            list.Insert(0, new TimeRange(TimeRange.RangeId.BeyondNextMonth, exDateTime, exDateTime2));
            exDateTime2 = exDateTime;
            int num2 = ExDateTime.DaysInMonth(normalizedDate.Year, normalizedDate.Month) - normalizedDate.Day;

            if (21 < num2)
            {
                exDateTime = TimeRange.GetNormalizedDate(exDateTime2.AddMonths(-1));
            }
            else
            {
                exDateTime = TimeRange.GetNormalizedDate(normalizedDate6.IncrementDays(7));
            }
            list.Insert(0, new TimeRange(TimeRange.RangeId.NextMonth, exDateTime, exDateTime2));
            if ((TimeRange.RangeId) 0 < (rangeId & TimeRange.RangeId.LaterThisMonth))
            {
                exDateTime2 = exDateTime;
                exDateTime  = TimeRange.GetNormalizedDate(normalizedDate6.IncrementDays(7));
                list.Insert(0, new TimeRange(TimeRange.RangeId.LaterThisMonth, exDateTime, exDateTime2));
            }
            exDateTime2 = exDateTime;
            exDateTime  = normalizedDate6;
            list.Insert(0, new TimeRange(TimeRange.RangeId.ThreeWeeksAway, exDateTime, exDateTime2));
            exDateTime2 = exDateTime;
            exDateTime  = normalizedDate5;
            list.Insert(0, new TimeRange(TimeRange.RangeId.TwoWeeksAway, exDateTime, exDateTime2));
            exDateTime2 = exDateTime;
            if (num == 6)
            {
                exDateTime = TimeRange.GetNormalizedDate(normalizedDate4.IncrementDays(1));
            }
            else
            {
                exDateTime = normalizedDate4;
            }
            list.Insert(0, new TimeRange(TimeRange.RangeId.NextWeek, exDateTime, exDateTime2));
            if ((TimeRange.RangeId) 0 < (rangeId & TimeRange.RangeId.Tomorrow))
            {
                exDateTime2 = exDateTime;
                exDateTime  = TimeRange.GetNormalizedDate(exDateTime.IncrementDays(-1));
                list.Insert(0, new TimeRange(TimeRange.RangeId.Tomorrow, exDateTime, exDateTime2));
            }
            int num3 = 7;

            while (0 < num3)
            {
                exDateTime2 = exDateTime;
                exDateTime  = TimeRange.GetNormalizedDate(exDateTime.IncrementDays(-1));
                TimeRange.RangeId rangeId2 = TimeRange.RangeId.None;
                if (normalizedDate2.Equals(exDateTime))
                {
                    rangeId2 = TimeRange.RangeId.Tomorrow;
                }
                else if (normalizedDate.Equals(exDateTime))
                {
                    rangeId2 = TimeRange.RangeId.Today;
                }
                else if (normalizedDate3.Equals(exDateTime))
                {
                    rangeId2 = TimeRange.RangeId.Yesterday;
                }
                else
                {
                    switch (exDateTime.DayOfWeek)
                    {
                    case DayOfWeek.Sunday:
                        rangeId2 = TimeRange.RangeId.Sunday;
                        break;

                    case DayOfWeek.Monday:
                        rangeId2 = TimeRange.RangeId.Monday;
                        break;

                    case DayOfWeek.Tuesday:
                        rangeId2 = TimeRange.RangeId.Tuesday;
                        break;

                    case DayOfWeek.Wednesday:
                        rangeId2 = TimeRange.RangeId.Wednesday;
                        break;

                    case DayOfWeek.Thursday:
                        rangeId2 = TimeRange.RangeId.Thursday;
                        break;

                    case DayOfWeek.Friday:
                        rangeId2 = TimeRange.RangeId.Friday;
                        break;

                    case DayOfWeek.Saturday:
                        rangeId2 = TimeRange.RangeId.Saturday;
                        break;
                    }
                }
                list.Insert(0, new TimeRange(rangeId2, exDateTime, exDateTime2));
                num3--;
            }
            if ((TimeRange.RangeId) 0 < (rangeId & TimeRange.RangeId.Yesterday))
            {
                exDateTime2 = exDateTime;
                exDateTime  = TimeRange.GetNormalizedDate(exDateTime.IncrementDays(-1));
                list.Insert(0, new TimeRange(TimeRange.RangeId.Yesterday, exDateTime, exDateTime2));
            }
            exDateTime2 = exDateTime;
            exDateTime  = normalizedDate8;
            list.Insert(0, new TimeRange(TimeRange.RangeId.LastWeek, exDateTime, exDateTime2));
            exDateTime2 = exDateTime;
            exDateTime  = normalizedDate9;
            list.Insert(0, new TimeRange(TimeRange.RangeId.TwoWeeksAgo, exDateTime, exDateTime2));
            exDateTime2 = exDateTime;
            exDateTime  = normalizedDate10;
            list.Insert(0, new TimeRange(TimeRange.RangeId.ThreeWeeksAgo, exDateTime, exDateTime2));
            if ((TimeRange.RangeId) 0 < (rangeId & TimeRange.RangeId.EarlierThisMonth))
            {
                exDateTime2 = exDateTime;
                exDateTime  = TimeRange.GetNormalizedDate(exDateTime.IncrementDays(-1 * (exDateTime.Day - 1)));
                list.Insert(0, new TimeRange(TimeRange.RangeId.EarlierThisMonth, exDateTime, exDateTime2));
            }
            exDateTime2 = exDateTime;
            if (exDateTime2.Day == 1)
            {
                exDateTime = TimeRange.GetNormalizedDate(exDateTime.IncrementDays(-1));
            }
            exDateTime = TimeRange.GetNormalizedDate(exDateTime.IncrementDays(-1 * (exDateTime.Day - 1)));
            list.Insert(0, new TimeRange(TimeRange.RangeId.LastMonth, exDateTime, exDateTime2));
            exDateTime2 = exDateTime;
            exDateTime  = ExDateTime.MinValue.AddTicks(1L);
            list.Insert(0, new TimeRange(TimeRange.RangeId.Older, exDateTime, exDateTime2));
            list.Insert(0, new TimeRange(TimeRange.RangeId.None, ExDateTime.MinValue, ExDateTime.MinValue));
            return(list);
        }
Exemplo n.º 3
0
            public static byte[][] ToBinary(IEnumerable <PublicFolderFreeBusyAppointment> sortedAppointments, BusyType requestedFreeBusyType, ExDateTime startMonth, int numberOfMonths)
            {
                byte[][]   array      = new byte[numberOfMonths][];
                ExDateTime exDateTime = startMonth.AddMonths(1);
                bool       flag       = true;

                for (int i = 0; i < array.Length; i++)
                {
                    double totalMinutes = (exDateTime - startMonth).TotalMinutes;
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
                        {
                            ushort num = 0;
                            foreach (PublicFolderFreeBusyAppointment publicFolderFreeBusyAppointment in sortedAppointments)
                            {
                                if (!(publicFolderFreeBusyAppointment.EndTime < startMonth))
                                {
                                    if (publicFolderFreeBusyAppointment.StartTime >= exDateTime)
                                    {
                                        break;
                                    }
                                    bool flag2 = publicFolderFreeBusyAppointment.BusyType == requestedFreeBusyType || (requestedFreeBusyType == BusyType.Unknown && publicFolderFreeBusyAppointment.BusyType != BusyType.Free && publicFolderFreeBusyAppointment.BusyType != BusyType.WorkingElseWhere);
                                    if (flag2)
                                    {
                                        double totalMinutes2 = (publicFolderFreeBusyAppointment.StartTime - startMonth).TotalMinutes;
                                        ushort num2;
                                        if (totalMinutes2 < 0.0)
                                        {
                                            num2 = 0;
                                        }
                                        else
                                        {
                                            num2 = (ushort)totalMinutes2;
                                        }
                                        double totalMinutes3 = (publicFolderFreeBusyAppointment.EndTime - startMonth).TotalMinutes;
                                        ushort val;
                                        if (totalMinutes3 > totalMinutes)
                                        {
                                            val = (ushort)totalMinutes;
                                        }
                                        else
                                        {
                                            val = (ushort)totalMinutes3;
                                        }
                                        if (flag)
                                        {
                                            binaryWriter.Write(num2);
                                            flag = false;
                                        }
                                        else if (num2 > num)
                                        {
                                            binaryWriter.Write(num);
                                            binaryWriter.Write(num2);
                                        }
                                        num = Math.Max(num, val);
                                    }
                                }
                            }
                            if (num != 0)
                            {
                                binaryWriter.Write(num);
                            }
                        }
                        array[i]   = memoryStream.ToArray();
                        startMonth = exDateTime;
                        exDateTime = startMonth.AddMonths(1);
                        flag       = true;
                    }
                }
                return(array);
            }
 public void LoadTombstoneRecords(byte[] tombstoneInfo, int monthsCount)
 {
     if (tombstoneInfo != null)
     {
         List <TombstoneRecord> list        = new List <TombstoneRecord>();
         ExDateTime             exDateTime  = new ExDateTime(ExTimeZone.UtcTimeZone, ExDateTime.Now.Year, ExDateTime.Now.Month, 1);
         ExDateTime             exDateTime2 = ExDateTime.UtcNow.AddDays((double)(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek - ExDateTime.UtcNow.DayOfWeek));
         exDateTime2 = new ExDateTime(ExTimeZone.UtcTimeZone, exDateTime2.Year, exDateTime2.Month, exDateTime2.Day);
         ExDateTime t  = (exDateTime < exDateTime2) ? exDateTime : exDateTime2;
         ExDateTime t2 = t.AddMonths(monthsCount);
         try
         {
             using (MemoryStream memoryStream = new MemoryStream(tombstoneInfo))
             {
                 using (BinaryReader binaryReader = new BinaryReader(memoryStream, CTSGlobals.AsciiEncoding))
                 {
                     byte[] array = new byte[4];
                     binaryReader.Read(array, 0, 4);
                     if (BitConverter.ToUInt32(array, 0) != 3202265037U)
                     {
                         ExTraceGlobals.MeetingMessageTracer.TraceError <string>((long)this.GetHashCode(), "AppointmentTombstone.Identifier field MUST have a value of 0xBEDEAFCD. Value found in the stream: {0}", BitConverter.ToUInt32(array, 0).ToString("X"));
                         throw new CorruptDataException(ServerStrings.AppointmentTombstoneCorrupt);
                     }
                     binaryReader.Read(array, 0, 4);
                     if (BitConverter.ToUInt32(array, 0) != 20U)
                     {
                         ExTraceGlobals.MeetingMessageTracer.TraceError <string>((long)this.GetHashCode(), "AppointmentTombstone.Headersize field MUST have a value of 0x00000014. Value found in the stream: {0}", BitConverter.ToUInt32(array, 0).ToString("X"));
                         throw new CorruptDataException(ServerStrings.AppointmentTombstoneCorrupt);
                     }
                     binaryReader.Read(array, 0, 4);
                     if (BitConverter.ToUInt32(array, 0) != 3U)
                     {
                         ExTraceGlobals.MeetingMessageTracer.TraceError <string>((long)this.GetHashCode(), "AppointmentTombstone.Version field MUST have a value of 0x00000003. Value found in the stream: {0}", BitConverter.ToUInt32(array, 0).ToString("X"));
                         throw new CorruptDataException(ServerStrings.AppointmentTombstoneCorrupt);
                     }
                     binaryReader.Read(array, 0, 4);
                     int num = BitConverter.ToInt32(array, 0);
                     if (num <= 0)
                     {
                         ExTraceGlobals.MeetingMessageTracer.TraceError <int>((long)this.GetHashCode(), "AppointmentTombstone.Record count field MUST have a positive value. Value found in the stream {0}", num);
                         throw new CorruptDataException(ServerStrings.AppointmentTombstoneCorrupt);
                     }
                     binaryReader.Read(array, 0, 4);
                     if (BitConverter.ToUInt32(array, 0) != 20U)
                     {
                         ExTraceGlobals.MeetingMessageTracer.TraceError <string>((long)this.GetHashCode(), "AppointmentTombstone.RecordSize field MUST have a value of 0x00000014. Value found in the stream: {0}", BitConverter.ToUInt32(array, 0).ToString("X"));
                         throw new CorruptDataException(ServerStrings.AppointmentTombstoneCorrupt);
                     }
                     for (int i = 0; i < num; i++)
                     {
                         binaryReader.Read(array, 0, 4);
                         int num2 = BitConverter.ToInt32(array, 0);
                         if (num2 <= 0)
                         {
                             ExTraceGlobals.MeetingMessageTracer.TraceError((long)this.GetHashCode(), "Tombstone record MUST have a positive start time value");
                             break;
                         }
                         binaryReader.Read(array, 0, 4);
                         int num3 = BitConverter.ToInt32(array, 0);
                         if (num3 <= 0)
                         {
                             ExTraceGlobals.MeetingMessageTracer.TraceError((long)this.GetHashCode(), "Tombstone record MUST have a positive end time value");
                             break;
                         }
                         binaryReader.Read(array, 0, 4);
                         int num4 = BitConverter.ToInt32(array, 0);
                         if (num4 <= 0)
                         {
                             ExTraceGlobals.MeetingMessageTracer.TraceError((long)this.GetHashCode(), "Tombstone record MUST have a positive global object id value");
                             break;
                         }
                         byte[] array2 = new byte[num4];
                         binaryReader.Read(array2, 0, num4);
                         binaryReader.Read(array, 0, 2);
                         short num5 = BitConverter.ToInt16(array, 0);
                         if (num5 <= 0)
                         {
                             ExTraceGlobals.MeetingMessageTracer.TraceError((long)this.GetHashCode(), "Tombstone record MUST have a positive user name size value");
                             break;
                         }
                         byte[] array3 = new byte[(int)num5];
                         binaryReader.Read(array3, 0, (int)num5);
                         TombstoneRecord tombstoneRecord = new TombstoneRecord
                         {
                             StartTime      = ExDateTime.FromFileTimeUtc((long)num2 * 600000000L),
                             EndTime        = ExDateTime.FromFileTimeUtc((long)num3 * 600000000L),
                             GlobalObjectId = array2,
                             UserName       = array3
                         };
                         if (tombstoneRecord.StartTime <= t2 && tombstoneRecord.EndTime >= t)
                         {
                             list.Add(tombstoneRecord);
                         }
                     }
                 }
             }
         }
         catch (IOException ex)
         {
             ExTraceGlobals.MeetingMessageTracer.TraceError <string>((long)this.GetHashCode(), "Unable to process the tombstone record with exception:'{0}'", ex.Message);
         }
         catch (ArgumentOutOfRangeException ex2)
         {
             ExTraceGlobals.MeetingMessageTracer.TraceError <string>((long)this.GetHashCode(), "Unable to process the tombstone record with exception:'{0}'", ex2.Message);
         }
         catch (ArgumentException ex3)
         {
             ExTraceGlobals.MeetingMessageTracer.TraceError <string>((long)this.GetHashCode(), "Unable to process the tombstone record with exception:'{0}'", ex3.Message);
         }
         ExTraceGlobals.MeetingMessageTracer.Information <int>((long)this.GetHashCode(), "Number of tombstone records loaded: {0}", list.Count);
         this.tombstoneRecords = list.ToArray();
     }
 }