Ejemplo n.º 1
0
        internal static ExTimeZone PromoteCustomizedTimeZone(ExTimeZone customizedTimeZone)
        {
            ExTimeZone exTimeZone = null;

            if (customizedTimeZone.IsCustomTimeZone && !ExTimeZoneEnumerator.Instance.TryGetTimeZoneByName(customizedTimeZone.AlternativeId, out exTimeZone))
            {
                string            displayName = customizedTimeZone.LocalizableDisplayName.ToString();
                List <ExTimeZone> list        = TimeZoneHelper.MatchCustomTimeZoneByEffectiveRule(customizedTimeZone);
                exTimeZone = TimeZoneHelper.GetUniqueTimeZoneMatch(list, displayName);
                if (exTimeZone == null && list.Count > 1)
                {
                    List <ExTimeZone> timeZones = TimeZoneHelper.MatchCustomTimeZoneByRules(customizedTimeZone, list);
                    exTimeZone = TimeZoneHelper.GetUniqueTimeZoneMatch(timeZones, displayName);
                }
            }
            return(exTimeZone);
        }
Ejemplo n.º 2
0
        public static StorageWorkingHours LoadFrom(MailboxSession session, StoreId folderId)
        {
            WorkHoursInCalendar fromCalendar = WorkHoursInCalendar.GetFromCalendar(session, folderId);

            if (fromCalendar == null || fromCalendar.WorkHoursVersion1 == null)
            {
                return(null);
            }
            if (fromCalendar.WorkHoursVersion1.TimeSlot == null)
            {
                throw new WorkingHoursXmlMalformedException(ServerStrings.NullWorkHours);
            }
            ExTimeZone exTimeZone = null;

            try
            {
                if (!string.IsNullOrEmpty(fromCalendar.WorkHoursVersion1.TimeZone.Name))
                {
                    if (ExTimeZoneEnumerator.Instance.TryGetTimeZoneByName(fromCalendar.WorkHoursVersion1.TimeZone.Name, out exTimeZone))
                    {
                        WorkHoursTimeZone workHoursTimeZone = fromCalendar.WorkHoursVersion1.TimeZone;
                        if (!workHoursTimeZone.IsSameTimeZoneInfo(TimeZoneHelper.RegTimeZoneInfoFromExTimeZone(exTimeZone)))
                        {
                            exTimeZone = null;
                        }
                    }
                    else
                    {
                        exTimeZone = null;
                    }
                }
                if (exTimeZone == null)
                {
                    exTimeZone = TimeZoneHelper.CreateCustomExTimeZoneFromRegTimeZoneInfo(fromCalendar.WorkHoursVersion1.TimeZone.TimeZoneInfo, "tzone://Microsoft/Custom", "Customized Time Zone");
                }
            }
            catch (InvalidTimeZoneException ex)
            {
                throw new WorkingHoursXmlMalformedException(ServerStrings.MalformedTimeZoneWorkingHours(session.MailboxOwner.MailboxInfo.DisplayName, ex.ToString()), ex);
            }
            return(new StorageWorkingHours(exTimeZone, fromCalendar.WorkHoursVersion1.WorkDays, fromCalendar.WorkHoursVersion1.TimeSlot.StartTimeInMinutes, fromCalendar.WorkHoursVersion1.TimeSlot.EndTimeInMinutes));
        }
Ejemplo n.º 3
0
        internal static REG_TIMEZONE_INFO RegTimeZoneInfoFromExTimeZoneRuleGroup(ExTimeZoneRuleGroup group)
        {
            REG_TIMEZONE_INFO result          = default(REG_TIMEZONE_INFO);
            ExTimeZoneRule    exTimeZoneRule  = group.Rules[0];
            ExTimeZoneRule    exTimeZoneRule2 = (group.Rules.Count > 1) ? group.Rules[1] : null;

            if (exTimeZoneRule2 != null && exTimeZoneRule.Bias > exTimeZoneRule2.Bias)
            {
                ExTimeZoneRule exTimeZoneRule3 = exTimeZoneRule;
                exTimeZoneRule  = exTimeZoneRule2;
                exTimeZoneRule2 = exTimeZoneRule3;
            }
            result.Bias         = (int)(-(int)exTimeZoneRule.Bias.TotalMinutes);
            result.StandardBias = 0;
            if (exTimeZoneRule2 != null)
            {
                result.DaylightBias = (int)(exTimeZoneRule.Bias.TotalMinutes - exTimeZoneRule2.Bias.TotalMinutes);
                result.StandardDate = TimeZoneHelper.Win32SystemTimeFromRecurringTime(exTimeZoneRule2.ObservanceEnd);
                result.DaylightDate = TimeZoneHelper.Win32SystemTimeFromRecurringTime(exTimeZoneRule.ObservanceEnd);
            }
            return(result);
        }
Ejemplo n.º 4
0
        public static ExTimeZone GetExTimeZoneFromItem(Item item)
        {
            ExTimeZone exTimeZone = TimeZoneHelper.GetRecurringTimeZoneFromPropertyBag(item.PropertyBag);

            if (exTimeZone == null)
            {
                exTimeZone = TimeZoneHelper.GetTimeZoneFromProperties("Customized Time Zone", null, item.GetValueOrDefault <byte[]>(InternalSchema.TimeZoneDefinitionStart));
            }
            if (exTimeZone == null)
            {
                if (item.Session != null && item.Session.ExTimeZone != ExTimeZone.UtcTimeZone)
                {
                    exTimeZone = item.Session.ExTimeZone;
                }
                else
                {
                    ExTimeZoneHelperForMigrationOnly.CheckValidationLevel(false, ExTimeZoneHelperForMigrationOnly.ValidationLevel.Low, "TimeZoneHelper.GetTimeZoneFromItem: no time zone", new object[0]);
                    exTimeZone = ExTimeZone.CurrentTimeZone;
                }
            }
            return(exTimeZone);
        }
Ejemplo n.º 5
0
 private void DemoteVEvents(IList <Item> items)
 {
     foreach (Item item in items)
     {
         ExTimeZone exTimeZone = item.PropertyBag.ExTimeZone;
         try
         {
             REG_TIMEZONE_INFO reg_TIMEZONE_INFO = TimeZoneHelper.RegTimeZoneInfoFromExTimeZone(TimeZoneHelper.GetExTimeZoneFromItem(item));
             string            text = this.demotingTimeZones[reg_TIMEZONE_INFO];
             item.PropertyBag.ExTimeZone = TimeZoneHelper.CreateCustomExTimeZoneFromRegTimeZoneInfo(reg_TIMEZONE_INFO, text, text);
             VEvent vevent = new VEvent(this);
             vevent.Demote(item);
             if (!base.OutboundContext.SuppressExceptionAndAttachmentDemotion && (base.Context.Method == CalendarMethod.Request || base.Context.Method == CalendarMethod.Cancel || base.Context.Method == CalendarMethod.Publish))
             {
                 InternalRecurrence recurrenceFromItem = CalendarItem.GetRecurrenceFromItem(item);
                 if (recurrenceFromItem != null)
                 {
                     IList <OccurrenceInfo> modifiedOccurrences = recurrenceFromItem.GetModifiedOccurrences();
                     foreach (OccurrenceInfo occurrenceInfo in modifiedOccurrences)
                     {
                         ExceptionInfo exceptionInfo = (ExceptionInfo)occurrenceInfo;
                         VEvent        vevent2       = new VEvent(this);
                         vevent2.DemoteException(exceptionInfo, vevent);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             ExTraceGlobals.ICalTracer.TraceError <Exception>((long)this.GetHashCode(), "VCalendar::DemoteVEvents. Skipping item due to {0}", ex);
             base.Context.AddError(ServerStrings.InvalidICalElement(ex.ToString()));
         }
         finally
         {
             item.PropertyBag.ExTimeZone = exTimeZone;
         }
     }
 }
Ejemplo n.º 6
0
        public static REG_TIMEZONE_INFO RegTimeZoneInfoFromExTimeZone(ExTimeZone timeZone, ExDateTime effectiveTime)
        {
            DateTime            t = (DateTime)effectiveTime.ToUtc();
            ExTimeZoneRuleGroup exTimeZoneRuleGroup = null;

            foreach (ExTimeZoneRuleGroup exTimeZoneRuleGroup2 in timeZone.TimeZoneInformation.Groups)
            {
                if (exTimeZoneRuleGroup == null)
                {
                    exTimeZoneRuleGroup = exTimeZoneRuleGroup2;
                }
                if (exTimeZoneRuleGroup2.EffectiveUtcStart <= t && exTimeZoneRuleGroup2.EffectiveUtcEnd > t)
                {
                    exTimeZoneRuleGroup = exTimeZoneRuleGroup2;
                    break;
                }
            }
            if (exTimeZoneRuleGroup.Rules.Count > 2)
            {
                throw new NotImplementedException();
            }
            return(TimeZoneHelper.RegTimeZoneInfoFromExTimeZoneRuleGroup(exTimeZoneRuleGroup));
        }
Ejemplo n.º 7
0
 internal static REG_TIMEZONE_INFO RegTimeZoneInfoFromExTimeZone(ExTimeZone timeZone)
 {
     return(TimeZoneHelper.RegTimeZoneInfoFromExTimeZone(timeZone));
 }
Ejemplo n.º 8
0
        public static ExTimeZone CreateExTimeZoneFromRegTimeZoneInfo(REG_TIMEZONE_INFO regInfo, string keyName)
        {
            ExTimeZone exTimeZone = TimeZoneHelper.CreateCustomExTimeZoneFromRegTimeZoneInfo(regInfo, keyName, keyName);

            return(TimeZoneHelper.PromoteCustomizedTimeZone(exTimeZone) ?? exTimeZone);
        }
Ejemplo n.º 9
0
 public static ExTimeZone GetRecurringTimeZoneFromPropertyBag(PropertyBag propertyBag)
 {
     return(TimeZoneHelper.GetRecurringTimeZoneFromPropertyBag(propertyBag.AsIStorePropertyBag()));
 }
Ejemplo n.º 10
0
 public static REG_TIMEZONE_INFO RegTimeZoneInfoFromExTimeZone(ExTimeZone timeZone)
 {
     return(TimeZoneHelper.RegTimeZoneInfoFromExTimeZone(timeZone, ExDateTime.Now));
 }
Ejemplo n.º 11
0
        protected override object InternalTryGetValue(PropertyBag.BasicPropertyStore propertyBag)
        {
            StoreSession session = propertyBag.Context.Session;

            if (session == null)
            {
                ExTraceGlobals.StorageTracer.TraceDebug((long)propertyBag.GetHashCode(), "ReminderDueByProperty: StoreObject is not present and the property bag is not a QueryResultsPropertyBag. First should be present when accessing a property on an object, and the second one - when called from a view. All other cases are wrong.");
                return(propertyBag.GetValue(InternalSchema.ReminderDueByInternal));
            }
            PropertyError      result             = new PropertyError(InternalSchema.ReminderDueBy, PropertyErrorCode.GetCalculatedPropertyError);
            CalendarItem       calendarItem       = propertyBag.Context.StoreObject as CalendarItem;
            InternalRecurrence internalRecurrence = null;

            if (calendarItem != null)
            {
                try
                {
                    internalRecurrence = (InternalRecurrence)calendarItem.Recurrence;
                    goto IL_206;
                }
                catch (RecurrenceFormatException ex)
                {
                    ExTraceGlobals.StorageTracer.TraceDebug <string, StoreObjectId>((long)session.GetHashCode(), "Unable to parse recurrence info. Using the stored value for DueBy.\r\n\tError: {0}\r\n\tID:{1}", ex.Message, (calendarItem.Id != null) ? calendarItem.Id.ObjectId : null);
                    return(result);
                }
                catch (CorruptDataException ex2)
                {
                    ExTraceGlobals.StorageTracer.TraceDebug <string, StoreObjectId>((long)session.GetHashCode(), "Unable to parse the organizer timezone. Using the stored value for DueBy.\r\n\tError: {0}\r\n\tID:{1}", ex2.Message, (calendarItem.Id != null) ? calendarItem.Id.ObjectId : null);
                    return(result);
                }
            }
            byte[] entryId;
            if (Util.TryConvertTo <byte[]>(propertyBag.GetValue(InternalSchema.EntryId), out entryId))
            {
                VersionedId versionedId = new VersionedId(StoreObjectId.FromProviderSpecificId(entryId), Array <byte> .Empty);
                byte[]      array       = propertyBag.GetValue(InternalSchema.AppointmentRecurrenceBlob) as byte[];
                if (array != null)
                {
                    string     valueOrDefault         = propertyBag.GetValueOrDefault <string>(InternalSchema.TimeZone, string.Empty);
                    byte[]     valueOrDefault2        = propertyBag.GetValueOrDefault <byte[]>(InternalSchema.TimeZoneBlob);
                    byte[]     valueOrDefault3        = propertyBag.GetValueOrDefault <byte[]>(InternalSchema.TimeZoneDefinitionRecurring);
                    ExTimeZone timeZoneFromProperties = TimeZoneHelper.GetTimeZoneFromProperties(valueOrDefault, valueOrDefault2, valueOrDefault3);
                    if (timeZoneFromProperties == null)
                    {
                        ExTraceGlobals.StorageTracer.TraceDebug <string, StoreObjectId>((long)session.GetHashCode(), "Unable to parse the organizer timezone. Using the stored value for DueBy.\r\n\tError: {0}\r\n\tID:{1}", "organizerTimeZone is null", versionedId.ObjectId);
                        return(result);
                    }
                    try
                    {
                        internalRecurrence = InternalRecurrence.GetRecurrence(versionedId, session, array, timeZoneFromProperties, CalendarItem.DefaultCodePage);
                    }
                    catch (RecurrenceFormatException ex3)
                    {
                        ExTraceGlobals.StorageTracer.TraceDebug <string, StoreObjectId>((long)session.GetHashCode(), "Unable to parse recurrence info. Using the stored value for DueBy.\r\n\tError: {0}\r\n\tID:{1}", ex3.Message, versionedId.ObjectId);
                        return(result);
                    }
                    catch (CorruptDataException ex4)
                    {
                        ExTraceGlobals.StorageTracer.TraceDebug <string, StoreObjectId>((long)session.GetHashCode(), "Unable to parse the organizer timezone. Using the stored value for DueBy.\r\n\tError: {0}\r\n\tID:{1}", ex4.Message, versionedId.ObjectId);
                        return(result);
                    }
                }
            }
IL_206:
            bool defaultIsSet;
            int        defaultMinutesBeforeStart;
            ExDateTime value;

            if (internalRecurrence == null || !Util.TryConvertTo <bool>(propertyBag.GetValue(InternalSchema.ReminderIsSetInternal), out defaultIsSet) || !Util.TryConvertTo <int>(propertyBag.GetValue(InternalSchema.ReminderMinutesBeforeStartInternal), out defaultMinutesBeforeStart) || !Util.TryConvertTo <ExDateTime>(propertyBag.GetValue(InternalSchema.ReminderNextTime), out value))
            {
                return(propertyBag.GetValue(InternalSchema.ReminderDueByInternal));
            }
            ExDateTime     probeTime = Reminder.GetProbeTime(Reminder.GetTimeNow(session.ExTimeZone), new ExDateTime?(value));
            OccurrenceInfo mostRecentOccurrence;

            try
            {
                mostRecentOccurrence = CalendarItem.CustomReminder.GetMostRecentOccurrence(internalRecurrence, probeTime, defaultIsSet, defaultMinutesBeforeStart);
            }
            catch (CorruptDataException)
            {
                return(result);
            }
            if (mostRecentOccurrence == null)
            {
                return(new PropertyError(this, PropertyErrorCode.NotFound));
            }
            return(mostRecentOccurrence.StartTime);
        }
Ejemplo n.º 12
0
 private void PopulateExceptionOccurrence(object[] occurrence, PropertyDefinition[] columns, ExceptionInfo exception, ref AttachmentCollection attachments, ref Item master, VersionedId versionedId)
 {
     object[] array = null;
     for (int i = 0; i < columns.Length; i++)
     {
         if (!columns[i].Equals(InternalSchema.ItemId) && !columns[i].Equals(InternalSchema.IsRecurring) && !columns[i].Equals(InternalSchema.IsException) && !columns[i].Equals(InternalSchema.AppointmentRecurring) && !columns[i].Equals(InternalSchema.MapiStartTime) && !columns[i].Equals(InternalSchema.MapiPRStartDate) && !columns[i].Equals(InternalSchema.MapiEndTime) && !columns[i].Equals(InternalSchema.MapiPREndDate) && !columns[i].Equals(InternalSchema.CalendarItemType) && !columns[i].Equals(InternalSchema.GlobalObjectId) && !columns[i].Equals(InternalSchema.TimeZoneDefinitionStart) && !columns[i].Equals(InternalSchema.TimeZoneDefinitionEnd) && !columns[i].Equals(InternalSchema.Codepage) && !RecurrenceManager.MasterOnlyProperties.Contains(columns[i]))
         {
             if (RecurrenceManager.CanPropertyBeInExceptionData(columns[i]))
             {
                 object        obj           = exception.PropertyBag.TryGetProperty(columns[i]);
                 PropertyError propertyError = obj as PropertyError;
                 if (propertyError != null)
                 {
                     if (propertyError.PropertyErrorCode != PropertyErrorCode.NotFound)
                     {
                         throw PropertyError.ToException(new PropertyError[]
                         {
                             propertyError
                         });
                     }
                 }
                 else
                 {
                     occurrence[i] = obj;
                 }
             }
             else
             {
                 ExTraceGlobals.RecurrenceTracer.Information <PropertyDefinition>((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand, Opening embedded message for {0} property", columns[i]);
                 if (array == null)
                 {
                     if (attachments == null)
                     {
                         if (master == null)
                         {
                             ExTraceGlobals.RecurrenceTracer.Information((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand. Fetching master message when constructing view");
                             StoreObjectId masterId = versionedId.ObjectId;
                             bool          flag     = false;
                             try
                             {
                                 master = ItemBuilder.ConstructItem <Item>(this.storeSession, masterId, null, CalendarItemBaseSchema.Instance.AutoloadProperties, () => new StoreObjectPropertyBag(this.storeSession, this.storeSession.GetMapiProp(masterId), CalendarItemBaseSchema.Instance.AutoloadProperties), ItemCreateInfo.GenericItemInfo.Creator, Origin.Existing, ItemLevel.TopLevel);
                                 flag   = true;
                             }
                             finally
                             {
                                 if (!flag && master != null)
                                 {
                                     master.Dispose();
                                     master = null;
                                 }
                             }
                         }
                         attachments = master.AttachmentCollection;
                         ExTraceGlobals.RecurrenceTracer.Information((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand, Fetching attachments");
                     }
                     ItemAttachment itemAttachment = null;
                     using (Item item = RecurrenceManager.OpenEmbeddedMessageAndAttachment(attachments, TimeZoneHelper.GetRecurringTimeZoneFromPropertyBag(attachments.ContainerItem.PropertyBag), exception.StartTime, exception.EndTime, out itemAttachment, columns))
                     {
                         ExTraceGlobals.RecurrenceTracer.Information <ExDateTime>((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand, Fetching Embedded Message for exception occurence dateId: {0}", exception.OccurrenceDateId);
                         if (item != null)
                         {
                             array = item.GetProperties(columns);
                             itemAttachment.Dispose();
                         }
                         else
                         {
                             array = new object[columns.Length];
                         }
                     }
                 }
                 if (array[i] != null && !(array[i] is PropertyError))
                 {
                     occurrence[i] = array[i];
                 }
             }
         }
     }
 }
Ejemplo n.º 13
0
 internal WorkHoursTimeZone(ExTimeZone timeZone)
 {
     this.timeZoneInfo = TimeZoneHelper.RegTimeZoneInfoFromExTimeZone(timeZone);
     this.Name         = timeZone.Id;
 }
Ejemplo n.º 14
0
        public static bool TryParseTimeZoneBlob(byte[] bytes, string defaultDisplayName, out ExTimeZone timeZone)
        {
            timeZone = null;
            if (bytes == null || defaultDisplayName == null)
            {
                ExTraceGlobals.StorageTracer.TraceError(0L, "Time zone blob or default display name is null.");
                return(false);
            }
            O12TimeZoneFormatter.ExchangeTimeZoneHeader exchangeTimeZoneHeader;
            if (!O12TimeZoneFormatter.ExchangeTimeZoneHeader.TryParse(bytes, out exchangeTimeZoneHeader))
            {
                ExTraceGlobals.StorageTracer.TraceError(0L, "Failed to parse time zone blob header. Invalid time zone found.");
                return(false);
            }
            if (exchangeTimeZoneHeader.MajorVersion != 2 || exchangeTimeZoneHeader.MinVersion != 1)
            {
                ExTraceGlobals.StorageTracer.TraceError <byte, byte>(0L, "TimeZone blob version mismatch. Version read is Major: {0} Minor: {1}", exchangeTimeZoneHeader.MajorVersion, exchangeTimeZoneHeader.MinVersion);
            }
            if (exchangeTimeZoneHeader.RuleCount == 0)
            {
                ExTraceGlobals.StorageTracer.TraceError(0L, "Invalid time zone found. No rules in time zone blob");
                return(false);
            }
            O12TimeZoneFormatter.ExchangeTimeZoneRule?exchangeTimeZoneRule = null;
            List <RegistryTimeZoneRule> list = new List <RegistryTimeZoneRule>((int)exchangeTimeZoneHeader.RuleCount);
            int num = exchangeTimeZoneHeader.GetSize();

            for (int i = 0; i < (int)exchangeTimeZoneHeader.RuleCount; i++)
            {
                if (bytes.Length < num + O12TimeZoneFormatter.ExchangeTimeZoneRule.Size)
                {
                    ExTraceGlobals.StorageTracer.TraceError(0L, "Incomplete time zone blob found");
                    return(false);
                }
                O12TimeZoneFormatter.ExchangeTimeZoneRule value;
                if (!O12TimeZoneFormatter.ExchangeTimeZoneRule.TryParse(new ArraySegment <byte>(bytes, num, O12TimeZoneFormatter.ExchangeTimeZoneRule.Size), out value))
                {
                    ExTraceGlobals.StorageTracer.TraceError(0L, "Invalid time zone found. Incomplete rules in time zone blob");
                    return(false);
                }
                if (value.MajorVersion != 2 || value.MinVersion != 1)
                {
                    ExTraceGlobals.StorageTracer.TraceError(0L, string.Concat(new object[]
                    {
                        "Time zone rule version mismatch. Version read is Major: ",
                        value.MajorVersion,
                        " Minor: ",
                        value.MinVersion
                    }));
                }
                if (exchangeTimeZoneRule == null || (value.Flags & 2) != 0)
                {
                    exchangeTimeZoneRule = new O12TimeZoneFormatter.ExchangeTimeZoneRule?(value);
                }
                int num2 = Math.Max(DateTime.MinValue.Year, Math.Min((int)value.Start.Year, DateTime.MaxValue.Year));
                if (num2 != (int)value.Start.Year)
                {
                    ExTraceGlobals.StorageTracer.TraceError(0L, "Start year of rule in blob is out of range. Forced to valid range. Value in blob is " + value.Start.Year);
                }
                list.Add(new RegistryTimeZoneRule(num2, value.RegTimeZoneInfo));
                num += O12TimeZoneFormatter.ExchangeTimeZoneRule.Size;
            }
            ExTraceGlobals.StorageTracer.TraceInformation(0, 0L, "Effective rule is from year " + exchangeTimeZoneRule.Value.Start.Year);
            string     displayName = defaultDisplayName;
            ExTimeZone exTimeZone;

            if (ExTimeZoneEnumerator.Instance.TryGetTimeZoneByName(exchangeTimeZoneHeader.KeyName, out exTimeZone))
            {
                displayName = exTimeZone.LocalizableDisplayName;
            }
            bool result;

            try
            {
                timeZone = TimeZoneHelper.CreateCustomExTimeZoneFromRegRules(exchangeTimeZoneRule.Value.RegTimeZoneInfo, exchangeTimeZoneHeader.KeyName, displayName, list);
                result   = true;
            }
            catch (ArgumentException ex)
            {
                ExTraceGlobals.StorageTracer.TraceError(0L, "Invalid time zone found. Inner message is " + ex.Message);
                result = false;
            }
            return(result);
        }