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);
        }
 public static bool TryParse(ArraySegment <byte> source, out O12TimeZoneFormatter.ExchangeTimeZoneRule rule)
 {
     rule = default(O12TimeZoneFormatter.ExchangeTimeZoneRule);
     if (source.Count < O12TimeZoneFormatter.ExchangeTimeZoneRule.Size)
     {
         return(false);
     }
     rule.MajorVersion    = source.Array[source.Offset + O12TimeZoneFormatter.ExchangeTimeZoneRule.MajorVersionOffset];
     rule.MinVersion      = source.Array[source.Offset + O12TimeZoneFormatter.ExchangeTimeZoneRule.MinVersionOffset];
     rule.ruleSize        = BitConverter.ToUInt16(source.Array, source.Offset + O12TimeZoneFormatter.ExchangeTimeZoneRule.RuleSizeOffset);
     rule.Flags           = BitConverter.ToUInt16(source.Array, source.Offset + O12TimeZoneFormatter.ExchangeTimeZoneRule.FlagsOffset);
     rule.Start           = NativeMethods.SystemTime.Parse(new ArraySegment <byte>(source.Array, source.Offset + O12TimeZoneFormatter.ExchangeTimeZoneRule.StartOffset, NativeMethods.SystemTime.Size));
     rule.RegTimeZoneInfo = REG_TIMEZONE_INFO.Parse(new ArraySegment <byte>(source.Array, source.Offset + O12TimeZoneFormatter.ExchangeTimeZoneRule.RegTimeZoneInfoOffset, REG_TIMEZONE_INFO.Size));
     return(true);
 }