public void Value_Success() { var source = new TaskCompletionSource <bool>(); source.TrySetResult(true); ResumeHelper.Complete(ref _tcs, new ValueTask(source.Task)); Assert.True(_tcs.Task.IsCompleted); Assert.True(_tcs.Task.Result); }
public void Value_Error() { var source = new TaskCompletionSource <bool>(); var ex = new InvalidOperationException(); source.TrySetException(ex); ResumeHelper.Complete(ref _tcs, new ValueTask(source.Task)); Assert.True(_tcs.Task.IsFaulted); Assert.Same(ex, ExceptionHelper.Extract(ExceptionHelper.Extract(_tcs.Task.Exception))); }
private bool UploadFileOverlay(string file, bool overLay = false) { // string filePath = LocalFile; if (uploadResult == null) { uploadResult = new StringBuilder(); } if (putPolicy != null) { string key = Path.GetFileName(file); System.IO.Stream fs = System.IO.File.OpenRead(file); if (overLay) { putPolicy.Scope = bucket + ":" + key; } else { putPolicy.Scope = bucket; } putPolicy.SetExpires(3600); putPolicy.DeleteAfterDays = qiNiuClientCfg.DeleteAfterDays; string token = Auth.CreateUploadToken(mac, putPolicy.ToJsonString()); ResumableUploader target = new ResumableUploader(config); PutExtra extra = new PutExtra { ResumeRecordFile = ResumeHelper.GetDefaultRecordKey(file, key) }; //设置断点续传进度记录文件 uploadResult.AppendLine("record file:" + extra.ResumeRecordFile); // extra.ResumeRecordFile = "test.progress"; //todo:未实现上传进度 HttpResult result = target.UploadStream(fs, key, token, extra); if (result.Code == 200) { uploadResult.AppendLine("上传成功! "); return(true); } else { string s = $"Code={result.Code},Text={result.Text}"; uploadResult.AppendLine("uploadResult:" + s); return(false); } } uploadResult.AppendLine("成员变量putPolicy为空!"); return(false); }
/// <summary> /// 分片上传(断点续传) /// </summary> /// <param name="key"></param> /// <param name="path"></param> /// <returns></returns> public string ChunkUpload(string key, string path) { ResumableUploader resumableUploader = new ResumableUploader(ConfigUtil); PutExtra putExtra = new PutExtra { ResumeRecordFile = ResumeHelper.GetDefaultRecordKey(path, key) }; HttpResult httpResult = resumableUploader.UploadFile(path, key, TokenUtil, putExtra); return(httpResult.Text); }
private void Enqueue(TaskTask task) { lock (_queue) { _queue.Add(new IndexDueTime { Index = _index++, DueTime = task.DueTime }, task); } ResumeHelper.Resume(ref _taskQueued); }
public void FileUpload() { try { int fileid = 0; var files = Request.Form.Files; if (files.Count > 0) { var file = files.First(); if (file.Length > (200 * 1024 * 1024)) { //return Json("文件过大,不能大于200M"); } PutExtra putExtra = new PutExtra();// { ProgressHandler = UploadProgressHandler, ResumeRecordFile }; putExtra.ProgressHandler = UploadProgressHandler; putExtra.UploadController = DefaultUploadController; putExtra.ResumeRecordFile = ResumeHelper.GetDefaultRecordKey($"{Environment.CurrentDirectory}\\{file.FileName}", file.FileName); var aa = putExtra.ResumeRecordFile; putExtra.ResumeRecordFile = file.FileName + ".progress"; HttpResult result = new HttpResult(); Stream stream = file.OpenReadStream(); result = qiniu.UploadStream(file.FileName, stream, putExtra); if (result.Code == (int)HttpCode.OK) { //todo 入库文件信息 var rj = JObject.Parse(result.Text); string hash = rj["hash"].ToString(); string key = rj["key"].ToString(); var hashentity = ossfile.GetList(t => t.FileHash == hash); OssFile ossFileEntity = new OssFile { FileKey = key, FileHash = hash, FileDomain = "" }; ossfile.Insert_Return_Id(ossFileEntity, out fileid); } //检查删除文件 if (System.IO.File.Exists($"{Environment.CurrentDirectory}\\{file.FileName}")) { System.IO.File.Delete($"{Environment.CurrentDirectory}\\{file.FileName}"); } } } catch (Exception ex) { // return Json(ex.Message); } }
/// <summary> /// Determines if max level for difficulty is reached if not /// next round is initialized /// </summary> public bool NextRound() { GameModel.Level += 1; if (GameModel.Level <= DifficultySetting.MaxLevel) { ResumeModel.Level = GameModel.Level - 1; ResumeModel.MatchesNeeded = GameModel.MatchesNeeded; ResumeHelper.SetResume(ResumeModel); GameModel.MatchesNeeded += 1; InitializeRound(); return(true); } ResumeHelper.RemoveResume(ResumeModel.GameType); return(false); }
public async void Async_Cancelled() { var source = new TaskCompletionSource <bool>(); ResumeHelper.Complete(ref _tcs, new ValueTask(source.Task)); source.TrySetCanceled(); try { await _tcs.Task; } catch (Exception) { // ignored } Assert.True(_tcs.Task.IsCanceled); }
public async void Async_Error() { var source = new TaskCompletionSource <bool>(); ResumeHelper.Complete(ref _tcs, new ValueTask(source.Task)); var ex = new InvalidOperationException(); source.TrySetException(ex); try { await _tcs.Task; } catch (AggregateException g) { Assert.Same(ex, ExceptionHelper.Extract(ExceptionHelper.Extract(g))); } Assert.True(_tcs.Task.IsFaulted); }
public async ValueTask <bool> MoveNextAsync() { await ResumeHelper.Await(ref _valueReady); ResumeHelper.Clear(ref _valueReady); if (_error != null) { throw _error; } if (_done) { return(false); } Current = _value; _value = default; ResumeHelper.Resume(ref _consumed); return(true); }
/// <summary> /// 断点续传 /// </summary> /// <param name="localFile"></param> /// <returns></returns> public string ResumeUploadFile(string localFile) { if (!File.Exists(localFile)) { return("文件不存在"); } var filename = Path.GetFileName(localFile); //文件名 var extension = Path.GetExtension(localFile); //扩展名 var mac = new Mac(AccessKey, SecretKey); var rand = new Random(); string key = $"jnkj_{rand.Next()}{extension}"; Stream fs = File.OpenRead(localFile); var putPolicy = new PutPolicy { Scope = Bucket + ":" + key }; putPolicy.SetExpires(3600); putPolicy.DeleteAfterDays = 1; var token = Auth.CreateUploadToken(mac, putPolicy.ToJsonString()); var config = new Config { UseHttps = true, Zone = Zone.ZONE_CN_East, UseCdnDomains = true, ChunkSize = ChunkUnit.U512K }; var target = new ResumableUploader(config); var extra = new PutExtra { ResumeRecordFile = ResumeHelper.GetDefaultRecordKey(localFile, key) }; //设置断点续传进度记录文件 Console.WriteLine("record file:" + extra.ResumeRecordFile); extra.ResumeRecordFile = "test.progress"; var result = target.UploadStream(fs, key, token, extra); Console.WriteLine("resume upload: " + result); return(result.ToString()); }
public async Task ResumeUploadFileTest() { var mac = new Mac(AccessKey, SecretKey); var rand = new Random(); var key = $"UploadFileTest_{rand.Next()}.dat"; var filePath = LocalFile; Stream fs = File.OpenRead(filePath); var putPolicy = new PutPolicy { Scope = Bucket + ":" + key, DeleteAfterDays = 1 }; putPolicy.SetExpires(3600); var token = Auth.CreateUploadToken(mac, putPolicy.ToJsonString()); var config = new Config { UseHttps = true, Zone = Zone.ZoneCnEast, UseCdnDomains = true, ChunkSize = ChunkUnit.U512K }; var target = new ResumableUploader(config); //设置断点续传进度记录文件 var extra = new PutExtra { ResumeRecordFile = ResumeHelper.GetDefaultRecordKey(filePath, key) }; Console.WriteLine("record file:" + extra.ResumeRecordFile); extra.ResumeRecordFile = "test.progress"; var result = await target.UploadStream(fs, key, token, extra); Console.WriteLine("resume upload: " + result); Assert.Equal((int)HttpCode.OK, result.Code); }
public void Signal() { ResumeHelper.Resume(ref Resume); }
public async ValueTask Run() { await _observer.OnSubscribeAsync(this).ConfigureAwait(false); try { var done = false; while (true) { while (true) { if (IsCanceled) { return; } done = Volatile.Read(ref _done); if (_queue.TryDequeue(out var item)) { var t = _observer.OnNextAsync(item); try { await t.ConfigureAwait(false); } catch (Exception ex) { await _observer.OnErrorAsync(ex).ConfigureAwait(false); return; } } else { break; } } if (done) { break; } await ResumeHelper.Await(ref _tcs).ConfigureAwait(false); ResumeHelper.Clear(ref _tcs); } if (!IsCanceled) { if (_error == null) { await _observer.OnCompletedAsync().ConfigureAwait(false); } else { await _observer.OnErrorAsync(_error).ConfigureAwait(false); } } Dispose(); } finally { await _observer.OnFinallyAsync().ConfigureAwait(false); } }
private void Signal() { ResumeHelper.Resume(ref _tcs); }
/// <summary> /// Signals when the first task has been queued. /// </summary> /// <returns>The task to await for the queue to become non-empty.</returns> public async Task TaskQueued() { await ResumeHelper.Await(ref _taskQueued); ResumeHelper.Clear(ref _taskQueued); }
public ActionResult UploadResume(string languageType, string sourceSite, string projectName) //, string postName { if (string.IsNullOrWhiteSpace(sourceSite) || string.IsNullOrWhiteSpace(languageType) || string.IsNullOrWhiteSpace(projectName)) // || string.IsNullOrWhiteSpace(postName) { var projects = proBll.GetAllProjects(); ViewData["Projects"] = ChangeProjectModelToViewModel(projects.ToList()); return(View("Create")); } if (!sourceSite.Equals("ZL") && !sourceSite.Equals("WY")) { var projects = proBll.GetAllProjects(); ViewData["Projects"] = ChangeProjectModelToViewModel(projects.ToList()); return(View("Create")); } app = new ApplicationClass(); for (int k = 0; k < Request.Files.Count; k++) { HttpPostedFileBase file = Request.Files.Get(k); List <string> content = new List <string>(); if (file == null || file.ContentLength <= 0) { return(Content("没有文件!", "text/plain")); } string fileName = string.Format("{0}--{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), Path.GetFileName(file.FileName)); string filePath = Path.Combine(LocalResumeFolderPath, fileName); FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write); fs.Close(); file.SaveAs(filePath); Resume resume; try { object fileobj = (object)filePath; app.Visible = false; doc = app.Documents.Open( ref fileobj, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow); for (int i = 1; i <= doc.Paragraphs.Count; i++) { if (doc.Paragraphs[i].Range.Text.Equals("\r\a")) { continue; } content.Add(doc.Paragraphs[i].Range.Text.Replace(" ", " ").Replace("/", "").Replace("\v", "\r")); } doc.Close(); if (sourceSite.Equals("ZL")) { resume = ResumeHelper.getZLResumeEntity(content); } else { resume = ResumeHelper.GetWYResumeEntity(content); } switch (sourceSite) { case "ZL": resume.SourceSite = "智联招聘"; break; case "WY": resume.SourceSite = "前程无忧"; break; default: resume.SourceSite = ""; break; } resume.Id = Guid.NewGuid().ToString(); resume.FilePath = fileName; resume.UploadTime = DateTime.Now; resume.LanguageType = languageType; resume.ProjectName = projectName; ResumeBLL opt = new ResumeBLL(); opt.SaveResume(resume); } catch (Exception e) { if (doc != null) { doc.Close(); } if (app != null) { app.Quit(); } return(Content("上传异常!" + e.Message, "text/plain")); } } app.Quit(); return(RedirectToAction("Index")); }