Example #1
0
        public TResponse Run()
        {
            try
            {
                RestRequest = new SynologyRestRequest();

                AddParametersFromObjectProperties(_args, RestRequest);

                if (_optionalArgs != null)
                {
                    AddParametersFromObjectProperties(_optionalArgs, RestRequest);
                }

                RestRequest.AddParameter("_sid", _sid);

                IRestClient client = new RestClient(Config.ApiBaseAddressAndPathNoTrailingSlash + _scriptPath);

                var response = client.Execute <TResponse>(RestRequest);

                return(response.Data);
            }
            catch (Exception e)
            {
                throw new SynologyClientException(e.Message, e);
            }
        }
Example #2
0
        // This was tricky had to copy link from synology
        // webapi/entry.cgi?api=SYNO.FileStation.Thumb&amp;
        //  method=get&amp;version=2&amp;
        // SynoToken=itXJMhBSq7YL6&amp;
        // path=%22%2Fphoto%2F2017%2FIMG_0285.JPG%22&amp;
        // mt=1499625080


        public byte[] GetThumb(string path, ThumbnailSizeOption size = ThumbnailSizeOption.small,
                               ThumbnailRotateOptions rotate         = ThumbnailRotateOptions.none)
        {
            var request = new SynologyRestRequest();

            request.AddParameter("api", "SYNO.FileStation.Thumb");
            request.AddParameter("version", "2");
            request.AddParameter("method", "get");



            request.AddParameter("path", "\"" + path + "\"");
            request.AddParameter("size", size.ToString());
            request.AddParameter("rotate", (int)rotate);
            request.AddParameter("_sid", _session.sid);
            var config   = new AppSettingsClientConfig();
            var client   = new RestClient(config.ApiBaseAddressAndPathNoTrailingSlash + "/entry.cgi");
            var response = client.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new SynologyClientException("The request failed with " + response.StatusCode);
            }
            return(response.RawBytes);
        }
Example #3
0
        public RawSynologyResponse Upload(FileInfo fileName, string destinationFilePath, bool createParents = true,
                                          bool?overwrite = true)
        {
            var request = new SynologyRestRequest(Method.POST);

            request.AddParameter("_sid", _session.sid, ParameterType.QueryString);
            request.AddParameter("api", "SYNO.FileStation.Upload", ParameterType.QueryString);
            request.AddParameter("version", "2", ParameterType.QueryString);
            request.AddParameter("method", "upload", ParameterType.QueryString);
            request.AddParameter("path", destinationFilePath);
            request.AddParameter("create_parents", createParents);
            request.AddParameter("mtime", DateTimeExtender.GetUnixTimeFromDate(fileName.LastWriteTimeUtc).ToString());
            request.AddParameter("crtime", DateTimeExtender.GetUnixTimeFromDate(fileName.CreationTimeUtc).ToString());
            request.AddParameter("atime", DateTimeExtender.GetUnixTimeFromDate(fileName.LastAccessTimeUtc).ToString());
            request.AddParameter("overwrite", overwrite);

            request.AddFile(fileName.Name, fileName.FullName);

            var config = new AppSettingsClientConfig();
            var client = new RestClient(config.ApiBaseAddressAndPathNoTrailingSlash + "/entry.cgi");

            var response = client.Execute <RawSynologyResponse>(request);

            return(response.Data);
        }
Example #4
0
        public void LogOut()
        {
            var client  = new RestClient(_authBaseUrl);
            var request = new SynologyRestRequest();

            request.AddParameter("api", "SYNO.API.Auth");
            request.AddParameter("version", "1");
            request.AddParameter("method", "logout");
            request.AddParameter("session", "FileStation");
            client.Execute(request);
        }
Example #5
0
        public byte[] Download(string filePath, DownloadMode mode = DownloadMode.download)
        {
            var request = new SynologyRestRequest();

            request.AddParameter("api", "SYNO.FileStation.Download");
            request.AddParameter("version", "1");
            request.AddParameter("method", "download");
            request.AddParameter("path", filePath);
            request.AddParameter("mode", mode);
            request.AddParameter("_sid", _session.sid);
            var config   = new AppSettingsClientConfig();
            var client   = new RestClient(config.ApiBaseAddressAndPathNoTrailingSlash + "/entry.cgi");
            var response = client.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new SynologyClientException("Errored with http status code " + response.StatusCode);
            }
            return(response.RawBytes);
        }
Example #6
0
        public ISynologySession Login()
        {
            var client  = new RestClient(_authBaseUrl);
            var request = new SynologyRestRequest();

            request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
            request.AddParameter("api", "SYNO.API.Auth");
            request.AddParameter("version", "3");
            request.AddParameter("method", "login");
            request.AddParameter("account", _config.User);
            request.AddParameter("passwd", _config.Password);
            request.AddParameter("session", "FileStation");
            request.AddParameter("format", "cookie");

            var response = client.Execute <RawSynologyResponse>(request);

            if (response.Data.success)
            {
                sid          = response.Data.data["sid"];
                loggedInTime = DateTime.UtcNow;
                return(this);
            }
            throw new SynologyClientException("Login failure.");
        }