Exemple #1
0
 public object Apply(object oldValue, string key)
 {
     if (adds.Count == 0 && removes.Count == 0)
     {
         return(null);
     }
     if (oldValue == null)
     {
         return(AVRelationBase.CreateRelation(null, key, targetClassName));
     }
     if (oldValue is AVRelationBase)
     {
         var oldRelation  = (AVRelationBase)oldValue;
         var oldClassName = oldRelation.TargetClassName;
         if (oldClassName != null && oldClassName != targetClassName)
         {
             throw new InvalidOperationException("Related object must be a " + oldClassName
                                                 + ", but a " + targetClassName + " was passed in.");
         }
         oldRelation.TargetClassName = targetClassName;
         return(oldRelation);
     }
     throw new InvalidOperationException("Operation is invalid after previous operation.");
 }
Exemple #2
0
        public object Decode(object data)
        {
            if (data == null)
            {
                return(null);
            }

            var dict = data as IDictionary <string, object>;

            if (dict != null)
            {
                if (dict.ContainsKey("__op"))
                {
                    return(AVFieldOperations.Decode(dict));
                }

                object type;
                dict.TryGetValue("__type", out type);
                var typeString = type as string;

                if (typeString == null)
                {
                    var newDict = new Dictionary <string, object>();
                    foreach (var pair in dict)
                    {
                        newDict[pair.Key] = Decode(pair.Value);
                    }
                    return(newDict);
                }

                if (typeString == "Date")
                {
                    return(AVDate(dict["iso"] as string));
                }

                if (typeString == "Bytes")
                {
                    return(Convert.FromBase64String(dict["base64"] as string));
                }

                if (typeString == "Pointer")
                {
                    return(DecodePointer(dict["className"] as string, dict["objectId"] as string));
                }

                if (typeString == "File")
                {
                    return(new AVFile(dict["name"] as string, new Uri(dict["url"] as string)));
                }

                if (typeString == "GeoPoint")
                {
                    return(new AVGeoPoint((double)AVClient.ConvertTo <double>(dict["latitude"]),
                                          (double)AVClient.ConvertTo <double>(dict["longitude"])));
                }

                if (typeString == "Object")
                {
                    var output = AVObject.CreateWithoutData(dict["className"] as string, null);
                    output.HandleFetchResult(AVObjectCoder.Instance.Decode(dict, this));
                    return(output);
                }

                if (typeString == "Relation")
                {
                    return(AVRelationBase.CreateRelation(null, null, dict["className"] as string));
                }

                var converted = new Dictionary <string, object>();
                foreach (var pair in dict)
                {
                    converted[pair.Key] = Decode(pair.Value);
                }
                return(converted);
            }

            var list = data as IList <object>;

            if (list != null)
            {
                return((from item in list
                        select Decode(item)).ToList());
            }

            return(data);
        }
Exemple #3
0
        public object Decode(object data)
        {
            if (data == null)
            {
                return(null);
            }

            var dict = data as IDictionary <string, object>;

            if (dict != null)
            {
                if (dict.ContainsKey("__op"))
                {
                    return(ParseFieldOperations.Decode(dict));
                }

                object type;
                dict.TryGetValue("__type", out type);
                var typeString = type as string;

                if (typeString == null)
                {
                    var newDict = new Dictionary <string, object>();
                    foreach (var pair in dict)
                    {
                        newDict[pair.Key] = Decode(pair.Value);
                    }
                    return(newDict);
                }

                if (typeString == "Date")
                {
                    return(ParseDate(dict["iso"] as string));
                }

                if (typeString == "Bytes")
                {
                    return(Convert.FromBase64String(dict["base64"] as string));
                }

                if (typeString == "Pointer")
                {
                    //set a include key to fetch or query.
                    if (dict.Keys.Count > 3)
                    {
                        return(DecodeAVObject(dict));
                    }
                    return(DecodePointer(dict["className"] as string, dict["objectId"] as string));
                }

                if (typeString == "File")
                {
                    return(DecodeAVFile(dict));
                }

                if (typeString == "GeoPoint")
                {
                    return(new AVGeoPoint(Conversion.To <double>(dict["latitude"]),
                                          Conversion.To <double>(dict["longitude"])));
                }

                if (typeString == "Object")
                {
                    return(DecodeAVObject(dict));
                }

                if (typeString == "Relation")
                {
                    return(AVRelationBase.CreateRelation(null, null, dict["className"] as string));
                }

                var converted = new Dictionary <string, object>();
                foreach (var pair in dict)
                {
                    converted[pair.Key] = Decode(pair.Value);
                }
                return(converted);
            }

            var list = data as IList <object>;

            if (list != null)
            {
                return((from item in list
                        select Decode(item)).ToList());
            }

            return(data);
        }