Example #1
0
        public async Task <Dictionary <string, object> > HandleRequest(ExternalTask externalTask, Dictionary <string, object> resultVariables)
        {
            double lat = externalTask.Variables.ContainsKey("latitude") ? Double.Parse(externalTask.Variables["latitude"].Value.ToString(), System.Globalization.NumberStyles.Number) : 0;
            double lon = externalTask.Variables.ContainsKey("longitude") ? Double.Parse(externalTask.Variables["longitude"].Value.ToString(), System.Globalization.NumberStyles.Number) : 0;

            HttpResponseMessage response = new HttpResponseMessage();

            HandleRequestContext a = new HandleRequestContext(_httpClient);
            string result          = await a.Get(resultVariables, "/weather/" + lat + "/" + lon);

            Forecast forecast = JsonConvert.DeserializeObject <Forecast>(result);
            Dictionary <string, object> rv = new Dictionary <string, object>()
            {
                { "weather_temp", forecast.Currently.Temperature },
                { "weather_summary", forecast.Currently.Summary }
            };

            return(rv);
        }
Example #2
0
        public async Task <Dictionary <string, object> > HandleRequest(ExternalTask externalTask, Dictionary <string, object> resultVariables)
        {
            string action     = externalTask.Variables.ContainsKey("Action") ? externalTask.Variables["Action"].Value.ToString() : null;
            string table      = externalTask.Variables.ContainsKey("Table") ? externalTask.Variables["Table"].Value.ToString() : null;
            string primaryKey = externalTask.Variables.ContainsKey("PrimaryKey") ? externalTask.Variables["PrimaryKey"].Value.ToString() : null;
            string data       = externalTask.Variables.ContainsKey("Data") ? externalTask.Variables["Data"].Value.ToString() : null;

            DataDescriptor descriptor = new DataDescriptor()
            {
                Table_Name = table,
                PrimaryKey = primaryKey,
                Data       = data != null?JsonConvert.DeserializeObject <IDictionary <string, JToken> >(data) : null
            };

            StringContent stringContent = new StringContent(JsonConvert.SerializeObject(descriptor), System.Text.Encoding.UTF8, "application/json");


            HttpResponseMessage response = new HttpResponseMessage();

            HandleRequestContext a = new HandleRequestContext(_httpClient);

            switch (action)
            {
            case "GET":
                string result = await a.Get(resultVariables, Postfix + "/" + descriptor.Table_Name + "/" + descriptor.PrimaryKey);

                resultVariables = JsonConvert.DeserializeObject <Dictionary <string, object> >(result);
                break;

            case "POST":
                resultVariables = await a.Post(resultVariables, Postfix, stringContent);

                break;

            case "PUT":
                resultVariables = await a.Put(resultVariables, Postfix, stringContent);

                break;
            }

            return(resultVariables);
        }