示例#1
0
        public void Visit(IDomElement element, bool metaExists)
        {
            bool isNew;

            _repository.GetOrAdd(element.GetDomPath(_factory), out isNew);
            Visit(element, null, isNew, true, metaExists);
        }
        public Property CreateProperty(IRepository repository)
        {
            var property = _factory.CreateProperty(_jObject.GetDomPath(_factory), _jObject.Properties().Any());

            property.InitializeDefaultPropertyDefinitionSet(
                propertyDefinitions =>
                {
                    var userDefinedClassPropertyDefinition = _factory.CreatePropertyDefinition(repository.GetOrAdd(_jObject.GetDomPath(_factory)), _name, true, true, AttributeProxy.DataMember(_name));
                    propertyDefinitions.Append(userDefinedClassPropertyDefinition);
                });

            return property;
        }
示例#3
0
        public IClass ToClass(IRepository repository, IFactory factory)
        {
            var userDefinedClassProxy = this as UserDefinedClassProxy;
            if (userDefinedClassProxy != null)
            {
                return repository.GetOrAdd(userDefinedClassProxy.GetDomPath(factory));
            }

            var bclClassProxy = this as BclClassProxy;
            if (bclClassProxy != null)
            {
                return BclClassProxy.ToBclClass(bclClassProxy, factory);
            }

            return ListClassProxy.ToListClass((ListClassProxy)this, repository, factory);
        }
示例#4
0
        public IClass ToClass(IRepository repository, IFactory factory)
        {
            var userDefinedClassProxy = this as UserDefinedClassProxy;

            if (userDefinedClassProxy != null)
            {
                return(repository.GetOrAdd(userDefinedClassProxy.GetDomPath(factory)));
            }

            var bclClassProxy = this as BclClassProxy;

            if (bclClassProxy != null)
            {
                return(BclClassProxy.ToBclClass(bclClassProxy, factory));
            }

            return(ListClassProxy.ToListClass((ListClassProxy)this, repository, factory));
        }
        public Property CreateProperty(IRepository repository)
        {
            var property = _factory.CreateProperty(_jObject.GetDomPath(_factory), _jObject.Properties().Any());

            property.InitializeDefaultPropertyDefinitionSet(
                propertyDefinitions =>
            {
                var userDefinedClassPropertyDefinition = _factory.CreatePropertyDefinition(repository.GetOrAdd(_jObject.GetDomPath(_factory)), _name, true, true, AttributeProxy.DataMember(_name));
                propertyDefinitions.Append(userDefinedClassPropertyDefinition);
            });

            return(property);
        }
示例#6
0
        public Property CreateProperty(IRepository repository)
        {
            var property = _factory.CreateProperty(_jArray.GetDomPath(_factory), _jArray.Count > 0);

            var bestFitType = GetBestFitType();

            // If JTokenType.None, then there weren't any elements.
            // If JTokenType.Null, then no JTokenType is able to contain the values of all the other elements.
            // Else, we have a JTokenType that can contain all the values of the other elements.

            // The 'else' condition is the happy path. We'll want to create a property custom tailored for
            // bestFitType. When (or if) it gets merged, the merge mechanism will ensure that we end up with
            // the best type for the property. This should be relatively easy to implement.

            // As for the sad paths, which won't be as easy to implement...

            // There's a strong possibility that we'll need to be able to determine whether a property should
            // even be added to its parent class. If there were no elements in the json array, should we
            // do anything with that array? I don't think so. And what about if no single type exists that
            // could hold all the elements? Should we do anything with *that* array? Or throw an exception?
            // Questions to ponder...

            switch (bestFitType)
            {
            case JTokenType.Null:
            case JTokenType.None:
            {
                throw new NotImplementedException();
            }

            case JTokenType.Object:
            {
                property.InitializeDefaultPropertyDefinitionSet(
                    propertyDefinitions =>
                    propertyDefinitions.Append(
                        _factory.CreatePropertyDefinition(
                            ListClass.FromClass(repository.GetOrAdd(_jArray.GetDomPath(_factory))),
                            _name,
                            true,
                            true,
                            AttributeProxy.DataMember(_name))));
                break;
            }

            case JTokenType.Array:
            {
                throw new NotImplementedException();
            }

            case JTokenType.Integer:
            case JTokenType.Float:
            case JTokenType.String:
            case JTokenType.Boolean:
            case JTokenType.Date:
            case JTokenType.Guid:
            case JTokenType.Uri:
            case JTokenType.TimeSpan:
            {
                property.InitializeDefaultPropertyDefinitionSet(propertyDefinitions => {});

                foreach (var item in _jArray.OfType <JValue>())
                {
                    var mergeProperty = _factory.CreateProperty(_jArray.GetDomPath(_factory), _jArray.Count > 0);

                    mergeProperty.InitializeDefaultPropertyDefinitionSet(
                        propertyDefinitions =>
                        propertyDefinitions.Append(
                            _factory.GetAllBclClasses()
                            .Select(
                                bclClass =>
                                _factory.CreatePropertyDefinition(
                                    ListClass.FromClass(bclClass),
                                    _name,
                                    bclClass.IsLegalObjectValue(item.Value),
                                    true,
                                    AttributeProxy.DataMember(_name)))));

                    property.MergeWith(mergeProperty);
                }
                break;
            }

            default:
            {
                throw new InvalidOperationException("Unsupported item in json array: " + bestFitType);
            }
            }

            return(property);
        }
示例#7
0
        public Property CreateProperty(IRepository repository)
        {
            var property = _factory.CreateProperty(_element.GetDomPath(_factory), _element.HasElements || _element.HasAttributes || !string.IsNullOrEmpty(_element.Value));

            property.InitializeDefaultPropertyDefinitionSet(
                propertyDefinitions =>
            {
                if (!_element.HasElements && !_element.HasAttributes)
                {
                    propertyDefinitions.Append(
                        _factory.GetAllBclClasses()
                        .Select(bclClass =>
                                _factory.CreatePropertyDefinition(bclClass, _element.Name.ToString(), bclClass.IsLegalStringValue(_element.Value), true, AttributeProxy.XmlElement(_element.Name.ToString()))));
                }
                else
                {
                    propertyDefinitions.Append(
                        _factory.GetAllBclClasses()
                        .Select(bclClass =>
                                _factory.CreatePropertyDefinition(bclClass, _element.Name.ToString(), false, true, AttributeProxy.XmlElement(_element.Name.ToString()))));
                }

                var userDefinedClassPropertyDefinition =
                    _factory.CreatePropertyDefinition(repository.GetOrAdd(_element.GetDomPath(_factory)), _element.Name.ToString(), true, true, AttributeProxy.XmlElement(_element.Name.ToString()));

                if (_element.HasElements || _element.HasAttributes)
                {
                    propertyDefinitions.Prepend(userDefinedClassPropertyDefinition);
                }
                else
                {
                    propertyDefinitions.Append(userDefinedClassPropertyDefinition);
                }

                if (!_element.HasAttributes && _element.HasElements)
                {
                    var first = _element.Elements().First();

                    if (_element.Elements().Skip(1).All(x => x.Name == first.Name))
                    {
                        var xmlArraySet       = property.GetOrAddExtraPropertyDefinitionSet("xml_array_list");
                        xmlArraySet.IsEnabled = true;

                        var xmlArrayListPropertyDefinition =
                            _factory.CreatePropertyDefinition(
                                ListClass.FromClass(repository.GetOrAdd(first.GetDomPath(_factory))),
                                first.Name.ToString(),
                                true,
                                true,
                                AttributeProxy.XmlArray(_element.Name.ToString()),
                                AttributeProxy.XmlArrayItem(first.Name.ToString()));

                        xmlArraySet.PropertyDefinitions = new List <PropertyDefinition> {
                            xmlArrayListPropertyDefinition
                        };

                        if (_element.Elements().Count() > 1)
                        {
                            xmlArraySet.Order = -1;
                        }
                        else
                        {
                            xmlArraySet.Order = 2;
                        }
                    }
                    else
                    {
                        if (property.ExtraPropertyDefinitionSetExists("xml_array_list"))
                        {
                            var xmlArraySet       = property.GetOrAddExtraPropertyDefinitionSet("xml_array_list");
                            xmlArraySet.IsEnabled = false;
                        }
                    }
                }
                else
                {
                    if (property.ExtraPropertyDefinitionSetExists("xml_array_list"))
                    {
                        var xmlArraySet       = property.GetOrAddExtraPropertyDefinitionSet("xml_array_list");
                        xmlArraySet.IsEnabled = false;
                    }
                }

                var xmlElementSet = property.GetOrAddExtraPropertyDefinitionSet("xml_element_list");

                var xmlElementListPropertyDefinitions = propertyDefinitions
                                                        .Where(x => !(x.Class is ListClass))
                                                        .Select(x =>
                                                                _factory.CreatePropertyDefinition(
                                                                    ListClass.FromClass(x.Class),
                                                                    _element.Name.ToString(),
                                                                    x.IsLegal,
                                                                    x.IsEnabled,
                                                                    AttributeProxy.XmlElement(_element.Name.ToString()))
                                                                ).ToList();

                xmlElementSet.PropertyDefinitions = xmlElementListPropertyDefinitions;

                if (_element.Parent != null)
                {
                    xmlElementSet.IsEnabled = true;

                    if (_element.Parent.Elements(_element.Name).Count() > 1)
                    {
                        xmlElementSet.Order = -2;
                    }
                    else
                    {
                        xmlElementSet.Order = 1;
                    }
                }
                else
                {
                    xmlElementSet.IsEnabled = false;
                }
            });

            return(property);
        }
示例#8
0
        public Property CreateProperty(IRepository repository)
        {
            var property = _factory.CreateProperty(_element.GetDomPath(_factory), _element.HasElements || _element.HasAttributes || !string.IsNullOrEmpty(_element.Value));

            property.InitializeDefaultPropertyDefinitionSet(
                propertyDefinitions =>
                {
                    if (!_element.HasElements && !_element.HasAttributes)
                    {
                        propertyDefinitions.Append(
                            _factory.GetAllBclClasses()
                                .Select(bclClass =>
                                    _factory.CreatePropertyDefinition(bclClass, _element.Name.ToString(), bclClass.IsLegalStringValue(_element.Value), true, AttributeProxy.XmlElement(_element.Name.ToString()))));
                    }
                    else
                    {
                        propertyDefinitions.Append(
                            _factory.GetAllBclClasses()
                                .Select(bclClass =>
                                    _factory.CreatePropertyDefinition(bclClass, _element.Name.ToString(), false, true, AttributeProxy.XmlElement(_element.Name.ToString()))));
                    }

                    var userDefinedClassPropertyDefinition =
                        _factory.CreatePropertyDefinition(repository.GetOrAdd(_element.GetDomPath(_factory)), _element.Name.ToString(), true, true, AttributeProxy.XmlElement(_element.Name.ToString()));

                    if (_element.HasElements || _element.HasAttributes)
                    {
                        propertyDefinitions.Prepend(userDefinedClassPropertyDefinition);
                    }
                    else
                    {
                        propertyDefinitions.Append(userDefinedClassPropertyDefinition);
                    }

                    if (!_element.HasAttributes && _element.HasElements)
                    {
                        var first = _element.Elements().First();

                        if (_element.Elements().Skip(1).All(x => x.Name == first.Name))
                        {
                            var xmlArraySet = property.GetOrAddExtraPropertyDefinitionSet("xml_array_list");
                            xmlArraySet.IsEnabled = true;

                            var xmlArrayListPropertyDefinition =
                                    _factory.CreatePropertyDefinition(
                                        ListClass.FromClass(repository.GetOrAdd(first.GetDomPath(_factory))),
                                        first.Name.ToString(),
                                        true,
                                        true,
                                        AttributeProxy.XmlArray(_element.Name.ToString()),
                                        AttributeProxy.XmlArrayItem(first.Name.ToString()));

                            xmlArraySet.PropertyDefinitions = new List<PropertyDefinition> { xmlArrayListPropertyDefinition };

                            if (_element.Elements().Count() > 1)
                            {
                                xmlArraySet.Order = -1;
                            }
                            else
                            {
                                xmlArraySet.Order = 2;
                            }
                        }
                        else
                        {
                            if (property.ExtraPropertyDefinitionSetExists("xml_array_list"))
                            {
                                var xmlArraySet = property.GetOrAddExtraPropertyDefinitionSet("xml_array_list");
                                xmlArraySet.IsEnabled = false;
                            }
                        }
                    }
                    else
                    {
                        if (property.ExtraPropertyDefinitionSetExists("xml_array_list"))
                        {
                            var xmlArraySet = property.GetOrAddExtraPropertyDefinitionSet("xml_array_list");
                            xmlArraySet.IsEnabled = false;
                        }
                    }

                    var xmlElementSet = property.GetOrAddExtraPropertyDefinitionSet("xml_element_list");

                    var xmlElementListPropertyDefinitions = propertyDefinitions
                        .Where(x => !(x.Class is ListClass))
                        .Select(x =>
                            _factory.CreatePropertyDefinition(
                                ListClass.FromClass(x.Class),
                                _element.Name.ToString(),
                                x.IsLegal,
                                x.IsEnabled,
                                AttributeProxy.XmlElement(_element.Name.ToString()))
                        ).ToList();

                    xmlElementSet.PropertyDefinitions = xmlElementListPropertyDefinitions;

                    if (_element.Parent != null)
                    {
                        xmlElementSet.IsEnabled = true;

                        if (_element.Parent.Elements(_element.Name).Count() > 1)
                        {
                            xmlElementSet.Order = -2;
                        }
                        else
                        {
                            xmlElementSet.Order = 1;
                        }
                    }
                    else
                    {
                        xmlElementSet.IsEnabled = false;
                    }
                });

            return property;
        }
        public Property CreateProperty(IRepository repository)
        {
            var property = _factory.CreateProperty(_jArray.GetDomPath(_factory), _jArray.Count > 0);

            var bestFitType = GetBestFitType();

            // If JTokenType.None, then there weren't any elements.
            // If JTokenType.Null, then no JTokenType is able to contain the values of all the other elements.
            // Else, we have a JTokenType that can contain all the values of the other elements.

            // The 'else' condition is the happy path. We'll want to create a property custom tailored for
            // bestFitType. When (or if) it gets merged, the merge mechanism will ensure that we end up with
            // the best type for the property. This should be relatively easy to implement.

            // As for the sad paths, which won't be as easy to implement...

            // There's a strong possibility that we'll need to be able to determine whether a property should
            // even be added to its parent class. If there were no elements in the json array, should we
            // do anything with that array? I don't think so. And what about if no single type exists that
            // could hold all the elements? Should we do anything with *that* array? Or throw an exception?
            // Questions to ponder...

            switch (bestFitType)
            {
                case JTokenType.Null:
                case JTokenType.None:
                {
                    throw new NotImplementedException();
                }
                case JTokenType.Object:
                {
                    property.InitializeDefaultPropertyDefinitionSet(
                        propertyDefinitions =>
                        propertyDefinitions.Append(
                            _factory.CreatePropertyDefinition(
                                ListClass.FromClass(repository.GetOrAdd(_jArray.GetDomPath(_factory))),
                                _name,
                                true,
                                true,
                                AttributeProxy.DataMember(_name))));
                    break;
                }
                case JTokenType.Array:
                {
                    throw new NotImplementedException();
                }
                case JTokenType.Integer:
                case JTokenType.Float:
                case JTokenType.String:
                case JTokenType.Boolean:
                case JTokenType.Date:
                case JTokenType.Guid:
                case JTokenType.Uri:
                case JTokenType.TimeSpan:
                {
                    property.InitializeDefaultPropertyDefinitionSet(propertyDefinitions => {});

                    foreach (var item in _jArray.OfType<JValue>())
                    {
                        var mergeProperty = _factory.CreateProperty(_jArray.GetDomPath(_factory), _jArray.Count > 0);

                        mergeProperty.InitializeDefaultPropertyDefinitionSet(
                            propertyDefinitions =>
                            propertyDefinitions.Append(
                                _factory.GetAllBclClasses()
                                        .Select(
                                            bclClass =>
                                            _factory.CreatePropertyDefinition(
                                                ListClass.FromClass(bclClass),
                                                _name,
                                                bclClass.IsLegalObjectValue(item.Value),
                                                true,
                                                AttributeProxy.DataMember(_name)))));

                        property.MergeWith(mergeProperty);
                    }
                    break;
                }
                default:
                {
                    throw new InvalidOperationException("Unsupported item in json array: " + bestFitType);
                }
            }

            return property;
        }