/// <summary> /// Logs off the DSM system. /// </summary> /// <returns>The task containing the log off operation.</returns> public async Task LogOff() { DsmApiResponse response = await this.ApiContext.Request( this.ApiInfo.Path, AuthenticationApiName, this.ApiInfo.MaxVersion, "logout", null); }
/// <summary> /// Throws a <see cref="DsmApiException"/> with the correct error code and message when the response contains an error. /// </summary> /// <param name="apiResponse">The response to check.</param> protected void ThrowIfError(DsmApiResponse apiResponse) { if (apiResponse == null) { throw new ArgumentNullException("apiResponse"); } if (!apiResponse.Success) { throw new DsmApiException(apiResponse.Error.Code, this.ConvertErrorCodeToErrorMessage(apiResponse.Error.Code)); } }
public async Task <EncryptionInformation> GetInfo() { DsmApiResponse response = await this.ApiContext.Request( this.ApiInfo.Path, EncryptionApiName, this.ApiInfo.MaxVersion, "getinfo", null); var encryptionInfo = JsonConvert.DeserializeObject <EncryptionInformation>(response.Data.ToString()); return(encryptionInfo); }
/// <inheritdoc /> public async Task <DsmApiResponse> Request(string apiPath, string api, int version, string method, IDictionary <string, string> additionalParameters) { Uri requestUri = this.BuildRequestUri(apiPath, api, version, method, additionalParameters); string responseString; using (WebResponse response = await this.ExecuteRequest(requestUri)) { responseString = GetJsonStringFromWebResponse(response); } DsmApiResponse apiResponse = JsonConvert.DeserializeObject <DsmApiResponse>(responseString); return(apiResponse); }
public async Task <IDictionary <string, DsmApiInfo> > QueryAll() { DsmApiResponse response = await this.ApiContext.Request( this.ApiInfo.Path, InformationApiName, this.ApiInfo.MaxVersion, "query", new Dictionary <string, string>() { { "query", "all" } }); var allApiInfo = JsonConvert.DeserializeObject <Dictionary <string, DsmApiInfo> >(response.Data.ToString()); return(allApiInfo); }
/// <summary> /// Logs on the DSM system. /// </summary> /// <param name="account">The name of the account.</param> /// <param name="password">The password of the account.</param> /// <returns>The information about the authenticated connection.</returns> public async Task <AuthenticationInformation> LogOn(string account, string password) { DsmApiResponse response = await this.ApiContext.Request( this.ApiInfo.Path, AuthenticationApiName, this.ApiInfo.MaxVersion, "login", new Dictionary <string, string>() { { "account", account }, { "passwd", password } }); var authenticationInformation = JsonConvert.DeserializeObject <AuthenticationInformation>(response.Data.ToString()); return(authenticationInformation); }
/// <inheritdoc /> public async Task LoadAllApiInfo() { if (this.allApiInfo == null) { DsmApiResponse response = await this.Request( "query.cgi", "SYNO.API.Info", 1, "query", new Dictionary <string, string>() { { "query", "all" } }); if (response.Success) { this.allApiInfo = JsonConvert.DeserializeObject <Dictionary <string, DsmApiInfo> >(response.Data.ToString()); } } }