public static NCDCResponse <NCDCLocation> GetLocationInformation(string datasetName, string locationId, string token = null, NCDCOptions options = null) { token = token ?? NCDCUtilities.GetUnlockedToken(); var command = new ShowLocationCommand(datasetName, locationId, token, options); return(NCDCCommand <NCDCLocation> .PerformAction(command)); }
public static NCDCResponse <NCDCDataCollection> GetDataForLocationTypeLocationAndDataType(string datasetName, string locationTypeId, string locationId, string dataTypeId, string token = null, NCDCOptions options = null) { token = token ?? NCDCUtilities.GetUnlockedToken(); var command = new ListDataCommand(token, options); command.BuildDatasetLocationTypeLocationDataTypeUri(datasetName, locationTypeId, locationId, dataTypeId); return(NCDCCommand <NCDCDataCollection> .PerformAction(command)); }
public static NCDCResponse <NCDCDatasetCollection> GetDataSets(string token = null, NCDCOptions options = null) { token = token ?? NCDCUtilities.GetUnlockedToken(); var command = new ListDatasetsCommand(token, options); return(NCDCCommand <NCDCDatasetCollection> .PerformAction(command)); }
public static NCDCResponse <NCDCDataType> GetDataTypeInformationForLocation(string datasetName, string locationId, string dataTypeId, string token = null, NCDCOptions options = null) { token = token ?? NCDCUtilities.GetUnlockedToken(); var command = new ShowDataTypesCommand(token, options); command.BuildDatasetsLocationsUri(datasetName, locationId, dataTypeId); return(NCDCCommand <NCDCDataType> .PerformAction(command)); }
public static NCDCResponse <NCDCDataTypeCollection> GetDataTypesForStation(string datasetName, string stationId, string token = null, NCDCOptions options = null) { token = token ?? NCDCUtilities.GetUnlockedToken(); var command = new ListDataTypesCommand(token, options); command.BuildDatasetsStationsUri(datasetName, stationId); return(NCDCCommand <NCDCDataTypeCollection> .PerformAction(command)); }
public static NCDCResponse <NCDCLocationTypeCollection> GetLocationTypes(string datasetName, string token = null, NCDCOptions options = null) { token = token ?? NCDCUtilities.GetUnlockedToken(); var command = new ListLocationTypesCommand(datasetName, token, options); return(NCDCCommand <NCDCLocationTypeCollection> .PerformAction(command)); }
/// <summary> /// Executes the command. /// </summary> /// <returns>The results of the command.</returns> /// <remarks></remarks> public NCDCResponse <T> ExecuteCommand() { this.Token = NCDCUtilities.GetUnlockedToken(); lock (Token) { NCDCResponse <T> ncdcResponse = new NCDCResponse <T>(); ncdcResponse.Command = this; if (true) // use SSL { this.Uri = new Uri(this.Uri.AbsoluteUri.Replace("http://", "https://")); } // check if token exists if (string.IsNullOrEmpty(this.Token)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Token is required for the \"{0}\" command.", this.GetType())); } // Prepare the query parameters Dictionary <string, object> queryParameters = new Dictionary <string, object>(); foreach (KeyValuePair <string, object> item in this.RequestParameters) { queryParameters.Add(item.Key, item.Value); } // Declare the variable to be returned ncdcResponse.ResponseObject = default(T); ncdcResponse.RequestUrl = this.Uri.AbsoluteUri; byte[] responseData; try { NCDCWebRequest requestBuilder = new NCDCWebRequest(this.Uri, this.Verb, this.Token); foreach (var item in queryParameters) { requestBuilder.Parameters.Add(item.Key, item.Value); } HttpWebResponse response = requestBuilder.ExecuteRequest(); if (response == null) { ncdcResponse.Result = RequestResult.Unknown; return(ncdcResponse); } responseData = NCDCUtilities.ReadStream(response.GetResponseStream()); ncdcResponse.Content = Encoding.UTF8.GetString(responseData, 0, responseData.Length); ncdcResponse.RequestUrl = requestBuilder.RequestUri.AbsoluteUri; SetStatusCode(ncdcResponse, response.StatusCode); } catch (WebException wex) { if (new[] { WebExceptionStatus.Timeout, WebExceptionStatus.ConnectionClosed, WebExceptionStatus.ConnectFailure }.Contains(wex.Status)) { ncdcResponse.Result = RequestResult.ConnectionFailure; ncdcResponse.ErrorMessage = wex.Message; return(ncdcResponse); } // The exception response should always be an HttpWebResponse, but we check for good measure. HttpWebResponse exceptionResponse = wex.Response as HttpWebResponse; if (exceptionResponse == null) { throw; } responseData = NCDCUtilities.ReadStream(exceptionResponse.GetResponseStream()); ncdcResponse.Content = Encoding.UTF8.GetString(responseData, 0, responseData.Length); SetStatusCode(ncdcResponse, exceptionResponse.StatusCode); if (wex.Status == WebExceptionStatus.UnknownError) { throw; } return(ncdcResponse); } try { ncdcResponse.ResponseObject = NCDCSerialization <T> .Deserialize(responseData, this.DeserializationHandler); } catch (Newtonsoft.Json.JsonReaderException) { ncdcResponse.ErrorMessage = "Unable to parse JSON"; ncdcResponse.Result = RequestResult.Unknown; return(ncdcResponse); } catch (Newtonsoft.Json.JsonSerializationException) { ncdcResponse.ErrorMessage = "Unable to parse JSON"; ncdcResponse.Result = RequestResult.Unknown; return(ncdcResponse); } // Pass the current oauth tokens into the new object, so method calls from there will keep the authentication. ncdcResponse.Token = this.Token; //ncdcResponse.UpdateContent(); return(ncdcResponse); } }