/// <summary>
 /// Executes an arbitrary JSON-RPC method
 /// </summary>
 /// <remarks>if the codeGetter returns a non-zero code, the method will be retried</remarks>
 /// <param name="method">method to be executed</param>
 /// <param name="codeGetter">an implementation  of ICodeGetter capable of parsing return codes (e.g. DictCodeGetter or CodeGetter) </param>
 /// <param name="args">arguments to be passed into the method</param>
 /// <returns>JSON-RPC result</returns>
 public object ExecRawJson(string method, ICodeGetter codeGetter, params object[] args)
 {
     try
     {
         var argMaker = new AutoTokenArgMaker(args);
         return(this.rpcRetry.Invoke(method, argMaker, codeGetter));
     }
     catch (ApiException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new UnknownApiException(string.Format("Failed sending {0} {1}", method, args), ex);
     }
 }
        /// <summary>
        /// Completes a multipart file
        /// </summary>
        /// <param name="mpId">multipart id</param>
        /// <returns>The number of pieces in the multipart file</returns>
        public int CompleteMultipart(string mpId)
        {
            try
            {
                var argMaker   = new AutoTokenArgMaker(mpId);
                var codeGetter = new DictCodeGetter();
                var result     = this.rpcRetry.Invoke("completeMultipart", argMaker, codeGetter);

                var dict = (JsonObject)result;
                return(((JsonNumber)dict["numpieces"]).ToInt32());
            }
            catch (ApiException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new UnknownApiException(string.Format("getMultipartStatus failed with mpId={0}", mpId), ex);
            }
        }
        /// <summary>
        /// returns stat data for a file or directory
        /// </summary>
        /// <param name="remotePath">full path to the file or directory</param>
        public StatResult Stat(string remotePath)
        {
            try
            {
                var argMaker   = new AutoTokenArgMaker(remotePath, true);
                var codeGetter = new DictCodeGetter();
                var result     = this.rpcRetry.Invoke("stat", argMaker, codeGetter);

                var statusResult = new StatResult();
                statusResult.FromJsonObject(result);
                return(statusResult);
            }
            catch (ApiException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new UnknownApiException(string.Format("stat failed with remotePath={0}", remotePath), ex);
            }
        }
 /// <summary>
 /// lists files and directories with in remotePath
 /// </summary>
 /// <param name="remotePath">full path in which to list files and directories</param>
 /// <param name="pageOffset">offset from which to start listing items</param>
 /// <param name="pageSize">number of items per page</param>
 /// <param name="includeStat">include stat data </param>
 public ListPathResults ListPath(string remotePath, int pageSize, string pageOffset, bool includeStat)
 {
     try
     {
         var argMaker   = new AutoTokenArgMaker(remotePath, pageSize, pageOffset, includeStat);
         var codeGetter = new DictCodeGetter();
         var result     = this.rpcRetry.Invoke("listPath", argMaker, codeGetter);
         var results    = new ListPathResults();
         results.FromJsonObject(result);
         return(results);
     }
     catch (ApiException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new UnknownApiException(string.Format("listPath failed with remotePath={0}, pageOffset={1}, pageSize={2}",
                                                     remotePath, pageOffset, pageSize), ex);
     }
 }
        /// <summary>
        /// returns the status of a multipart file
        /// </summary>
        /// <param name="mpId">multipart id</param>
        public MultipartInfo GetMultipartStatus(string mpId)
        {
            try
            {
                var argMaker   = new AutoTokenArgMaker(mpId);
                var codeGetter = new DictCodeGetter();
                var result     = this.rpcRetry.Invoke("getMultipartStatus", argMaker, codeGetter);

                var mpResult = new MultipartInfo();
                mpResult.FromJsonObject(result);
                return(mpResult);
            }
            catch (ApiException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new UnknownApiException(string.Format("getMultipartStatus failed with mpId={0}", mpId), ex);
            }
        }
        /// <summary>
        /// lists multipart pieces within a multipart file
        /// </summary>
        /// <param name="mpId">multipart id</param>
        /// <param name="pageOffset">offset from which to start listing items</param>
        /// <param name="pageSize">number of items per page</param>
        public MultipartPieceResults ListMultipartPiece(string mpId, int pageSize, int pageOffset)
        {
            try
            {
                var argMaker   = new AutoTokenArgMaker(mpId, pageOffset, pageSize);
                var codeGetter = new DictCodeGetter();
                var result     = this.rpcRetry.Invoke("listMultipartPiece", argMaker, codeGetter);

                var results = new MultipartPieceResults();
                results.FromJsonObject(result);
                return(results);
            }
            catch (ApiException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new UnknownApiException(string.Format("listMultipartPiece failed with mpId={0}, pageOffset={1}, pageSize={2}",
                                                            mpId, pageOffset, pageSize), ex);
            }
        }