Esempio n. 1
0
            public static object GetObject(CollectionItemType itemType, ComplianceSerializer.CollectionItem item)
            {
                switch (itemType)
                {
                case CollectionItemType.Short:
                    return(ComplianceSerializer.ReadShortFromBlob(item.ItemBlob, 0));

                case CollectionItemType.Int:
                    return(ComplianceSerializer.ReadIntFromBlob(item.ItemBlob, 0));

                case CollectionItemType.Long:
                    return(ComplianceSerializer.ReadLongFromBlob(item.ItemBlob, 0));

                case CollectionItemType.Double:
                    return(ComplianceSerializer.ReadDoubleFromBlob(item.ItemBlob, 0));

                case CollectionItemType.Guid:
                    return(ComplianceSerializer.ReadGuidFromBlob(item.ItemBlob, 0));

                case CollectionItemType.String:
                    return(Encoding.UTF8.GetString(item.ItemBlob));

                case CollectionItemType.Blob:
                    return(item.ItemBlob);

                default:
                    return(null);
                }
            }
Esempio n. 2
0
 protected internal virtual string GetDisplayText(object value)
 {
     if (value == null)
     {
         return(CollectionItemType.ToString());
     }
     return(value.ToString());
 }
Esempio n. 3
0
        public static byte[] Serialize <T>(ComplianceSerializationDescription <T> description, T inputObject) where T : class, new()
        {
            if (inputObject == null)
            {
                return(null);
            }
            int num = 1;

            num = num + 1 + description.TotalByteFields;
            num = num + 1 + 2 * description.TotalShortFields;
            num = num + 1 + 4 * description.TotalIntegerFields;
            num = num + 1 + 8 * description.TotalLongFields;
            num = num + 1 + 8 * description.TotalDoubleFields;
            num = num + 1 + 16 * description.TotalGuidFields;
            num = num + 1 + 4 * description.TotalStringFields;
            List <Tuple <int, byte[]> > variableWidthMemberBytes = ComplianceSerializer.GetVariableWidthMemberBytes <T>(description, inputObject, ComplianceSerializer.VariableWidthType.String);

            foreach (Tuple <int, byte[]> tuple in variableWidthMemberBytes)
            {
                num += tuple.Item1;
            }
            num = num + 1 + 4 * description.TotalBlobFields;
            List <Tuple <int, byte[]> > variableWidthMemberBytes2 = ComplianceSerializer.GetVariableWidthMemberBytes <T>(description, inputObject, ComplianceSerializer.VariableWidthType.Blob);

            foreach (Tuple <int, byte[]> tuple2 in variableWidthMemberBytes2)
            {
                num += tuple2.Item1;
            }
            num++;
            List <ComplianceSerializer.CollectionField> list = new List <ComplianceSerializer.CollectionField>();
            byte b = 0;

            while ((int)b < description.TotalCollectionFields)
            {
                CollectionItemType itemType = CollectionItemType.NotDefined;
                if (description.TryGetCollectionPropertyItemType(b, out itemType))
                {
                    IEnumerable <object> collectionItems = description.GetCollectionItems(inputObject, b);
                    ComplianceSerializer.CollectionField collectionField = ComplianceSerializer.CollectionField.GetCollectionField(itemType, collectionItems);
                    list.Add(collectionField);
                    num += collectionField.GetSizeOfSerializedCollectionField();
                }
                b += 1;
            }
            byte[] array = new byte[num];
            array[0] = description.ComplianceStructureId;
            int num2 = ComplianceSerializer.WriteFixedWidthFieldsToBlob <T>(ref description, ref inputObject, array, 1, 1, ComplianceSerializer.FixedWidthType.Byte, description.TotalByteFields);

            num2 = ComplianceSerializer.WriteFixedWidthFieldsToBlob <T>(ref description, ref inputObject, array, num2, 2, ComplianceSerializer.FixedWidthType.Short, description.TotalShortFields);
            num2 = ComplianceSerializer.WriteFixedWidthFieldsToBlob <T>(ref description, ref inputObject, array, num2, 4, ComplianceSerializer.FixedWidthType.Int, description.TotalIntegerFields);
            num2 = ComplianceSerializer.WriteFixedWidthFieldsToBlob <T>(ref description, ref inputObject, array, num2, 8, ComplianceSerializer.FixedWidthType.Long, description.TotalLongFields);
            num2 = ComplianceSerializer.WriteFixedWidthFieldsToBlob <T>(ref description, ref inputObject, array, num2, 8, ComplianceSerializer.FixedWidthType.Double, description.TotalDoubleFields);
            num2 = ComplianceSerializer.WriteFixedWidthFieldsToBlob <T>(ref description, ref inputObject, array, num2, 16, ComplianceSerializer.FixedWidthType.Guid, description.TotalGuidFields);
            num2 = ComplianceSerializer.WriteVariableWidthFieldsToBlob(array, num2, variableWidthMemberBytes);
            num2 = ComplianceSerializer.WriteVariableWidthFieldsToBlob(array, num2, variableWidthMemberBytes2);
            num2 = ComplianceSerializer.WriteCollectionsToBlob(array, num2, list);
            return(array);
        }
 public bool TryGetCollectionPropertyItemType(byte fieldIndex, out CollectionItemType type)
 {
     type = CollectionItemType.NotDefined;
     if ((int)fieldIndex >= this.collectionItemTypeGetters.Count || fieldIndex < 0)
     {
         return(false);
     }
     type = this.collectionItemTypeGetters[(int)fieldIndex]();
     return(true);
 }
Esempio n. 5
0
            public static bool TryGetCollectionItemFromBlob(CollectionItemType itemType, byte[] blob, int index, int totalLength, out ComplianceSerializer.CollectionItem item, ref StringBuilder errorBuilder)
            {
                item = new ComplianceSerializer.CollectionItem();
                int num  = 0;
                int num2 = 0;

                switch (itemType)
                {
                case CollectionItemType.Short:
                    item.IsFixedWidth = true;
                    num = 2;
                    break;

                case CollectionItemType.Int:
                    item.IsFixedWidth = true;
                    num = 4;
                    break;

                case CollectionItemType.Long:
                    item.IsFixedWidth = true;
                    num = 8;
                    break;

                case CollectionItemType.Double:
                    item.IsFixedWidth = true;
                    num = 8;
                    break;

                case CollectionItemType.Guid:
                    item.IsFixedWidth = true;
                    num = 16;
                    break;

                case CollectionItemType.String:
                case CollectionItemType.Blob:
                    item.IsFixedWidth = false;
                    num2 = 4;
                    if (index + num2 > totalLength)
                    {
                        errorBuilder.AppendFormat("Blob length:{0} is not sufficient to read the collection item width at index:{1}", totalLength, index);
                        return(false);
                    }
                    num = ComplianceSerializer.ReadIntFromBlob(blob, index);
                    break;
                }
                item.ItemBlob = new byte[num];
                if (index + num2 + num > totalLength)
                {
                    errorBuilder.AppendFormat("Blob length:{0} is not sufficient to read the collection item at index:{1}", totalLength, index + num2);
                    return(false);
                }
                Array.Copy(blob, index + num2, item.ItemBlob, 0, num);
                return(true);
            }
Esempio n. 6
0
            public static ComplianceSerializer.CollectionField GetCollectionField(CollectionItemType itemType, IEnumerable <object> objects)
            {
                ComplianceSerializer.CollectionField collectionField = new ComplianceSerializer.CollectionField();
                collectionField.CollectionItemType = itemType;
                int num = 0;

                foreach (object obj in objects)
                {
                    ComplianceSerializer.CollectionItem collectionItemFromObject = ComplianceSerializer.CollectionItem.GetCollectionItemFromObject(itemType, obj);
                    num++;
                    collectionField.CollectionItems.Add(collectionItemFromObject);
                }
                collectionField.NumberItems = num;
                return(collectionField);
            }
Esempio n. 7
0
        private static bool TryWriteCollectionsToObject <T>(ref ComplianceSerializationDescription <T> description, ref T parsedObject, byte[] blob, int startIndex, int totalLength, out int index, ref StringBuilder errorBuilder) where T : class, new()
        {
            index = startIndex;
            if (startIndex >= totalLength)
            {
                errorBuilder.AppendFormat("StartIndex:{0} is bigger than blob length:{1}", startIndex, totalLength);
                return(false);
            }
            byte b = blob[index++];

            for (byte b2 = 0; b2 < b; b2 += 1)
            {
                Type typeFromHandle = typeof(CollectionItemType);
                CollectionItemType collectionItemType = (CollectionItemType)Enum.ToObject(typeFromHandle, blob[index++]);
                if (!Enum.IsDefined(typeFromHandle, collectionItemType))
                {
                    errorBuilder.AppendFormat("Byte value:{0} at index:{1} does not represent a valid CollectionItemType", collectionItemType, index - 1);
                    return(false);
                }
                if (index + 4 > totalLength)
                {
                    errorBuilder.AppendFormat("Blob length:{0} is not sufficient to read the field count:{1} at index:{2}.", totalLength, b, index);
                    return(false);
                }
                int num = ComplianceSerializer.ReadIntFromBlob(blob, index);
                index += 4;
                List <object> list = new List <object>();
                for (int i = 0; i < num; i++)
                {
                    ComplianceSerializer.CollectionItem collectionItem = null;
                    if (!ComplianceSerializer.CollectionItem.TryGetCollectionItemFromBlob(collectionItemType, blob, index, totalLength, out collectionItem, ref errorBuilder))
                    {
                        return(false);
                    }
                    list.Add(ComplianceSerializer.CollectionItem.GetObject(collectionItemType, collectionItem));
                    index += collectionItem.GetSerializedSize();
                }
                description.TrySetCollectionItems(parsedObject, b2, list);
            }
            return(true);
        }
Esempio n. 8
0
            public static ComplianceSerializer.CollectionItem GetCollectionItemFromObject(CollectionItemType itemType, object obj)
            {
                ComplianceSerializer.CollectionItem collectionItem = new ComplianceSerializer.CollectionItem();
                switch (itemType)
                {
                case CollectionItemType.Short:
                    collectionItem.IsFixedWidth = true;
                    collectionItem.ItemBlob     = new byte[2];
                    ComplianceSerializer.WriteShortToBlob(collectionItem.ItemBlob, 0, (short)obj);
                    break;

                case CollectionItemType.Int:
                    collectionItem.IsFixedWidth = true;
                    collectionItem.ItemBlob     = new byte[4];
                    ComplianceSerializer.WriteIntToBlob(collectionItem.ItemBlob, 0, (int)obj);
                    break;

                case CollectionItemType.Long:
                    collectionItem.IsFixedWidth = true;
                    collectionItem.ItemBlob     = new byte[8];
                    ComplianceSerializer.WriteLongToBlob(collectionItem.ItemBlob, 0, (long)obj);
                    break;

                case CollectionItemType.Double:
                    collectionItem.IsFixedWidth = true;
                    collectionItem.ItemBlob     = new byte[8];
                    ComplianceSerializer.WriteDoubleToBlob(collectionItem.ItemBlob, 0, (double)obj);
                    break;

                case CollectionItemType.Guid:
                    collectionItem.IsFixedWidth = true;
                    collectionItem.ItemBlob     = new byte[16];
                    ComplianceSerializer.WriteGuidToBlob(collectionItem.ItemBlob, 0, (Guid)obj);
                    break;

                case CollectionItemType.String:
                    collectionItem.IsFixedWidth = false;
                    collectionItem.ItemBlob     = Encoding.UTF8.GetBytes((string)obj);
                    break;

                case CollectionItemType.Blob:
                    collectionItem.IsFixedWidth = false;
                    collectionItem.ItemBlob     = (byte[])obj;
                    break;
                }
                return(collectionItem);
            }
Esempio n. 9
0
 /// <summary>
 /// Creates a new form to display and edit the current collection.
 /// </summary>
 /// <returns>
 /// A <see cref="T:System.ComponentModel.Design.CollectionEditor.CollectionForm"></see> to provide as the user interface for editing the collection.
 /// </returns>
 protected override CollectionForm CreateCollectionForm()
 {
     EditorForm      = base.CreateCollectionForm();
     EditorForm.Text = CollectionItemType.GetCustomAttributeValue <DisplayNameAttribute, string>(x => x.DisplayName);
     return(EditorForm);
 }