Beispiel #1
0
        private SparkFunctionResult CloudPost(string functionKey, string[] args)
        {
            try
            {
                var response   = CloudApiClient.GetRawResultForPost(functionKey, args);
                var rawContent = response.Content.ReadAsStringAsync().Result;
                if (!response.IsSuccessStatusCode || rawContent.StartsWith("{\n  \"error\":"))
                {
                    var sparkError = JsonConvert.DeserializeObject <SparkError>(rawContent);
                    if (API_ERROR_MESSAGES.Contains(sparkError.Error))
                    {
                        throw new SparkApiException(sparkError.Error, sparkError);
                    }

                    throw new SparkDeviceException(sparkError.Error, sparkError);
                }
                return(JsonConvert.DeserializeObject <SparkFunctionResult>(rawContent));
            }
            catch (AggregateException)
            {
                var sparkError = new SparkError()
                {
                    Error = "Too slow to respond or offline"
                };
                throw new SparkDeviceException(sparkError.Error, sparkError);
            }
        }
Beispiel #2
0
 private SparkVariableResult CloudGet(string variableName)
 {
     try
     {
         var response   = CloudApiClient.GetRawResultForGet(variableName);
         var rawContent = response.Content.ReadAsStringAsync().Result;
         if (!response.IsSuccessStatusCode || rawContent.StartsWith("{\n  \"error\":"))
         {
             var sparkError = JsonConvert.DeserializeObject <SparkError>(rawContent);
             throw new SparkDeviceException(sparkError.Error, sparkError);
         }
         return(JsonConvert.DeserializeObject <SparkVariableResult>(rawContent));
     }
     catch (AggregateException)
     {
         var sparkError = new SparkError()
         {
             Error = "Too slow to respond or offline"
         };
         throw new SparkDeviceException(sparkError.Error, sparkError);
     }
 }
Beispiel #3
0
 public SparkException(string message, SparkError error)
     : base(message)
 {
     this.SparkError = error;
 }
 public SparkDeviceException(string message, SparkError error)
     : base(message, error)
 {
 }