Exemplo n.º 1
0
        /// <summary>
        /// get remote option
        /// </summary>
        /// <returns></returns>
        public RemoteOption GetRemoteOption()
        {
            if (RemoteConfigs == null || RemoteConfigs.Count <= 0)
            {
                return(null);
            }
            int serverCount = RemoteConfigs.Count;

            if (serverCount == 1)
            {
                return(RemoteConfigs[0]);
            }
            RemoteOption remoteOption = null;

            switch (RemoteServerChoicePattern)
            {
            case RemoteServerChoicePattern.First:
                remoteOption = RemoteConfigs[0];
                break;

            case RemoteServerChoicePattern.Latest:
                remoteOption = RemoteConfigs[RemoteConfigs.Count - 1];
                break;

            default:
                var random   = new Random();
                int ranIndex = random.Next(0, serverCount);
                remoteOption = RemoteConfigs[ranIndex];
                break;
            }
            return(remoteOption);
        }
Exemplo n.º 2
0
        /// <summary>
        /// remote upload file
        /// </summary>
        /// <param name="remoteOption">remote options</param>
        /// <param name="fileOption">file option</param>
        /// <param name="file">upload file</param>
        /// <param name="parameters">parameters</param>
        /// <returns></returns>
        public static async Task <UploadResult> RemoteUploadAsync(RemoteOption remoteOption, UploadFile fileOption, byte[] file, object parameters = null)
        {
            if (fileOption == null)
            {
                throw new ArgumentNullException(nameof(fileOption));
            }
            Dictionary <string, string> parameterDic = null;

            if (parameters != null)
            {
                parameterDic = parameters.ObjectToStringDcitionary();
            }
            return(await RemoteUploadAsync(remoteOption, new List <UploadFile>() { fileOption }, new Dictionary <string, byte[]>() { { "file1", file } }, parameterDic).ConfigureAwait(false));
        }
Exemplo n.º 3
0
        /// <summary>
        /// remote upload file
        /// </summary>
        /// <param name="remoteOption">remote option</param>
        /// <param name="fileOptions">file options</param>
        /// <param name="files">upload files</param>
        /// <param name="parameters">parameters</param>
        /// <returns></returns>
        public static async Task <UploadResult> RemoteUploadAsync(RemoteOption remoteOption, List <UploadFile> fileOptions, Dictionary <string, byte[]> files, Dictionary <string, string> parameters = null)
        {
            if (remoteOption == null || string.IsNullOrWhiteSpace(remoteOption.Server))
            {
                throw new ArgumentNullException(nameof(remoteOption));
            }
            if (files == null || files.Count <= 0)
            {
                throw new ArgumentNullException(nameof(files));
            }
            RemoteUploadParameter uploadParameter = new RemoteUploadParameter()
            {
                Files = fileOptions
            };

            parameters = parameters ?? new Dictionary <string, string>();
            parameters.Add(RemoteUploadParameter.REQUEST_KEY, JsonSerialize.ObjectToJson(uploadParameter));
            string url = remoteOption.GetUploadUrl();

            return(await HttpUtil.UploadAsync(url, files, parameters).ConfigureAwait(false));
        }