Esempio n. 1
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);
        }
Esempio n. 2
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));
        }
Esempio n. 3
0
        internal EntityKey(JNode jn, MetadataStore metadataStore)
        {
            var etName = jn.Get <String>("entityType");

            EntityType = metadataStore.GetEntityType(etName);
            ClrType    = EntityType.ClrType;
            // coerce the incoming data
            Values = jn.GetArray("values", EntityType.KeyProperties.Select(kp => kp.ClrType)).ToArray();
        }
Esempio n. 4
0
        JNode IJsonSerializable.ToJNode(object config)
        {
            var jn = new JNode();

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

            return(jn);
        }
Esempio n. 5
0
 internal JNode ToJNode()
 {
     // This ONLY works because of the immutability convention for all Internables
     if (_jNode == null)
     {
         _jNode = JNode.FromObject(this, true);
     }
     return(_jNode);
 }
 internal void UpdateFromJNode(JNode jNode)
 {
     Check(EntityType.Name, jNode.Get <String>("entityTypeName"), "EntityTypeName");
     IsScalar        = jNode.Get <bool>("isScalar", true);
     AssociationName = jNode.Get <String>("associationName");
     _validators     = new ValidatorCollection(jNode.GetJNodeArray("validators"));
     SetFkNames(jNode.GetArray <String>("foreignKeyNames"));
     SetInvFkNames(jNode.GetArray <String>("invForeignKeyNames"));
     // custom
 }
Esempio n. 7
0
        internal SaveException(EntityManager em, JNode jn)
            : base()
        {
            _message = jn.Get <String>("ExceptionMessage") ?? "see EntityErrors";
            var entityErrors = jn.GetArray <EntityError>("Errors", "errors", "EntityErrors", "entityErrors");

            entityErrors  = entityErrors.Select(ee => ee.Resolve(em));
            _entityErrors = new SafeList <EntityError>(entityErrors);
            IsServerError = true;
        }
Esempio n. 8
0
        internal String GetStructuralTypeNameFromJNode(JNode jNode, String key, bool isFromServer)
        {
            var stName = jNode.Get <String>(key);

            if (stName != null && isFromServer)
            {
                stName = TypeNameInfo.FromStructuralTypeName(stName).ToClient(this).StructuralTypeName;
            }
            return(stName);
        }
Esempio n. 9
0
        internal String GetPropertyNameFromJNode(JNode jn)
        {
            var dpName = jn.Get <String>("name");

            if (dpName == null)
            {
                var dpNameOnServer = jn.Get <String>("nameOnServer");
                dpName = MetadataStore.NamingConvention.ServerPropertyNameToClient(dpNameOnServer, this);
            }
            return(dpName);
        }
Esempio n. 10
0
        /// <summary>
        /// For internal use only.
        /// </summary>
        /// <param name="jNode"></param>
        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"));
            // TODO: need to do the same as above with JsonResultsAdapter.
            JsonResultsAdapter = Adapter.JsonResultsAdapter;
            InitializeHttpClient(null);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
 internal void ImportMetadata(JNode jNode, bool isFromServer)
 {
     DeserializeFrom(jNode, isFromServer);
     EntityTypes.ForEach(et => {
         // cross entity/complex type fixup.
         et.UpdateNavigationProperties();
         et.ComplexProperties
         .Where(cp => cp.ComplexType == null)
         .ForEach(cp => cp.ComplexType = GetComplexType(cp.ComplexType.Name));
     });
 }
        internal void UpdateFromJNode(JNode jNode, bool isFromServer)
        {
            var etName = MetadataStore.GetStructuralTypeNameFromJNode(jNode, "entityTypeName", isFromServer);

            Check(EntityType.Name, etName, "EntityTypeName");
            IsScalar        = jNode.Get <bool>("isScalar", true);
            AssociationName = jNode.Get <String>("associationName");
            _validators     = new ValidatorCollection(jNode.GetJNodeArray("validators"));
            SetFkNames(jNode.GetArray <String>(isFromServer ? "foreignKeyNamesOnServer" : "foreignKeyNames"));
            SetInvFkNames(jNode.GetArray <String>(isFromServer ? "invForeignKeyNamesOnServer" : "invForeignKeyNames"));
            // custom
        }
Esempio n. 14
0
 public void AddJNode(String propName, JNode jn)
 {
     if (jn == null)
     {
         return;
     }
     if (jn.IsEmpty)
     {
         return;
     }
     AddRaw(propName, jn._jo);
 }
Esempio n. 15
0
        public JNode GetJNode(String propName)
        {
            var item = (JObject)GetToken <JObject>(propName);

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

            return(jNode);
        }
Esempio n. 16
0
 internal override void UpdateFromJNode(JNode jNode, bool isFromServer)
 {
     Name = this.MetadataStore.GetStructuralTypeNameFromJNode(jNode, isFromServer);
     // BaseTypeName = jnode.Get<String>("baseTypeName");
     // IsAbstract = jnode.Get<bool>("isAbstract");
     jNode.GetJNodeArray("dataProperties").ForEach(jn => {
         var dpName = GetPropertyNameFromJNode(jn);
         var dp     = this.GetDataProperty(dpName);
         dp.UpdateFromJNode(jn, isFromServer);
     });
     // validators
     // custom
 }
Esempio n. 17
0
        JNode IJsonSerializable.ToJNode(Object config)
        {
            var jo = new JNode();

            jo.AddPrimitive("name", this.Name);
            jo.AddPrimitive("entityTypeName", this.EntityType.Name);
            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);
        }
Esempio n. 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);
        }
Esempio n. 19
0
 JNode IJsonSerializable.ToJNode(Object config)
 {
     lock (_structuralTypes) {
         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);
     }
 }
Esempio n. 20
0
            private T InternableFromJNode(JNode jNode)
            {
                var  name = jNode.Get <String>("name");
                Type type;

                if (!TypeMap.TryGetValue(name, out type))
                {
                    return(null);
                }
                // Deserialize the object
                var vr = (T)jNode.ToObject(type, true);

                return(vr);
            }
Esempio n. 21
0
        private static async Task <string> ReadResult(HttpResponseMessage response)
        {
            var result = await response.Content.ReadAsStringAsync();

            if (!response.IsSuccessStatusCode)
            {
                try {
                    var json = JNode.DeserializeFrom(result);
                    response.ReasonPhrase = json.Get <string>("Message");
                } catch (Exception) { }

                throw new DataServiceRequestException(response, result);
            }
            return(result);
        }
Esempio n. 22
0
        private void UpdateStructuralTypeFromJNode(JNode jNode, bool isFromServer)
        {
            var name  = GetStructuralTypeNameFromJNode(jNode, isFromServer);
            var stype = GetStructuralTypeCore(name);

            if (stype == null)
            {
                var isComplexType = jNode.Get <bool>("isComplexType", false);
                OnMetadataMismatch(name, null, isComplexType ?
                                   MetadataMismatchType.MissingCLRComplexType : MetadataMismatchType.MissingCLREntityType);
                return;
            }

            stype.UpdateFromJNode(jNode, isFromServer);
        }
Esempio n. 23
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);
            }
        }
Esempio n. 24
0
        private Validator ValidatorFromJNode(JNode jNode)
        {
            var  vrName = jNode.Get <String>("name");
            Type vrType;

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

            return(vr);
        }
Esempio n. 25
0
        internal override void UpdateFromJNode(JNode jNode, bool isFromServer)
        {
            var name         = this.MetadataStore.GetStructuralTypeNameFromJNode(jNode, isFromServer);
            var et           = MetadataStore.GetEntityType(name);
            var baseTypeName = this.MetadataStore.GetStructuralTypeNameFromJNode(jNode, "baseTypeName", isFromServer);

            if (baseTypeName != null)
            {
                Check(et.BaseEntityTypeName, baseTypeName, "BaseEntityType");
            }
            // For now this doesn't need to match
            et.IsAbstract = jNode.Get <bool>("isAbstract");

            et.AutoGeneratedKeyType = jNode.GetEnum <AutoGeneratedKeyType>("autoGeneratedKeyType");
            var drn = jNode.Get <String>("defaultResourceName");

            if (drn != null)
            {
                MetadataStore.SetResourceName(drn, et, true);
            }
            jNode.GetJNodeArray("dataProperties").ForEach(jn => {
                var dpName = GetPropertyNameFromJNode(jn);
                var dp     = et.GetDataProperty(dpName);
                if (dp == null)
                {
                    MetadataStore.OnMetadataMismatch(name, dpName, MetadataMismatchTypes.MissingCLRDataProperty);
                    return;
                }
                dp.UpdateFromJNode(jn, isFromServer);
            });
            jNode.GetJNodeArray("navigationProperties").ForEach(jn => {
                var npName = GetPropertyNameFromJNode(jn);
                var np     = et.GetNavigationProperty(npName);
                if (np == null)
                {
                    MetadataStore.OnMetadataMismatch(name, npName, MetadataMismatchTypes.MissingCLRNavigationProperty);
                    return;
                }
                np.UpdateFromJNode(jn, isFromServer);
            });
            et._validators = new ValidatorCollection(jNode.GetJNodeArray("validators"));
            // custom
            // next 2 lines are only needed if importing 'native' breeze metadata.
            if (et.KeyProperties.Count == 1 && et.AutoGeneratedKeyType != AutoGeneratedKeyType.None)
            {
                et.KeyProperties.First().IsAutoIncrementing = true;
            }
        }
Esempio n. 26
0
        internal String GetStructuralTypeNameFromJNode(JNode jNode, bool isFromServer)
        {
            var    shortName = jNode.Get <String>("shortName");
            var    ns        = jNode.Get <String>("namespace");
            String stName;

            if (isFromServer)
            {
                stName = new TypeNameInfo(shortName, ns).ToClient(this).StructuralTypeName;
            }
            else
            {
                stName = TypeNameInfo.ToStructuralTypeName(shortName, ns);
            }
            return(stName);
        }
Esempio n. 27
0
        JNode IJsonSerializable.ToJNode(Object config)
        {
            var jo = new JNode();

            jo.AddPrimitive("shortName", this.ShortName);
            jo.AddPrimitive("namespace", this.Namespace);
            jo.AddPrimitive("baseTypeName", this.BaseEntityTypeName);
            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.AddArray("validators", this.Validators);
            // jo.AddProperty("custom", this.Custom.ToJObject)
            return(jo);
        }
Esempio n. 28
0
        public void UpdateFromJNode(JNode jNode)
        {
            var shortName = jNode.Get <String>("shortName");
            var ns        = jNode.Get <String>("namespace");

            Name = TypeNameInfo.QualifyTypeName(shortName, ns);
            // BaseTypeName = jnode.Get<String>("baseTypeName");
            // IsAbstract = jnode.Get<bool>("isAbstract");
            jNode.GetJNodeArray("dataProperties").ForEach(jn => {
                var dpName = jn.Get <String>("name");
                var dp     = this.GetDataProperty(dpName);
                dp.UpdateFromJNode(jn);
            });
            // validators
            // custom
        }
Esempio n. 29
0
        private void DeserializeFrom(JNode jNode, bool isFromServer)
        {
            MetadataVersion = jNode.Get <String>("metadataVersion");
            // may be more than just a name

            var ncNode = jNode.GetJNode("namingConvention");

            if (ncNode != null)
            {
                var nc = Configuration.Instance.FindOrCreateNamingConvention(ncNode);
                if (nc == null)
                {
                    OnMetadataMismatch(null, null, MetadataMismatchTypes.MissingCLRNamingConvention, ncNode.ToString());
                }
                else
                {
                    // keep any preexisting ClientServerNamespaceMap info
                    NamingConvention = nc.WithClientServerNamespaceMapping(this.NamingConvention.ClientServerNamespaceMap);
                }
            }

            // localQueryComparisonOptions
            jNode.GetJNodeArray("dataServices").Select(jn => new DataService(jn)).ForEach(ds => {
                if (GetDataService(ds.ServiceName) == null)
                {
                    AddDataService(ds);
                }
            });
            jNode.GetJNodeArray("structuralTypes")
            .ForEach(jn => UpdateStructuralTypeFromJNode(jn, isFromServer));

            jNode.GetMap <String>("resourceEntityTypeMap").ForEach(kvp => {
                var stName = kvp.Value;
                if (isFromServer)
                {
                    stName = TypeNameInfo.FromStructuralTypeName(stName).ToClient(this).StructuralTypeName;
                }
                // okIfNotFound because metadata may contain refs to types that were already excluded earlier in
                // UpdateStructuralTypeFromJNode
                var et = GetEntityType(stName, true);
                if (et != null)
                {
                    SetResourceName(kvp.Key, et);
                }
            });
        }
        private void UpdateStructuralTypeFromJNode(JNode jNode)
        {
            var shortName     = jNode.Get <String>("shortName");
            var ns            = jNode.Get <String>("namespace");
            var name          = TypeNameInfo.ToStructuralTypeName(shortName, ns);
            var isComplexType = jNode.Get <bool>("isComplexType", false);

            if (isComplexType)
            {
                var ct = MetadataStore.Instance.GetComplexType(name);
                ct.UpdateFromJNode(jNode);
            }
            else
            {
                var et = MetadataStore.Instance.GetEntityType(name);
                et.UpdateFromJNode(jNode);
            }
        }