Пример #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);
            }
        }
Пример #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);
     }
 }
Пример #3
0
 public SparkException(string message, SparkError error)
     : base(message)
 {
     this.SparkError = error;
 }
Пример #4
0
 public SparkDeviceException(string message, SparkError error)
     : base(message, error)
 {
 }