public void Modify(XElement root, IModificationContext context)
 {
     foreach (IElementModifier modifier in this.modifiers)
     {
         modifier.Modify(root, context);
     }
 }
Exemplo n.º 2
0
        public void Modify(XElement element, IModificationContext context)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            foreach (XElement selected in this.elementSelector.SelectElements(element))
            {
                if (this.attributeSelector != null && this.attributeModifier != null)
                {
                    XAttribute attribute = this.attributeSelector.SelectAttribute(selected);

                    if (attribute != null)
                    {
                        this.attributeModifier.Modify(attribute, context);
                    }
                }

                if (this.elementModifier != null)
                {
                    this.elementModifier.Modify(selected, context);
                }
            }
        }
Exemplo n.º 3
0
 public void Modify(XElement root, IModificationContext context)
 {
     foreach (IElementModifier modifier in this.modifiers)
     {
         modifier.Modify(root, context);
     }
 }
        public void Modify(XElement element, IModificationContext context)
        {
            var functionMappings = element.Descendants(
                XName.Get(
                    "ModificationFunctionMapping",
                    "http://schemas.microsoft.com/ado/2009/11/mapping/cs"))
                .ToList();

            foreach (var mappingElement in functionMappings)
            {
                mappingElement.Remove();
            }
        }
        public void Modify(XElement element, IModificationContext context)
        {
            var functionMappings = element.Descendants(
                XName.Get(
                    "ModificationFunctionMapping",
                    "http://schemas.microsoft.com/ado/2009/11/mapping/cs"))
                                   .ToList();

            foreach (var mappingElement in functionMappings)
            {
                mappingElement.Remove();
            }
        }
Exemplo n.º 6
0
        public void Modify(XElement element, IModificationContext context)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (element.Name != this.nameProvider.PropertyElement)
            {
                throw new ArgumentException("", "context");
            }

            StorageTypeConverter converter = ModificationContextHelper.GetTypeConverter(context);

            XAttribute typeAttribute = element.Attribute(this.nameProvider.TypeAttribute);

            Facet[] facets         = null;
            string  oldStorageType = typeAttribute.Value;
            string  newStorageType = null;

            if (converter.TryConvertType(oldStorageType, out newStorageType, out facets))
            {
                typeAttribute.Value = newStorageType;

                foreach (XName commonAttributeName in this.CommonPropertyAttributeNames)
                {
                    if (element.Attribute(commonAttributeName) != null)
                    {
                        // Element contains the attribute
                        continue;
                    }

                    // Seach for default facet value
                    Facet facet = facets.FirstOrDefault(f => f.Name == commonAttributeName.LocalName);

                    if (facet != null && facet.Value != null)
                    {
                        element.Add(new XAttribute(commonAttributeName, facet.Value));
                    }
                }
            }
        }
Exemplo n.º 7
0
        public void Modify(XElement element, IModificationContext context)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (element.Name != this.nameProvider.PropertyElement)
            {
                throw new ArgumentException("", "context");
            }

            StorageTypeConverter converter = ModificationContextHelper.GetTypeConverter(context);

            XAttribute typeAttribute = element.Attribute(this.nameProvider.TypeAttribute);

            Facet[] facets = null;
            string oldStorageType = typeAttribute.Value;
            string newStorageType = null;

            if (converter.TryConvertType(oldStorageType, out newStorageType, out facets))
            {
                typeAttribute.Value = newStorageType;

                foreach (XName commonAttributeName in this.CommonPropertyAttributeNames)
                {
                    if (element.Attribute(commonAttributeName) != null)
                    {
                        // Element contains the attribute
                        continue;
                    }

                    // Seach for default facet value
                    Facet facet = facets.FirstOrDefault(f => f.Name == commonAttributeName.LocalName);

                    if (facet != null && facet.Value != null)
                    {
                        element.Add(new XAttribute(commonAttributeName, facet.Value));
                    }
                }
            }
        }
Exemplo n.º 8
0
        public void Modify(XElement ssdl, IModificationContext context)
        {
            if (ssdl == null)
            {
                throw new ArgumentNullException("ssdl");
            }

            if (ssdl.Name != this.nameProvider.SchemaElement)
            {
                throw new ArgumentException("", "ssdl");
            }

            // Parse and store original provider information
            IProviderInformation providerInfo = this.providerParser.VisitElement(ssdl);
            context.Set(ModificationContextHelper.OriginalProvider, providerInfo);

            // Modify the xml
            this.modificationLogic.Modify(ssdl, context);
        }
        public void Modify(XAttribute attribute, IModificationContext context)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            string oldStorageType          = attribute.Value;
            StorageTypeConverter converter = ModificationContextHelper.GetTypeConverter(context);

            // Try to get the collection value
            string pattern      = @"Collection\(([^ \t]{1,}(?:\.[^ \\t]{1,}){0,})\)";
            Match  regex        = Regex.Match(oldStorageType, pattern);
            bool   isCollection = regex.Success;

            // If it was a collection type, get the inside value
            if (isCollection)
            {
                oldStorageType = regex.Groups[1].Value;
            }

            string newStorageType = null;

            Facet[] facets = null;

            if (converter.TryConvertType(oldStorageType, out newStorageType, out facets))
            {
                if (isCollection)
                {
                    attribute.Value = string.Format("Collection({0})", newStorageType);
                }
                else
                {
                    attribute.Value = newStorageType;
                }
            }
        }
        public void Modify(XAttribute attribute, IModificationContext context)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            string oldStorageType = attribute.Value;
            StorageTypeConverter converter = ModificationContextHelper.GetTypeConverter(context);

            // Try to get the collection value
            string pattern = @"Collection\(([^ \t]{1,}(?:\.[^ \\t]{1,}){0,})\)";
            Match regex = Regex.Match(oldStorageType, pattern);
            bool isCollection = regex.Success;

            // If it was a collection type, get the inside value
            if (isCollection)
            {
                oldStorageType = regex.Groups[1].Value;
            }

            string newStorageType = null;

            Facet[] facets = null;

            if (converter.TryConvertType(oldStorageType, out newStorageType, out facets))
            {
                if (isCollection)
                {
                    attribute.Value = string.Format("Collection({0})", newStorageType);
                }
                else
                {
                    attribute.Value = newStorageType;
                }
            }
        }
Exemplo n.º 11
0
        public void Modify(XElement ssdl, IModificationContext context)
        {
            if (ssdl == null)
            {
                throw new ArgumentNullException("ssdl");
            }

            if (ssdl.Name != this.nameProvider.SchemaElement)
            {
                throw new ArgumentException("", "ssdl");
            }

            // Parse and store original provider information
            IProviderInformation providerInfo = this.providerParser.VisitElement(ssdl);

            context.Set(ModificationContextHelper.OriginalProvider, providerInfo);

            // Modify the xml
            this.modificationLogic.Modify(ssdl, context);
        }
Exemplo n.º 12
0
        public void Modify(XAttribute attribute, IModificationContext context)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            IProviderInformation newProvider = context.Get<IProviderInformation>(ModificationContextHelper.NewProvider, null);

            if (newProvider == null)
            {
                throw new InvalidOperationException();
            }

            attribute.Value = newProvider.InvariantName;
        }
        public void Modify(XAttribute attribute, IModificationContext context)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            IProviderInformation newProvider = context.Get <IProviderInformation>(ModificationContextHelper.NewProvider, null);

            if (newProvider == null)
            {
                throw new InvalidOperationException();
            }

            attribute.Value = newProvider.ManifestToken;
        }
Exemplo n.º 14
0
        public static StorageTypeConverter GetTypeConverter(IModificationContext context)
        {
            if (context == null)
            {
                throw new ArgumentException("context");
            }

            StorageTypeConverter converter = context.Get<StorageTypeConverter>(TypeConverter, null);

            if (converter != null)
            {
                return converter;
            }

            // Create the converter
            // Get the provider informations first
            IProviderInformation originalProvider =
                context.Get<IProviderInformation>(ModificationContextHelper.OriginalProvider, null);

            IProviderInformation newProvider =
                context.Get<IProviderInformation>(ModificationContextHelper.NewProvider, null);

            if (originalProvider == null)
            {
                throw new ArgumentException("", "context");
            }

            if (newProvider == null)
            {
                throw new ArgumentException("", "context");
            }

            converter = new StorageTypeConverter(originalProvider, newProvider);

            // Store for future usage
            context.Set(TypeConverter, converter);
            
            return converter;
        }
Exemplo n.º 15
0
        public static StorageTypeConverter GetTypeConverter(IModificationContext context)
        {
            if (context == null)
            {
                throw new ArgumentException("context");
            }

            StorageTypeConverter converter = context.Get <StorageTypeConverter>(TypeConverter, null);

            if (converter != null)
            {
                return(converter);
            }

            // Create the converter
            // Get the provider informations first
            IProviderInformation originalProvider =
                context.Get <IProviderInformation>(ModificationContextHelper.OriginalProvider, null);

            IProviderInformation newProvider =
                context.Get <IProviderInformation>(ModificationContextHelper.NewProvider, null);

            if (originalProvider == null)
            {
                throw new ArgumentException("", "context");
            }

            if (newProvider == null)
            {
                throw new ArgumentException("", "context");
            }

            converter = new StorageTypeConverter(originalProvider, newProvider);

            // Store for future usage
            context.Set(TypeConverter, converter);

            return(converter);
        }
        public void Modify(XAttribute attribute, IModificationContext context)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            string oldStorageType = attribute.Value;
            StorageTypeConverter converter = ModificationContextHelper.GetTypeConverter(context);

            string newStorageType = null;
            Facet[] facets;

            if (converter.TryConvertType(oldStorageType, out newStorageType, out facets))
            {
                attribute.Value = newStorageType;
            }
        }
        public void Modify(XAttribute attribute, IModificationContext context)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException("attribute");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            string oldStorageType          = attribute.Value;
            StorageTypeConverter converter = ModificationContextHelper.GetTypeConverter(context);

            string newStorageType = null;

            Facet[] facets;

            if (converter.TryConvertType(oldStorageType, out newStorageType, out facets))
            {
                attribute.Value = newStorageType;
            }
        }