public ResumeUploader(HttpManager httpManager, ResumeRecorder recorder, string recordKey, Stream stream, string key, string token, UploadOptions uploadOptions, UpCompletionHandler upCompletionHandler) { this.httpManager = httpManager; this.resumeRecorder = recorder; this.recordKey = recordKey; this.fileStream = stream; this.key = key; this.storage = IsolatedStorageFile.GetUserStoreForApplication(); this.uploadOptions = (uploadOptions == null) ? UploadOptions.defaultOptions() : uploadOptions; this.upCompletionHandler = new UpCompletionHandler(delegate(string fileKey, ResponseInfo respInfo, string response) { uploadOptions.ProgressHandler(key, 1.0); if (this.fileStream != null) { try { this.fileStream.Close(); } catch (Exception) { } } if (upCompletionHandler != null) { upCompletionHandler(key, respInfo, response); } }); this.httpManager.setAuthHeader("UpToken " + token); this.chunkBuffer = new byte[Config.CHUNK_SIZE]; }
public Pfop(Mac mac, string bucket, string key, string fops) { this.httpManager = new HttpManager(); this.Mac = mac; this.Bucket = bucket; this.Key = key; this.Fops = fops; }
/// <summary> /// 上传沙盒文件 /// </summary> /// <param name="httpManager">HttpManager对象</param> /// <param name="filePath">沙盒文件的完整路径</param> /// <param name="key">保存在七牛的文件名</param> /// <param name="token">上传凭证</param> /// <param name="uploadOptions">上传可选设置</param> /// <param name="upCompletionHandler">上传完成结果处理器</param> public void uploadFile(HttpManager httpManager, string filePath, string key, string token, UploadOptions uploadOptions, UpCompletionHandler upCompletionHandler) { PostArgs postArgs = new PostArgs(); postArgs.File = filePath; postArgs.FileName = Path.GetFileName(filePath); httpManager.FileContentType = PostContentType.FILE; upload(httpManager, postArgs, key, token, uploadOptions, upCompletionHandler); }
/// <summary> /// 以表单方式上传字节数据 /// </summary> /// <param name="httpManager">HttpManager对象</param> /// <param name="data">字节数据</param> /// <param name="key">保存在七牛的文件名</param> /// <param name="token">上传凭证</param> /// <param name="uploadOptions">上传可选设置</param> /// <param name="upCompletionHandler">上传完成结果处理器</param> public void uploadData(HttpManager httpManager, byte[] data, string key, string token, UploadOptions uploadOptions, UpCompletionHandler upCompletionHandler) { PostArgs postArgs = new PostArgs(); postArgs.Data = data; if (key != null) { postArgs.FileName = key; } httpManager.FileContentType = PostContentType.BYTES; upload(httpManager, postArgs, key, token, uploadOptions, upCompletionHandler); }
public void reqGetTest() { HttpManager target = new HttpManager(); string url = "http://ip.taobao.com/service/getIpInfo.php?ip=100.123.199.44"; Dictionary<string, string> pHeaders = new Dictionary<string, string>(); pHeaders.Add("X-Reqid", "TestReqId"); CompletionHandler pCompletionHandler = new CompletionHandler(delegate(ResponseInfo respInfo, string response) { Assert.AreEqual(respInfo.StatusCode, 200); }); target.get(url, pHeaders, pCompletionHandler); }
/// <summary> /// 以表单方式上传数据流 /// </summary> /// <param name="httpManager">HttpManager对象</param> /// <param name="stream">文件数据流</param> /// <param name="key">保存在七牛的文件名</param> /// <param name="token">上传凭证</param> /// <param name="uploadOptions">上传可选设置</param> /// <param name="upCompletionHandler">上传完成结果处理器</param> public void uploadStream(HttpManager httpManager, Stream stream, string key, string token, UploadOptions uploadOptions, UpCompletionHandler upCompletionHandler) { PostArgs postArgs = new PostArgs(); postArgs.Stream = stream; if (key != null) { postArgs.FileName = key; } httpManager.FileContentType = PostContentType.STREAM; upload(httpManager, postArgs, key, token, uploadOptions, upCompletionHandler); }
public void reqPostTest() { HttpManager target = new HttpManager(); string pUrl = "http://ip.taobao.com/service/getIpInfo.php"; Dictionary<string, string> pHeaders = new Dictionary<string, string>(); Dictionary<string, string[]> pPostParams = new Dictionary<string, string[]>(); pPostParams.Add("ip", new string[] { "100.123.199.44", "100.123.199.45" }); CompletionHandler pCompletionHandler = new CompletionHandler(delegate(ResponseInfo respInfo, string response) { Assert.AreEqual(respInfo.StatusCode, 200); }); target.postForm(pUrl, pHeaders, pPostParams, pCompletionHandler); }
public HttpResult delete(string bucket, string key) { HttpResult deleteResult = null; string url = string.Format("{0}{1}", Config.RS_HOST, deleteOp(bucket, key)); string token = Auth.createManageToken(url, null, this.mac); HttpManager httpManager = new HttpManager(); httpManager.setAuthHeader(token); httpManager.CompletionHandler = new CompletionHandler(delegate(ResponseInfo respInfo, string response) { deleteResult = new HttpResult(); deleteResult.Response = response; deleteResult.ResponseInfo = respInfo; }); httpManager.post(url); return deleteResult; }
public HttpResult move(string srcBucket, string srcKey, string destBucket, string destKey) { HttpResult moveResult = null; string url = string.Format("{0}{1}", Config.RS_HOST, moveOp(srcBucket, srcKey, destBucket, destKey)); string token = Auth.createManageToken(url, null, this.mac); HttpManager httpManager = new HttpManager(); httpManager.setAuthHeader(token); httpManager.CompletionHandler = new CompletionHandler(delegate(ResponseInfo respInfo, string response) { moveResult = new HttpResult(); moveResult.Response = response; moveResult.ResponseInfo = respInfo; }); httpManager.post(url); return moveResult; }
/// <summary> /// 构建分片上传对象 /// </summary> /// <param name="recorder">分片上传进度记录器</param> /// <param name="recordKey">分片上传进度记录文件名</param> /// <param name="filePath">上传的文件全路径</param> /// <param name="key">保存在七牛的文件名</param> /// <param name="token">上传凭证</param> /// <param name="uploadOptions">上传可选设置</param> /// <param name="upCompletionHandler">上传完成结果处理器</param> public ResumeUploader(ResumeRecorder recorder, string recordKey, string filePath, string key, string token, UploadOptions uploadOptions, UpCompletionHandler upCompletionHandler) { this.mHttpManager = new HttpManager(); this.resumeRecorder = recorder; this.recordKey = recordKey; this.filePath = filePath; this.key = key; this.uploadOptions = (uploadOptions == null) ? UploadOptions.defaultOptions() : uploadOptions; this.upCompletionHandler = new UpCompletionHandler(delegate(string fileKey, ResponseInfo respInfo, string response) { if (respInfo.isOk()) { this.uploadOptions.ProgressHandler(key, 1.0); } if (this.fileStream != null) { try { this.fileStream.Close(); this.fileStream = null; } catch (Exception) { } } try { if (upCompletionHandler != null) { upCompletionHandler(key, respInfo, response); } } catch (Exception ex) { Console.WriteLine("resumable upload completion error, {0}", ex.Message); } }); string upTokenHeader = string.Format("UpToken {0}", token); this.upHeaders = new Dictionary<string, string>(); this.upHeaders.Add("Authorization", upTokenHeader); this.chunkBuffer = new byte[Config.CHUNK_SIZE]; }
public StatResult stat(string bucket, string key) { StatResult statResult = null; string url = string.Format("{0}{1}", Config.RS_HOST, statOp(bucket, key)); string token = Auth.createManageToken(url, null, this.mac); HttpManager httpManager = new HttpManager(); httpManager.setAuthHeader(token); httpManager.CompletionHandler = new CompletionHandler(delegate(ResponseInfo respInfo, string response) { if (respInfo.isOk()) { statResult = StringUtils.jsonDecode<StatResult>(response); } else { statResult = new StatResult(); } statResult.Response = response; statResult.ResponseInfo = respInfo; }); httpManager.get(url); return statResult; }
public BucketManager(Mac mac) { this.mac = mac; this.mHttpManager = new HttpManager(); }
public Dfop(Mac mac) { this.mHttpManager = new HttpManager(); this.mac = mac; }
public BucketsResult buckets() { BucketsResult bucketsResult = null; List<string> buckets = new List<string>(); string url = string.Format("{0}/buckets", Config.RS_HOST); string token = Auth.createManageToken(url, null, this.mac); HttpManager httpManager = new HttpManager(); httpManager.setAuthHeader(token); httpManager.CompletionHandler = new CompletionHandler(delegate(ResponseInfo respInfo, string response) { bucketsResult = new BucketsResult(); bucketsResult.Response = response; bucketsResult.ResponseInfo = respInfo; if (respInfo.isOk()) { buckets = JsonConvert.DeserializeObject<List<string>>(response); bucketsResult.Buckets = buckets; } }); httpManager.post(url); return bucketsResult; }
public FetchResult fetch(string remoteResUrl, string bucket, string key) { FetchResult fetchResult = null; string url = string.Format("{0}{1}", Config.IOVIP_HOST, fetchOp(remoteResUrl, bucket, key)); string token = Auth.createManageToken(url, null, this.mac); HttpManager httpManager = new HttpManager(); httpManager.setAuthHeader(token); httpManager.CompletionHandler = new CompletionHandler(delegate(ResponseInfo respInfo, string response) { if (respInfo.isOk()) { fetchResult = StringUtils.jsonDecode<FetchResult>(response); } else { fetchResult = new FetchResult(); } fetchResult.Response = response; fetchResult.ResponseInfo = respInfo; }); httpManager.post(url); return fetchResult; }
public HttpResult batch(string ops) { HttpResult batchResult = null; string url = string.Format("{0}{1}", Config.RS_HOST, "/batch"); string token = Auth.createManageToken(url, Encoding.UTF8.GetBytes(ops), this.mac); HttpManager httpManager = new HttpManager(); httpManager.setAuthHeader(token); httpManager.CompletionHandler = new CompletionHandler(delegate(ResponseInfo respInfo, string response) { batchResult = new FetchResult(); batchResult.Response = response; batchResult.ResponseInfo = respInfo; }); PostArgs postArgs = new PostArgs(); postArgs.Data = Encoding.UTF8.GetBytes(ops); httpManager.Headers.Set(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded"); httpManager.PostArgs = postArgs; httpManager.postData(url); return batchResult; }
private void upload(HttpManager httpManager, PostArgs postArgs, string key, string token, UploadOptions uploadOptions, UpCompletionHandler upCompletionHandler) { if (uploadOptions == null) { uploadOptions = UploadOptions.defaultOptions(); } postArgs.Params = new Dictionary<string, string>(); //设置key if (!string.IsNullOrEmpty(key)) { postArgs.Params.Add("key", key); } //设置token postArgs.Params.Add("token", token); //设置crc32校验 if (uploadOptions.CheckCrc32) { switch (httpManager.FileContentType) { case PostContentType.BYTES: postArgs.Params.Add("crc32", string.Format("{0}", CRC32.CheckSumBytes(postArgs.Data, postArgs.Data.Length))); break; case PostContentType.STREAM: long streamLength = postArgs.Stream.Length; byte[] buffer = new byte[streamLength]; int cnt = postArgs.Stream.Read(buffer, 0, (int)streamLength); postArgs.Params.Add("crc32", string.Format("{0}", CRC32.CheckSumBytes(buffer, cnt))); postArgs.Stream.Seek(0, SeekOrigin.Begin); break; case PostContentType.FILE: postArgs.Params.Add("crc32", string.Format("{0}", CRC32.CheckSumFile(postArgs.File))); break; } } //设置MimeType postArgs.MimeType = uploadOptions.MimeType; //设置扩展参数 foreach (KeyValuePair<string, string> kvp in uploadOptions.ExtraParams) { postArgs.Params.Add(kvp.Key, kvp.Value); } //设置进度处理和取消信号 httpManager.ProgressHandler = new ProgressHandler(delegate(int bytesWritten, int totalBytes) { double percent = (double)bytesWritten / totalBytes; //这样做是为了等待回复 if (percent > 0.95) { percent = 0.95; } uploadOptions.ProgressHandler(key, percent); }); httpManager.CancellationSignal = new CancellationSignal(delegate() { return uploadOptions.CancellationSignal(); }); httpManager.PostArgs = postArgs; //第一次失败后使用备用域名重试一次 httpManager.CompletionHandler = new CompletionHandler(delegate(ResponseInfo respInfo, string response) { if (respInfo.needRetry()) { if (httpManager.PostArgs.Stream != null) { httpManager.PostArgs.Stream.Seek(0, SeekOrigin.Begin); } CompletionHandler retried = new CompletionHandler(delegate(ResponseInfo retryRespInfo, string retryResponse) { uploadOptions.ProgressHandler(key, 1.0); if (httpManager.PostArgs.Stream != null) { httpManager.PostArgs.Stream.Close(); } if (upCompletionHandler != null) { upCompletionHandler(key, retryRespInfo, retryResponse); } }); httpManager.CompletionHandler = retried; httpManager.multipartPost(Config.UP_HOST); } else { uploadOptions.ProgressHandler(key, 1.0); if (httpManager.PostArgs.Stream != null) { httpManager.PostArgs.Stream.Close(); } if (upCompletionHandler != null) { upCompletionHandler(key, respInfo, response); } } }); httpManager.multipartPost(Config.UPLOAD_HOST); }
public FormUploader() { this.mHttpManager = new HttpManager(); }
public FusionManager(Mac mac) { this.mac = mac; httpMgr = new HttpManager(); }
public Prefop(string persistentId) { this.mHttpManager = new HttpManager(); this.PersistentId = persistentId; }
/// <summary> /// 以指定的分片上传进度记录器和分片上传记录文件名构建上传管理器 /// /// 可以指定这两个参数来使分片上传支持断点续传功能 /// </summary> /// <param name="recorder">分片上传进度记录器</param> /// <param name="generator">分片上传进度记录文件名</param> public UploadManager(ResumeRecorder recorder, KeyGenerator generator) { this.httpManager = new HttpManager(); this.resumeRecorder = recorder; this.keyGenerator = generator; }
/// <summary> /// 默认上传管理器 /// </summary> public UploadManager() { this.httpManager = new HttpManager(); this.resumeRecorder = null; this.keyGenerator = null; }