public ActionResult SheetDataStructure(int index) { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; //set current stepinfo based on index if (TaskManager != null) { TaskManager.SetCurrent(index); // remove if existing TaskManager.RemoveExecutedStep(TaskManager.Current()); } SelectSheetFormatModel model = new SelectSheetFormatModel(); // when jumping back to this step // check if sheet format is selected if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_FORMAT)) { if (!String.IsNullOrEmpty(Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT]))) { model.SelectedSheetFormat = TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT].ToString(); } } model.StepInfo = TaskManager.Current(); return(PartialView(model)); }
public ActionResult SheetSelectMetaData(int index) { MetadataStructureManager msm = new MetadataStructureManager(); try { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; //set current stepinfo based on index if (TaskManager != null) { TaskManager.SetCurrent(index); // remove if existing TaskManager.RemoveExecutedStep(TaskManager.Current()); } SelectMetaDataModel model = new SelectMetaDataModel(); //Load available metadata structures IEnumerable <MetadataStructure> metadataStructureList = msm.Repo.Get(); foreach (MetadataStructure metadataStructure in metadataStructureList) { if (xmlDatasetHelper.IsActive(metadataStructure.Id) && xmlDatasetHelper.HasEntityType(metadataStructure.Id, "bexis.dlm.entities.data.dataset")) { model.AvailableMetadata.Add(new Tuple <long, string>(metadataStructure.Id, metadataStructure.Name)); } } //Sort the metadata structures model.AvailableMetadata.Sort((md1, md2) => md1.Item1.CompareTo(md2.Item1)); //If there's already a selected Metadata schema, load its id into the model if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SCHEMA)) { model.SelectedMetaDataId = Convert.ToInt64(TaskManager.Bus[EasyUploadTaskManager.SCHEMA]); } //if the title was changed at some point during the upload, load the title into the model if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE)) { model.DescriptionTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]); } //if it wasn't changed yet, the default title is the filename else { model.DescriptionTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]); } model.StepInfo = TaskManager.Current(); return(PartialView(model)); } finally { msm.Dispose(); } }
public ActionResult SheetDataStructure(int index) { /* SKIP BECAUSE ONLY ONE SELECTION IS POSSIBLE * * TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; * * //set current stepinfo based on index * if (TaskManager != null) * { * TaskManager.SetCurrent(index); * * // remove if existing * TaskManager.RemoveExecutedStep(TaskManager.Current()); * } * * SelectSheetFormatModel model = new SelectSheetFormatModel(); * * // when jumping back to this step * // check if sheet format is selected * if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_FORMAT)) * { * if (!String.IsNullOrEmpty(Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT]))) * { * model.SelectedSheetFormat = TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT].ToString(); * } * } * * model.StepInfo = TaskManager.Current(); */ TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; if (TaskManager != null) { // set SHEET_FORMAT TaskManager.AddToBus(EasyUploadTaskManager.SHEET_FORMAT, "TopDown"); TaskManager.Current().SetValid(true); if (TaskManager.Current().IsValid()) { TaskManager.GoToNext(); Session["TaskManager"] = TaskManager; ActionInfo actionInfo = TaskManager.Current().GetActionInfo; return(RedirectToAction(actionInfo.ActionName, actionInfo.ControllerName, new RouteValueDictionary { { "area", actionInfo.AreaName }, { "index", TaskManager.GetCurrentStepInfoIndex() } })); } } return(PartialView(new SelectSheetFormatModel())); }
public ActionResult Verification(object[] data) { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; SelectVerificationModel model = new SelectVerificationModel(); model.StepInfo = TaskManager.Current(); //convert all rowmodels to tuples for the next steps if (TaskManager != null) { TaskManager.Current().SetValid(false); if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.ROWS)) { List <RowModel> rows = (List <RowModel>)TaskManager.Bus[EasyUploadTaskManager.ROWS]; model.Rows = rows; bool allSelectionMade = true; foreach (var r in rows) { if (r.SelectedDataAttribute == null || r.SelectedDataType == null || r.SelectedUnit == null) { allSelectionMade = false; model.ErrorList.Add(new Error(ErrorType.Other, "Some Areas are not selected.")); break; } } TaskManager.Current().SetValid(allSelectionMade); } else { model.ErrorList.Add(new Error(ErrorType.Other, "Some Areas are not selected.")); } if (TaskManager.Current().valid == true) { TaskManager.AddExecutedStep(TaskManager.Current()); TaskManager.GoToNext(); Session["TaskManager"] = TaskManager; ActionInfo actionInfo = TaskManager.Current().GetActionInfo; return(RedirectToAction(actionInfo.ActionName, actionInfo.ControllerName, new RouteValueDictionary { { "area", actionInfo.AreaName }, { "index", TaskManager.GetCurrentStepInfoIndex() } })); } else { TaskManager.Current().SetStatus(StepStatus.error); //reload model model.StepInfo = TaskManager.Current(); } } return(PartialView(model)); }
public ActionResult SelectAFile(int index) { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; //set current stepinfo based on index if (TaskManager != null) { TaskManager.SetCurrent(index); } //Get Bus infomations SelectFileViewModel model = new SelectFileViewModel(); if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.FILENAME)) { model.SelectedFileName = TaskManager.Bus[EasyUploadTaskManager.FILENAME].ToString(); } //get datastuctureType model.SupportedFileExtentions = supportedExtensions; //Get StepInfo model.StepInfo = TaskManager.Current(); model.serverFileList = GetServerFileList(); return(PartialView(model)); }
public ActionResult AddSelectedDatasetStructureToBus(string format) { SelectSheetFormatModel model = new SelectSheetFormatModel(); EasyUploadTaskManager TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; if (!String.IsNullOrEmpty(format) && validateSheetFormat(format)) { //Valid sheet format was selected, add it to the bus TaskManager.AddToBus(EasyUploadTaskManager.SHEET_FORMAT, format); } else { //No valid format was selected, display an error model.ErrorList.Add(new Error(ErrorType.Other, "Please select a sheet format.")); } Session["TaskManager"] = TaskManager; //create Model model.StepInfo = TaskManager.Current(); //Make sure the selected sheet is correctly displayed model.SelectedSheetFormat = format; //Stay on the same page return(PartialView("SheetDataStructure", model)); }
public ActionResult SheetDataStructure(object[] data) { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; SelectSheetFormatModel model = new SelectSheetFormatModel(); model.StepInfo = TaskManager.Current(); if (TaskManager != null) { TaskManager.Current().SetValid(false); if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_FORMAT)) //Check if there is a Sheet Format on the bus //it's only added to the bus if it's valid so there's no need to double check that { TaskManager.Current().SetValid(true); } else { model.ErrorList.Add(new Error(ErrorType.Other, "Please select a sheet format.")); //No Format selected yet } if (TaskManager.Current().valid == true) //Jump to the next step { TaskManager.AddExecutedStep(TaskManager.Current()); TaskManager.GoToNext(); Session["TaskManager"] = TaskManager; ActionInfo actionInfo = TaskManager.Current().GetActionInfo; return(RedirectToAction(actionInfo.ActionName, actionInfo.ControllerName, new RouteValueDictionary { { "area", actionInfo.AreaName }, { "index", TaskManager.GetCurrentStepInfoIndex() } })); } else //Stay on the same page { TaskManager.Current().SetStatus(StepStatus.error); //reload model model.StepInfo = TaskManager.Current(); } } return(PartialView(model)); }
public ActionResult SaveMetaDescription(object[] data) { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; SelectMetaDataModel model = new SelectMetaDataModel(); if (TaskManager != null) { //Grab the description from the Http-Request and store it in the TaskManager foreach (string key in Request.Form.AllKeys) { if ("DescriptionTitle" == key) { model.DescriptionTitle = Request.Form[key]; TaskManager.AddToBus(EasyUploadTaskManager.DESCRIPTIONTITLE, model.DescriptionTitle); } } TaskManager.Current().SetValid(true); } //No need to update the model because the response will just be ignored in the calling javascript return(PartialView("SheetSelectMetaData", model)); }
public ActionResult Summary(object[] data) { MetadataStructureManager msm = new MetadataStructureManager(); try { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; EasyUploadSummaryModel model = new EasyUploadSummaryModel(); model.StepInfo = TaskManager.Current(); model.ErrorList = FinishUpload(TaskManager); if (model.ErrorList.Count > 0) { #region Populate model with data from the TaskManager if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.FILENAME)) { model.DatasetTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]); } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SCHEMA)) { long id = Convert.ToInt64(TaskManager.Bus[EasyUploadTaskManager.SCHEMA]); model.MetadataSchemaTitle = msm.Repo.Get(m => m.Id == id).FirstOrDefault().Name; } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_FORMAT)) { model.FileFormat = TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT].ToString(); } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_HEADER_AREA)) { string selectedHeaderAreaJsonArray = TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA].ToString(); int[] areaHeaderValues = JsonConvert.DeserializeObject <int[]>(selectedHeaderAreaJsonArray); if (model.FileFormat.ToLower() == "topdown") { model.NumberOfHeaders = (areaHeaderValues[3]) - (areaHeaderValues[1]) + 1; } if (model.FileFormat.ToLower() == "leftright") { model.NumberOfHeaders = (areaHeaderValues[2]) - (areaHeaderValues[0]) + 1; } } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_DATA_AREA)) { List <string> selectedDataAreaJsonArray = (List <string>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA]; List <int[]> areaDataValuesList = new List <int[]>(); foreach (string area in selectedDataAreaJsonArray) { areaDataValuesList.Add(JsonConvert.DeserializeObject <int[]>(area)); } foreach (int[] areaDataValues in areaDataValuesList) { if (model.FileFormat.ToLower() == "leftright") { model.NumberOfData = (areaDataValues[3]) - (areaDataValues[1]) + 1; } if (model.FileFormat.ToLower() == "topdown") { model.NumberOfData = (areaDataValues[2]) - (areaDataValues[0]) + 1; } } } #endregion Populate model with data from the TaskManager return(PartialView("EasyUploadSummary", model)); } else { return(null); } } finally { msm.Dispose(); } }
public ActionResult Verification(int index) { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; List <Dlm.Entities.DataStructure.Unit> tempUnitList = new List <Dlm.Entities.DataStructure.Unit>(); List <DataType> allDataypes = new List <DataType>(); List <DataAttribute> allDataAttributes = new List <DataAttribute>(); using (IUnitOfWork unitOfWork = this.GetUnitOfWork()) { //set current stepinfo based on index if (TaskManager != null) { TaskManager.SetCurrent(index); // remove if existing TaskManager.RemoveExecutedStep(TaskManager.Current()); } SelectVerificationModel model = new SelectVerificationModel(); List <DataTypeInfo> dataTypeInfos = new List <DataTypeInfo>(); List <UnitInfo> unitInfos = new List <UnitInfo>(); List <DataAttrInfo> dataAttributeInfos = new List <DataAttrInfo>(); List <EasyUploadSuggestion> suggestions = new List <EasyUploadSuggestion>(); List <string> headers = new List <string>(); tempUnitList = unitOfWork.GetReadOnlyRepository <Dlm.Entities.DataStructure.Unit>().Get().ToList(); allDataypes = unitOfWork.GetReadOnlyRepository <DataType>().Get().ToList(); allDataAttributes = unitOfWork.GetReadOnlyRepository <DataAttribute>().Get().ToList(); //Important for jumping back to this step if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.ROWS)) { model.Rows = (List <RowModel>)TaskManager.Bus[EasyUploadTaskManager.ROWS]; } // get all DataTypes for each Units foreach (Dlm.Entities.DataStructure.Unit unit in tempUnitList) { UnitInfo unitInfo = new UnitInfo(); unitInfo.UnitId = unit.Id; unitInfo.Description = unit.Description; unitInfo.Name = unit.Name; unitInfo.Abbreviation = unit.Abbreviation; unitInfo.DimensionId = unit.Dimension.Id; if (unit.Name.ToLower() == "none") { foreach (DataType fullDataType in allDataypes) { DataTypeInfo dataTypeInfo = new DataTypeInfo(); dataTypeInfo.DataTypeId = fullDataType.Id; dataTypeInfo.Description = fullDataType.Description; dataTypeInfo.Name = fullDataType.Name; unitInfo.DataTypeInfos.Add(dataTypeInfo); } unitInfos.Add(unitInfo); } else { Boolean hasDatatype = false; //Make sure only units that have at least one datatype are shown foreach (DataType dummyDataType in unit.AssociatedDataTypes) { if (!hasDatatype) { hasDatatype = true; } DataTypeInfo dataTypeInfo = new DataTypeInfo(); DataType fullDataType = allDataypes.Where(p => p.Id == dummyDataType.Id).FirstOrDefault(); dataTypeInfo.DataTypeId = fullDataType.Id; dataTypeInfo.Description = fullDataType.Description; dataTypeInfo.Name = fullDataType.Name; unitInfo.DataTypeInfos.Add(dataTypeInfo); } if (hasDatatype) { unitInfos.Add(unitInfo); } } } //Sort the units by name unitInfos.Sort(delegate(UnitInfo u1, UnitInfo u2) { return(String.Compare(u1.Name, u2.Name, StringComparison.InvariantCultureIgnoreCase)); }); TaskManager.AddToBus(EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS, unitInfos); // all datatypesinfos dataTypeInfos = unitInfos.SelectMany(u => u.DataTypeInfos).GroupBy(d => d.DataTypeId).Select(g => g.Last()).ToList(); TaskManager.AddToBus(EasyUploadTaskManager.ALL_DATATYPES, dataTypeInfos); //Setall Data AttrInfos to Session -> default allDataAttributes.ForEach(d => dataAttributeInfos.Add(new DataAttrInfo(d.Id, d.Unit.Id, d.DataType.Id, d.Description, d.Name, d.Unit.Dimension.Id))); Session["DataAttributes"] = dataAttributeInfos; string filePath = TaskManager.Bus[EasyUploadTaskManager.FILEPATH].ToString(); string selectedHeaderAreaJson = TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA].ToString(); FileStream fis = null; fis = new FileStream(filePath, FileMode.Open, FileAccess.Read); using (ExcelPackage ep = new ExcelPackage(fis)) { fis.Close(); ExcelWorkbook excelWorkbook = ep.Workbook; ExcelWorksheet firstWorksheet = excelWorkbook.Worksheets[1]; string sheetFormatString = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT]); SheetFormat sheetFormat = 0; Enum.TryParse <SheetFormat>(sheetFormatString, true, out sheetFormat); headers = GetExcelHeaderFields(firstWorksheet, sheetFormat, selectedHeaderAreaJson); headers = makeHeaderUnique(headers); suggestions = new List <EasyUploadSuggestion>(); if (!model.Rows.Any()) { foreach (string varName in headers) { #region suggestions //Add a variable to the suggestions if the names are similar suggestions = getSuggestions(varName, dataAttributeInfos); #endregion //set rowmodel RowModel row = new RowModel( headers.IndexOf(varName), varName, null, null, null, suggestions, unitInfos, dataAttributeInfos, dataTypeInfos ); model.Rows.Add(row); TaskManager.AddToBus(EasyUploadTaskManager.ROWS, model.Rows); TaskManager.AddToBus(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS, RowsToTuples()); } } TaskManager.AddToBus(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS, headers); model.StepInfo = TaskManager.Current(); return(PartialView(model)); } } }
public ActionResult SheetSelectMetaData(object[] data) { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; SelectMetaDataModel model = new SelectMetaDataModel(); model.StepInfo = TaskManager.Current(); if (TaskManager != null) { TaskManager.Current().SetValid(false); //SetValid only if a metadata-structure was selected if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SCHEMA)) { if (Convert.ToInt64(TaskManager.Bus[EasyUploadTaskManager.SCHEMA]) >= 0) { TaskManager.Current().SetValid(true); } else { model.ErrorList.Add(new Error(ErrorType.Other, "No valid Metadata schema is selected.")); } } else { model.ErrorList.Add(new Error(ErrorType.Other, "No Metadata schema is selected.")); } //If the user typed in a title, the title must not be empty if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE)) { string tmp = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]); if (String.IsNullOrWhiteSpace(tmp)) { TaskManager.Current().SetValid(false); model.ErrorList.Add(new Error(ErrorType.Other, "The title must not be empty.")); } } if (TaskManager.Current().valid == true) //Jump to next step of the upload { TaskManager.AddExecutedStep(TaskManager.Current()); TaskManager.GoToNext(); Session["TaskManager"] = TaskManager; ActionInfo actionInfo = TaskManager.Current().GetActionInfo; return(RedirectToAction(actionInfo.ActionName, actionInfo.ControllerName, new RouteValueDictionary { { "area", actionInfo.AreaName }, { "index", TaskManager.GetCurrentStepInfoIndex() } })); } else //Model isn't valid, display an error and stay on the same site { TaskManager.Current().SetStatus(StepStatus.error); MetadataStructureManager msm = new MetadataStructureManager(); try { IEnumerable <MetadataStructure> metadataStructureList = msm.Repo.Get(); foreach (MetadataStructure metadataStructure in metadataStructureList) { if (xmlDatasetHelper.IsActive(metadataStructure.Id) && xmlDatasetHelper.HasEntityType(metadataStructure.Id, "bexis.dlm.entities.data.dataset")) { model.AvailableMetadata.Add(new Tuple <long, string>(metadataStructure.Id, metadataStructure.Name)); } } //Sort the metadata structures model.AvailableMetadata.Sort((md1, md2) => md1.Item1.CompareTo(md2.Item1)); //reload model model.StepInfo = TaskManager.Current(); //if the title was changed at some point during the upload, load the title into the model if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE)) { model.DescriptionTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]); } //if it wasn't changed yet, the default title is the filename else { model.DescriptionTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]); } } finally { msm.Dispose(); } } } return(PartialView(model)); }
public ActionResult SelectAreas(int index) { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; //set current stepinfo based on index if (TaskManager != null) { TaskManager.SetCurrent(index); // remove if existing TaskManager.RemoveExecutedStep(TaskManager.Current()); } //Use the given file and the given sheet format to create a json-table string filePath = TaskManager.Bus[EasyUploadTaskManager.FILEPATH].ToString(); FileStream fis = null; string jsonTable = "[]"; SelectAreasModel model = new SelectAreasModel(); try { //FileStream for the users file fis = new FileStream(filePath, FileMode.Open, FileAccess.Read); //Grab the sheet format from the bus string sheetFormatString = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT]); SheetFormat CurrentSheetFormat = 0; Enum.TryParse <SheetFormat>(sheetFormatString, true, out CurrentSheetFormat); //Transforms the content of the file into a 2d-json-array JsonTableGenerator EUEReader = new JsonTableGenerator(fis); //If the active worksheet was never changed, we default to the first one string activeWorksheet; if (!TaskManager.Bus.ContainsKey(EasyUploadTaskManager.ACTIVE_WOKSHEET_URI)) { activeWorksheet = EUEReader.GetFirstWorksheetUri().ToString(); TaskManager.AddToBus(EasyUploadTaskManager.ACTIVE_WOKSHEET_URI, activeWorksheet); } else { activeWorksheet = TaskManager.Bus[EasyUploadTaskManager.ACTIVE_WOKSHEET_URI].ToString(); } //Generate the table for the active worksheet jsonTable = EUEReader.GenerateJsonTable(CurrentSheetFormat, activeWorksheet); //Save the worksheet uris to the model model.SheetUriDictionary = EUEReader.GetWorksheetUris(); if (!String.IsNullOrEmpty(jsonTable)) { TaskManager.AddToBus(EasyUploadTaskManager.SHEET_JSON_DATA, jsonTable); } //Add uri of the active sheet to the model to be able to preselect the correct option in the dropdown model.activeSheetUri = activeWorksheet; } catch (Exception ex) { LoggerFactory.LogCustom(ex.Message); } finally { if (fis != null) { fis.Close(); } } // Check if the areas have already been selected, if yes, use them (Important when jumping back to this step) if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_DATA_AREA)) { model.DataArea = (List <string>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA]; } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_HEADER_AREA)) { model.HeaderArea = TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA].ToString(); } model.StepInfo = TaskManager.Current(); return(PartialView(model)); }
public ActionResult Verification(object[] data) { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; SelectVerificationModel model = new SelectVerificationModel(); model.StepInfo = TaskManager.Current(); if (TaskManager != null) { TaskManager.Current().SetValid(false); if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS)) { List <Tuple <int, String, UnitInfo> > mappedHeaderUnits = (List <Tuple <int, String, UnitInfo> >)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS]; //Moved handling of this case to SaveUnitSelection, just leaving it here in case of problems: /*foreach (Tuple<int, String, UnitInfo> tuple in mappedHeaderUnits) * { * * if (tuple.Item3.SelectedDataTypeId < 0) * { * tuple.Item3.SelectedDataTypeId = tuple.Item3.DataTypeInfos.FirstOrDefault().DataTypeId; * } * }*/ model.AssignedHeaderUnits = mappedHeaderUnits; TaskManager.Current().SetValid(true); } else { model.ErrorList.Add(new Error(ErrorType.Other, "Some Areas are not selected.")); } if (TaskManager.Current().valid == true) { TaskManager.AddExecutedStep(TaskManager.Current()); TaskManager.GoToNext(); Session["TaskManager"] = TaskManager; ActionInfo actionInfo = TaskManager.Current().GetActionInfo; return(RedirectToAction(actionInfo.ActionName, actionInfo.ControllerName, new RouteValueDictionary { { "area", actionInfo.AreaName }, { "index", TaskManager.GetCurrentStepInfoIndex() } })); } else { TaskManager.Current().SetStatus(StepStatus.error); //reload model model.StepInfo = TaskManager.Current(); } } //Default unit should be "none" if it exists, otherwise just take the first unit UnitInfo currentUnitInfo = model.AvailableUnits.FirstOrDefault(u => u.Name.ToLower() == "none"); if (currentUnitInfo != null) { currentUnitInfo = (UnitInfo)currentUnitInfo.Clone(); } else { currentUnitInfo = (UnitInfo)model.AvailableUnits.FirstOrDefault().Clone(); } DataTypeInfo dtinfo = currentUnitInfo.DataTypeInfos.FirstOrDefault(); currentUnitInfo.SelectedDataTypeId = dtinfo.DataTypeId; ViewData["defaultUnitID"] = currentUnitInfo.UnitId; ViewData["defaultDatatypeID"] = dtinfo.DataTypeId; return(PartialView(model)); }
public ActionResult Summary(int index) { MetadataStructureManager msm = new MetadataStructureManager(); try { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; //set current stepinfo based on index if (TaskManager != null) { TaskManager.SetCurrent(index); // remove if existing TaskManager.RemoveExecutedStep(TaskManager.Current()); } EasyUploadSummaryModel model = new EasyUploadSummaryModel(); model.StepInfo = TaskManager.Current(); if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.FILENAME)) { model.DatasetTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]); if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE)) { string tmp = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]); if (!String.IsNullOrWhiteSpace(tmp)) { model.DatasetTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]); } } } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SCHEMA)) { long id = Convert.ToInt64(TaskManager.Bus[EasyUploadTaskManager.SCHEMA]); model.MetadataSchemaTitle = msm.Repo.Get(m => m.Id == id).FirstOrDefault().Name; msm.Dispose(); } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_FORMAT)) { model.FileFormat = TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT].ToString(); } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_HEADER_AREA)) { string selectedHeaderAreaJsonArray = TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA].ToString(); int[] areaHeaderValues = JsonConvert.DeserializeObject <int[]>(selectedHeaderAreaJsonArray); if (model.FileFormat.ToLower() == "topdown") { model.NumberOfHeaders = (areaHeaderValues[3]) - (areaHeaderValues[1]) + 1; } if (model.FileFormat.ToLower() == "leftright") { model.NumberOfHeaders = (areaHeaderValues[2]) - (areaHeaderValues[0]) + 1; } } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_DATA_AREA)) { List <string> selectedDataAreaJsonArray = (List <String>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA]; List <int[]> areaDataValuesList = new List <int[]>(); model.NumberOfData = 0; foreach (string jsonArray in selectedDataAreaJsonArray) { areaDataValuesList.Add(JsonConvert.DeserializeObject <int[]>(jsonArray)); } foreach (int[] areaDataValues in areaDataValuesList) { if (model.FileFormat.ToLower() == "leftright") { model.NumberOfData += (areaDataValues[3]) - (areaDataValues[1]) + 1; } if (model.FileFormat.ToLower() == "topdown") { model.NumberOfData += (areaDataValues[2]) - (areaDataValues[0]) + 1; } } } return(PartialView("EasyUploadSummary", model)); } finally { msm.Dispose(); } }
public ActionResult SaveSuggestionSelection() { SelectVerificationModel model = new SelectVerificationModel(); int? selectFieldId = null; int? selectedUnitId = null; int? selectedDatatypeId = null; string selectedVariableName = null; //Keys submitted by Javascript in Verification.cshtml foreach (string key in Request.Form.AllKeys) { if ("headerfieldId" == key) { selectFieldId = Convert.ToInt32(Request.Form[key]); } if ("selectedVariableName" == key) { selectedVariableName = Convert.ToString(Request.Form[key]); } if ("selectedUnitId" == key) { selectedUnitId = Convert.ToInt32(Request.Form[key]); } if ("selectedDataTypeId" == key) { var test = Request.Form[key]; selectedDatatypeId = Convert.ToInt32(Request.Form[key]); } } EasyUploadTaskManager TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS)) { model.AssignedHeaderUnits = (List <Tuple <int, string, UnitInfo> >)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS]; } /* * Copy the assignedHeaderUnits, change the entry for which the suggestion was selected * */ if (selectFieldId != null) { //Find the position of the Tuple that is about to be changed Tuple <int, string, UnitInfo> exTuple = model.AssignedHeaderUnits.Where(t => t.Item1 == selectFieldId).FirstOrDefault(); int i = model.AssignedHeaderUnits.FindIndex(t => t.Equals(exTuple)); //Insert a new Tuple at this position model.AssignedHeaderUnits[i] = new Tuple <int, string, UnitInfo>(exTuple.Item1, selectedVariableName, exTuple.Item3); } //Save unit and datatype if (selectFieldId != null && selectedUnitId != null) { //Get all units List <UnitInfo> availableUnits = (List <UnitInfo>)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS]; //Get the current unit and clone it UnitInfo currentUnit = (UnitInfo)availableUnits.Where(u => u.UnitId == selectedUnitId).FirstOrDefault().Clone(); currentUnit.SelectedDataTypeId = Convert.ToInt32(selectedDatatypeId); //Find the index of the suggestion that is about to be changed Tuple <int, string, UnitInfo> existingTuple = model.AssignedHeaderUnits.Where(t => t.Item1 == (int)selectFieldId).FirstOrDefault(); int j = model.AssignedHeaderUnits.FindIndex(t => t.Equals(existingTuple)); //Save the new unit with the new datatype model.AssignedHeaderUnits[j] = new Tuple <int, string, UnitInfo>(existingTuple.Item1, selectedVariableName, currentUnit); } TaskManager.AddToBus(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS, model.AssignedHeaderUnits); if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_HEADERFIELDS)) { model.HeaderFields = (string[])TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_HEADERFIELDS]; } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS)) { model.AvailableUnits = (List <UnitInfo>)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS]; } model.Suggestions = (Dictionary <int, List <EasyUploadSuggestion> >)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_ATTRIBUTESUGGESTIONS]; Session["TaskManager"] = TaskManager; //create Model model.StepInfo = TaskManager.Current(); //Submit default datatype id //Default unit should be "none" if it exists, otherwise just take the first unit UnitInfo currentUnitInfo = model.AvailableUnits.FirstOrDefault(u => u.Name.ToLower() == "none"); if (currentUnitInfo != null) { currentUnitInfo = (UnitInfo)currentUnitInfo.Clone(); } else { currentUnitInfo = (UnitInfo)model.AvailableUnits.FirstOrDefault().Clone(); } DataTypeInfo dtinfo = currentUnitInfo.DataTypeInfos.FirstOrDefault(); currentUnitInfo.SelectedDataTypeId = dtinfo.DataTypeId; ViewData["defaultUnitID"] = currentUnitInfo.UnitId; ViewData["defaultDatatypeID"] = dtinfo.DataTypeId; return(PartialView("Verification", model)); }
public ActionResult SaveDataTypeSelection() { int?selectFieldId = null; int?selectedDataTypeId = null; //Keys submitted by Javascript in Verification.cshtml foreach (string key in Request.Form.AllKeys) { if ("headerfieldId" == key) { selectFieldId = Convert.ToInt32(Request.Form[key]); } if ("selectedDataTypeId" == key) { selectedDataTypeId = Convert.ToInt32(Request.Form[key]); } } SelectVerificationModel model = new SelectVerificationModel(); EasyUploadTaskManager TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS)) { model.AssignedHeaderUnits = (List <Tuple <int, string, UnitInfo> >)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS]; } //Reset the name of the variable and save the new Datatype string[] headerFields = (string[])TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_HEADERFIELDS]; string currentHeader = headerFields.ElementAt((int)selectFieldId); Tuple <int, string, UnitInfo> existingTuple = model.AssignedHeaderUnits.Where(t => t.Item1 == selectFieldId).FirstOrDefault(); existingTuple = new Tuple <int, string, UnitInfo>(existingTuple.Item1, existingTuple.Item2, (UnitInfo)existingTuple.Item3.Clone()); int j = model.AssignedHeaderUnits.FindIndex(i => ((i.Item1 == existingTuple.Item1))); model.AssignedHeaderUnits[j] = new Tuple <int, string, UnitInfo>(existingTuple.Item1, currentHeader, existingTuple.Item3); model.AssignedHeaderUnits[j].Item3.SelectedDataTypeId = Convert.ToInt32(selectedDataTypeId); TaskManager.AddToBus(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS, model.AssignedHeaderUnits); if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_HEADERFIELDS)) { model.HeaderFields = (string[])TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_HEADERFIELDS]; } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS)) { model.AvailableUnits = (List <UnitInfo>)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS]; } //Grab the suggestions from the bus and filter them to only show those, that use the selected datatype model.Suggestions = (Dictionary <int, List <EasyUploadSuggestion> >)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_ATTRIBUTESUGGESTIONS]; //Filter the suggestions to only show those, that use the selected unit int index = selectFieldId ?? -1; List <EasyUploadSuggestion> suggestionList = null; if (model.Suggestions.TryGetValue(index, out suggestionList)) { if (suggestionList != null) { foreach (EasyUploadSuggestion suggestion in suggestionList) { suggestion.show = (suggestion.dataTypeID == selectedDataTypeId); } } } Session["TaskManager"] = TaskManager; model.StepInfo = TaskManager.Current(); //Default unit should be "none" if it exists, otherwise just take the first unit UnitInfo currentUnitInfo = model.AvailableUnits.FirstOrDefault(u => u.Name.ToLower() == "none"); if (currentUnitInfo != null) { currentUnitInfo = (UnitInfo)currentUnitInfo.Clone(); } else { currentUnitInfo = (UnitInfo)model.AvailableUnits.FirstOrDefault().Clone(); } DataTypeInfo dtinfo = currentUnitInfo.DataTypeInfos.FirstOrDefault(); currentUnitInfo.SelectedDataTypeId = dtinfo.DataTypeId; ViewData["defaultUnitID"] = currentUnitInfo.UnitId; ViewData["defaultDatatypeID"] = dtinfo.DataTypeId; return(PartialView("Verification", model)); }
public ActionResult Verification(int index) { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; List <Dlm.Entities.DataStructure.Unit> tempUnitList = new List <Dlm.Entities.DataStructure.Unit>(); List <DataType> allDataypes = new List <DataType>(); List <DataAttribute> allDataAttributes = new List <DataAttribute>(); using (IUnitOfWork unitOfWork = this.GetUnitOfWork()) { //set current stepinfo based on index if (TaskManager != null) { TaskManager.SetCurrent(index); // remove if existing TaskManager.RemoveExecutedStep(TaskManager.Current()); } SelectVerificationModel model = new SelectVerificationModel(); //Grab all necessary managers and lists //UnitManager unitManager = new UnitManager(); //this.Disposables.Add(unitManager); //DataTypeManager dataTypeManager = new DataTypeManager(); //this.Disposables.Add(dataTypeManager); tempUnitList = unitOfWork.GetReadOnlyRepository <Dlm.Entities.DataStructure.Unit>().Get().ToList(); allDataypes = unitOfWork.GetReadOnlyRepository <DataType>().Get().ToList(); allDataAttributes = unitOfWork.GetReadOnlyRepository <DataAttribute>().Get().ToList(); //DataStructureManager dsm = new DataStructureManager(); //this.Disposables.Add(dsm); //DataContainerManager dam = new DataContainerManager(); //this.Disposables.Add(dam); //Important for jumping back to this step if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS)) { model.AssignedHeaderUnits = (List <Tuple <int, string, UnitInfo> >)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS]; } // get all DataTypes for each Units foreach (Dlm.Entities.DataStructure.Unit unit in tempUnitList) { UnitInfo unitInfo = new UnitInfo(); unitInfo.UnitId = unit.Id; unitInfo.Description = unit.Description; unitInfo.Name = unit.Name; unitInfo.Abbreviation = unit.Abbreviation; if (unit.Name.ToLower() == "none") { foreach (DataType fullDataType in allDataypes) { DataTypeInfo dataTypeInfo = new DataTypeInfo(); dataTypeInfo.DataTypeId = fullDataType.Id; dataTypeInfo.Description = fullDataType.Description; dataTypeInfo.Name = fullDataType.Name; unitInfo.DataTypeInfos.Add(dataTypeInfo); } model.AvailableUnits.Add(unitInfo); } else { Boolean hasDatatype = false; //Make sure only units that have at least one datatype are shown foreach (DataType dummyDataType in unit.AssociatedDataTypes) { if (!hasDatatype) { hasDatatype = true; } DataTypeInfo dataTypeInfo = new DataTypeInfo(); DataType fullDataType = allDataypes.Where(p => p.Id == dummyDataType.Id).FirstOrDefault(); dataTypeInfo.DataTypeId = fullDataType.Id; dataTypeInfo.Description = fullDataType.Description; dataTypeInfo.Name = fullDataType.Name; unitInfo.DataTypeInfos.Add(dataTypeInfo); } if (hasDatatype) { model.AvailableUnits.Add(unitInfo); } } } //Sort the units by name model.AvailableUnits.Sort(delegate(UnitInfo u1, UnitInfo u2) { return(String.Compare(u1.Name, u2.Name, StringComparison.InvariantCultureIgnoreCase)); }); if (!TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS)) { TaskManager.AddToBus(EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS, model.AvailableUnits); } string filePath = TaskManager.Bus[EasyUploadTaskManager.FILEPATH].ToString(); string selectedHeaderAreaJson = TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA].ToString(); FileStream fis = null; fis = new FileStream(filePath, FileMode.Open, FileAccess.Read); ExcelPackage ep = new ExcelPackage(fis); fis.Close(); ExcelWorkbook excelWorkbook = ep.Workbook; ExcelWorksheet firstWorksheet = excelWorkbook.Worksheets[1]; string sheetFormatString = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT]); SheetFormat sheetFormat = 0; Enum.TryParse <SheetFormat>(sheetFormatString, true, out sheetFormat); model.HeaderFields = GetExcelHeaderFields(firstWorksheet, sheetFormat, selectedHeaderAreaJson).ToArray(); if (!TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_HEADERFIELDS)) { TaskManager.AddToBus(EasyUploadTaskManager.VERIFICATION_HEADERFIELDS, model.HeaderFields); } model.Suggestions = new Dictionary <int, List <EasyUploadSuggestion> >(); for (int i = 0; i < model.HeaderFields.Length; i++) { //Default unit should be "none" if it exists, otherwise just take the first unit UnitInfo currentUnitInfo = model.AvailableUnits.FirstOrDefault(u => u.Name.ToLower() == "none"); if (currentUnitInfo != null) { currentUnitInfo = (UnitInfo)currentUnitInfo.Clone(); } else { currentUnitInfo = (UnitInfo)model.AvailableUnits.FirstOrDefault().Clone(); } DataTypeInfo dtinfo = currentUnitInfo.DataTypeInfos.FirstOrDefault(); currentUnitInfo.SelectedDataTypeId = dtinfo.DataTypeId; ViewData["defaultUnitID"] = currentUnitInfo.UnitId; ViewData["defaultDatatypeID"] = dtinfo.DataTypeId; if (model.AssignedHeaderUnits.Where(t => t.Item1 == i).FirstOrDefault() == null) { model.AssignedHeaderUnits.Add(new Tuple <int, string, UnitInfo>(i, model.HeaderFields[i], currentUnitInfo)); } #region suggestions //Add a variable to the suggestions if the names are similar model.Suggestions.Add(i, new List <EasyUploadSuggestion>()); //Calculate similarity metric //Accept suggestion if the similarity is greater than some threshold double threshold = 0.5; IEnumerable <DataAttribute> suggestions = allDataAttributes.Where(att => similarity(att.Name, model.HeaderFields[i]) >= threshold); //Order the suggestions according to the similarity List <DataAttribute> ordered = suggestions.ToList <DataAttribute>(); ordered.Sort((x, y) => (similarity(y.Name, model.HeaderFields[i])).CompareTo(similarity(x.Name, model.HeaderFields[i]))); //Add the ordered suggestions to the model foreach (DataAttribute att in ordered) { model.Suggestions[i].Add(new EasyUploadSuggestion(att.Name, att.Unit.Id, att.DataType.Id, att.Unit.Name, att.DataType.Name, true)); } //Use the following to order suggestions alphabetically instead of ordering according to the metric //model.Suggestions[i] = model.Suggestions[i].Distinct().OrderBy(s => s.attributeName).ToList<EasyUploadSuggestion>(); //Each Name-Unit-Datatype-Tuple should be unique model.Suggestions[i] = model.Suggestions[i].Distinct().ToList <EasyUploadSuggestion>(); #endregion } TaskManager.AddToBus(EasyUploadTaskManager.VERIFICATION_ATTRIBUTESUGGESTIONS, model.Suggestions); TaskManager.AddToBus(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS, model.AssignedHeaderUnits); // when jumping back to this step if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_JSON_DATA)) { if (!String.IsNullOrEmpty(Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.SHEET_JSON_DATA]))) { } } model.StepInfo = TaskManager.Current(); return(PartialView(model)); } }
public ActionResult SaveUnitSelection() { int?selectFieldId = null; int?selectOptionId = null; //Keys submitted by Javascript in Verification.cshtml foreach (string key in Request.Form.AllKeys) { if ("selectFieldId" == key) { selectFieldId = Convert.ToInt32(Request.Form[key]); } if ("selectOptionId" == key) { selectOptionId = Convert.ToInt32(Request.Form[key]); } } SelectVerificationModel model = new SelectVerificationModel(); EasyUploadTaskManager TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS)) { model.AssignedHeaderUnits = (List <Tuple <int, string, UnitInfo> >)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS]; } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_ATTRIBUTESUGGESTIONS)) { model.Suggestions = (Dictionary <int, List <EasyUploadSuggestion> >)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_ATTRIBUTESUGGESTIONS]; } /* * Find the selected unit and adjust the AssignedHeaderUnits * Also resets the Variable name * */ if (selectFieldId != null && selectOptionId != null) { List <UnitInfo> availableUnits = (List <UnitInfo>)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS]; string[] headerFields = (string[])TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_HEADERFIELDS]; string currentHeader = headerFields.ElementAt((int)selectFieldId); UnitInfo currentUnit = availableUnits.Where(u => u.UnitId == selectOptionId).FirstOrDefault(); Tuple <int, string, UnitInfo> existingTuple = model.AssignedHeaderUnits.Where(t => t.Item1 == (int)selectFieldId).FirstOrDefault(); if (existingTuple != null) { model.AssignedHeaderUnits.Remove(existingTuple); } model.AssignedHeaderUnits.Add(new Tuple <int, string, UnitInfo>((int)selectFieldId, currentHeader, currentUnit)); //Set the Datatype to the first one suitable for the selected unit if (currentUnit.SelectedDataTypeId < 0) { currentUnit.SelectedDataTypeId = currentUnit.DataTypeInfos.FirstOrDefault().DataTypeId; } //Filter the suggestions to only show those, that use the selected unit int index = selectFieldId ?? -1; List <EasyUploadSuggestion> suggestionList = null; if (model.Suggestions.TryGetValue(index, out suggestionList)) { if (suggestionList != null) { foreach (EasyUploadSuggestion suggestion in suggestionList) { suggestion.show = (suggestion.unitID == selectOptionId); } } } } TaskManager.AddToBus(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS, model.AssignedHeaderUnits); if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_HEADERFIELDS)) { model.HeaderFields = (string[])TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_HEADERFIELDS]; } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS)) { model.AvailableUnits = (List <UnitInfo>)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS]; } Session["TaskManager"] = TaskManager; //create Model model.StepInfo = TaskManager.Current(); //Submit default datatype id //Default unit should be "none" if it exists, otherwise just take the first unit UnitInfo currentUnitInfo = model.AvailableUnits.FirstOrDefault(u => u.Name.ToLower() == "none"); if (currentUnitInfo != null) { currentUnitInfo = (UnitInfo)currentUnitInfo.Clone(); } else { currentUnitInfo = (UnitInfo)model.AvailableUnits.FirstOrDefault().Clone(); } DataTypeInfo dtinfo = currentUnitInfo.DataTypeInfos.FirstOrDefault(); currentUnitInfo.SelectedDataTypeId = dtinfo.DataTypeId; ViewData["defaultUnitID"] = currentUnitInfo.UnitId; ViewData["defaultDatatypeID"] = dtinfo.DataTypeId; return(PartialView("Verification", model)); }
public ActionResult SelectAreas(object[] data) { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; SelectAreasModel model = new SelectAreasModel(); model.StepInfo = TaskManager.Current(); if (TaskManager != null) { TaskManager.Current().SetValid(false); //If Header and data areas have been selected, you can proceed with the next step if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_JSON_DATA) && TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_DATA_AREA) && TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_HEADER_AREA)) { bool isJsonDataEmpty = String.IsNullOrEmpty(Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.SHEET_JSON_DATA])); bool isDataAreaEmpty = ((List <string>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA]).Count == 0; bool isHeadAreaEmpty = String.IsNullOrEmpty(Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA])); if (!isJsonDataEmpty && !isDataAreaEmpty && !isHeadAreaEmpty) { TaskManager.Current().SetValid(true); } else { model.ErrorList.Add(new Error(ErrorType.Other, "Some Areas are not selected.")); } } else //Else stay on the same page, display an error { model.ErrorList.Add(new Error(ErrorType.Other, "Some Areas are not selected.")); } if (TaskManager.Current().valid == true) //Redirect if the state is valid { TaskManager.AddExecutedStep(TaskManager.Current()); TaskManager.GoToNext(); Session["TaskManager"] = TaskManager; ActionInfo actionInfo = TaskManager.Current().GetActionInfo; return(RedirectToAction(actionInfo.ActionName, actionInfo.ControllerName, new RouteValueDictionary { { "area", actionInfo.AreaName }, { "index", TaskManager.GetCurrentStepInfoIndex() } })); } else { TaskManager.Current().SetStatus(StepStatus.error); //reload model if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_DATA_AREA)) { model.DataArea = (List <string>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA]; } if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_HEADER_AREA)) { model.HeaderArea = TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA].ToString(); } #region Generate sheet-list and table for active sheet //Grab the sheet format from the bus string sheetFormatString = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT]); SheetFormat CurrentSheetFormat = 0; Enum.TryParse <SheetFormat>(sheetFormatString, true, out CurrentSheetFormat); //Open the users file string filePath = TaskManager.Bus[EasyUploadTaskManager.FILEPATH].ToString(); FileStream fis = null; string jsonTable = "{}"; fis = new FileStream(filePath, FileMode.Open, FileAccess.Read); //Generate the Sheet-List and grab the active worksheet JsonTableGenerator EUEReader = new JsonTableGenerator(fis); //If the active worksheet was never changed, we default to the first one string activeWorksheet; if (!TaskManager.Bus.ContainsKey(EasyUploadTaskManager.ACTIVE_WOKSHEET_URI)) { activeWorksheet = EUEReader.GetFirstWorksheetUri().ToString(); TaskManager.AddToBus(EasyUploadTaskManager.ACTIVE_WOKSHEET_URI, activeWorksheet); } else { activeWorksheet = TaskManager.Bus[EasyUploadTaskManager.ACTIVE_WOKSHEET_URI].ToString(); } //Generate the table for the active worksheet jsonTable = EUEReader.GenerateJsonTable(CurrentSheetFormat, activeWorksheet); //Save the worksheet uris to the model model.SheetUriDictionary = EUEReader.GetWorksheetUris(); if (!String.IsNullOrEmpty(jsonTable)) { TaskManager.AddToBus(EasyUploadTaskManager.SHEET_JSON_DATA, jsonTable); } //Add uri of the active sheet to the model to be able to preselect the correct option in the dropdown model.activeSheetUri = activeWorksheet; #endregion model.StepInfo = TaskManager.Current(); } } return(PartialView(model)); }
public ActionResult SelectAFile(object[] data) { SelectFileViewModel model = new SelectFileViewModel(); TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; if (data != null) { TaskManager.AddToBus(data); } model.StepInfo = TaskManager.Current(); TaskManager.Current().SetValid(false); if (TaskManager != null) { // is path of FileStream exist if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.FILEPATH)) { if (IsSupportedExtention(TaskManager)) { try { string filePath = TaskManager.Bus[EasyUploadTaskManager.FILEPATH].ToString(); //TaskManager.AddToBus(EasyUploadTaskManager.IS_TEMPLATE, "false"); TaskManager.Current().SetValid(true); } catch { model.ErrorList.Add(new Error(ErrorType.Other, "Cannot access FileStream on server.")); } } else { model.ErrorList.Add(new Error(ErrorType.Other, "File is not supported.")); } } else { model.ErrorList.Add(new Error(ErrorType.Other, "No FileStream selected or submitted.")); } if (TaskManager.Current().IsValid()) { TaskManager.AddExecutedStep(TaskManager.Current()); TaskManager.GoToNext(); Session["TaskManager"] = TaskManager; ActionInfo actionInfo = TaskManager.Current().GetActionInfo; return(RedirectToAction(actionInfo.ActionName, actionInfo.ControllerName, new RouteValueDictionary { { "area", actionInfo.AreaName }, { "index", TaskManager.GetCurrentStepInfoIndex() } })); } } model.serverFileList = GetServerFileList(); model.SupportedFileExtentions = supportedExtensions; return(PartialView(model)); }
public ActionResult SelectedAreaToBus() { string headerArea = null; string dataArea = null; foreach (string key in Request.Form.AllKeys) { if ("dataArea" == key) { dataArea = Request.Form[key]; } if ("headerArea" == key) { headerArea = Request.Form[key]; } } SelectAreasModel model = new SelectAreasModel(); EasyUploadTaskManager TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; if (dataArea != null) { if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SHEET_DATA_AREA)) { model.DataArea = (List <string>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA]; } //dataArea == "" means the resetButton was clicked if (model.DataArea == null || dataArea == "") { model.DataArea = new List <string>(); } if (dataArea != "") { int[] newArea = JsonConvert.DeserializeObject <int[]>(dataArea); Boolean contains = false; foreach (string area in model.DataArea) { int[] oldArea = JsonConvert.DeserializeObject <int[]>(area); //If one of the already selected areas contains the new one, don't add the new one to the selection (prevents duplicate selection) if (oldArea[0] <= newArea[0] && oldArea[2] >= newArea[2] && oldArea[1] <= newArea[1] && oldArea[3] >= newArea[3]) { contains = true; } } if (!contains) { //If the new area contains one (or several) of the already selected areas, remove the old ones for (int i = model.DataArea.Count - 1; i >= 0; i--) { int[] oldArea = JsonConvert.DeserializeObject <int[]>(model.DataArea[i]); if (newArea[0] <= oldArea[0] && newArea[2] >= oldArea[2] && newArea[1] <= oldArea[1] && newArea[3] >= oldArea[3]) { model.DataArea.RemoveAt(i); } } //Insert the new area model.DataArea.Add(dataArea); } } TaskManager.AddToBus(EasyUploadTaskManager.SHEET_DATA_AREA, model.DataArea); } if (headerArea != null) { TaskManager.AddToBus(EasyUploadTaskManager.SHEET_HEADER_AREA, headerArea); model.HeaderArea = headerArea; } string filePath = TaskManager.Bus[EasyUploadTaskManager.FILEPATH].ToString(); FileStream fis = null; try { //FileStream for the users file fis = new FileStream(filePath, FileMode.Open, FileAccess.Read); JsonTableGenerator EUEReader = new JsonTableGenerator(fis); //Get the worksheet uris and save them to the model model.SheetUriDictionary = EUEReader.GetWorksheetUris(); } catch (Exception ex) { LoggerFactory.LogCustom(ex.Message); } finally { if (fis != null) { fis.Close(); } } Session["TaskManager"] = TaskManager; model.StepInfo = TaskManager.Current(); return(PartialView("SelectAreas", model)); }
public ActionResult SaveMetaDataSelection(object[] data) { MetadataStructureManager msm = new MetadataStructureManager(); try { TaskManager = (EasyUploadTaskManager)Session["TaskManager"]; SelectMetaDataModel model = new SelectMetaDataModel(); long metadataId = -1; if (TaskManager != null) { //Load available metadata structures and store them in the model IEnumerable <MetadataStructure> metadataStructureList = msm.Repo.Get(); foreach (MetadataStructure metadataStructure in metadataStructureList) { if (xmlDatasetHelper.IsActive(metadataStructure.Id) && xmlDatasetHelper.HasEntityType(metadataStructure.Id, "bexis.dlm.entities.data.dataset")) { model.AvailableMetadata.Add(new Tuple <long, string>(metadataStructure.Id, metadataStructure.Name)); } } //Sort the metadata structures model.AvailableMetadata.Sort((md1, md2) => md1.Item1.CompareTo(md2.Item1)); TaskManager.Current().SetValid(false); //Grabs the id of the selected metadata from the Http-Request foreach (string key in Request.Form.AllKeys) { if ("metadataId" == key) { metadataId = Convert.ToInt64(Request.Form[key]); } } //If a valid id was submitted, save its id as the currently selected model id model.SelectedMetaDataId = metadataId; TaskManager.AddToBus(EasyUploadTaskManager.SCHEMA, model.SelectedMetaDataId); TaskManager.Current().SetValid(true); //Store all other information in the model if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE)) { model.DescriptionTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]); } else { model.DescriptionTitle = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]); } } return(PartialView("SheetSelectMetaData", model)); } finally { msm.Dispose(); } }