Пример #1
0
        public ActionResult UploadWizard()
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Upload Data", this.Session.GetTenant());

            Session["TaskManager"] = null;
            TaskManager            = null;

            try
            {
                string path = "";

                path = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "EasyUploadTaskInfo.xml");

                XmlDocument xmlTaskInfo = new XmlDocument();
                xmlTaskInfo.Load(path);

                Session["TaskManager"] = EasyUploadTaskManager.Bind(xmlTaskInfo);

                TaskManager = (EasyUploadTaskManager)Session["TaskManager"];
            }
            catch (Exception e)
            {
                ModelState.AddModelError(String.Empty, e.Message);
            }

            TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

            return(View((EasyUploadTaskManager)Session["TaskManager"]));
        }
Пример #2
0
        public ActionResult FinishUpload()
        {
            TaskManager = (EasyUploadTaskManager)Session["TaskManager"];
            //TaskManager.SetCurrent(null);


            FinishUploadModel finishModel = new FinishUploadModel();

            if (TaskManager != null)
            {
                finishModel.DatasetTitle = TaskManager.Bus[EasyUploadTaskManager.DATASET_TITLE].ToString();
                finishModel.Filename     = TaskManager.Bus[EasyUploadTaskManager.FILENAME].ToString();
            }

            Session["TaskManager"] = null;
            try
            {
                string      path        = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "SubmitTaskInfo.xml");
                XmlDocument xmlTaskInfo = new XmlDocument();
                xmlTaskInfo.Load(path);


                Session["TaskManager"] = EasyUploadTaskManager.Bind(xmlTaskInfo);
            }
            catch (Exception e)
            {
                ModelState.AddModelError(String.Empty, e.Message);
            }


            return(ShowData((long)TaskManager.Bus[EasyUploadTaskManager.DATASET_ID]));
        }
Пример #3
0
        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 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));
        }
        /// <summary>
        /// Selected File from server and store into BUS
        /// </summary>
        /// <param name="SelectFileUploader"></param>
        /// <returns></returns>
        public ActionResult SelectFileFromServerProcess(string fileName)
        {
            EasyUploadTaskManager TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

            #region Remove selected information from the bus
            TaskManager.Bus.Remove(EasyUploadTaskManager.SHEET_JSON_DATA);
            TaskManager.Bus.Remove(EasyUploadTaskManager.SHEET_HEADER_AREA);
            TaskManager.Bus.Remove(EasyUploadTaskManager.SHEET_DATA_AREA);
            TaskManager.Bus.Remove(EasyUploadTaskManager.SHEET_FORMAT);
            TaskManager.Bus.Remove(EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS);
            TaskManager.Bus.Remove(EasyUploadTaskManager.VERIFICATION_HEADERFIELDS);
            TaskManager.Bus.Remove(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS);
            TaskManager.Bus.Remove(EasyUploadTaskManager.VERIFICATION_ATTRIBUTESUGGESTIONS);
            #endregion

            if (fileName != null)
            {
                //string path = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "ServerFiles",fileName);

                //data/datasets/1/1/
                string dataPath = AppConfiguration.DataPath; //Path.Combine(AppConfiguration.WorkspaceRootPath, "Data");
                string path     = Path.Combine(dataPath, "Temp", GetUsernameOrDefault(), fileName);

                TaskManager.AddToBus(EasyUploadTaskManager.FILEPATH, path);

                TaskManager.AddToBus(EasyUploadTaskManager.FILENAME, fileName);
                TaskManager.AddToBus(EasyUploadTaskManager.EXTENTION, "." + fileName.Split('.').Last());
                Session["TaskManager"] = TaskManager;
            }

            //return RedirectToAction("UploadWizard");
            return(Content(""));
        }
        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));
        }
Пример #7
0
        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();
            }
        }
Пример #8
0
        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));
        }
Пример #9
0
        public ActionResult ChangeWorksheet(string sheetIdentifier)
        {
            TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

            #region Reset selected units, datatypes and suggestions

            TaskManager.Bus.Remove(EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS);
            TaskManager.Bus.Remove(EasyUploadTaskManager.VERIFICATION_HEADERFIELDS);
            TaskManager.Bus.Remove(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS);
            TaskManager.Bus.Remove(EasyUploadTaskManager.VERIFICATION_ATTRIBUTESUGGESTIONS);
            TaskManager.Bus.Remove(EasyUploadTaskManager.ROWS);

            #endregion Reset selected units, datatypes and suggestions

            #region Generate table for selected sheet

            string     filePath  = TaskManager.Bus[EasyUploadTaskManager.FILEPATH].ToString();
            FileStream fis       = null;
            string     jsonTable = "[]";

            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);
                jsonTable = EUEReader.GenerateJsonTable(CurrentSheetFormat, sheetIdentifier);

                if (!String.IsNullOrEmpty(jsonTable))
                {
                    TaskManager.AddToBus(EasyUploadTaskManager.SHEET_JSON_DATA, jsonTable);
                }

                TaskManager.AddToBus(EasyUploadTaskManager.ACTIVE_WOKSHEET_URI, sheetIdentifier);
            }
            catch (Exception ex)
            {
                LoggerFactory.LogCustom(ex.Message);
            }
            finally
            {
                if (fis != null)
                {
                    fis.Close();
                }
            }

            #endregion Generate table for selected sheet

            //Send back the table-data
            return(Content(jsonTable, "application/json"));
        }
Пример #10
0
        public ActionResult CancelUpload()
        {
            TaskManager = (EasyUploadTaskManager)Session["Taskmanager"];

            Session["Taskmanager"] = null;
            TaskManager            = null;

            return(RedirectToAction("UploadWizard", "EasyUpload", new RouteValueDictionary {
                { "area", "DCM" }
            }));
        }
        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()));
        }
        /// <summary>
        /// returns true if Extention in the Bus will supported
        /// </summary>
        /// <param name="taskManager"></param>
        /// <returns></returns>
        private bool IsSupportedExtention(EasyUploadTaskManager taskManager)
        {
            if (taskManager.Bus.ContainsKey(EasyUploadTaskManager.EXTENTION))
            {
                string ext = taskManager.Bus[EasyUploadTaskManager.EXTENTION].ToString();

                if (supportedExtensions.Contains(ext.ToLower()))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #13
0
        public ActionResult ValidateSelection()
        {
            TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

            string JsonArray = TaskManager.Bus[EasyUploadTaskManager.SHEET_JSON_DATA].ToString();

            List <Tuple <int, Error> >     ErrorList        = ValidateRows(JsonArray);
            List <Tuple <int, ErrorInfo> > ErrorMessageList = new List <Tuple <int, ErrorInfo> >();

            foreach (Tuple <int, Error> error in ErrorList)
            {
                ErrorMessageList.Add(new Tuple <int, ErrorInfo>(error.Item1, new ErrorInfo(error.Item2)));
            }

            return(Json(new { errors = ErrorMessageList.ToArray(), errorCount = (ErrorList.Count) }));
        }
Пример #14
0
        private List <Tuple <int, String, UnitInfo> > RowsToTuples()
        {
            List <Tuple <int, String, UnitInfo> > tmp = new List <Tuple <int, string, UnitInfo> >();

            TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

            if (TaskManager != null && TaskManager.Bus[EasyUploadTaskManager.ROWS] != null)
            {
                List <RowModel> rows = (List <RowModel>)TaskManager.Bus[EasyUploadTaskManager.ROWS];

                foreach (var row in rows)
                {
                    tmp.Add(RowToTuple(row));
                }
            }

            return(tmp);
        }
        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));
        }
        /// <summary>
        /// Selected File store din the BUS
        /// </summary>
        /// <param name="SelectFileUploader"></param>
        /// <returns></returns>
        public ActionResult SelectFileProcess(HttpPostedFileBase SelectFileUploader)
        {
            EasyUploadTaskManager TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

            #region Remove selected information from the bus
            TaskManager.Bus.Remove(EasyUploadTaskManager.SHEET_JSON_DATA);
            TaskManager.Bus.Remove(EasyUploadTaskManager.SHEET_HEADER_AREA);
            TaskManager.Bus.Remove(EasyUploadTaskManager.SHEET_DATA_AREA);
            TaskManager.Bus.Remove(EasyUploadTaskManager.SHEET_FORMAT);
            TaskManager.Bus.Remove(EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS);
            TaskManager.Bus.Remove(EasyUploadTaskManager.VERIFICATION_HEADERFIELDS);
            TaskManager.Bus.Remove(EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS);
            TaskManager.Bus.Remove(EasyUploadTaskManager.VERIFICATION_ATTRIBUTESUGGESTIONS);
            #endregion

            if (SelectFileUploader != null)
            {
                //data/datasets/1/1/
                string dataPath  = AppConfiguration.DataPath; //Path.Combine(AppConfiguration.WorkspaceRootPath, "Data");
                string storepath = Path.Combine(dataPath, "Temp", GetUsernameOrDefault());

                // if folder not exist
                if (!Directory.Exists(storepath))
                {
                    Directory.CreateDirectory(storepath);
                }

                string path = Path.Combine(storepath, SelectFileUploader.FileName);

                SelectFileUploader.SaveAs(path);
                TaskManager.AddToBus(EasyUploadTaskManager.FILEPATH, path);

                TaskManager.AddToBus(EasyUploadTaskManager.FILENAME, SelectFileUploader.FileName);
                TaskManager.AddToBus(EasyUploadTaskManager.EXTENTION, SelectFileUploader.FileName.Split('.').Last());
                Session["TaskManager"] = TaskManager;
            }

            //return RedirectToAction("UploadWizard");
            return(Content(""));
        }
Пример #17
0
        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));
        }
Пример #18
0
        private void UpdateRowInBus(RowModel row)
        {
            TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

            if (TaskManager != null && TaskManager.Bus[EasyUploadTaskManager.ROWS] != null)
            {
                List <RowModel> rows = (List <RowModel>)TaskManager.Bus[EasyUploadTaskManager.ROWS];
                if (rows.Any(r => r.Index.Equals(row.Index)))
                {
                    for (int i = 0; i < rows.Count; i++)
                    {
                        RowModel tmp = rows.ElementAt(i);
                        if (tmp.Index.Equals(row.Index))
                        {
                            rows[i] = row;
                            break;
                        }
                    }
                }

                TaskManager.AddToBus(EasyUploadTaskManager.ROWS, rows);
            }
        }
Пример #19
0
        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));
        }
Пример #20
0
        /// <summary>
        /// Determin whether the selected datatypes are suitable
        /// </summary>
        private List <Error> ValidateRows(string JsonArray)
        {
            DataTypeManager dtm = new DataTypeManager();

            try
            {
                const int maxErrorsPerColumn = 20;

                TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

                string[][] DeserializedJsonArray = JsonConvert.DeserializeObject <string[][]>(JsonArray);

                List <Error>    ErrorList       = new List <Error>();
                List <RowModel> Rows            = (List <RowModel>)TaskManager.Bus[EasyUploadTaskManager.ROWS];
                RowModel[]      MappedRowsArray = Rows.ToArray();

                List <string> DataArea        = (List <string>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA];
                List <int[]>  IntDataAreaList = new List <int[]>();
                foreach (string area in DataArea)
                {
                    IntDataAreaList.Add(JsonConvert.DeserializeObject <int[]>(area));
                }

                foreach (int[] IntDataArea in IntDataAreaList)
                {
                    string[,] SelectedDataArea = new string[(IntDataArea[2] - IntDataArea[0]), (IntDataArea[3] - IntDataArea[1])];

                    for (int x = IntDataArea[1]; x <= IntDataArea[3]; x++)
                    {
                        int errorsInColumn = 0;
                        for (int y = IntDataArea[0]; y <= IntDataArea[2]; y++)
                        {
                            int    SelectedY = y - (IntDataArea[0]);
                            int    SelectedX = x - (IntDataArea[1]);
                            string vv        = DeserializedJsonArray[y][x];

                            RowModel mappedHeader = MappedRowsArray.Where(t => t.Index == SelectedX).FirstOrDefault();

                            DataType datatype = null;

                            datatype = dtm.Repo.Get(mappedHeader.SelectedDataType.DataTypeId);

                            string datatypeName = datatype.SystemType;

                            DataTypeCheck dtc;
                            double        DummyValue = 0;
                            if (Double.TryParse(vv, out DummyValue))
                            {
                                if (vv.Contains("."))
                                {
                                    dtc = new DataTypeCheck(mappedHeader.SelectedDataAttribute.Name, datatypeName, DecimalCharacter.point);
                                }
                                else
                                {
                                    dtc = new DataTypeCheck(mappedHeader.SelectedDataAttribute.Name, datatypeName, DecimalCharacter.comma);
                                }
                            }
                            else
                            {
                                dtc = new DataTypeCheck(mappedHeader.SelectedDataAttribute.Name, datatypeName, DecimalCharacter.point);
                            }

                            var ValidationResult = dtc.Execute(vv, y);
                            if (ValidationResult is Error)
                            {
                                ErrorList.Add((Error)ValidationResult);
                                errorsInColumn++;
                            }

                            if (errorsInColumn >= maxErrorsPerColumn)
                            {
                                //Break inner (row) loop to jump to the next column
                                break;
                            }
                        }
                    }
                }

                return(ErrorList);
            }
            finally
            {
                dtm.Dispose();
            }
        }
Пример #21
0
        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();
            }
        }
Пример #22
0
        //[MeasurePerformance]
        //temporary solution: norman
        //For original solution, look into Aquadiva Code
        public List <Error> FinishUpload(EasyUploadTaskManager taskManager)
        {
            DataStructureManager dsm = new DataStructureManager();
            DatasetManager       dm  = new DatasetManager();
            DataContainerManager dam = new DataContainerManager();
            //SubjectManager sm = new SubjectManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();

            List <Error> temp = new List <Error>();

            try
            {
                using (IUnitOfWork unitOfWork = this.GetUnitOfWork())
                {
                    // initialize all necessary manager

                    DataTuple[] rows = null;

                    //First, try to validate - if there are errors, return immediately
                    string       JsonArray        = TaskManager.Bus[EasyUploadTaskManager.SHEET_JSON_DATA].ToString();
                    List <Error> ValidationErrors = ValidateRows(JsonArray);
                    if (ValidationErrors.Count != 0)
                    {
                        temp.AddRange(ValidationErrors);
                        return(temp);
                    }

                    string timestamp = DateTime.UtcNow.ToString("r");
                    string title     = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]);

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE))
                    {
                        string tmp = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                        if (!String.IsNullOrWhiteSpace(tmp))
                        {
                            title = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                        }
                    }

                    StructuredDataStructure   sds         = null;
                    List <VariableIdentifier> identifiers = new List <VariableIdentifier>(); //Used in Excel reader
                    //Try to find an exact matching datastructure
                    Boolean foundReusableDataStructure = false;

                    List <RowModel> headers = (List <RowModel>)TaskManager.Bus[EasyUploadTaskManager.ROWS];

                    //For some reason, MappedHeaders might be in a different order in this list than what's indicated by its IDs - to prevent mismatching, sort the headers
                    headers.Sort((m1, m2) => m1.Index.CompareTo(m2.Index));

                    List <StructuredDataStructure> allDatastructures = dsm.StructuredDataStructureRepo.Get().ToList();
                    foreach (StructuredDataStructure existingStructure in allDatastructures)
                    {
                        if (!foundReusableDataStructure)
                        {
                            //For now a datastructure is considered an exact match if it contains variables with
                            //the same names (labels), datatypes and units in the correct order
                            List <Variable> variablesOfExistingStructure = existingStructure.Variables.ToList();
                            foundReusableDataStructure = true;
                            if (variablesOfExistingStructure.Count != headers.Count)
                            {
                                foundReusableDataStructure = false;
                            }
                            else
                            {
                                for (int i = 0; i < variablesOfExistingStructure.Count; i++)
                                {
                                    Variable exVar         = variablesOfExistingStructure.ElementAt(i);
                                    RowModel currentHeader = headers.ElementAt(i);
                                    if (exVar.Label != currentHeader.Name ||
                                        exVar.Unit.Id != currentHeader.SelectedUnit.UnitId ||
                                        exVar.DataAttribute.DataType.Id != currentHeader.SelectedDataType.DataTypeId)
                                    {
                                        foundReusableDataStructure = false;
                                    }
                                }
                            }
                            if (foundReusableDataStructure)
                            {
                                sds = existingStructure;
                                foreach (Variable exVar in variablesOfExistingStructure)
                                {
                                    VariableIdentifier vi = new VariableIdentifier
                                    {
                                        name = exVar.Label,
                                        id   = exVar.Id
                                    };
                                    identifiers.Add(vi);
                                }
                            }
                        }
                    }

                    if (!foundReusableDataStructure)
                    {
                        sds = dsm.CreateStructuredDataStructure(title, title + " " + timestamp, "", "", DataStructureCategory.Generic);
                    }

                    TaskManager.AddToBus(EasyUploadTaskManager.DATASTRUCTURE_ID, sds.Id);
                    TaskManager.AddToBus(EasyUploadTaskManager.DATASTRUCTURE_TITLE, title + " " + timestamp);

                    if (!TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DATASET_TITLE))
                    {
                        TaskManager.AddToBus(EasyUploadTaskManager.DATASET_TITLE, title);
                        TaskManager.AddToBus(EasyUploadTaskManager.TITLE, title);
                    }

                    MetadataStructure metadataStructure = null;
                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SCHEMA))
                    {
                        long metadataStructureId = Convert.ToInt64(TaskManager.Bus[EasyUploadTaskManager.SCHEMA]);
                        metadataStructure = unitOfWork.GetReadOnlyRepository <MetadataStructure>()
                                            .Get(m => m.Id == metadataStructureId).FirstOrDefault();
                    }
                    else
                    {
                        //Default option but shouldn't happen because previous steps can't be finished without selecting the metadata-structure
                        metadataStructure = unitOfWork.GetReadOnlyRepository <MetadataStructure>()
                                            .Get(m => m.Name.ToLower().Contains("eml")).FirstOrDefault();
                    }
                    ResearchPlan rp = unitOfWork.GetReadOnlyRepository <ResearchPlan>().Get().FirstOrDefault();
                    TaskManager.AddToBus(EasyUploadTaskManager.RESEARCHPLAN_ID, rp.Id);
                    TaskManager.AddToBus(EasyUploadTaskManager.RESEARCHPLAN_TITLE, rp.Title);

                    #region Progress Information

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.CURRENTPACKAGESIZE))
                    {
                        TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGESIZE] = 0;
                    }
                    else
                    {
                        TaskManager.Bus.Add(EasyUploadTaskManager.CURRENTPACKAGESIZE, 0);
                    }

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.CURRENTPACKAGE))
                    {
                        TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGE] = 0;
                    }
                    else
                    {
                        TaskManager.Bus.Add(EasyUploadTaskManager.CURRENTPACKAGE, 0);
                    }

                    #endregion Progress Information

                    if (!foundReusableDataStructure)
                    {
                        #region Set Variables and information for new DataStructure

                        XmlDocument xmldoc       = new XmlDocument();
                        XmlElement  extraElement = xmldoc.CreateElement("extra");
                        XmlElement  orderElement = xmldoc.CreateElement("order");

                        //Sorting necessary to prevent problems when inserting the tuples
                        headers.OrderBy(r => r.Index);

                        var dataTypeRepo      = unitOfWork.GetReadOnlyRepository <DataType>();
                        var unitRepo          = unitOfWork.GetReadOnlyRepository <Unit>();
                        var dataAttributeRepo = unitOfWork.GetReadOnlyRepository <DataAttribute>();

                        List <DataAttribute> allDataAttributes = dataAttributeRepo.Get().ToList();

                        foreach (RowModel header in headers)
                        {
                            int i = headers.IndexOf(header);

                            DataType dataType            = dataTypeRepo.Get(header.SelectedDataType.DataTypeId);
                            Unit     CurrentSelectedUnit = unitRepo.Get(header.SelectedUnit.UnitId);

                            DataAttribute CurrentDataAttribute = new DataAttribute();
                            //If possible, map the chosen variable name, unit and datatype to an existing DataAttribute (Exact match)
                            DataAttribute existingDataAttribute = allDataAttributes.Where(da => da.Name.ToLower().Equals(TrimAndLimitString(header.SelectedDataAttribute.Name).ToLower()) &&
                                                                                          da.Unit.Dimension == CurrentSelectedUnit.Dimension).FirstOrDefault();
                            if (existingDataAttribute != null)
                            {
                                CurrentDataAttribute = existingDataAttribute;
                            }
                            else
                            {
                                //No matching DataAttribute => Create a new one
                                CurrentDataAttribute = dam.CreateDataAttribute(TrimAndLimitString(header.Name), header.Name, header.SelectedDataAttribute.Description, false, false, "", MeasurementScale.Categorial, DataContainerType.ReferenceType, "", dataType, CurrentSelectedUnit, null, null, null, null, null, null);
                            }

                            Variable           newVariable = dsm.AddVariableUsage(sds, CurrentDataAttribute, true, header.Name, "", "", "", CurrentSelectedUnit);
                            VariableIdentifier vi          = new VariableIdentifier
                            {
                                name = newVariable.Label,
                                id   = newVariable.Id
                            };
                            identifiers.Add(vi);

                            XmlElement newVariableXml = xmldoc.CreateElement("variable");
                            newVariableXml.InnerText = Convert.ToString(newVariable.Id);

                            orderElement.AppendChild(newVariableXml);
                        }
                        extraElement.AppendChild(orderElement);
                        xmldoc.AppendChild(extraElement);

                        sds.Extra       = xmldoc;
                        sds.Name        = "generated import structure " + timestamp;
                        sds.Description = "automatically generated structured data structure by user " + GetUsernameOrDefault() + " for file " + title + " on " + timestamp;

                        #endregion Set Variables and information for new DataStructure
                    }

                    Dataset ds = null;
                    ds = dm.CreateEmptyDataset(sds, rp, metadataStructure);

                    long datasetId = ds.Id;
                    long sdsId     = sds.Id;

                    if (dm.IsDatasetCheckedOutFor(datasetId, GetUsernameOrDefault()) || dm.CheckOutDataset(datasetId, GetUsernameOrDefault()))
                    {
                        DatasetVersion    dsv = dm.GetDatasetWorkingCopy(datasetId);
                        long              METADATASTRUCTURE_ID = metadataStructure.Id;
                        XmlMetadataWriter xmlMetadatWriter     = new XmlMetadataWriter(XmlNodeMode.xPath);
                        XDocument         metadataX            = xmlMetadatWriter.CreateMetadataXml(METADATASTRUCTURE_ID);
                        XmlDocument       metadataXml          = XmlMetadataWriter.ToXmlDocument(metadataX);
                        dsv.Metadata = metadataXml;
                        try
                        {
                            dsv.Metadata = xmlDatasetHelper.SetInformation(dsv, metadataXml, NameAttributeValues.title, title);
                            dsv.Title    = title;
                        }
                        catch (NullReferenceException ex)
                        {
                            //Reference of the title node is missing
                            throw new NullReferenceException("The extra-field of this metadata-structure is missing the title-node-reference!");
                        }
                        dm.EditDatasetVersion(dsv, null, null, null);
                    }

                    #region security

                    // add security
                    if (GetUsernameOrDefault() != "DEFAULT")
                    {
                        foreach (RightType rightType in Enum.GetValues(typeof(RightType)).Cast <RightType>())
                        {
                            //The user gets full permissions
                            // add security
                            if (GetUsernameOrDefault() != "DEFAULT")
                            {
                                entityPermissionManager.Create <User>(GetUsernameOrDefault(), "Dataset", typeof(Dataset), ds.Id, Enum.GetValues(typeof(RightType)).Cast <RightType>().ToList());
                            }
                        }
                    }

                    #endregion security

                    #region excel reader

                    int packageSize  = 100000;
                    int numberOfRows = 0;
                    //HACK ?
                    TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGESIZE] = packageSize;

                    int counter = 0;

                    dm.CheckOutDatasetIfNot(ds.Id, GetUsernameOrDefault()); // there are cases, the dataset does not get checked out!!
                    if (!dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault()))
                    {
                        throw new Exception(string.Format("Not able to checkout dataset '{0}' for  user '{1}'!", ds.Id, GetUsernameOrDefault()));
                    }

                    DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(ds.Id);

                    counter++;
                    TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGE] = counter;

                    //rows = reader.ReadFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), oldSds, (int)id, packageSize).ToArray();

                    List <string> selectedDataAreaJsonArray   = (List <string>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA];
                    string        selectedHeaderAreaJsonArray = TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA].ToString();
                    List <int[]>  areaDataValuesList          = new List <int[]>();
                    foreach (string area in selectedDataAreaJsonArray)
                    {
                        areaDataValuesList.Add(JsonConvert.DeserializeObject <int[]>(area));
                    }
                    int[] areaHeaderValues = JsonConvert.DeserializeObject <int[]>(selectedHeaderAreaJsonArray);

                    Orientation orientation = 0;

                    switch (TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT].ToString())
                    {
                    case "LeftRight":
                        orientation = Orientation.rowwise;
                        break;

                    case "Matrix":
                        //orientation = Orientation.matrix;
                        break;

                    default:
                        orientation = Orientation.columnwise;
                        break;
                    }

                    String worksheetUri = null;
                    //Get the Uri to identify the correct worksheet
                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.ACTIVE_WOKSHEET_URI))
                    {
                        worksheetUri = TaskManager.Bus[EasyUploadTaskManager.ACTIVE_WOKSHEET_URI].ToString();
                    }

                    int batchSize = (new Object()).GetUnitOfWork().PersistenceManager.PreferredPushSize;
                    int batchnr   = 1;
                    foreach (int[] areaDataValues in areaDataValuesList)
                    {
                        //First batch starts at the start of the current data area
                        int currentBatchStartRow = areaDataValues[0] + 1;
                        while (currentBatchStartRow <= areaDataValues[2] + 1) //While the end of the current data area has not yet been reached
                        {
                            //End row is start row plus batch size
                            int currentBatchEndRow = currentBatchStartRow + batchSize;

                            //Set the indices for the reader
                            EasyUploadFileReaderInfo fri = new EasyUploadFileReaderInfo
                            {
                                DataStartRow = currentBatchStartRow,
                                //End row is either at the end of the batch or the end of the marked area
                                //DataEndRow = (currentBatchEndRow > areaDataValues[2] + 1) ? areaDataValues[2] + 1 : currentBatchEndRow,
                                DataEndRow = Math.Min(currentBatchEndRow, areaDataValues[2] + 1),
                                //Column indices as marked in a previous step
                                DataStartColumn = areaDataValues[1] + 1,
                                DataEndColumn   = areaDataValues[3] + 1,

                                //Header area as marked in a previous step
                                VariablesStartRow    = areaHeaderValues[0] + 1,
                                VariablesStartColumn = areaHeaderValues[1] + 1,
                                VariablesEndRow      = areaHeaderValues[2] + 1,
                                VariablesEndColumn   = areaHeaderValues[3] + 1,

                                Offset      = areaDataValues[1],
                                Orientation = orientation
                            };
                            //Create a new reader each time because the reader saves ALL tuples it read and therefore the batch processing wouldn't work
                            EasyUploadExcelReader reader = new EasyUploadExcelReader(sds, fri);
                            // open file
                            Stream = reader.Open(TaskManager.Bus[EasyUploadTaskManager.FILEPATH].ToString());

                            //Set variable identifiers because they might differ from the variable names in the file
                            reader.setSubmittedVariableIdentifiers(identifiers);

                            //Read the rows and convert them to DataTuples
                            rows = reader.ReadFile(Stream, TaskManager.Bus[EasyUploadTaskManager.FILENAME].ToString(), fri, (int)datasetId, worksheetUri);

                            //After reading the rows, add them to the dataset
                            if (rows != null)
                            {
                                dm.EditDatasetVersion(workingCopy, rows.ToList(), null, null);
                                numberOfRows += rows.Count();
                            }

                            //Close the Stream so the next ExcelReader can open it again
                            Stream.Close();

                            //Debug information
                            int lines   = (areaDataValues[2] + 1) - (areaDataValues[0] + 1);
                            int batches = lines / batchSize;
                            batchnr++;

                            //Next batch starts after the current one
                            currentBatchStartRow = currentBatchEndRow + 1;
                        }
                    }

                    #endregion excel reader

                    //set modification
                    workingCopy.ModificationInfo = new EntityAuditInfo()
                    {
                        Performer  = GetUsernameOrDefault(),
                        Comment    = "Data",
                        ActionType = AuditActionType.Create
                    };

                    dm.EditDatasetVersion(workingCopy, null, null, null);

                    dm.CheckInDataset(ds.Id, "Import " + numberOfRows + " rows", GetUsernameOrDefault());

                    //Reindex search
                    if (this.IsAccessible("DDM", "SearchIndex", "ReIndexSingle"))
                    {
                        this.Run("DDM", "SearchIndex", "ReIndexSingle", new RouteValueDictionary()
                        {
                            { "id", datasetId }
                        });
                    }

                    TaskManager.AddToBus(EasyUploadTaskManager.DATASET_ID, ds.Id);

                    return(temp);
                }
            }
            catch (Exception ex)
            {
                temp.Add(new Error(ErrorType.Other, "An error occured during the upload. " +
                                   "Please try again later. If this problem keeps occuring, please contact your administrator."));
                return(temp);
            }
            finally
            {
                dsm.Dispose();
                dm.Dispose();
                dam.Dispose();
                //sm.Dispose();
                entityPermissionManager.Dispose();
            }
        }
Пример #23
0
        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();
            }
        }
Пример #24
0
        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));
                }
            }
        }
Пример #25
0
        public ActionResult RefreshTaskList()
        {
            TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

            return(PartialView("_taskListView", TaskManager.GetStatusOfStepInfos()));
        }
Пример #26
0
        //[MeasurePerformance]
        //temporary solution: norman
        //For original solution, look into Aquadiva Code
        public List <Error> FinishUpload(EasyUploadTaskManager taskManager)
        {
            DataStructureManager dsm = new DataStructureManager();
            DatasetManager       dm  = new DatasetManager();
            DataContainerManager dam = new DataContainerManager();
            //SubjectManager sm = new SubjectManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();

            List <Error> temp = new List <Error>();

            try
            {
                using (IUnitOfWork unitOfWork = this.GetUnitOfWork())
                {
                    // initialize all necessary manager

                    DataTuple[] rows = null;

                    //First, try to validate - if there are errors, return immediately
                    string       JsonArray        = TaskManager.Bus[EasyUploadTaskManager.SHEET_JSON_DATA].ToString();
                    List <Error> ValidationErrors = ValidateRows(JsonArray);
                    if (ValidationErrors.Count != 0)
                    {
                        temp.AddRange(ValidationErrors);
                        return(temp);
                    }

                    string timestamp = DateTime.UtcNow.ToString("r");
                    string title     = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]);

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE))
                    {
                        string tmp = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                        if (!String.IsNullOrWhiteSpace(tmp))
                        {
                            title = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                        }
                    }

                    StructuredDataStructure sds = dsm.CreateStructuredDataStructure(title, title + " " + timestamp, "", "", DataStructureCategory.Generic);

                    TaskManager.AddToBus(EasyUploadTaskManager.DATASTRUCTURE_ID, sds.Id);
                    TaskManager.AddToBus(EasyUploadTaskManager.DATASTRUCTURE_TITLE, title + " " + timestamp);

                    if (!TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DATASET_TITLE))
                    {
                        TaskManager.AddToBus(EasyUploadTaskManager.DATASET_TITLE, title);
                        TaskManager.AddToBus(EasyUploadTaskManager.TITLE, title);
                    }

                    MetadataStructure metadataStructure = null;
                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SCHEMA))
                    {
                        long metadataStructureId = Convert.ToInt64(TaskManager.Bus[EasyUploadTaskManager.SCHEMA]);
                        metadataStructure = unitOfWork.GetReadOnlyRepository <MetadataStructure>()
                                            .Get(m => m.Id == metadataStructureId).FirstOrDefault();
                    }
                    else
                    {
                        //Default option but shouldn't happen because previous steps can't be finished without selecting the metadata-structure
                        metadataStructure = unitOfWork.GetReadOnlyRepository <MetadataStructure>()
                                            .Get(m => m.Name.ToLower().Contains("eml")).FirstOrDefault();
                    }
                    ResearchPlan rp = unitOfWork.GetReadOnlyRepository <ResearchPlan>().Get().FirstOrDefault();
                    TaskManager.AddToBus(EasyUploadTaskManager.RESEARCHPLAN_ID, rp.Id);
                    TaskManager.AddToBus(EasyUploadTaskManager.RESEARCHPLAN_TITLE, rp.Title);

                    #region Progress Information

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.CURRENTPACKAGESIZE))
                    {
                        TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGESIZE] = 0;
                    }
                    else
                    {
                        TaskManager.Bus.Add(EasyUploadTaskManager.CURRENTPACKAGESIZE, 0);
                    }

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.CURRENTPACKAGE))
                    {
                        TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGE] = 0;
                    }
                    else
                    {
                        TaskManager.Bus.Add(EasyUploadTaskManager.CURRENTPACKAGE, 0);
                    }

                    #endregion

                    #region DataStructure
                    XmlDocument xmldoc       = new XmlDocument();
                    XmlElement  extraElement = xmldoc.CreateElement("extra");
                    XmlElement  orderElement = xmldoc.CreateElement("order");


                    List <Tuple <int, string, UnitInfo> > MappedHeaders = (List <Tuple <int, string, UnitInfo> >)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS];
                    //Sorting necessary to prevent problems when inserting the tuples
                    MappedHeaders.Sort((head1, head2) => head1.Item1.CompareTo(head2.Item1));
                    List <VariableIdentifier> identifiers = new List <VariableIdentifier>();

                    var dataTypeRepo      = unitOfWork.GetReadOnlyRepository <DataType>();
                    var unitRepo          = unitOfWork.GetReadOnlyRepository <Unit>();
                    var dataAttributeRepo = unitOfWork.GetReadOnlyRepository <DataAttribute>();

                    List <DataAttribute> allDataAttributes = dataAttributeRepo.Get().ToList();

                    foreach (Tuple <int, string, UnitInfo> Entry in MappedHeaders)
                    {
                        int i = MappedHeaders.IndexOf(Entry);

                        DataType dataType            = dataTypeRepo.Get(Entry.Item3.SelectedDataTypeId);
                        Unit     CurrentSelectedUnit = unitRepo.Get(Entry.Item3.UnitId);

                        DataAttribute CurrentDataAttribute = new DataAttribute();
                        //If possible, map the chosen variable name, unit and datatype to an existing DataAttribute (Exact match)
                        DataAttribute existingDataAttribute = allDataAttributes.Where(da => da.Name.ToLower().Equals(TrimAndLimitString(Entry.Item2).ToLower()) &&
                                                                                      da.DataType.Id == dataType.Id &&
                                                                                      da.Unit.Id == CurrentSelectedUnit.Id).FirstOrDefault();
                        if (existingDataAttribute != null)
                        {
                            CurrentDataAttribute = existingDataAttribute;
                        }
                        else
                        {
                            //No matching DataAttribute => Create a new one
                            CurrentDataAttribute = dam.CreateDataAttribute(TrimAndLimitString(Entry.Item2), Entry.Item2, "", false, false, "", MeasurementScale.Categorial, DataContainerType.ReferenceType, "", dataType, CurrentSelectedUnit, null, null, null, null, null, null);
                        }

                        Variable           newVariable = dsm.AddVariableUsage(sds, CurrentDataAttribute, true, Entry.Item2, "", "", "");
                        VariableIdentifier vi          = new VariableIdentifier
                        {
                            name = newVariable.Label,
                            id   = newVariable.Id
                        };
                        identifiers.Add(vi);

                        XmlElement newVariableXml = xmldoc.CreateElement("variable");
                        newVariableXml.InnerText = Convert.ToString(newVariable.Id);

                        orderElement.AppendChild(newVariableXml);
                    }
                    extraElement.AppendChild(orderElement);
                    xmldoc.AppendChild(extraElement);

                    sds.Extra       = xmldoc;
                    sds.Name        = "generated import structure " + timestamp;
                    sds.Description = "automatically generated structured data structure by user " + GetUsernameOrDefault() + " for file " + title + " on " + timestamp;

                    #endregion

                    Dataset ds = null;
                    ds = dm.CreateEmptyDataset(sds, rp, metadataStructure);

                    //TODO Should a template be created?

                    /*ExcelTemplateProvider etp = new ExcelTemplateProvider();
                     * etp.CreateTemplate(sds);*/

                    long datasetId = ds.Id;
                    long sdsId     = sds.Id;


                    if (dm.IsDatasetCheckedOutFor(datasetId, GetUsernameOrDefault()) || dm.CheckOutDataset(datasetId, GetUsernameOrDefault()))
                    {
                        DatasetVersion    dsv = dm.GetDatasetWorkingCopy(datasetId);
                        long              METADATASTRUCTURE_ID = metadataStructure.Id;
                        XmlMetadataWriter xmlMetadatWriter     = new XmlMetadataWriter(XmlNodeMode.xPath);
                        XDocument         metadataX            = xmlMetadatWriter.CreateMetadataXml(METADATASTRUCTURE_ID);
                        XmlDocument       metadataXml          = XmlMetadataWriter.ToXmlDocument(metadataX);
                        dsv.Metadata = metadataXml;
                        try
                        {
                            dsv.Metadata = xmlDatasetHelper.SetInformation(dsv, metadataXml, NameAttributeValues.title, title);
                        }
                        catch (NullReferenceException ex)
                        {
                            //Reference of the title node is missing
                            throw new NullReferenceException("The extra-field of this metadata-structure is missing the title-node-reference!");
                        }
                        dm.EditDatasetVersion(dsv, null, null, null);
                    }


                    #region security
                    // add security
                    if (GetUsernameOrDefault() != "DEFAULT")
                    {
                        //PermissionManager pm = new PermissionManager();

                        //User user = sm.GetUserByName(GetUsernameOrDefault());

                        //Rights-Management

                        /*
                         * TODO: Use the BExIS Party API for that
                         *
                         * */
                        /*
                         * UserPiManager upm = new UserPiManager();
                         * List<long> piList = (new UserSelectListModel(GetUsernameOrDefault())).UserList.Select(x => x.Id).ToList();
                         */


                        foreach (RightType rightType in Enum.GetValues(typeof(RightType)).Cast <RightType>())
                        {
                            //The user gets full permissions
                            // add security
                            if (GetUsernameOrDefault() != "DEFAULT")
                            {
                                entityPermissionManager.Create <User>(GetUsernameOrDefault(), "Dataset", typeof(Dataset), ds.Id, Enum.GetValues(typeof(RightType)).Cast <RightType>().ToList());
                            }

                            // adding the rights for the pis

                            /*foreach (long piId in piList)
                             * {
                             *  //Each pi gets full permissions
                             *  pm.CreateDataPermission(piId, 1, ds.Id, rightType);
                             *
                             *  // get all pi members
                             *  List<UserPi> currentMembers = upm.GetAllPiMember(piId).ToList();
                             *
                             *  foreach (UserPi currentMapping in currentMembers)
                             *  {
                             *      switch (rightType)
                             *      {
                             *          //Each member of each of the pis gets view-rights
                             *          case RightType.View:
                             *              pm.CreateDataPermission(currentMapping.UserId, 1, ds.Id, rightType);
                             *              break;
                             *          //Each member of each of the pis gets download-rights
                             *          case RightType.Download:
                             *              pm.CreateDataPermission(currentMapping.UserId, 1, ds.Id, rightType);
                             *              break;
                             *          default:
                             *              //No other permissions - is this call necessary?
                             *              pm.CreateDataPermission(currentMapping.UserId, 0, ds.Id, rightType);
                             *              break;
                             *      }
                             *  }
                             * }*/
                        }
                    }
                    #endregion security


                    #region excel reader

                    int packageSize = 10000;
                    //HACK ?
                    TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGESIZE] = packageSize;

                    int counter = 0;

                    dm.CheckOutDatasetIfNot(ds.Id, GetUsernameOrDefault()); // there are cases, the dataset does not get checked out!!
                    if (!dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault()))
                    {
                        throw new Exception(string.Format("Not able to checkout dataset '{0}' for  user '{1}'!", ds.Id, GetUsernameOrDefault()));
                    }

                    DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(ds.Id);

                    counter++;
                    TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGE] = counter;

                    //rows = reader.ReadFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), oldSds, (int)id, packageSize).ToArray();

                    List <string> selectedDataAreaJsonArray   = (List <string>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA];
                    string        selectedHeaderAreaJsonArray = TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA].ToString();
                    List <int[]>  areaDataValuesList          = new List <int[]>();
                    foreach (string area in selectedDataAreaJsonArray)
                    {
                        areaDataValuesList.Add(JsonConvert.DeserializeObject <int[]>(area));
                    }
                    int[] areaHeaderValues = JsonConvert.DeserializeObject <int[]>(selectedHeaderAreaJsonArray);

                    Orientation orientation = 0;

                    switch (TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT].ToString())
                    {
                    case "LeftRight":
                        orientation = Orientation.rowwise;
                        break;

                    case "Matrix":
                        //orientation = Orientation.matrix;
                        break;

                    default:
                        orientation = Orientation.columnwise;
                        break;
                    }

                    String worksheetUri = null;
                    //Get the Uri to identify the correct worksheet
                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.ACTIVE_WOKSHEET_URI))
                    {
                        worksheetUri = TaskManager.Bus[EasyUploadTaskManager.ACTIVE_WOKSHEET_URI].ToString();
                    }

                    int batchSize = (new Object()).GetUnitOfWork().PersistenceManager.PreferredPushSize;
                    int batchnr   = 1;
                    foreach (int[] areaDataValues in areaDataValuesList)
                    {
                        //First batch starts at the start of the current data area
                        int currentBatchStartRow = areaDataValues[0] + 1;
                        while (currentBatchStartRow <= areaDataValues[2] + 1) //While the end of the current data area has not yet been reached
                        {
                            //Create a new reader each time because the reader saves ALL tuples it read and therefore the batch processing wouldn't work
                            EasyUploadExcelReader reader = new EasyUploadExcelReader();
                            // open file
                            Stream = reader.Open(TaskManager.Bus[EasyUploadTaskManager.FILEPATH].ToString());

                            //End row is start row plus batch size
                            int currentBatchEndRow = currentBatchStartRow + batchSize;

                            //Set the indices for the reader
                            EasyUploadFileReaderInfo fri = new EasyUploadFileReaderInfo
                            {
                                DataStartRow = currentBatchStartRow,
                                //End row is either at the end of the batch or the end of the marked area
                                //DataEndRow = (currentBatchEndRow > areaDataValues[2] + 1) ? areaDataValues[2] + 1 : currentBatchEndRow,
                                DataEndRow = Math.Min(currentBatchEndRow, areaDataValues[2] + 1),
                                //Column indices as marked in a previous step
                                DataStartColumn = areaDataValues[1] + 1,
                                DataEndColumn   = areaDataValues[3] + 1,

                                //Header area as marked in a previous step
                                VariablesStartRow    = areaHeaderValues[0] + 1,
                                VariablesStartColumn = areaHeaderValues[1] + 1,
                                VariablesEndRow      = areaHeaderValues[2] + 1,
                                VariablesEndColumn   = areaHeaderValues[3] + 1,

                                Offset      = areaDataValues[1],
                                Orientation = orientation
                            };

                            //Set variable identifiers because they might differ from the variable names in the file
                            reader.setSubmittedVariableIdentifiers(identifiers);

                            //Read the rows and convert them to DataTuples
                            rows = reader.ReadFile(Stream, TaskManager.Bus[EasyUploadTaskManager.FILENAME].ToString(), fri, sds, (int)datasetId, worksheetUri);

                            //After reading the rows, add them to the dataset
                            if (rows != null)
                            {
                                dm.EditDatasetVersion(workingCopy, rows.ToList(), null, null);
                            }

                            //Close the Stream so the next ExcelReader can open it again
                            Stream.Close();

                            //Debug information
                            int lines   = (areaDataValues[2] + 1) - (areaDataValues[0] + 1);
                            int batches = lines / batchSize;
                            batchnr++;

                            //Next batch starts after the current one
                            currentBatchStartRow = currentBatchEndRow + 1;
                        }
                    }

                    #endregion


                    dm.CheckInDataset(ds.Id, "upload data from upload wizard", GetUsernameOrDefault());

                    //Reindex search
                    if (this.IsAccessibale("DDM", "SearchIndex", "ReIndexSingle"))
                    {
                        this.Run("DDM", "SearchIndex", "ReIndexSingle", new RouteValueDictionary()
                        {
                            { "id", datasetId }
                        });
                    }

                    TaskManager.AddToBus(EasyUploadTaskManager.DATASET_ID, ds.Id);

                    return(temp);
                }
            }
            catch (Exception ex)
            {
                temp.Add(new Error(ErrorType.Other, "An error occured during the upload. " +
                                   "Please try again later. If this problem keeps occuring, please contact your administrator."));
                return(temp);
            }
            finally
            {
                dsm.Dispose();
                dm.Dispose();
                dam.Dispose();
                //sm.Dispose();
                entityPermissionManager.Dispose();
            }
        }
Пример #27
0
        public ActionResult RefreshNavigation()
        {
            TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

            return(PartialView("_uploadWizardNav", TaskManager));
        }
Пример #28
0
        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));
        }
Пример #29
0
        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));
        }
Пример #30
0
        public ActionResult SaveSelection(int index, long selectedUnit, long selectedDataType, long selectedAttribute, string varName, string lastSelection)
        {
            /**
             * if selectedAttribute == -1 == Unknown
             *    selectedAttribute == -2 ==  Not found
             *
             */


            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>();


            EasyUploadTaskManager TaskManager = (EasyUploadTaskManager)Session["TaskManager"];

            //suggestions

            #region load all lists

            //dataattr
            if (Session["DataAttributes"] != null)
            {
                dataAttributeInfos = (List <DataAttrInfo>)Session["DataAttributes"];
            }

            if (!string.IsNullOrEmpty(varName))
            {
                suggestions = getSuggestions(varName, dataAttributeInfos);
            }

            unitInfos = (List <UnitInfo>)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_AVAILABLEUNITS];

            dataTypeInfos = (List <DataTypeInfo>)TaskManager.Bus[EasyUploadTaskManager.ALL_DATATYPES];

            #endregion


            #region load current seleted items

            UnitInfo     currentUnit         = unitInfos.FirstOrDefault(u => u.UnitId == selectedUnit);
            DataTypeInfo currentDataTypeInfo = dataTypeInfos.FirstOrDefault(d => d.DataTypeId.Equals(selectedDataType));

            DataAttrInfo currentDataAttrInfo = null;
            if (selectedAttribute > 0)
            {
                currentDataAttrInfo = dataAttributeInfos.FirstOrDefault(da => da.Id.Equals(selectedAttribute));
            }
            if (selectedAttribute == -1)
            {
                currentDataAttrInfo = new DataAttrInfo(-1, 0, 0, "Unknown", "Unknow", 1);
            }
            if (selectedAttribute == -2)
            {
                currentDataAttrInfo = new DataAttrInfo(-2, 0, 0, "Not found", "Not found", 1);
            }
            ;

            #endregion

            #region filtering



            if (currentUnit != null)
            {
                unitInfos = unitInfos.Where(u => u.UnitId.Equals(currentUnit.UnitId) || u.DimensionId.Equals(currentUnit.DimensionId)).ToList();

                // filtering data attrs where the attr has the unit or there dimension
                if (selectedAttribute == 0)
                {
                    dataAttributeInfos = dataAttributeInfos.Where(d => d.UnitId.Equals(currentUnit.UnitId) || d.DimensionId.Equals(currentUnit.DimensionId)).ToList();
                }
                else
                {
                    dataAttributeInfos = dataAttributeInfos.Where(d => d.Id.Equals(currentDataAttrInfo.Id)).ToList();
                }

                if (selectedDataType == 0)
                {
                    dataTypeInfos = dataTypeInfos.Where(d => currentUnit.DataTypeInfos.Any(ud => ud.DataTypeId.Equals(d.DataTypeId))).ToList();
                }
                else
                {
                    dataTypeInfos = dataTypeInfos.Where(dt => dt.DataTypeId.Equals(currentDataTypeInfo.DataTypeId)).ToList();
                }
            }

            if (currentDataTypeInfo != null)
            {
                dataTypeInfos = dataTypeInfos.Where(dt => dt.DataTypeId.Equals(currentDataTypeInfo.DataTypeId)).ToList();

                if (selectedAttribute == 0)
                {
                    dataAttributeInfos = dataAttributeInfos.Where(d => d.DataTypeId.Equals(currentDataTypeInfo.DataTypeId)).ToList();
                }
                else
                {
                    dataAttributeInfos = dataAttributeInfos.Where(d => d.Id.Equals(currentDataAttrInfo.Id)).ToList();
                }

                if (selectedUnit == 0)
                {
                    unitInfos = unitInfos.Where(u => u.DataTypeInfos.Any(d => d.DataTypeId.Equals(currentDataTypeInfo.DataTypeId))).ToList();
                }
                else
                {
                    unitInfos.Where(u => u.UnitId.Equals(currentUnit.UnitId) || u.DimensionId.Equals(currentUnit.DimensionId)).ToList();
                }
            }


            if (currentDataAttrInfo != null)
            {
                // is the seletced currentDataAttrInfo a suggestion then overrigth all selected items
                if (currentDataAttrInfo.Id > 0)
                {
                    #region existing selected dataset

                    if (suggestions.Any(s => s.attributeName.Equals(currentDataAttrInfo.Name)))
                    {
                        dataAttributeInfos = dataAttributeInfos.Where(d => d.Id.Equals(currentDataAttrInfo.Id)).ToList();
                        unitInfos          = unitInfos.Where(u => u.UnitId.Equals(currentDataAttrInfo.UnitId) || u.DimensionId.Equals(currentDataAttrInfo.DimensionId)).ToList();
                        dataTypeInfos      = unitInfos.SelectMany(u => u.DataTypeInfos).GroupBy(d => d.DataTypeId).Select(g => g.Last()).ToList();

                        if (lastSelection == "Suggestions")
                        {
                            currentUnit         = unitInfos.FirstOrDefault(u => u.UnitId.Equals(dataAttributeInfos.First().UnitId));
                            currentDataTypeInfo = dataTypeInfos.FirstOrDefault(d => d.DataTypeId.Equals(dataAttributeInfos.First().DataTypeId));
                        }
                    }
                    else
                    {
                        dataAttributeInfos = dataAttributeInfos.Where(d => d.Id.Equals(currentDataAttrInfo.Id)).ToList();

                        //filtering units when data attr is selected, if id or dimension is the same
                        if (selectedUnit == 0)
                        {
                            unitInfos   = unitInfos.Where(u => u.UnitId.Equals(currentDataAttrInfo.UnitId) || u.DimensionId.Equals(currentDataAttrInfo.DimensionId)).ToList();
                            currentUnit = unitInfos.FirstOrDefault(u => u.UnitId.Equals(currentDataAttrInfo.UnitId));
                        }
                        else
                        {
                            unitInfos = unitInfos.Where(u => u.UnitId.Equals(currentUnit.UnitId) || u.DimensionId.Equals(currentUnit.DimensionId)).ToList();
                        }

                        if (selectedDataType == 0)
                        {
                            dataTypeInfos = unitInfos.SelectMany(u => u.DataTypeInfos).GroupBy(d => d.DataTypeId).Select(g => g.Last()).ToList();

                            currentDataTypeInfo = dataTypeInfos.FirstOrDefault(d => d.DataTypeId.Equals(currentDataAttrInfo.DataTypeId));
                        }
                        else
                        {
                            dataTypeInfos = dataTypeInfos.Where(dt => dt.DataTypeId.Equals(currentDataTypeInfo.DataTypeId)).ToList();
                        }
                    }

                    #endregion existing selected dataset
                }
                else
                if (currentDataAttrInfo.Id == -1) //unknow
                {
                    // do nothing
                }
                else
                if (currentDataAttrInfo.Id == -2) //not found
                {
                    // do nothing
                }
            }



            #endregion


            RowModel model = new RowModel(
                index,
                varName,
                currentDataAttrInfo,
                currentUnit,
                currentDataTypeInfo,
                suggestions,
                unitInfos,
                dataAttributeInfos,
                dataTypeInfos
                );

            //update row in the bus of the taskmanager
            UpdateRowInBus(model);

            return(PartialView("Row", model));
        }