public ImportExecutor(HttpPostedFile file, MCS.Web.WebControls.UploadProgressResult result) { this.file = file; this.result = result; this.log = new System.Text.StringBuilder(4096); this.status = new UploadProgressStatus(); }
protected void DoFileUpload(HttpPostedFile file, MCS.Web.WebControls.UploadProgressResult result) { var fileType = Path.GetExtension(file.FileName).ToLower(); if (fileType != ".xml") { throw new InvalidDataException("上传的文件类型错误"); } ImportExecutor executor = new ImportExecutor(file, result); var rootOU = PC.SCOrganization.GetRoot(); executor.AddAction(new OguOrganizationImportAction(rootOU) { }); if (Request.Form["includeAcl"] == "includeAcl") { executor.AddAction(new OguAclImportAction(rootOU) { }); } executor.Execute(); }
private bool EnsureFileLoaded() { bool result = false; if (this.objectSet == null) { SCObjectSet aObjectSet = new SCObjectSet(); try { using (System.IO.StreamReader reader = new StreamReader(this.file.InputStream)) { aObjectSet.Load(reader); } this.objectSet = aObjectSet; result = true; } catch (Exception ex) { this.status.StatusText = "上传的文件格式错误无法解析:" + ex.Message; this.status.Response(); this.log.AppendFormat("无法读取上传的文件:" + ex.Message); } this.log.AppendLine("已读取上传的文件,正在查找对象"); this.status.MinStep = 0; this.status.CurrentStep = 0; this.status.MaxStep = 100; this.status.StatusText = "开始导入"; this.status.Response(); } return(result); }
protected void DoFileUpload(HttpPostedFile file, MCS.Web.WebControls.UploadProgressResult result) { var fileType = Path.GetExtension(file.FileName).ToLower(); if (fileType != ".xml") { throw new InvalidDataException("上传的文件类型错误"); } ImportExecutor exec = new ImportExecutor(file, result); exec.AddAction(new AppImportAction() { CopyMode = Request.Form["mergeMode"] == "copyMode", IncludeRoles = Request.Form["iRoles"] == "iRoles", IncludeAcls = Request.Form["iAcl"] == "iAcl", IncludePermissions = Request.Form["iFun"] == "iFun", IncludeRoleDefinitions = Request.Form["iDef"] == "iDef", IncludeRoleMembers = Request.Form["iRoleMembers"] == "iRoleMembers", IncludeRoleConditions = Request.Form["iRoleConditions"] == "iRoleConditions" }); exec.Execute(); return; }
protected void DoDeepFileUpload(HttpPostedFile file, MCS.Web.WebControls.UploadProgressResult result) { if (Path.GetExtension(file.FileName).ToLower() != ".xml") { throw new InvalidDataException("上传的文件类型错误"); } string oguId = Request.Form["parentId"]; if (string.IsNullOrEmpty(oguId)) { throw new HttpException("没有使用parentId"); } Util.EnsureOperationSafe(); PC.SCOrganization parent = oguId == PC.SCOrganization.RootOrganizationID ? PC.SCOrganization.GetRoot() : (PC.SCOrganization)DbUtil.GetEffectiveObject(oguId, "当前组织不存在或已删除"); ImportExecutor executor = new ImportExecutor(file, result); if (Request.Form["includeAcl"] == "includeAcl") { executor.AddAction(new OguAclImportAction(parent) { }); } if (Request.Form["includeUser"] == "includeUser") { executor.AddAction(new OguUserImportAction(parent) { IncludeSecretaries = Request.Form["includeSecretary"] == "includeSecretary" }); } if (Request.Form["includeGroup"] == "includeGroup") { executor.AddAction(new OguGroupImportAction(parent) { IncludeConditions = Request.Form["includeGroupConditions"] == "includeGroupConditions", IncludeMembers = Request.Form["includeGroupMembers"] == "includeGroupMembers" }); } executor.AddAction(new OguFullImportAction(parent) { IncludeOrganizations = this.Request.Form["includeOrg"] == "includeOrg", IncludeAcl = this.Request.Form["includeAcl"] == "includeAcl", IncludeUser = this.Request.Form["includeUser"] == "includeUser", IncludeSecretaries = this.Request.Form["includeSecretary"] == "includeSecretary", IncludeGroup = this.Request.Form["includeGroup"] == "includeGroup", IncludeGroupConditions = this.Request.Form["includeGroupConditions"] == "includeGroupConditions", IncludeGroupMembers = this.Request.Form["includeGroupMembers"] == "includeGroupMembers" }); executor.Execute(); }
private void ProcessUploadData() { HttpResponse response = HttpContext.Current.Response; HttpRequest request = HttpContext.Current.Request; try { ExceptionHelper.FalseThrow(request["postedData"].IsNotEmpty(), Translator.Translate(Define.DefaultCulture, "没有上传的数据")); ProcessProgress.Current.RegisterResponser(UploadProgressResponser.Instance); response.Write(new string(' ', 4096)); this.ClientExtraPostedData = request.Form["clientExtraPostedData"]; PostProgressPrepareDataEventArgs prepareDataArgs = new PostProgressPrepareDataEventArgs() { SerializedData = request["postedData"] }; OnPrepareData(this, prepareDataArgs); if (prepareDataArgs.DeserializedData == null) { prepareDataArgs.DeserializedData = (IList)JSONSerializerExecute.DeserializeObject(prepareDataArgs.SerializedData); } response.Buffer = false; response.BufferOutput = false; UploadProgressResult result = new UploadProgressResult(); OnDoPostedData(this, new PostProgressDoPostedDataEventArgs() { Result = result, ClientExtraPostedData = this.ClientExtraPostedData, Steps = prepareDataArgs.DeserializedData }); result.Response(); } catch (System.Exception ex) { response.Write(string.Format("<script type=\"text/javascript\">top.document.getElementById(\"resetInterfaceButton\").click();</script>")); WebUtility.ResponseShowClientErrorScriptBlock(ex.Message, ex.StackTrace, Translator.Translate(Define.DefaultCulture, "错误")); } finally { response.End(); } }
protected void DoFileUpload(HttpPostedFile file, MCS.Web.WebControls.UploadProgressResult result) { var fileType = Path.GetExtension(file.FileName).ToLower(); if (fileType != ".xml") { throw new InvalidDataException("上传的文件类型错误"); } ImportExecutor exec = new ImportExecutor(file, result); exec.AddAction(new RoleConstMembersImportAction(this.ctlUpload.Tag)); exec.Execute(); return; }
protected void DoFileUpload(HttpPostedFile file, MCS.Web.WebControls.UploadProgressResult result) { var fileType = Path.GetExtension(file.FileName).ToLower(); if (fileType != ".xml") { throw new InvalidDataException("上传的文件类型错误"); } ImportExecutor executor = new ImportExecutor(file, result); executor.AddAction(new AUSchemaImportAction() { IncludeSchemaRoles = Request.Form["includeSchemaRoles"] == "includeSchemaRoles", TargetCategory = Request.QueryString["category"] }); executor.Execute(); }
protected void DoFileUpload(HttpPostedFile file, MCS.Web.WebControls.UploadProgressResult result) { var fileType = Path.GetExtension(file.FileName).ToLower(); if (fileType != ".xml") { throw new InvalidDataException("上传的文件类型错误"); } ImportExecutor executor = new ImportExecutor(file, result); executor.AddAction(new AllGroupImportAction() { IncludeConditions = Request.Form["includeConditionMembers"] == "includeConditionMembers", IncludeMembers = Request.Form["includeConstMembers"] == "includeConstMembers" }); executor.Execute(); }
protected void DoFileUpload(HttpPostedFile file, MCS.Web.WebControls.UploadProgressResult result) { var fileType = Path.GetExtension(file.FileName).ToLower(); if (fileType != ".xml") { throw new InvalidDataException("上传的文件类型错误"); } ImportExecutor exec = new ImportExecutor(file, result); exec.AddAction(new PermissionImportAction(this.ctlUpload.Tag) { ApplicationId = Request.Form["parentId"], CopyMode = Request.Form["mergeMode"] == "copyMode" }); exec.Execute(); return; }
protected void DoFileUpload(HttpPostedFile file, MCS.Web.WebControls.UploadProgressResult result) { var fileType = Path.GetExtension(file.FileName).ToLower(); if (fileType != ".xml") { throw new InvalidDataException("上传的文件类型错误"); } ImportExecutor executor = new ImportExecutor(file, result); executor.AddAction(new AdminUnitImportAction() { ParentID = this.ctlUpload.Tag, IncludeRoleMembers = Request.Form["includeSchemaRoles"] == "includeSchemaRoles", IncludeScopeConditions = Request.Form["includeScopeCondition"] == "includeScopeCondition", ImportSubUnits = Request.Form["deepImport"] == "deepImport" }); executor.Execute(); }
private void ProcessUploadFile() { HttpResponse response = HttpContext.Current.Response; HttpRequest request = HttpContext.Current.Request; try { ExceptionHelper.FalseThrow(request.Files.Count > 0 && request.Files[0].ContentLength > 0, Translator.Translate(Define.DefaultCulture, "请选择一个上传文件")); ProcessProgress.Current.RegisterResponser(UploadProgressResponser.Instance); response.Write(new string(' ', 4096)); this.PostedData = request.Form["postedData"]; response.Buffer = false; response.BufferOutput = false; UploadProgressResult result = new UploadProgressResult(); if (DoUploadProgress != null) { DoUploadProgress(request.Files[0], result); } result.Response(); } catch (System.Exception ex) { response.Write(string.Format("<script type=\"text/javascript\">top.document.getElementById(\"resetInterfaceButton\").click();</script>")); WebUtility.ResponseShowClientErrorScriptBlock(ex.Message, ex.StackTrace, Translator.Translate(Define.DefaultCulture, "错误")); } finally { response.End(); } }
protected void uploadProgress_DoUploadProgress(HttpPostedFile file, UploadProgressResult result) { ExceptionHelper.FalseThrow(Path.GetExtension(file.FileName).ToLower() == ".xml", "'{0}'权限矩阵必须是xml电子表格", file.FileName); UploadProgressStatus status = new UploadProgressStatus(); status.CurrentStep = 1; status.MinStep = 0; status.MaxStep = 20; WfMatrix.ImportExistMatrixFromExcelXml(file.InputStream, () => { if (status.CurrentStep + 1 < status.MaxStep) { status.CurrentStep++; } status.Response(); }, Request["processkey"]); status.MaxStep = 20; status.Response(); string logInfo = string.Format("导入完成"); PrepareResultInfo(result, logInfo); }
protected void uploadProgress_DoUploadProgress(HttpPostedFile file, UploadProgressResult result) { var fileType = Path.GetExtension(file.FileName).ToLower(); if (fileType != ".xml" && fileType != ".zip") { throw new InvalidDataException("请上传一个xml或zip文件!"); } if (fileType == ".xml") { var logger = ParseXmlFile(file); result.DataChanged = true; result.CloseWindow = false; result.ProcessLog = logger.ToString(); return; } if (fileType == ".zip") { var logger = ParseZipFile(file); result.DataChanged = true; result.CloseWindow = false; result.ProcessLog = logger.ToString(); return; } }
protected void uploadProgress_DoUploadProgress(HttpPostedFile file, UploadProgressResult result) { string tag = uploadProgress.Tag; const int baseRowIndex = 3; ExceptionHelper.FalseThrow(Path.GetExtension(file.FileName).ToLower() == ".xml", "'{0}' must be a xml file.", file.FileName); WorkbookNode workbook = new WorkbookNode(); workbook.Load(file.InputStream); ExceptionHelper.FalseThrow(workbook.Worksheets.Contains("PC Tracker Form"), "The workbook must contains a 'PC Tracker Form' worksheet."); Dictionary<string, CellLocation> fieldLocations = BuildNameColumnDictionary(workbook); TableNode table = workbook.Worksheets["PC Tracker Form"].Table; StringBuilder strB = new StringBuilder(); if (table.Rows.Count > 3) { int currentRowIndex = baseRowIndex; UploadProgressStatus status = new UploadProgressStatus(); status.CurrentStep = 1; status.MinStep = 0; status.MaxStep = table.Rows.Count - currentRowIndex; int currentVirtualRow = baseRowIndex; for (int i = status.MinStep; i < status.MaxStep; i++) { currentRowIndex = baseRowIndex + i; RowNode row = table.Rows[currentRowIndex]; if (row.Index > 0) currentVirtualRow = row.Index; else currentVirtualRow++; if (strB.Length > 0) strB.Append("\n"); strB.AppendFormat("Processed={0}, Row={1}:", (i + 1), currentVirtualRow); foreach (KeyValuePair<string, CellLocation> kp in fieldLocations) { CellNode cell = row.GetCellByIndex(kp.Value.Column); strB.AppendFormat(";Name={0}, Value={1}", kp.Key, cell != null ? cell.Data.Value : string.Empty); } status.CurrentStep = i; status.Response(); int ms = 1000; if (Request.Form["longProgress"] == "true") ms = 2000; Thread.Sleep(ms); //假装等待 } status.CurrentStep = status.MaxStep; status.Response(); } result.DataChanged = true; result.CloseWindow = false; result.ProcessLog = strB.ToString(); }
private static void PrepareResultInfo(UploadProgressResult result, string logInfo) { result.DataChanged = true; result.CloseWindow = false; result.ProcessLog = logInfo; }
/// <summary> /// 上传属性定义 /// </summary> /// <param name="file"></param> /// <param name="result"></param> protected void ImportSOARole_DoUploadProgress(HttpPostedFile file, UploadProgressResult result) { var fileType = Path.GetExtension(file.FileName).ToLower(); if (string.Compare(fileType, ".xml", true) == 0) { StringBuilder logger = new StringBuilder(); try { CheckEditMode(); var xmlDoc = XDocument.Load(file.InputStream); var wfProcesses = xmlDoc.Descendants("Root"); XElementFormatter formatter = new XElementFormatter(); UploadProgressStatus status = new UploadProgressStatus(); status.CurrentStep = 1; status.MinStep = 0; status.MaxStep = wfProcesses.Count() + 1; logger.AppendFormat("开始导入角色属性定义...\n", file.FileName, status.MaxStep); SOARole role = new SOARole { ID = this.DefinitionID }; SOARolePropertyDefinitionAdapter.Instance.Delete(role); foreach (var wfProcess in wfProcesses) { SOARolePropertyDefinitionCollection rowsColl = (SOARolePropertyDefinitionCollection)formatter.Deserialize(wfProcess); SOARolePropertyDefinitionAdapter.Instance.Update(role, rowsColl); logger.Append("保存成功...\n"); status.CurrentStep++; status.Response(); } logger.AppendFormat("导入完成!", file.FileName); } catch (Exception ex) { logger.AppendFormat("导入错误,{0},错误堆栈:{1}", ex.Message, ex.StackTrace); } result.DataChanged = true; result.CloseWindow = false; result.ProcessLog = logger.ToString(); } }
/// <summary> /// 上传矩阵的内容(行) /// </summary> /// <param name="file"></param> /// <param name="result"></param> protected void uploadProgress_DoUploadProgress(HttpPostedFile file, UploadProgressResult result) { CheckEditMode(); var fileType = Path.GetExtension(file.FileName).ToLower(); if (fileType != ".xml" && fileType != ".xlsx") throw new SystemSupportException("'{0}' 必须是 xml 或 xlsx 文件。"); UploadProgressStatus status = new UploadProgressStatus(); status.CurrentStep = 1; status.MinStep = 0; status.MaxStep = 20; Action notifier = () => { if (status.CurrentStep + 1 < status.MaxStep) { status.CurrentStep++; } status.Response(); }; if (fileType == ".xml") { ImportFromXml(file.InputStream); } else if (fileType == ".xlsx") { ImportFromExcel2007(file.InputStream, notifier); } result.DataChanged = true; result.CloseWindow = true; }
protected void DoFileUpload(HttpPostedFile file, UploadProgressResult result) { var fileType = Path.GetExtension(file.FileName).ToLower(); if (fileType != ".xml") throw new InvalidDataException("上传的文件类型错误"); ImportExecutor exec = new ImportExecutor(file, result); exec.AddAction(new AllUserImportAction() { IncludeOrganizationRelation = Request.Form["includeOrg"] == "includeOrg", IncludeSecretaries = Request.Form["includeSecretaries"] == "includeSecretaries", IncludeGroupConstMembers = this.Request.Form["includeGroupMembers"] == "includeGroupMembers" }); exec.Execute(); }
protected void uploadProgress_DoUploadProgress(HttpPostedFile file, UploadProgressResult result) { ExceptionHelper.FalseThrow(Path.GetExtension(file.FileName).ToLower() == ".xml", "'{0}' must be a xml file.", file.FileName); WorkbookNode workbook = new WorkbookNode(); workbook.Load(file.InputStream); ExceptionHelper.FalseThrow(workbook.Worksheets.Contains("Matrix"), "The workbook must contains a 'Matrix' worksheet."); NamedLocationCollection fieldLocations = workbook.Names.ToLocations(); TableNode table = workbook.Worksheets["Matrix"].Table; StringBuilder strB = new StringBuilder(); int baseRowIndex = GetStartRow(fieldLocations); RowNode titleRow = table.GetRowByIndex(baseRowIndex); int currentRowIndex = table.Rows.IndexOf(titleRow) + 1; if (table.Rows.Count > currentRowIndex) { UploadProgressStatus status = new UploadProgressStatus(); status.CurrentStep = 1; status.MinStep = 0; status.MaxStep = table.Rows.Count - currentRowIndex; int currentVirtualRow = baseRowIndex; for (int i = status.MinStep; i < status.MaxStep; i++) { RowNode row = table.Rows[currentRowIndex]; if (row.Index > 0) currentVirtualRow = row.Index; else currentVirtualRow++; if (strB.Length > 0) strB.Append("\n"); strB.AppendFormat("Processed={0}, Row={1}:", (i + 1), currentVirtualRow); foreach (CellLocation location in fieldLocations) { CellNode cell = row.GetCellByIndex(location.Column); strB.AppendFormat(";Name={0}, Value={1}", location.Name, cell != null ? cell.Data.Value : string.Empty); } status.CurrentStep = i; status.Response(); currentRowIndex++; } status.CurrentStep = status.MaxStep; status.Response(); } result.DataChanged = true; result.CloseWindow = false; result.ProcessLog = strB.ToString(); }
protected void uploadProgress_DoUploadProgress(HttpPostedFile file, UploadProgressResult result) { var fileType = Path.GetExtension(file.FileName).ToLower(); if (fileType != ".xml" && fileType != ".xlsx") { throw new Exception("'{0}' must be a xml or xlsx file."); } UploadProgressStatus status = new UploadProgressStatus(); status.CurrentStep = 1; status.MinStep = 0; status.MaxStep = 20; Action notifier = () => { if (status.CurrentStep + 1 < status.MaxStep) { status.CurrentStep++; } status.Response(); }; if (fileType == ".xml") { WfMatrix.ImportExistMatrixFromExcelXml(file.InputStream, notifier, ProcessKey); } else if (fileType == ".xlsx") { WfMatrix.ImportExistMatrixFromExcel2007(file.InputStream, notifier, ProcessKey); } result.DataChanged = true; result.CloseWindow = true; }
private bool EnsureFileLoaded() { bool result = false; if (this.objectSet == null) { SCObjectSet aObjectSet = new SCObjectSet(); try { using (System.IO.StreamReader reader = new StreamReader(this.file.InputStream)) { aObjectSet.Load(reader); } this.objectSet = aObjectSet; result = true; } catch (Exception ex) { this.status.StatusText = "上传的文件格式错误无法解析:" + ex.Message; this.status.Response(); this.log.AppendFormat("无法读取上传的文件:" + ex.Message); } this.log.AppendLine("已读取上传的文件,正在查找对象"); this.status.MinStep = 0; this.status.CurrentStep = 0; this.status.MaxStep = 100; this.status.StatusText = "开始导入"; this.status.Response(); } return result; }