Example #1
0
        public void AddMap <T>(String propName, IDictionary <String, T> map)
        {
            if (map == null)
            {
                return;
            }
            if (!map.Values.Any())
            {
                return;
            }

            var jn = new JNode();

            map.ForEach(kvp => {
                var val = CvtValue(kvp.Value);
                if (val != null)
                {
                    if (val is JToken)
                    {
                        jn.AddRaw(kvp.Key, (JToken)val);
                    }
                    else
                    {
                        jn.AddRaw(kvp.Key, new JValue(val));
                    }
                }
                else
                {
                    jn.AddRaw(kvp.Key, null);
                }
            });

            AddRaw(propName, jn._jo);
        }
Example #2
0
 public DataService(JNode jNode)
 {
     ServiceName = jNode.Get <String>("serviceName");
     // Adapter = null;
     HasServerMetadata = jNode.Get <bool>("hasServerMetadata");
     // JsonResultsAdapter
     UseJsonP = jNode.Get <bool>("useJsonp");
 }
Example #3
0
        private JNode PrepareSaveBundle(IEnumerable <IEntity> entitiesToSave, SaveOptions saveOptions)
        {
            var jn = new JNode();

            jn.AddArray("entities", entitiesToSave.Select(e => EntityToJNode(e)));
            jn.AddJNode("saveOptions", saveOptions);
            return(jn);
        }
Example #4
0
        //public SaveOptions(JNode jNode) {


        //}

        JNode IJsonSerializable.ToJNode(object config)
        {
            var jn = new JNode();

            jn.AddPrimitive("allowConcurrentSaves", AllowConcurrentSaves);
            jn.AddPrimitive("tag", Tag);
            return(jn);
        }
Example #5
0
        internal EntityKey(JNode jn)
        {
            var etName = jn.Get <String>("entityType");

            EntityType = MetadataStore.Instance.GetEntityType(etName);
            ClrType    = EntityType.ClrType;
            // coerce the incoming data
            Values = jn.GetArray("values", EntityType.KeyProperties.Select(kp => kp.ClrType)).ToArray();
        }
Example #6
0
        public DataService(JNode jNode)
        {
            ServiceName       = jNode.Get <String>("serviceName");
            HasServerMetadata = jNode.Get <bool>("hasServerMetadata");

            UseJsonP = jNode.Get <bool>("useJsonp");
            Adapter  = GetAdapter(jNode.Get <String>("adapterName"));
            InitializeHttpClient();
        }
Example #7
0
        JNode IJsonSerializable.ToJNode(object config)
        {
            var jn = new JNode();

            jn.AddPrimitive("entityType", this.EntityType.Name);
            jn.AddArray("values", this.Values);

            return(jn);
        }
Example #8
0
 internal JNode ToJNode()
 {
     // This ONLY works because of the immutability convention for all Validators.
     if (_jNode == null)
     {
         _jNode = JNode.FromObject(this, true);
     }
     return(_jNode);
 }
Example #9
0
        private EntityKey ExtractEntityKey(EntityType entityType, JNode jn)
        {
            var keyValues = entityType.KeyProperties
                            .Select(p => jn.Get(p.Name, p.ClrType))
                            .ToArray();
            var entityKey = EntityKey.Create(entityType, keyValues);

            return(entityKey);
        }
Example #10
0
        public static SaveException Parse(EntityManager em, String json)
        {
            var jn           = JNode.DeserializeFrom(json);
            var message      = jn.Get <String>("ExceptionMessage");
            var entityErrors = jn.GetArray <EntityError>("EntityErrors");
            var saveErrors   = entityErrors.Select(ee => ee.Resolve(em));

            return(new SaveException(message ?? "see EntityErrors property", saveErrors));
        }
Example #11
0
 public ComplexType(JNode jNode)
 {
     ShortName = jNode.Get <String>("shortName");
     Namespace = jNode.Get <String>("namespace");
     // BaseTypeName = jnode.Get<String>("baseTypeName");
     // IsAbstract = jnode.Get<bool>("isAbstract");
     jNode.GetJNodeArray("dataProperties").Select(jn => new DataProperty(jn)).ForEach(dp => AddDataProperty(dp));
     // validators
     // custom
 }
Example #12
0
 public NavigationProperty(JNode jNode)
 {
     Name            = jNode.Get <String>("name");
     EntityTypeName  = jNode.Get <String>("entityTypeName");
     IsScalar        = jNode.Get <bool>("isScalar", true);
     AssociationName = jNode.Get <String>("associationName");
     // _validators.AddRange()
     _foreignKeyNames.AddRange(jNode.GetArray <String>("foreignKeyNames"));
     _invForeignKeyNames.AddRange(jNode.GetArray <String>("invForeignKeyNames"));
     // custom
 }
Example #13
0
        JNode IJsonSerializable.ToJNode(Object config)
        {
            var jo = new JNode();

            jo.AddPrimitive("serviceName", this.ServiceName);
            jo.AddPrimitive("adapterName", this.Adapter == null ? null : this.Adapter.Name);
            jo.AddPrimitive("hasServerMetadata", this.HasServerMetadata);
            jo.AddPrimitive("jsonResultsAdapter", this.JsonResultsAdapter == null ? null : this.JsonResultsAdapter.Name);
            jo.AddPrimitive("useJsonp", this.UseJsonP);
            return(jo);
        }
Example #14
0
        public JNode GetJNode(String propName)
        {
            var item = (JObject)GetToken <JObject>(propName);

            if (item == null)
            {
                return(null);
            }
            var jNode = new JNode(item);

            return(jNode);
        }
Example #15
0
 public void AddJNode(String propName, JNode jn)
 {
     if (jn == null)
     {
         return;
     }
     if (jn.IsEmpty)
     {
         return;
     }
     AddRaw(propName, jn._jo);
 }
Example #16
0
        private JNode ExportEntityAspectInfo(EntityAspect entityAspect)
        {
            var jn = new JNode();
            var es = entityAspect.EntityState;

            jn.AddEnum("entityState", entityAspect.EntityState);
            jn.AddArray("tempNavPropNames", GetTempNavPropNames(entityAspect));
            if (es.IsModified() || es.IsDeleted())
            {
                jn.AddMap("originalValuesMap", entityAspect._originalValuesMap);
            }
            return(jn);
        }
Example #17
0
        JNode IJsonSerializable.ToJNode(Object config)
        {
            var jo = new JNode();

            jo.AddPrimitive("metadataVersion", MetadataVersion);
            // jo.Add("name", this.Name);
            jo.AddPrimitive("namingConvention", this.NamingConvention.Name);
            // jo.AddProperty("localQueryComparisonOptions", this.LocalQueryComparisonOptions);
            jo.AddArray("dataServices", this._dataServiceMap.Values);
            jo.AddArray("structuralTypes", this._structuralTypes);
            jo.AddMap("resourceEntityTypeMap", this._resourceNameEntityTypeMap.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Name));
            return(jo);
        }
Example #18
0
        JNode IJsonSerializable.ToJNode(Object config)
        {
            var jo = new JNode();

            jo.AddPrimitive("shortName", this.ShortName);
            jo.AddPrimitive("namespace", this.Namespace);
            jo.AddPrimitive("isComplexType", true);
            // jo.AddProperty("baseTypeName", this.BaseTypeName);
            // jo.AddProperty("isAbstract", this.IsAbstract, false);
            jo.AddArray("dataProperties", this.DataProperties.Where(dp => dp.IsInherited == false));
            // jo.AddArrayProperty("validators", this.Validators);
            // jo.AddProperty("custom", this.Custom.ToJObject)
            return(jo);
        }
Example #19
0
        JNode IJsonSerializable.ToJNode(Object config)
        {
            var jo = new JNode();

            jo.AddPrimitive("name", this.Name);
            jo.AddPrimitive("entityTypeName", this.EntityTypeName);
            jo.AddPrimitive("isScalar", this.IsScalar);
            jo.AddPrimitive("associationName", this.AssociationName);
            // jo.AddArray("validators", this.Validators);
            jo.AddArray("foreignKeyNames", this.ForeignKeyNames);
            jo.AddArray("invForeignKeyNames", this.InvForeignKeyNames);
            // jo.Add("custom", this.Custom.ToJObject)
            return(jo);
        }
Example #20
0
        public static SaveException Parse(String json)
        {
            var jn      = JNode.DeserializeFrom(json);
            var message = jn.Get <String>("ExceptionMessage");

            if (message != null)
            {
                return(new SaveException(message, Enumerable.Empty <EntityError>()));
            }
            else
            {
                // TODO: parse EntityErrors;
                return(new SaveException("see EntityErrors property", Enumerable.Empty <EntityError>()));
            }
        }
Example #21
0
        internal Validator FindOrCreateValidator(JNode jNode)
        {
            lock (_validatorMap) {
                Validator vr;

                if (_validatorJNodeCache.TryGetValue(jNode, out vr))
                {
                    return(vr);
                }

                vr = ValidatorFromJNode(jNode);
                _validatorJNodeCache[jNode] = vr;
                return(vr);
            }
        }
Example #22
0
        private static void UpdateOriginalValues(StructuralAspect targetAspect, JNode jNode)
        {
            var stType     = targetAspect.StructuralType;
            var aspectNode = jNode.GetJNode(stType.IsEntityType ? "entityAspect" : "complexAspect");

            if (aspectNode == null)
            {
                return;               // aspect node can be null in a complexAspect with no originalValues
            }
            var originalValuesMap = aspectNode.GetMap("originalValuesMap", pn => stType.GetDataProperty(pn).ClrType);

            if (originalValuesMap != null)
            {
                targetAspect._originalValuesMap = new BackupValuesMap(originalValuesMap);
            }
        }
Example #23
0
        private Validator ValidatorFromJNode(JNode jNode)
        {
            var  vrName = jNode.Get <String>("name");
            Type vrType;

            if (!_validatorMap.TryGetValue(vrName, out vrType))
            {
                var e = new Exception("Unable to create a validator for " + vrName);
                _errors.Add(e);
                return(null);
            }
            // Deserialize the object
            var vr = (Validator)jNode.ToObject(vrType, true);

            return(vr);
        }
Example #24
0
        JNode IJsonSerializable.ToJNode(Object config)
        {
            var jo = new JNode();

            jo.AddPrimitive("shortName", this.ShortName);
            jo.AddPrimitive("namespace", this.Namespace);
            jo.AddPrimitive("baseTypeName", this.BaseTypeName);
            jo.AddPrimitive("isAbstract", this.IsAbstract, false);
            jo.AddPrimitive("autoGeneratedKeyType", this.AutoGeneratedKeyType.ToString());
            jo.AddPrimitive("defaultResourceName", this.DefaultResourceName);
            jo.AddArray("dataProperties", this.DataProperties.Where(dp => dp.IsInherited == false));
            jo.AddArray("navigationProperties", this.NavigationProperties.Where(np => np.IsInherited == false));
            // jo.AddArrayProperty("validators", this.Validators);
            // jo.AddProperty("custom", this.Custom.ToJObject)
            return(jo);
        }
Example #25
0
        public EntityType(JNode jNode)
        {
            ShortName            = jNode.Get <String>("shortName");
            Namespace            = jNode.Get <String>("namespace");
            BaseTypeName         = jNode.Get <String>("baseTypeName");
            IsAbstract           = jNode.Get <bool>("isAbstract");
            AutoGeneratedKeyType = jNode.GetEnum <AutoGeneratedKeyType>("autoGeneratedKeyType");
            var drn = jNode.Get <String>("defaultResourceName");

            if (drn != null)
            {
                MetadataStore.Instance.AddResourceName(drn, this, true);
            }
            jNode.GetJNodeArray("dataProperties").Select(jn => new DataProperty(jn)).ForEach(dp => AddDataProperty(dp));
            jNode.GetJNodeArray("navigationProperties").Select(jn => new NavigationProperty(jn)).ForEach(np => AddNavigationProperty(np));
            // validators
            // custom
        }
Example #26
0
        private JNode DataToJNode(StructuralAspect aspect)
        {
            var jn    = new JNode();
            var stype = aspect.StructuralType;

            stype.DataProperties.ForEach(dp => {
                var val = aspect.GetValue(dp.Name);
                // handle nonscalar dps
                if (dp.IsComplexProperty)
                {
                    jn.AddJNode(dp.NameOnServer, DataToJNode(((IComplexObject)val).ComplexAspect));
                }
                else
                {
                    jn.AddPrimitive(dp.NameOnServer, val, dp.DefaultValue);
                }
            });
            return(jn);
        }
Example #27
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));
        }
Example #28
0
        private void UpdateTempFks(IEntity targetEntity, JNode entityAspectNode, Dictionary <EntityKey, EntityKey> tempKeyMap)
        {
            var tempNavPropNames = entityAspectNode.GetArray <String>("tempNavPropNames");

            if (!tempNavPropNames.Any())
            {
                return;
            }
            var targetAspect = targetEntity.EntityAspect;
            var entityType   = targetAspect.EntityType;

            tempNavPropNames.ForEach(npName => {
                var np         = entityType.GetNavigationProperty(npName);
                var fkProp     = np.RelatedDataProperties[0];
                var oldFkValue = targetAspect.GetValue(fkProp);
                var oldFk      = new EntityKey(np.EntityType, oldFkValue);
                var newFk      = tempKeyMap[oldFk];
                targetAspect.SetValue(fkProp, newFk.Values[0]);
            });
        }
Example #29
0
        JNode IJsonSerializable.ToJNode(Object config)
        {
            var jn = new JNode();

            jn.AddPrimitive("name", this.Name);
            jn.AddPrimitive("dataType", this.DataType != null ? this.DataType.Name : null);
            jn.AddPrimitive("complexTypeName", this.ComplexType != null ? this.ComplexType.Name : null);
            jn.AddPrimitive("isNullable", this.IsNullable, true);
            jn.AddPrimitive("defaultValue", this.DefaultValue);
            jn.AddPrimitive("isPartOfKey", this.IsPartOfKey, false);
            jn.AddPrimitive("isUnmapped", this.IsUnmapped, false);
            jn.AddPrimitive("isAutoIncrementing", this.IsAutoIncrementing, false);
            jn.AddPrimitive("concurrencyMode", this.ConcurrencyMode == ConcurrencyMode.None ? null : this.ConcurrencyMode.ToString());
            jn.AddPrimitive("maxLength", this.MaxLength);
            jn.AddArray("validators", this.Validators);
            jn.AddPrimitive("enumType", this.EnumTypeName);
            jn.AddPrimitive("isScalar", this.IsScalar, true);
            // jo.AddProperty("custom", this.Custom.ToJObject)
            return(jn);
        }
Example #30
0
 public DataProperty(JNode jNode)
 {
     Name            = jNode.Get <String>("name");
     ComplexTypeName = jNode.Get <String>("complexTypeName");
     if (ComplexTypeName == null)
     {
         DataType = DataType.FromName(jNode.Get <String>("dataType"));
     }
     IsNullable = jNode.Get <bool>("isNullable", true);
     if (DataType != null)
     {
         DefaultValue = jNode.Get("defaultValue", DataType.ClrType);
     }
     IsPartOfKey        = jNode.Get <bool>("isPartOfKey", false);
     IsUnmapped         = jNode.Get <bool>("isUnmapped", false);
     IsAutoIncrementing = jNode.Get <bool>("isAutoIncrementing", false);
     ConcurrencyMode    = (ConcurrencyMode)Enum.Parse(typeof(ConcurrencyMode), jNode.Get <String>("conncurrencyMode", ConcurrencyMode.None.ToString()));
     MaxLength          = jNode.Get <int?>("maxLength");
     EnumTypeName       = jNode.Get <String>("enumType");
     IsScalar           = jNode.Get <bool>("isScalar", true);
 }