Ejemplo n.º 1
0
 public static ExTimeZone CreateCustomExTimeZoneFromRegTimeZoneInfo(REG_TIMEZONE_INFO regInfo, string keyName, string displayName)
 {
     return(TimeZoneHelper.CreateCustomExTimeZoneFromRegRules(regInfo, keyName, displayName, new List <RegistryTimeZoneRule>(1)
     {
         new RegistryTimeZoneRule(DateTime.MinValue.Year, regInfo)
     }));
 }
Ejemplo n.º 2
0
        internal ExTimeZone Promote()
        {
            ExTimeZone         result        = null;
            TimeZoneRule       timeZoneRule  = null;
            TimeZoneRule       timeZoneRule2 = null;
            SortedSet <ushort> sortedSet     = new SortedSet <ushort>();

            VTimeZone.CollectAllRuleYears(this.standardRules, sortedSet);
            VTimeZone.CollectAllRuleYears(this.daylightRules, sortedSet);
            List <RegistryTimeZoneRule> list = new List <RegistryTimeZoneRule>(sortedSet.Count);

            foreach (ushort num in sortedSet)
            {
                TimeZoneRule timeZoneRule3 = VTimeZone.UpdateAndGetCurrentRule(num, this.daylightRules, ref timeZoneRule2);
                TimeZoneRule timeZoneRule4 = VTimeZone.UpdateAndGetCurrentRule(num, this.standardRules, ref timeZoneRule);
                if (timeZoneRule3 != null || timeZoneRule4 != null)
                {
                    list.Add(new RegistryTimeZoneRule((int)num, this.GetNativeTimeZoneRule(timeZoneRule4, timeZoneRule3)));
                }
            }
            try
            {
                result = TimeZoneHelper.CreateCustomExTimeZoneFromRegRules(list[0].RegTimeZoneInfo, this.timeZoneId, this.timeZoneId, list);
            }
            catch (InvalidTimeZoneException ex)
            {
                ExTraceGlobals.ICalTracer.TraceDebug <string>((long)this.GetHashCode(), "ToExTimeZone::ToExTimeZone. Following error found when construct customized time zone: {0}", ex.Message);
                base.Context.AddError(ServerStrings.InvalidICalElement("VTIMEZONE"));
            }
            return(result);
        }
Ejemplo n.º 3
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);
        }