Esempio n. 1
0
        /// <summary>
        /// Find one or multiple drops that match filter
        /// </summary>
        /// <typeparam name="T">The type of the object to find</typeparam>
        /// <param name="filter">The filter string</param>
        /// <param name="encoder">An encode that handles T</param>
        /// <param name="parms">Additional parameters to be passed to the platform</param>
        /// <returns>A list of objects of type T that satisfy filter</returns>
        public async Task <List <T> > Find <T>(string filter, IJsonEncoder <T> encoder,
                                               Dictionary <string, string> parms = null)
        {
            if (!this.canRead)
            {
                throw new FlowThingsNotImplementedException();
            }

            if (parms == null)
            {
                parms = new Dictionary <string, string>();
            }
            parms.Add("filter", filter);

            string url = this.MakeURL("", parms);
            JToken jt  = await this.RequestAsync("GET", null, url);

            List <T> l = new List <T>();

            foreach (JToken t in (JArray)jt["body"])
            {
                l.Add(encoder.Decode(t));
            }

            return(l);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns multiple items based on the IDs passed
        /// </summary>
        /// <typeparam name="T">The type of the item expected as return</typeparam>
        /// <param name="targets">An array of the form accepted by the platform</param>
        /// <param name="encoder">An encoder that can parse T from a JToken</param>
        /// <param name="parms">The parameters to pass to the platform</param>
        /// <returns>An item of type T from the platform</returns>
        public async Task <Dictionary <string, List <T> > > FindMany <T>(dynamic targets, IJsonEncoder <T> encoder)
        {
            if (!this.canRead)
            {
                throw new FlowThingsNotImplementedException();
            }

            string url = (this.secure ? "https:" : "http:") + "//" + this.host + "/v" + this.version + "/" +
                         this.creds.account + "/drop";

            JToken jt = await this.RequestAsync("MGET", JObject.FromObject(targets), url);

            Dictionary <string, List <T> > items = new Dictionary <string, List <T> >();

            foreach (KeyValuePair <string, JToken> kvp in (JObject)jt["body"])
            {
                string flowId   = kvp.Key;
                JArray dropList = (JArray)kvp.Value;

                List <T> l = new List <T>();
                foreach (JToken t in dropList)
                {
                    T obj = encoder.Decode(t);
                    l.Add(obj);
                }

                items.Add(flowId, l);
            }

            return(items);
        }
Esempio n. 3
0
        public object[] Decode(IJsonEncoder encoder)
        {
            if (IsDecoded || encoder == null)
            {
                return(DecodedArgs);
            }
            IsDecoded = true;
            if (string.IsNullOrEmpty(Payload))
            {
                return(DecodedArgs);
            }
            List <object> list = encoder.Decode(Payload);

            if (list != null && list.Count > 0)
            {
                if (SocketIOEvent == SocketIOEventTypes.Ack || SocketIOEvent == SocketIOEventTypes.BinaryAck)
                {
                    DecodedArgs = list.ToArray();
                }
                else
                {
                    list.RemoveAt(0);
                    DecodedArgs = list.ToArray();
                }
            }
            return(DecodedArgs);
        }
Esempio n. 4
0
        /// <summary>
        /// Updates multiple items
        /// </summary>
        /// <typeparam name="T">The type of the item to be updated</typeparam>
        /// <param name="items">A dictionary of id => item where item can be encoded
        /// with encoder</param>
        /// <param name="encoder">The encoder that can handle T</param>
        /// <param name="parms">Additional params for the platform</param>
        /// <returns>A dictionary of id => item</returns>
        public async Task <Dictionary <string, T> > UpdateMany <T>(Dictionary <string, T> items,
                                                                   IJsonEncoder <T> encoder, Dictionary <string, string> parms = null)
        {
            if (!this.canUpdate)
            {
                throw new FlowThingsNotImplementedException();
            }

            JObject jo = new JObject();

            foreach (KeyValuePair <string, T> kvp in items)
            {
                jo.Add(new JProperty(kvp.Key, encoder.Encode(kvp.Value)));
            }

            JToken jt = await this.RequestAsync("MPUT", "", jo, parms);

            Dictionary <string, T> d = new Dictionary <string, T>();

            foreach (KeyValuePair <string, JToken> kvp in (JObject)jt["body"])
            {
                string id   = kvp.Key;
                T      item = encoder.Decode(kvp.Value);

                d.Add(id, item);
            }

            return(d);
        }
Esempio n. 5
0
        /// <summary>
        /// Updates the item with the passed ID on the platform.
        /// </summary>
        /// <typeparam name="T">The type of the item to be updated</typeparam>
        /// <param name="id">The ID of the item to be updated</param>
        /// <param name="item">The contents of the item -- all fields produced by Encode(item) will
        /// be updated on the platform; to update only certain fields use Update with dynamics
        /// below</param>
        /// <param name="encoder">The encoder that can encode/decode T to a JToken</param>
        /// <param name="parms">Additional parameters passed to the platform</param>
        /// <returns>The updated item as an object of type T</returns>
        public async Task <T> Update <T>(string id, T item, IJsonEncoder <T> encoder,
                                         Dictionary <string, string> parms = null)
        {
            if (!this.canUpdate)
            {
                throw new FlowThingsNotImplementedException();
            }

            JToken jt = await this.RequestAsync("PUT", "/" + id, encoder.Encode(item), parms);

            return(encoder.Decode(jt["body"]));
        }
Esempio n. 6
0
        /// <summary>
        /// Reads an item from the server by ID and decodes it with the encoder.
        /// </summary>
        /// <typeparam name="T">The type of the item expected as return</typeparam>
        /// <param name="id">The id of the item</param>
        /// <param name="encoder">An encoder that can parse T from a JToken</param>
        /// <param name="parms">The parameters to pass to the platform</param>
        /// <returns>An item of type T from the platform</returns>
        public async Task <T> Read <T>(string id, IJsonEncoder <T> encoder,
                                       Dictionary <string, string> parms = null)
        {
            if (!this.canRead)
            {
                throw new FlowThingsNotImplementedException();
            }

            JToken jt = await this.RequestAsync("GET", "/" + id, null, parms);

            return(encoder.Decode(jt["body"]));
        }
Esempio n. 7
0
        public object[] Decode(IJsonEncoder encoder)
        {
            if (this.IsDecoded || encoder == null)
            {
                return(this.DecodedArgs);
            }
            this.IsDecoded = true;
            if (string.IsNullOrEmpty(this.Payload))
            {
                return(this.DecodedArgs);
            }
            List <object> list = encoder.Decode(this.Payload);

            if (list != null && list.Count > 0)
            {
                list.RemoveAt(0);
                this.DecodedArgs = list.ToArray();
            }
            return(this.DecodedArgs);
        }