private static byte[] GenerateBlobFromRuleGroups(string keyName, IList <ExTimeZoneRuleGroup> groups)
        {
            O12TimeZoneFormatter.ExchangeTimeZoneHeader exchangeTimeZoneHeader = new O12TimeZoneFormatter.ExchangeTimeZoneHeader(keyName, (ushort)groups.Count);
            int size = exchangeTimeZoneHeader.GetSize();
            int num  = size + O12TimeZoneFormatter.ExchangeTimeZoneRule.Size * groups.Count;

            byte[] array = new byte[num];
            int    num2  = exchangeTimeZoneHeader.ToBytes(new ArraySegment <byte>(array, 0, size));

            foreach (ExTimeZoneRuleGroup exTimeZoneRuleGroup in groups)
            {
                O12TimeZoneFormatter.TzRuleFlags flag = O12TimeZoneFormatter.TzRuleFlags.None;
                if (groups.Count == 1 || (exTimeZoneRuleGroup.EffectiveUtcStart <= DateTime.UtcNow && exTimeZoneRuleGroup.EffectiveUtcEnd > DateTime.UtcNow))
                {
                    flag = O12TimeZoneFormatter.TzRuleFlags.EffectiveTimeZone;
                }
                int year;
                if (exTimeZoneRuleGroup.EffectiveUtcStart != DateTime.MinValue)
                {
                    ExTimeZoneRule ruleForUtcTime = exTimeZoneRuleGroup.GetRuleForUtcTime(exTimeZoneRuleGroup.EffectiveUtcStart);
                    year = ruleForUtcTime.FromUtc(exTimeZoneRuleGroup.EffectiveUtcStart).Year;
                }
                else
                {
                    year = exTimeZoneRuleGroup.EffectiveUtcStart.Year;
                }
                REG_TIMEZONE_INFO regInfo = TimeZoneHelper.RegTimeZoneInfoFromExTimeZoneRuleGroup(exTimeZoneRuleGroup);
                O12TimeZoneFormatter.ExchangeTimeZoneRule exchangeTimeZoneRule = new O12TimeZoneFormatter.ExchangeTimeZoneRule(flag, (ushort)year, regInfo);
                exchangeTimeZoneRule.ToBytes(new ArraySegment <byte>(array, num2, O12TimeZoneFormatter.ExchangeTimeZoneRule.Size));
                num2 += O12TimeZoneFormatter.ExchangeTimeZoneRule.Size;
            }
            return(array);
        }
Пример #2
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));
        }