示例#1
0
        public object Apply(object oldValue, string key)
        {
            if (oldValue == null)
            {
                return(objects.ToList());
            }
            var newList  = ((IList <object>)AVClient.ConvertTo <IList <object> >(oldValue)).ToList();
            var comparer = AVFieldOperations.AVObjectComparer;

            foreach (var objToAdd in objects)
            {
                if (objToAdd is AVObject)
                {
                    var matchedObj = newList.FirstOrDefault(listObj => comparer.Equals(objToAdd, listObj));
                    if (matchedObj == null)
                    {
                        newList.Add(objToAdd);
                    }
                    else
                    {
                        var index = newList.IndexOf(matchedObj);
                        newList[index] = objToAdd;
                    }
                }
                else if (!newList.Contains <object>(objToAdd, comparer))
                {
                    newList.Add(objToAdd);
                }
            }
            return(newList);
        }
 public IEnumerator <TOut> GetEnumerator()
 {
     foreach (var item in (IEnumerable)toWrap)
     {
         yield return((TOut)AVClient.ConvertTo <TOut>(item));
     }
 }
 public TOut this[int index] {
     get {
         return((TOut)AVClient.ConvertTo <TOut>(toWrap[index]));
     }
     set {
         toWrap[index] = (TIn)AVClient.ConvertTo <TIn>(value);
     }
 }
        public void CopyTo(KeyValuePair <string, TOut>[] array, int arrayIndex)
        {
            var converted = from pair in toWrap
                            select new KeyValuePair <string, TOut>(pair.Key,
                                                                   (TOut)AVClient.ConvertTo <TOut>(pair.Value));

            converted.ToList().CopyTo(array, arrayIndex);
        }
 public TOut this[string key] {
     get {
         return((TOut)AVClient.ConvertTo <TOut>(toWrap[key]));
     }
     set {
         toWrap[key] = (TIn)AVClient.ConvertTo <TIn>(value);
     }
 }
        public bool TryGetValue(string key, out TOut value)
        {
            TIn  outValue;
            bool result = toWrap.TryGetValue(key, out outValue);

            value = (TOut)AVClient.ConvertTo <TOut>(outValue);
            return(result);
        }
 public IEnumerator <KeyValuePair <string, TOut> > GetEnumerator()
 {
     foreach (var pair in toWrap)
     {
         yield return(new KeyValuePair <string, TOut>(pair.Key,
                                                      (TOut)AVClient.ConvertTo <TOut>(pair.Value)));
     }
 }
示例#8
0
        public object Apply(object oldValue, string key)
        {
            if (oldValue == null)
            {
                return(new List <object>());
            }
            var oldList = (IList <object>)AVClient.ConvertTo <IList <object> >(oldValue);

            return(oldList.Except(objects, AVFieldOperations.AVObjectComparer).ToList());
        }
示例#9
0
        public object Apply(object oldValue, string key)
        {
            if (oldValue == null)
            {
                return(objects.ToList());
            }
            var oldList = (IList <object>)AVClient.ConvertTo <IList <object> >(oldValue);

            return(oldList.Concat(objects).ToList());
        }
示例#10
0
 public static bool IsValidType(object value)
 {
     return(value == null ||
            value.GetType().IsPrimitive() ||
            value is string ||
            value is AVObject ||
            value is AVACL ||
            value is AVFile ||
            value is AVGeoPoint ||
            value is AVRelationBase ||
            value is DateTime ||
            value is byte[] ||
            AVClient.ConvertTo <IDictionary <string, object> >(value) is IDictionary <string, object> ||
            AVClient.ConvertTo <IList <object> >(value) is IList <object>);
 }
        public Task <T> CallFunctionAsync <T>(String name,
                                              IDictionary <string, object> parameters,
                                              string sessionToken,
                                              CancellationToken cancellationToken)
        {
            var command = new AVCommand(string.Format("/functions/{0}", Uri.EscapeUriString(name)),
                                        method: "POST",
                                        sessionToken: sessionToken,
                                        data: NoObjectsEncoder.Instance.Encode(parameters) as IDictionary <string, object>);

            return(commandRunner.RunCommandAsync(command, cancellationToken: cancellationToken).OnSuccess(t => {
                var decoded = AVDecoder.Instance.Decode(t.Result.Item2) as IDictionary <string, object>;
                if (!decoded.ContainsKey("result"))
                {
                    return default(T);
                }
                return (T)AVClient.ConvertTo <T>(decoded["result"]);
            }));
        }
示例#12
0
 public IAVFieldOperation MergeWithPrevious(IAVFieldOperation previous)
 {
     if (previous == null)
     {
         return(this);
     }
     if (previous is AVDeleteOperation)
     {
         return(new AVSetOperation(objects.ToList()));
     }
     if (previous is AVSetOperation)
     {
         var setOp   = (AVSetOperation)previous;
         var oldList = (IList <object>)AVClient.ConvertTo <IList <object> >(setOp.Value);
         return(new AVSetOperation(oldList.Concat(objects).ToList()));
     }
     if (previous is AVAddOperation)
     {
         return(new AVAddOperation(((AVAddOperation)previous).Objects.Concat(objects)));
     }
     throw new InvalidOperationException("Operation is invalid after previous operation.");
 }
 public void Add(TOut item)
 {
     toWrap.Add((TIn)AVClient.ConvertTo <TIn>(item));
 }
 public void Add(KeyValuePair <string, TOut> item)
 {
     toWrap.Add(new KeyValuePair <string, TIn>(item.Key,
                                               (TIn)AVClient.ConvertTo <TIn>(item.Value)));
 }
 public bool Contains(KeyValuePair <string, TOut> item)
 {
     return(toWrap.Contains(new KeyValuePair <string, TIn>(item.Key,
                                                           (TIn)AVClient.ConvertTo <TIn>(item.Value))));
 }
示例#16
0
        public object Encode(object value)
        {
            // If this object has a special encoding, encode it and return the
            // encoded object. Otherwise, just return the original object.
            if (value is DateTime)
            {
                return(new Dictionary <string, object> {
                    { "iso", ((DateTime)value).ToString(AVClient.DateFormatString) },
                    { "__type", "Date" }
                });
            }

            var bytes = value as byte[];

            if (bytes != null)
            {
                return(new Dictionary <string, object> {
                    { "__type", "Bytes" },
                    { "base64", Convert.ToBase64String(bytes) }
                });
            }

            var obj = value as AVObject;

            if (obj != null)
            {
                return(EncodeAVObject(obj));
            }

            var jsonConvertible = value as IJsonConvertible;

            if (jsonConvertible != null)
            {
                return(jsonConvertible.ToJSON());
            }

            var dict = AVClient.ConvertTo <IDictionary <string, object> >(value) as IDictionary <string, object>;

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

            var list = AVClient.ConvertTo <IList <object> >(value) as IList <object>;

            if (list != null)
            {
                return(EncodeList(list));
            }

            // TODO (hallucinogen): convert IAVFieldOperation to IJsonConvertible
            var operation = value as IAVFieldOperation;

            if (operation != null)
            {
                return(operation.Encode());
            }

            return(value);
        }
 public int IndexOf(TOut item)
 {
     return(toWrap.IndexOf((TIn)AVClient.ConvertTo <TIn>(item)));
 }
 public void Insert(int index, TOut item)
 {
     toWrap.Insert(index, (TIn)AVClient.ConvertTo <TIn>(item));
 }
 public bool Remove(TOut item)
 {
     return(toWrap.Remove((TIn)AVClient.ConvertTo <TIn>(item)));
 }
 public void CopyTo(TOut[] array, int arrayIndex)
 {
     toWrap.Select(item => (TOut)AVClient.ConvertTo <TOut>(item))
     .ToList().CopyTo(array, arrayIndex);
 }
 public void Add(string key, TOut value)
 {
     toWrap.Add(key, (TIn)AVClient.ConvertTo <TIn>(value));
 }
示例#22
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);
        }
 public bool Contains(TOut item)
 {
     return(toWrap.Contains((TIn)AVClient.ConvertTo <TIn>(item)));
 }