Example #1
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));
                    }
                }
            }
        }
        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;
                }
            }
        }
Example #3
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 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;
            }
        }