Пример #1
0
        internal static bool TryCreateFromBytes(byte[] bytes, Encoding encoding, out OrganizationId orgId)
        {
            orgId = null;
            if (bytes == null)
            {
                throw new ArgumentNullException("bytes");
            }
            if (bytes.Length < 6)
            {
                return(false);
            }
            byte b = bytes[0];

            if (b <= 0)
            {
                return(false);
            }
            int        num         = 1;
            int        num2        = (int)(1 + 5 * b);
            ADObjectId adobjectId  = null;
            ADObjectId adobjectId2 = null;

            for (int i = 0; i < (int)b; i++)
            {
                if (bytes.Length < num + 4 + 1)
                {
                    return(false);
                }
                OrganizationId.ByteRepresentationTag byteRepresentationTag = (OrganizationId.ByteRepresentationTag)bytes[num++];
                int num3 = BitConverter.ToInt32(bytes, num);
                num += 4;
                if (num3 < 0)
                {
                    return(false);
                }
                if (num3 != 0 && bytes.Length < num2 + num3)
                {
                    return(false);
                }
                switch (byteRepresentationTag)
                {
                case OrganizationId.ByteRepresentationTag.ForestWideOrgIdTag:
                    if (num3 != 0)
                    {
                        return(false);
                    }
                    orgId = OrganizationId.ForestWideOrgId;
                    return(true);

                case OrganizationId.ByteRepresentationTag.OrgUnitTag:
                    if (adobjectId != null || !ADObjectId.TryCreateFromBytes(bytes, num2, num3, encoding, out adobjectId))
                    {
                        return(false);
                    }
                    break;

                case OrganizationId.ByteRepresentationTag.ConfigUnitTag:
                    if (adobjectId2 != null || !ADObjectId.TryCreateFromBytes(bytes, num2, num3, encoding, out adobjectId2))
                    {
                        return(false);
                    }
                    if (!ADSession.IsTenantConfigObjectInCorrectNC(adobjectId2))
                    {
                        return(false);
                    }
                    break;
                }
                num2 += num3;
            }
            if (adobjectId == null || adobjectId2 == null)
            {
                return(false);
            }
            orgId = new OrganizationId();
            orgId.Initialize(adobjectId, adobjectId2);
            return(true);
        }