protected SynologyRequest(ISynologyApi api) { Api = api; //Fixed possible loop for LoadInfo if (ApiName == "SYNO.API.Info") { CgiPath = "query.cgi"; } else { //Request and Method returns null if the API or the Method is not found. var request = api.Connection.ServiceProvider.GetService <IInfoRequest>() as ISynologyRequest; var data = request?.Method <Dictionary <string, IApiInfo> >("query", new object[] { new[] { ApiName } }); //Request and Method returns null if the API or the Method is not found. //If the Info API has returned a value and contains the current API Info, this update the associated cgi. if (data != null && data.Data.ContainsKey(ApiName)) { CgiPath = data.Data[ApiName].Path; } else { throw new Exception("The API cannot be found on this Synology. Check if RequestAttribute exists on the relative SynologyRequest subclass or the SYNO.API.Info result."); } } Api.Connection.Logger.LogDebug($"Created request {ApiName} to path {CgiPath}"); }
protected SynologyRequest(ISynologyApi api) { Api = api; Api.Connection.Logger.LogDebug($"Created request {ApiName}"); }
internal static T Request <T>(this ISynologyApi api) where T : class, ISynologyRequest => api.Connection.Request <T>();
/// <summary> /// Perform asynchronous post requests returning generic success / error data /// </summary> /// <param name="api"></param> /// <param name="cgiPath">Path of the cgi handling the request</param> /// <param name="apiName">Name of the API handling the request</param> /// <param name="parameters">Parameters of the request</param> /// <returns>Result of the request</returns> internal static async Task <ResultData> PostDataAsync(this ISynologyApi api, string cgiPath, string apiName, SynologyPostParameters parameters) => await api.Connection.PostDataFromApiAsync(cgiPath, apiName, parameters.Version, parameters.Method, parameters.Additional);
/// <summary> /// Perform post requests returning generic success / error data /// </summary> /// <param name="api"></param> /// <param name="cgiPath">Path of the cgi handling the request</param> /// <param name="apiName">Name of the API handling the request</param> /// <param name="parameters">Parameters of the request</param> /// <returns>Result of the request</returns> internal static ResultData PostData(this ISynologyApi api, string cgiPath, string apiName, SynologyPostParameters parameters) => api.Connection.PostDataFromApi(cgiPath, apiName, parameters.Version, parameters.Method, parameters.Additional);
internal static ResultData <T> GetData <T>(this ISynologyApi api, string cgiPath, string apiName, SynologyRequestParameters parameters) => api.Connection.GetDataFromApi <T>(cgiPath, apiName, parameters.Version, parameters.Method, parameters.Additional);