Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EntityMapping"/> class.
 /// </summary>
 /// <param name="type">Type.</param>
 /// <param name="parentMapping">Parent mapping.</param>
 public EntityMapping(string type, Mapping parentMapping)
 {
     _Type = type;
     _Ids = new PrimaryKeyMappingCollection();
     _Attributes = new AttributeMappingCollection();
     _Attributes.TypeName = type;
     _References = new ReferenceMappingCollection();
     _ParentMapping = parentMapping;
 }
 void ExportElementMapping(XmlSchemaElement element, Mapping mapping, string ns, bool isAny) {
     if (mapping is ArrayMapping)
         ExportArrayMapping((ArrayMapping)mapping, ns, element);
     else if (mapping is PrimitiveMapping) {
         PrimitiveMapping pm = (PrimitiveMapping)mapping;
         if (pm.IsAnonymousType) {
             element.SchemaType = ExportAnonymousPrimitiveMapping(pm);
         }
         else {
             element.SchemaTypeName = ExportPrimitiveMapping(pm, ns);
         }
     }
     else if (mapping is StructMapping) {
         ExportStructMapping((StructMapping)mapping, ns, element);
     }
     else if (mapping is MembersMapping)
         element.SchemaType = ExportMembersMapping((MembersMapping)mapping, ns);
     else if (mapping is SpecialMapping)
         ExportSpecialMapping((SpecialMapping)mapping, ns, isAny, element);
     else if (mapping is NullableMapping) {
         ExportElementMapping(element, ((NullableMapping)mapping).BaseMapping, ns, isAny);
     }
     else
         throw new ArgumentException(Res.GetString(Res.XmlInternalError), "mapping");
 }
 static string GetMappingName(Mapping mapping) {
     if (mapping is MembersMapping)
         return "(method)";
     else if (mapping is TypeMapping)
         return ((TypeMapping)mapping).TypeDesc.FullName;
     else
         throw new ArgumentException(Res.GetString(Res.XmlInternalError), "mapping");
 }
 private void ExportMapping(Mapping mapping, string ns, bool isAny)
 {
     if (mapping is ArrayMapping)
         ExportArrayMapping((ArrayMapping)mapping, ns, null);
     else if (mapping is PrimitiveMapping)
     {
         ExportPrimitiveMapping((PrimitiveMapping)mapping, ns);
     }
     else if (mapping is StructMapping)
         ExportStructMapping((StructMapping)mapping, ns, null);
     else if (mapping is MembersMapping)
         ExportMembersMapping((MembersMapping)mapping, ns);
     else if (mapping is SpecialMapping)
         ExportSpecialMapping((SpecialMapping)mapping, ns, isAny, null);
     else if (mapping is NullableMapping)
         ExportMapping(((NullableMapping)mapping).BaseMapping, ns, isAny);
     else
         throw new ArgumentException(SR.XmlInternalError, nameof(mapping));
 }
Exemple #5
0
 protected Mapping(Mapping mapping)
 {
     _isSoap = mapping._isSoap;
 }
 private static string GetMappingName(Mapping mapping)
 {
     if (mapping is MembersMapping)
         return "(method)";
     else if (mapping is TypeMapping)
         return ((TypeMapping)mapping).TypeDesc.FullName;
     else
         throw new ArgumentException(SR.XmlInternalError, nameof(mapping));
 }
 private void ExportElementMapping(XmlSchemaElement element, Mapping mapping, string ns, bool isAny)
 {
     if (mapping is ArrayMapping)
     {
         this.ExportArrayMapping((ArrayMapping) mapping, ns, element);
     }
     else if (mapping is PrimitiveMapping)
     {
         PrimitiveMapping mapping2 = (PrimitiveMapping) mapping;
         if (mapping2.IsAnonymousType)
         {
             element.SchemaType = this.ExportAnonymousPrimitiveMapping(mapping2);
         }
         else
         {
             element.SchemaTypeName = this.ExportPrimitiveMapping(mapping2, ns);
         }
     }
     else if (mapping is StructMapping)
     {
         this.ExportStructMapping((StructMapping) mapping, ns, element);
     }
     else if (mapping is MembersMapping)
     {
         element.SchemaType = this.ExportMembersMapping((MembersMapping) mapping, ns);
     }
     else if (mapping is SpecialMapping)
     {
         this.ExportSpecialMapping((SpecialMapping) mapping, ns, isAny, element);
     }
     else
     {
         if (!(mapping is NullableMapping))
         {
             throw new ArgumentException(Res.GetString("XmlInternalError"), "mapping");
         }
         this.ExportElementMapping(element, ((NullableMapping) mapping).BaseMapping, ns, isAny);
     }
 }
Exemple #8
0
        private static void ParseChildAttributes(DB db, Mapping.Product amazonProduct, Product product)
        {
            // sku
            product.SKU = amazonProduct.Identifier.MerchantSku.Sku;

            // merchantid
            product.Merchant = amazonProduct.Identifier.MerchantSku.MerchantId;

            // url
            product.HREF = amazonProduct.HREF();

            Service.ParseOffer(amazonProduct.Offers, product);

            // db.SaveChanges();

            // swatch
            var imageRelations = new Mapping.Relation[]
            {
                Mapping.Relation.Main,
                Mapping.Relation.Swatch
            };

            Service.ParseAssets(db, amazonProduct.Assets, product.ID, imageRelations);

            foreach (var item in amazonProduct.Attributes.Fabrics)
            {
                var fabric = db.Fabrics.Where(f => f.Name == item.Value).SingleOrDefault();
                if (fabric == null)
                {
                    fabric = new Fabric() { Name = item.Value };

                    db.Fabrics.Add(fabric);
                    db.SaveChanges();
                }

                var productFabric = db.ProductFabrics.Where(pf => pf.ProductID == product.ID && pf.FabricID == fabric.ID).SingleOrDefault();
                if (productFabric == null)
                {
                    db.ProductFabrics.Add(new ProductFabric() { ProductID = product.ID, FabricID = fabric.ID });
                    db.SaveChanges();
                }
            }
        }
Exemple #9
0
        private static void ParseParentAttributes(DB db, Mapping.Product amazonProduct, Product product)
        {
            // title
            product.Title = amazonProduct.Attributes.Title;

            // description
            product.Description = Strip(amazonProduct.Attributes.Description);

            // bullets
            Service.ParseBullets(db, amazonProduct, product.ID);

            // main and part images
            var imageRelations = new Mapping.Relation[]
            {
                Mapping.Relation.Part1,
                Mapping.Relation.Part2,
                Mapping.Relation.Part3,
                Mapping.Relation.Part4,
                Mapping.Relation.Part5,
                Mapping.Relation.Part6,
                Mapping.Relation.Part7
            };

            Service.ParseAssets(db, amazonProduct.Assets, product.ID, imageRelations);
        }
Exemple #10
0
        private static void ParseAssets(DB db, Collection<Mapping.Link> assets, int product, Mapping.Relation[] relations)
        {
            foreach (var asset in assets.Where(a => relations.Contains(a.Relation)))
            {
                var type = Service.CreateAndGetImageType(db, asset.Relation.ToString());

                Service.CreateImage(db, product, asset.Href, type);
            }
        }
Exemple #11
0
        private static void ParseBullets(DB db, Mapping.Product amazonProduct, int product)
        {
            foreach (var item in amazonProduct.Attributes.BulletPoints)
            {
                var text = Strip(item);

                if (!string.IsNullOrWhiteSpace(text))
                {
                    Service.AddBullet(db, product, text);
                }
            }
        }
Exemple #12
0
        private static void CreateVariantIfRequired(DB db, Product product, Product variation, Mapping.Direction direction, Dictionary<Mapping.DimensionType, string> dimensions)
        {
            Product parent;
            Product child;

            if (direction == Mapping.Direction.Parent)
            {
                child = product;
                parent = variation;
            }
            else
            {
                child = variation;
                parent = product;
            }

            child.Parent = parent;

            foreach (var dimension in dimensions)
            {
                // Get ID of type of current dimension, create if doesn't exist
                var type = Service.CreateAndGetDimensionType(db, dimension.Key.ToString());

                // Get value of current dimension, create if doesn't exist
                var value = Service.CreateAndGetDimensionValue(db, dimension.Value, type);

                // Get all dimensions for current product (child)
                var existingDimensions = db.Dimensions.Where(dt => dt.ProductID == child.ID);

                // Delete dimensions other then the current
                foreach (var item in existingDimensions.Where(d => d.Value.TypeID == type && d.ValueID != value.ID))
                {
                    db.Dimensions.Remove(item);
                }

                // Add current dimension if it doesn't exist
                if (!existingDimensions.Any(d => d.ValueID == value.ID))
                {
                    var newDimension = new Dimension() { Product = child, Value = value };

                    db.Dimensions.Add(newDimension);
                }

                db.SaveChanges();
            }
        }
Exemple #13
0
 protected Mapping(Mapping mapping)
 {
 }
Exemple #14
0
        private StructMapping ImportStructType(XmlSchemaComplexType type, string typeNs, bool excludeFromImport)
        {
            if (type.Name == null)
            {
                XmlSchemaElement parent     = (XmlSchemaElement)type.Parent;
                XmlQualifiedName parentName = XmlSchemas.GetParentName(parent);
                throw new InvalidOperationException(Res.GetString("XmlInvalidSchemaElementType", new object[] { parentName.Name, parentName.Namespace, parent.Name }));
            }
            TypeDesc baseTypeDesc = null;
            Mapping  rootMapping  = null;

            if (!type.DerivedFrom.IsEmpty)
            {
                rootMapping = this.ImportType(type.DerivedFrom, excludeFromImport);
                if (rootMapping is StructMapping)
                {
                    baseTypeDesc = ((StructMapping)rootMapping).TypeDesc;
                }
                else
                {
                    rootMapping = null;
                }
            }
            if (rootMapping == null)
            {
                rootMapping = base.GetRootMapping();
            }
            Mapping mapping2 = (Mapping)base.ImportedMappings[type];

            if (mapping2 != null)
            {
                return((StructMapping)mapping2);
            }
            string        str      = base.GenerateUniqueTypeName(Accessor.UnescapeName(type.Name));
            StructMapping mapping3 = new StructMapping {
                IsReference = base.Schemas.IsReference(type)
            };
            TypeFlags reference = TypeFlags.Reference;

            if (type.IsAbstract)
            {
                reference |= TypeFlags.Abstract;
            }
            mapping3.TypeDesc    = new TypeDesc(str, str, TypeKind.Struct, baseTypeDesc, reference);
            mapping3.Namespace   = typeNs;
            mapping3.TypeName    = type.Name;
            mapping3.BaseMapping = (StructMapping)rootMapping;
            base.ImportedMappings.Add(type, mapping3);
            if (excludeFromImport)
            {
                mapping3.IncludeInSchema = false;
            }
            CodeIdentifiers scope = new CodeIdentifiers();

            scope.AddReserved(str);
            base.AddReservedIdentifiersForDataBinding(scope);
            mapping3.Members = this.ImportTypeMembers(type, typeNs, scope);
            base.Scope.AddTypeMapping(mapping3);
            this.ImportDerivedTypes(new XmlQualifiedName(type.Name, typeNs));
            return(mapping3);
        }
Exemple #15
0
 protected Mapping(Mapping mapping)
 {
     this.isSoap = mapping.isSoap;
 }
Exemple #16
0
 protected Mapping(Mapping mapping)
 {
     _isSoap = mapping._isSoap;
 }
Exemple #17
0
 protected Mapping(Mapping mapping)
 {
 }
 private static string GetMappingName(Mapping mapping)
 {
     if (mapping is MembersMapping)
     {
         return "(method)";
     }
     if (!(mapping is TypeMapping))
     {
         throw new ArgumentException(Res.GetString("XmlInternalError"), "mapping");
     }
     return ((TypeMapping) mapping).TypeDesc.FullName;
 }
 private void ExportMapping(Mapping mapping, string ns, bool isAny)
 {
     if (mapping is ArrayMapping)
     {
         this.ExportArrayMapping((ArrayMapping) mapping, ns, null);
     }
     else if (mapping is PrimitiveMapping)
     {
         this.ExportPrimitiveMapping((PrimitiveMapping) mapping, ns);
     }
     else if (mapping is StructMapping)
     {
         this.ExportStructMapping((StructMapping) mapping, ns, null);
     }
     else if (mapping is MembersMapping)
     {
         this.ExportMembersMapping((MembersMapping) mapping, ns);
     }
     else if (mapping is SpecialMapping)
     {
         this.ExportSpecialMapping((SpecialMapping) mapping, ns, isAny, null);
     }
     else
     {
         if (!(mapping is NullableMapping))
         {
             throw new ArgumentException(Res.GetString("XmlInternalError"), "mapping");
         }
         this.ExportMapping(((NullableMapping) mapping).BaseMapping, ns, isAny);
     }
 }
        StructMapping ImportStructType(XmlSchemaComplexType type, string typeNs, bool excludeFromImport)
        {
            if (type.Name == null)
            {
                XmlSchemaElement element    = (XmlSchemaElement)type.Parent;
                XmlQualifiedName parentType = XmlSchemas.GetParentName(element);
                throw new InvalidOperationException(Res.GetString(Res.XmlInvalidSchemaElementType, parentType.Name, parentType.Namespace, element.Name));
            }

            TypeDesc baseTypeDesc = null;

            Mapping baseMapping = null;

            if (!type.DerivedFrom.IsEmpty)
            {
                baseMapping = ImportType(type.DerivedFrom, excludeFromImport);

                if (baseMapping is StructMapping)
                {
                    baseTypeDesc = ((StructMapping)baseMapping).TypeDesc;
                }
                else
                {
                    baseMapping = null;
                }
            }
            if (baseMapping == null)
            {
                baseMapping = GetRootMapping();
            }
            Mapping previousMapping = (Mapping)ImportedMappings[type];

            if (previousMapping != null)
            {
                return((StructMapping)previousMapping);
            }
            string        typeName      = GenerateUniqueTypeName(Accessor.UnescapeName(type.Name));
            StructMapping structMapping = new StructMapping();

            structMapping.IsReference = Schemas.IsReference(type);
            TypeFlags flags = TypeFlags.Reference;

            if (type.IsAbstract)
            {
                flags |= TypeFlags.Abstract;
            }
            structMapping.TypeDesc    = new TypeDesc(typeName, typeName, TypeKind.Struct, baseTypeDesc, flags);
            structMapping.Namespace   = typeNs;
            structMapping.TypeName    = type.Name;
            structMapping.BaseMapping = (StructMapping)baseMapping;
            ImportedMappings.Add(type, structMapping);
            if (excludeFromImport)
            {
                structMapping.IncludeInSchema = false;
            }
            CodeIdentifiers members = new CodeIdentifiers();

            members.AddReserved(typeName);
            AddReservedIdentifiersForDataBinding(members);
            structMapping.Members = ImportTypeMembers(type, typeNs, members);
            Scope.AddTypeMapping(structMapping);
            ImportDerivedTypes(new XmlQualifiedName(type.Name, typeNs));
            return(structMapping);
        }