コード例 #1
0
        private void RegisterRequest <T>() where T : SynologyRequest
        {
            Logger.LogDebug($"Registering Request {typeof(T).Name}");

            var builder = new ContainerBuilder();
            var apiName = SynologyRequest.GetApiName <T>();

            if (!string.IsNullOrEmpty(apiName))
            {
                builder.RegisterType <T>().Named <SynologyRequest>(apiName).Named <T>(apiName).AsSelf().As <SynologyRequest>();
            }
            else
            {
                builder.RegisterType <T>().AsSelf().As <SynologyRequest>();
            }

            builder.Update(_container);
        }
コード例 #2
0
        protected SynologyParameters(SynologyRequest request, [CallerMemberName] string methodName = null)
        {
            var method = request.GetType().GetMethod(methodName);

            if (method != null)
            {
                var attr = method.GetCustomAttribute(typeof(RequestMethodAttribute)) as RequestMethodAttribute;

                if (attr != null)
                {
                    Method = attr.Name;
                }
                else
                {
                    throw new Exception("RequestMethodAttribute not found on caller method.");
                }
            }
            else
            {
                throw new Exception("Caller Method not found.");
            }

            Version = 1;
        }
コード例 #3
0
 public SynologyPostParameters(SynologyRequest request) : base(request)
 {
 }
コード例 #4
0
        private SynologyAPIInfo<SynologyTaskResponse> StartSearch(string searchName)
        {
            string queryString = string.Format("/webapi/FileStation/file_find.cgi?api={0}&version={1}&method=start&folder_path=%2Fvideo&recursive=true&pattern=1&_sid={2}",
                SynologyFileCommand.FILESEARCH, 1, this.synologyLogin.SID);

            SynologyAPIInfo<SynologyTaskResponse> searchResponse = new SynologyRequest<SynologyTaskResponse>(client).SendRequest(queryString);

            SynologyAPIInfo<SynologyFileList> searchFiles;
            while (true)
            {
                searchFiles = GetSearchResults(searchResponse.Data.TaskID);
                CancelSearch(searchResponse.Data.TaskID);
                ClearSearch(searchResponse.Data.TaskID);
                if (searchFiles.Data.FinishedSearch)
                {

                    break;
                }
            }

            return searchResponse;
        }
コード例 #5
0
        private void MoveFile(string sourceFiles, string destDirName)
        {
            string queryString = string.Format("/webapi/FileStation/file_MVCP.cgi?api={0}&version={1}&method=start&path={2}&dest_folder_path={3}&overwrite=true&remove_src=true",
                SynologyFileCommand.FILECOPYMOVE, 1, sourceFiles, destDirName);

            SynologyAPIInfo<SynologyTaskResponse> copyMoveTask = new SynologyRequest<SynologyTaskResponse>(client).SendRequest(queryString);

            SynologyCopyMoveResponse copyMoveStatus;
            while (true)
            {
                copyMoveStatus = CheckFileMoveStatus(copyMoveTask.Data.TaskID);

                if (copyMoveStatus.Finished)
                {
                    break;
                }
            }
        }
コード例 #6
0
        private SynologyAPIInfo<SynologyFileList> GetSearchResults(string searchID)
        {
            string queryString = string.Format("/webapi/FileStation/file_find.cgi?api={0}&version=1&method=list&taskid={1}&_sid={2}",
                SynologyFileCommand.FILESEARCH, searchID, this.synologyLogin.SID);

            SynologyAPIInfo<SynologyFileList> searchResponse = new SynologyRequest<SynologyFileList>(client).SendRequest(queryString);

            return searchResponse;
        }
コード例 #7
0
        private SynologyCopyMoveResponse CheckFileMoveStatus(string taskID)
        {
            string queryString = string.Format("/webapi/FileStation/file_MVCP.cgi?api={0}&version={1}&method=status&taskid={2}",
                SynologyFileCommand.FILECOPYMOVE, 1, taskID);

            SynologyAPIInfo<SynologyCopyMoveResponse> copyStatus = new SynologyRequest<SynologyCopyMoveResponse>(client).SendRequest(queryString);

            return copyStatus.Data;
        }
コード例 #8
0
        public void Login()
        {
            //string loginURI = string.Format("/webapi/auth.cgi?api=SYNO.API.Auth&version=3&method=login&account=admin&passwd=12345&session=FileStation&format=cookie");
            string queryString = string.Format("/webapi/{0}?api=SYNO.API.Auth&version={1}&method=login&account={2}&passwd={3}&session=FileStation&format=cookie", this.synologyLogin.URIDetails.Path, this.synologyLogin.URIDetails.MaxVersion, this.synologyLogin.Username, this.synologyLogin.Password);

            SynologyAPIInfo<SynologyLogin> loginSID = new SynologyRequest<SynologyLogin>(client).SendRequest(queryString);

            if (loginSID.Success)
            {
                this.synologyLogin.SID = loginSID.Data.SID;

                this.IsLoggedIn = true;
            }
        }
コード例 #9
0
        public SynologyAPIInfo<SynologyFileList> GetVideoFileList()
        {
            string queryString = string.Format("/webapi/FileStation/file_share.cgi?api={0}&version={1}&method=list&additional=real_path%2Csize%2Cowner%2Ctime%2Cperm%2Ctype&folder_path=%2Fvideo", SynologyFileCommand.LISTFILES, 1);

            SynologyAPIInfo<SynologyFileList> files = new SynologyRequest<SynologyFileList>(client).SendRequest(queryString); ;

            return files;
        }
コード例 #10
0
        public List<string> GetFolderList()
        {
            string queryString = string.Format("/webapi/FileStation/file_share.cgi?api={0}&version={1}&method=list_share&additional=real_path%2Cowner%2Ctime", SynologyFileCommand.LISTFILES, 1);

            SynologyAPIInfo<SynologyLogin> loginSID = new SynologyRequest<SynologyLogin>(client).SendRequest(queryString);

            if (loginSID.Success)
            {
                this.synologyLogin.SID = loginSID.Data.SID;
            }

            return null;
        }
コード例 #11
0
        public void GetFileAPIList()
        {
            try
            {
                this.logger.Log("Start connection");

                // List all products.
                string queryString = "/webapi/query.cgi?api=SYNO.API.Info&version=1&method=query&query=SYNO.API.Auth,SYNO.FileStation";

                SynologyAPIInfo<SynologyDataSources> apiInfo = new SynologyRequest<SynologyDataSources>(client).SendRequest(queryString);

                if (apiInfo.Success)
                {
                    this.synologyLogin.InitialiseLoginInfo(apiInfo);
                }
            }
            catch (Exception ex)
            {
                this.logger.Log(ex.ToString());
            }
        }