Esempio n. 1
0
        /// <summary>
        /// Set stream associated with entity in V1 stream support style.
        /// </summary>
        /// <param name="objectServices">IEntityModelObjectServices to get entity object adapter</param>
        /// <param name="wrappedEntity">entity to set stream</param>
        /// <param name="clientMediaEntryAnnotation">ClientMediaEntryAnnotation of the entity</param>
        /// <param name="streamValue">stream bytes</param>
        public static void SetSaveV1Stream(IEntityModelObjectServices objectServices, WrappedObject wrappedEntity, ClientMediaEntryAnnotation clientMediaEntryAnnotation, byte[] streamValue)
        {
            var objectAdapter = objectServices.GetObjectAdapter(wrappedEntity.Product.GetType().FullName);

            objectAdapter.SetMemberValue(wrappedEntity.Product, clientMediaEntryAnnotation.MediaEntryName, streamValue);
            objectAdapter.SetMemberValue(wrappedEntity.Product, clientMediaEntryAnnotation.MimeTypePropertyName, MimeTypes.TextPlain);
        }
Esempio n. 2
0
        private static void CachePropertiesValues(List <NamedValue> list, string path, string structuralTypeFullName, IEnumerable <MemberProperty> properties, object obj, IEntityModelObjectServices objectServices)
        {
            var adapter = objectServices.GetObjectAdapter(structuralTypeFullName);

            foreach (MemberProperty property in properties.Where(p => !(p.PropertyType is StreamDataType)))
            {
                object value = adapter.GetMemberValue <object>(obj, property.Name);

                ComplexDataType    complexDataType    = property.PropertyType as ComplexDataType;
                CollectionDataType collectionDataType = property.PropertyType as CollectionDataType;

                if (collectionDataType != null && value != null)
                {
                    var complexElementDataType = collectionDataType.ElementDataType as ComplexDataType;

                    IEnumerable enumerable = value as IEnumerable;
                    ExceptionUtilities.CheckObjectNotNull(enumerable, "Property type is a collection but does not implement IEnumerable. Property path: '{0}'.", path + property.Name);

                    int count = 0;
                    foreach (var collectionElement in enumerable)
                    {
                        string currentPath = path + property.Name + "." + count;
                        if (complexElementDataType == null || collectionElement == null)
                        {
                            list.Add(new NamedValue(currentPath, collectionElement));
                        }
                        else
                        {
                            CachePropertiesValues(
                                list,
                                currentPath + ".",
                                complexElementDataType.Definition.FullName,
                                complexElementDataType.Definition.Properties,
                                collectionElement,
                                objectServices);
                        }

                        count++;
                    }

                    if (count == 0)
                    {
                        list.Add(new NamedValue(path + property.Name, EmptyData.Value));
                    }
                }
                else if (value == null || complexDataType == null)
                {
                    list.Add(new NamedValue(path + property.Name, value));
                }
                else
                {
                    CachePropertiesValues(list, path + property.Name + ".", complexDataType.Definition.FullName, complexDataType.Definition.Properties, value, objectServices);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Set stream associated with entity in V1 stream support style.
 /// </summary>
 /// <param name="objectServices">IEntityModelObjectServices to get entity object adapter</param>
 /// <param name="wrappedEntity">entity to set stream</param>
 /// <param name="clientMediaEntryAnnotation">ClientMediaEntryAnnotation of the entity</param>
 /// <param name="streamValue">stream bytes</param>
 public static void SetSaveV1Stream(IEntityModelObjectServices objectServices, WrappedObject wrappedEntity, ClientMediaEntryAnnotation clientMediaEntryAnnotation, byte[] streamValue)
 {
     var objectAdapter = objectServices.GetObjectAdapter(wrappedEntity.Product.GetType().FullName);
     objectAdapter.SetMemberValue(wrappedEntity.Product, clientMediaEntryAnnotation.MediaEntryName, streamValue);
     objectAdapter.SetMemberValue(wrappedEntity.Product, clientMediaEntryAnnotation.MimeTypePropertyName, MimeTypes.TextPlain);
 }
        private static void CachePropertiesValues(List<NamedValue> list, string path, string structuralTypeFullName, IEnumerable<MemberProperty> properties, object obj, IEntityModelObjectServices objectServices)
        {
            var adapter = objectServices.GetObjectAdapter(structuralTypeFullName);

            foreach (MemberProperty property in properties.Where(p => !(p.PropertyType is StreamDataType)))
            {
                object value = adapter.GetMemberValue<object>(obj, property.Name);

                ComplexDataType complexDataType = property.PropertyType as ComplexDataType;
                CollectionDataType collectionDataType = property.PropertyType as CollectionDataType;

                if (collectionDataType != null && value != null)
                {
                    var complexElementDataType = collectionDataType.ElementDataType as ComplexDataType;

                    IEnumerable enumerable = value as IEnumerable;
                    ExceptionUtilities.CheckObjectNotNull(enumerable, "Property type is a collection but does not implement IEnumerable. Property path: '{0}'.", path + property.Name);

                    int count = 0;
                    foreach (var collectionElement in enumerable)
                    {
                        string currentPath = path + property.Name + "." + count;
                        if (complexElementDataType == null || collectionElement == null)
                        {
                            list.Add(new NamedValue(currentPath, collectionElement));
                        }
                        else
                        {
                            CachePropertiesValues(
                                list,
                                currentPath + ".",
                                complexElementDataType.Definition.FullName,
                                complexElementDataType.Definition.Properties,
                                collectionElement,
                                objectServices);
                        }

                        count++;
                    }

                    if (count == 0)
                    {
                        list.Add(new NamedValue(path + property.Name, EmptyData.Value));
                    }
                }
                else if (value == null || complexDataType == null)
                {
                    list.Add(new NamedValue(path + property.Name, value));
                }
                else
                {
                    CachePropertiesValues(list, path + property.Name + ".", complexDataType.Definition.FullName, complexDataType.Definition.Properties, value, objectServices);
                }
            }
        }