Exemplo n.º 1
0
        private ImportResult ImportEntities(JNode jn, ImportOptions importOptions)
        {
            importOptions = importOptions ?? ImportOptions.Default;
            if (importOptions.ShouldMergeMetadata)
            {
                var msNode = jn.GetJNode("metadataStore");
                if (msNode != null)
                {
                    MetadataStore.ImportMetadata(msNode);
                    var dsJn = jn.GetJNode("dataService");
                    if (dsJn != null)
                    {
                        DefaultDataService = new DataService(dsJn);
                    }
                    var qoJn = jn.GetJNode("queryOptions");
                    if (qoJn != null)
                    {
                        DefaultQueryOptions = new QueryOptions(qoJn);
                    }
                }
            }
            var entityGroupNodesMap = jn.GetJNodeArrayMap("entityGroupMap");
            // tempKeyMap will have a new values where collisions will occur
            var tempKeyMap = jn.GetJNodeArray("tempKeys").Select(jnEk => new EntityKey(jnEk)).ToDictionary(
                ek => ek,
                ek => this.FindEntityByKey(ek) == null ? ek : EntityKey.Create(ek.EntityType, KeyGenerator.GetNextTempId(ek.EntityType.KeyProperties.First()))
                );

            var mergeStrategy    = (importOptions.MergeStrategy ?? this.DefaultQueryOptions.MergeStrategy ?? QueryOptions.Default.MergeStrategy).Value;
            var importedEntities = new List <IEntity>();

            using (NewIsLoadingBlock()) {
                entityGroupNodesMap.ForEach(kvp => {
                    var entityTypeName = kvp.Key;
                    var entityNodes    = kvp.Value;
                    var entityType     = MetadataStore.GetEntityType(entityTypeName);
                    var entities       = ImportEntityGroup(entityNodes, entityType, tempKeyMap, mergeStrategy);
                    importedEntities.AddRange(entities);
                });
            }
            return(new ImportResult(importedEntities, tempKeyMap));
        }
Exemplo n.º 2
0
        public CsdlMetadataProcessor(MetadataStore metadataStore, String jsonMetadata)
        {
            _metadataStore = metadataStore;
            var json = (JObject)JsonConvert.DeserializeObject(jsonMetadata);

            _schema    = json["schema"];
            _namespace = (String)_schema["namespace"];

            var mapping = (String)_schema["cSpaceOSpaceMapping"];

            if (mapping != null)
            {
                var tmp = (JArray)JsonConvert.DeserializeObject(mapping);
                _cSpaceOSpaceMap = tmp.ToDictionary(v => (String)v[0], v => (String)v[1]);
            }

            var entityTypes = ToEnumerable(_schema["entityType"]).Cast <JObject>()
                              .Select(ParseCsdlEntityType).ToList();
            var complexTypes = ToEnumerable(_schema["complexType"]).Cast <JObject>()
                               .Select(ParseCsdlComplexType).ToList();

            entityTypes.ForEach(et => ResolveComplexTypeRefs(et));

            var entityContainer = _schema["entityContainer"];

            if (entityContainer != null)
            {
                var entitySets = ToEnumerable(entityContainer["entitySet"]).Cast <JObject>().ToList();
                entitySets.ForEach(es => {
                    var entityTypeInfo = ParseTypeName((String)es["entityType"]);
                    var entityType     = _metadataStore.GetEntityType(entityTypeInfo.TypeName);
                    var resourceName   = (String)es["name"];
                    _metadataStore.AddResourceName(resourceName, entityType, true);
                });
            }
        }