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(byte[] source, out O12TimeZoneFormatter.ExchangeTimeZoneHeader header)
 {
     header = default(O12TimeZoneFormatter.ExchangeTimeZoneHeader);
     if (source.Length < O12TimeZoneFormatter.ExchangeTimeZoneHeader.KeyNameOffset)
     {
         return(false);
     }
     header.MajorVersion  = source[O12TimeZoneFormatter.ExchangeTimeZoneHeader.MajorVersionOffset];
     header.MinVersion    = source[O12TimeZoneFormatter.ExchangeTimeZoneHeader.MinVersionOffset];
     header.headerSize    = BitConverter.ToUInt16(source, O12TimeZoneFormatter.ExchangeTimeZoneHeader.HeaderSizeOffset);
     header.flags         = BitConverter.ToUInt16(source, O12TimeZoneFormatter.ExchangeTimeZoneHeader.FlagsOffset);
     header.KeyNameLength = BitConverter.ToUInt16(source, O12TimeZoneFormatter.ExchangeTimeZoneHeader.KeyNameLengthOffset);
     if (source.Length < O12TimeZoneFormatter.ExchangeTimeZoneHeader.KeyNameOffset + (int)(header.KeyNameLength * 2) + 2)
     {
         return(false);
     }
     header.KeyName   = Encoding.Unicode.GetString(source, O12TimeZoneFormatter.ExchangeTimeZoneHeader.KeyNameOffset, (int)(header.KeyNameLength * 2));
     header.RuleCount = BitConverter.ToUInt16(source, O12TimeZoneFormatter.ExchangeTimeZoneHeader.KeyNameOffset + (int)(header.KeyNameLength * 2));
     return(true);
 }