/// <summary> /// Rolls back the specified <see cref="UploadSession" />. This cleans up the session storage for this session and /// requests. This also removes any files that were uploaded during the session. /// </summary> /// <param name="session">The <see cref="UploadSession" /> to roll back.</param> public static void RollbackSession(UploadSession session) { foreach (UploadRequest request in session.UploadRequests) CleanupRequest(request); EndSession(session); }
public ActionResult UploadResult(CustomSqlServerModel model, UploadSession session) { model.UploadSession = session; return View(model); }
/// <summary> /// Commits the specified <see cref="UploadSession" />. This completes the session so it won't be automatically /// rolled back when the session timeout expires. /// </summary> /// <param name="session">The <see cref="UploadSession" /> to commit.</param> public static void CommitSession(UploadSession session) { //session.State = UploadState.Complete; //SessionStorageProvider.SaveSession(session, false); EndSession(session); }
public ActionResult UploadResult(ValidationModel model, UploadSession session) { model.UploadSession = session; return View(model); }
internal static void EndSession(UploadSession session) { SessionStorageProvider.RemoveSession(session.UploadSessionId); if (CurrentUploadSessionInternal != null && CurrentUploadSessionInternal.UploadSessionId == session.UploadSessionId) { CurrentUploadSessionInternal = null; } }
/// <summary> /// Rolls back the specified <see cref="UploadSession" />. This cleans up the session storage for this session and /// requests. This also removes any files that were uploaded during the session. /// </summary> /// <param name="session">The <see cref="UploadSession" /> to roll back.</param> public static void RollbackSession(UploadSession session) { foreach (UploadRequest request in session.UploadRequests) { CleanupRequest(request); } EndSession(session); }
protected void uploadButton_Click(object sender, EventArgs e) { uploadResultPanel.Visible = true; uploadPanel.Visible = false; _uploadSession = SlickUploadContext.CurrentUploadSession; if (UploadSession != null && UploadSession.State == UploadState.Complete) { if (UploadSession.UploadedFiles.Count > 0) { resultsRepeater.DataSource = UploadSession.UploadedFiles; resultsRepeater.DataBind(); } } }
public ActionResult UploadResult(UploadSession session) { if (session != null && session.State == UploadState.Complete && session.UploadedFiles.Count > 0) { // Simulate post processing for (int i = 0; i <= 100; i++) { session.ProcessingStatus["percentComplete"] = i.ToString(); session.ProcessingStatus["percentCompleteText"] = i.ToString() + "%"; SlickUploadContext.UpdateSession(session); System.Threading.Thread.Sleep(100); } } return View(session); }
internal static void CompleteSession(UploadSession session, UploadErrorType errorType) { bool hasErrored = (errorType != UploadErrorType.None); int successfulFiles = 0; if (!hasErrored) { foreach (UploadRequest request in session.UploadRequests) { if (session.CancelledRequests != null && Array.IndexOf<string>(session.CancelledRequests, request.UploadRequestId) != -1) CancelRequest(request); // TODO: we assume if it is uploading that it is almost done and do nothing. Instead, we should block until it becomes not uploading, // or nuke it if it doesn't finish shortly /*if (request.State == UploadState.Uploading) throw new Exception("Request " + request.UploadRequestId + " is still processing."); if (request.State == UploadState.Uploading) CancelRequest(request);*/ // TODO: should we consider cancels as not errored? I guess not, because we still consider it an error if everything was cancelled. Maybe revisit when we do AllowPartialError if (request.ErrorType != UploadErrorType.None) hasErrored = true; else successfulFiles += request._uploadedFilesInternal.Count; } } if (hasErrored && errorType == UploadErrorType.None && session.UploadProfile.AllowPartialError && successfulFiles > 0) hasErrored = false; if (hasErrored && errorType == UploadErrorType.None) { // Try to find an error foreach (UploadRequest request in session.UploadRequests) { if (request.ErrorType != UploadErrorType.None) { errorType = request.ErrorType; break; } } if (errorType == UploadErrorType.None) errorType = UploadErrorType.Other; } session.State = !hasErrored ? UploadState.Complete : UploadState.Error; session.ErrorType = errorType; UpdateSession(session); // TODO: what happens here if a request is still in progress for some reason. Can we guarantee that never happens? foreach (UploadRequest request in session.UploadRequests) { bool isFailedRequest = (session.FailedRequests != null && Array.IndexOf<string>(session.FailedRequests, request.UploadRequestId) != -1); if (hasErrored || request.ErrorType != UploadErrorType.None || isFailedRequest) { if (isFailedRequest) { request.State = UploadState.Error; if (request.ErrorType == UploadErrorType.None) request.ErrorType = UploadErrorType.FailedByClient; } CleanupRequest(request); } } }
/// <summary> /// Updates the specified <see cref="UploadSession" /> in the current session storage provider. /// </summary> /// <param name="session">The <see cref="UploadSession" /> to update.</param> public static void UpdateSession(UploadSession session) { SessionStorageProvider.SaveSession(session, false); }
internal static void EndSession(UploadSession session) { SessionStorageProvider.RemoveSession(session.UploadSessionId); if (CurrentUploadSessionInternal != null && CurrentUploadSessionInternal.UploadSessionId == session.UploadSessionId) CurrentUploadSessionInternal = null; }
public ActionResult IndexUploadResult(OverviewModel model, UploadSession session) { model.UploadSession = session; return View(model); }
// // GET: /Upload/ /// <summary> /// path数据结构 /// 001_西山区|4567_虹桥立交|8889_日常巡检 解析为三个文件夹 /// 西山区(001) /// | /// |---虹桥立交(4567) /// | /// |----日常巡检(8889) /// </summary> public JsonResult Add(UploadSession uploadSession, string userId, string spaceId, string userName, string depId, string visible, string path) { //var userId = _requestProvider["UserId"]; //var spaceId = _requestProvider["SpaceId"]; //var userName = _requestProvider["UserName"]; //var depId = _requestProvider["DepId"]; //var visible = _requestProvider["Visible"]; //var path = _requestProvider["Path"]; _logger.Info("DocumentController 添加文档."); if (string.IsNullOrWhiteSpace(userId)) { _logger.Error("文档参数错误, 缺少 UserId 参数."); throw new HttpResponseException(HttpStatusCode.BadRequest); } _logger.InfoFormat("文档参数userId:{0}", userId); if (string.IsNullOrWhiteSpace(userName)) { _logger.Error("文档参数错误, 缺少 userName 参数."); throw new HttpResponseException(HttpStatusCode.BadRequest); } _logger.InfoFormat("文档参数userName:{0}", userName); if (string.IsNullOrWhiteSpace(depId)) { _logger.Error("文档参数缺少 depId 参数,默认设置为空"); depId = string.Empty; } _logger.InfoFormat("文档参数depId:{0}", depId); var visiblity = Visible.Public; if (!string.IsNullOrWhiteSpace(visible)) { visiblity = (Visible)Enum.Parse(typeof(Visible), visible); _logger.InfoFormat("文档参数为:{0}", visiblity); } else { _logger.Info("文档参数缺少 visible 参数,默认设置为Public"); } SpaceObject space; if (string.IsNullOrWhiteSpace(path)) { _logger.Info("文档参数缺少 path 参数,采用spaceId参数"); space = string.IsNullOrWhiteSpace(spaceId) ? _spaceService.GetDefaultSpace() : _spaceService.GetSpace(spaceId); } else { _logger.InfoFormat("文档参数path:{0}", path); space = _spaceService.MakeSpace(string.Empty, path, userId, userName, depId, visiblity); } if (uploadSession.UploadedFiles.Count == 0) { _logger.Error("文档参数错误, 上传文件失败."); throw new HttpResponseException(HttpStatusCode.BadRequest); } _logger.Info(string.Format("Add Document, spaceId:[{0}];userId:[{1}];userName:[{2}]。", spaceId, userId, userName)); try { var file = uploadSession.UploadedFiles.First(); var document = DocumentBuilder.Build(file, space.Id.ToString(), space.SpaceSeqNo, space.SpaceName, userId, userName, depId, visiblity); var documentObj = _documentService.Add(document); if (documentObj.DocumentCategory != DocumentCategory.Image) { documentObj.DisplayPath = documentObj.PreviewUrl; } return Json(documentObj.ToObject<DocumentContract>()); } catch (Exception ex) { _logger.Error(ex.Message); _logger.Error(ex.StackTrace); throw new HttpResponseException(HttpStatusCode.InternalServerError); } }
internal static void CompleteSession(UploadSession session, UploadErrorType errorType) { bool hasErrored = (errorType != UploadErrorType.None); int successfulFiles = 0; if (!hasErrored) { foreach (UploadRequest request in session.UploadRequests) { if (session.CancelledRequests != null && Array.IndexOf <string>(session.CancelledRequests, request.UploadRequestId) != -1) { CancelRequest(request); } // TODO: we assume if it is uploading that it is almost done and do nothing. Instead, we should block until it becomes not uploading, // or nuke it if it doesn't finish shortly /*if (request.State == UploadState.Uploading) * throw new Exception("Request " + request.UploadRequestId + " is still processing."); * if (request.State == UploadState.Uploading) * CancelRequest(request);*/ // TODO: should we consider cancels as not errored? I guess not, because we still consider it an error if everything was cancelled. Maybe revisit when we do AllowPartialError if (request.ErrorType != UploadErrorType.None) { hasErrored = true; } else { successfulFiles += request._uploadedFilesInternal.Count; } } } if (hasErrored && errorType == UploadErrorType.None && session.UploadProfile.AllowPartialError && successfulFiles > 0) { hasErrored = false; } if (hasErrored && errorType == UploadErrorType.None) { // Try to find an error foreach (UploadRequest request in session.UploadRequests) { if (request.ErrorType != UploadErrorType.None) { errorType = request.ErrorType; break; } } if (errorType == UploadErrorType.None) { errorType = UploadErrorType.Other; } } session.State = !hasErrored ? UploadState.Complete : UploadState.Error; session.ErrorType = errorType; UpdateSession(session); // TODO: what happens here if a request is still in progress for some reason. Can we guarantee that never happens? foreach (UploadRequest request in session.UploadRequests) { bool isFailedRequest = (session.FailedRequests != null && Array.IndexOf <string>(session.FailedRequests, request.UploadRequestId) != -1); if (hasErrored || request.ErrorType != UploadErrorType.None || isFailedRequest) { if (isFailedRequest) { request.State = UploadState.Error; if (request.ErrorType == UploadErrorType.None) { request.ErrorType = UploadErrorType.FailedByClient; } } CleanupRequest(request); } } }
public ActionResult Index(UploadSession session) { return View(session); }
public ActionResult ClientApiUploadResult(UploadSession session) { return View(session); }
public ActionResult UploadResult(UploadSession session) { return View(session); }
public ActionResult Upload(UploadSession session, string spaceId) { _logger.Info("DocumentController 添加文档"); try { var files = session.UploadedFiles; var userId = _contextService.UserId; var userName = _contextService.NickName; var depId = _contextService.DepId; var space = _spaceService.GetSpace(spaceId); _logger.Info(string.Format("Add Document, spaceId:[{0}];spaceSeqNo:[{1}], spaceName:[{2}], userId:[{3}];userName:[{4}]。", space.Id, space.SpaceSeqNo, space.SpaceName, userId, userName)); var documents = new List<DocumentObject>(); foreach (var file in files) { var document = DocumentBuilder.Build(file, space.Id.ToString(), space.SpaceSeqNo, space.SpaceName, userId, userName, depId, Visible.Public); documents.Add(document); } var contracts = _documentService.Add(documents); return Json(new UploadViewModel(ErrorMessages.Success, ErrorMessages.GetErrorMessages(ErrorMessages.Success), contracts)); } catch (Exception ex) { _logger.Error(ex.StackTrace); _logger.Error(ex.Message); return Json(new UploadViewModel(ErrorMessages.UploadFailed, ex.Message)); } }