/// <summary> /// Performs session login /// </summary> /// <param name="session">Login session name [DownloadStation, FileStation]</param> /// <param name="format">Returned format of session ID. Following are the two possible options and the default value is cookie. cookie: The login session ID will be set to cookie. sid: The login sid will only be returned as response json data and the cookie will not be set.</param> /// <param name="otp_code">This option is not required to log into Download Station sessions currently. However, please note that DSM 4.2 and later includes a 2-step verification option. If enabled, the user requires a verification code to log into DSM sessions.</param> /// <returns>Authorized session ID. When the user log in with format=sid, cookie will not be set and each API request should provide a request parameter sid=<sid> along with other parameters.</returns> public static SessionObject GetLogin(Init server, string session = "DownloadStation,FileStation", string format = "cookie", string otp_code = null) { string APIList = $"api=SYNO.API.Auth&version=2&method=login&account={server.Username}&passwd={server.Password}&session={session}&format={format}"; if (otp_code != null) { APIList += $"&otp_code={otp_code}"; } Uri fullPath = new UriBuilder(server.BaseAddress) { Path = BasePath, Query = APIList, }.Uri; Console.WriteLine(fullPath); string json = Init.Richiesta(fullPath).Result; Dictionary <string, string> results; SessionObject stato = new SessionObject(); try { results = JsonConvert.DeserializeObject <Dictionary <string, string> >(JObject.Parse(json)["data"].ToString()); stato.sid = results.Values.First(); } catch { throw SynoException.FromJson(json, SynoException.ExceptionType.API_Auth); } return(stato); }
/// <summary> /// Edit download instance /// </summary> /// <param name="id">Task IDs to be set destination, separated by ","</param> /// <param name="destination">Optional. Download destination path starting with a shared folder</param> /// <returns></returns> public static List <Task_Delete> Edit(Init server, string id, string destination = null) { string _destination = ""; if (destination != null) { _destination = $"&destination={destination}"; } Uri fullPath = new UriBuilder(server.BaseAddress) { Path = BasePath, Query = $"api=SYNO.DownloadStation.Task&version=1&method=edit&id={id}{_destination}", }.Uri; Console.WriteLine(fullPath); string json = Init.Richiesta(fullPath).Result; List <Task_Delete> results; try { results = JsonConvert.DeserializeObject <List <Task_Delete> >(JObject.Parse(json)["data"].ToString()); } catch { throw SynoException.FromJson(json, SynoException.ExceptionType.DownloadStation_Task); } return(results); }
/// <summary> /// Provides total download/upload statistics /// </summary> /// <param name="id">Task IDs to be set destination, separated by ","</param> /// <param name="destination">Optional. Download destination path starting with a shared folder</param> /// <returns></returns> public static Statistic_TotalInfo GetInfo(Init server) { Uri fullPath = new UriBuilder(server.BaseAddress) { Path = BasePath, Query = $"api=SYNO.DownloadStation.Statistic&version=1&method=getinfo", }.Uri; Console.WriteLine(fullPath); string json = Init.Richiesta(fullPath).Result; Statistic_TotalInfo results; try { results = JsonConvert.DeserializeObject <Statistic_TotalInfo>(JObject.Parse(json)["data"].ToString()); } catch { throw SynoException.FromJson(json, SynoException.ExceptionType.DownloadStation_Task); } return(results); }
/// <summary> /// Delete download instance /// </summary> /// <param name="id">Task IDs to be deleted, separated by ","</param> /// <param name="force_complete">Delete tasks and force to move uncompleted download files to the destination</param> /// <returns></returns> public static List <Task_Delete> Delete(Init server, string id, bool force_complete = false) { Uri fullPath = new UriBuilder(server.BaseAddress) { Path = BasePath, Query = $"api=SYNO.DownloadStation.Task&version=1&method=delete&id={id}&force_complete={force_complete}", }.Uri; Console.WriteLine(fullPath); string json = Init.Richiesta(fullPath).Result; List <Task_Delete> results; try { results = JsonConvert.DeserializeObject <List <Task_Delete> >(JObject.Parse(json)["data"].ToString()); } catch { throw SynoException.FromJson(json, SynoException.ExceptionType.DownloadStation_Task); } return(results); }
/// <summary> /// Create a new download instance /// </summary> /// <param name="uri">Optional. Accepts HTTP/FTP/magnet/ED2K links or the file path starting with a shared folder, separated by ",".</param> /// <param name="file">Optional. File uploading from client. For more info, please see Limitations on page 30. </param> /// <param name="unzip_password">Optional. Password for unzipping download tasks</param> /// <param name="destination">Optional. Download destination path starting with a shared folder</param> /// <returns></returns> public static bool Create(Init server, string uri = "", string file = "", string unzip_password = "", string destination = "") { if (uri != "") { uri = $"&uri={uri}"; } if (file != "") { file = $"&file={file}"; } if (unzip_password != "") { unzip_password = $"&unzip_password={unzip_password}"; } if (destination != "") { destination = $"&destination={destination}"; } Uri fullPath = new UriBuilder(server.BaseAddress) { Path = BasePath, Query = $"api=SYNO.DownloadStation.Task&version=1&method=create{uri}{file}{unzip_password}{destination}", }.Uri; Console.WriteLine(fullPath); string json = Init.Richiesta(fullPath).Result; Dictionary <string, string> results; try { results = JsonConvert.DeserializeObject <Dictionary <string, string> >(JObject.Parse(json).ToString()); } catch { throw SynoException.FromJson(json, SynoException.ExceptionType.DownloadStation_Task); } return(bool.Parse(results.Values.First())); }