Inheritance: BExIS.Dcm.Wizard.AbstractTaskManager
Esempio n. 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="xmlDocument"></param>
        /// <returns></returns>
        public static TaskManager Bind(XmlDocument xmlDocument)
        {
            XmlNodeList xmlStepInfos = xmlDocument.GetElementsByTagName("stepInfo");

            TaskManager tm = new TaskManager();
            tm.StepInfos = new List<StepInfo>();

            foreach (XmlNode xmlStepInfo in xmlStepInfos)
            {

                StepInfo si = new StepInfo(xmlStepInfo.Attributes.GetNamedItem("title").Value)
                {
                    GetActionInfo = new ActionInfo
                    {
                        ActionName = xmlStepInfo.Attributes.GetNamedItem("action").Value,
                        ControllerName = xmlStepInfo.Attributes.GetNamedItem("controller").Value,
                        AreaName = xmlStepInfo.Attributes.GetNamedItem("area").Value
                    },

                    PostActionInfo = new ActionInfo
                    {
                        ActionName = xmlStepInfo.Attributes.GetNamedItem("action").Value,
                        ControllerName = xmlStepInfo.Attributes.GetNamedItem("controller").Value,
                        AreaName = xmlStepInfo.Attributes.GetNamedItem("area").Value
                    }
                };

                tm.StepInfos.Add(si);
            }

            tm.currentStepInfo = tm.StepInfos.First();

            return tm;
        }
Esempio n. 2
0
        public ActionResult SelectAFile(int index)
        {
            TaskManager = (TaskManager)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(TaskManager.FILENAME))
            {
                model.SelectedFileName = TaskManager.Bus[TaskManager.FILENAME].ToString();
            }

            //get datastuctureType
            model.DataStructureType = GetDataStructureType();
            model.SupportedFileExtentions = UploadWizardHelper.GetExtentionList(model.DataStructureType);

            //Get StepInfo
            model.StepInfo = TaskManager.Current();

            model.serverFileList = GetServerFileList();

            return PartialView(model);
        }
Esempio n. 3
0
        public ActionResult FinishUpload()
        {
            TaskManager = (TaskManager)Session["TaskManager"];
            //TaskManager.SetCurrent(null);

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

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

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

            return ShowData((long)TaskManager.Bus[TaskManager.DATASET_ID]);
        }
        public ActionResult GetFileInformation(int index)
        {
            TaskManager = (TaskManager)Session["TaskManager"];

            //set current stepinfo based on index
            if (TaskManager != null)
            {
                TaskManager.SetCurrent(index);

                // remove if existing
                TaskManager.RemoveExecutedStep(TaskManager.Current());
            }

            //if its a template jumping direkt to the next step
            if (TaskManager.Bus[TaskManager.IS_TEMPLATE].ToString().Equals("true"))
            {
                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() } });
                }
            }
            else
            {
                GetFileInformationModel model = new GetFileInformationModel();
                model.StepInfo = TaskManager.Current();
                model.Extention = TaskManager.Bus[TaskManager.EXTENTION].ToString();

                if (TaskManager.Bus.ContainsKey(TaskManager.FILE_READER_INFO))
                {
                    model.FileInfoModel = GetFileInfoModel((AsciiFileReaderInfo)TaskManager.Bus[TaskManager.FILE_READER_INFO], TaskManager.Bus[TaskManager.EXTENTION].ToString());
                }
                else
                {
                    if (model.Extention.Equals(".txt") || model.Extention.Equals(".csv"))
                        TaskManager.Bus[TaskManager.FILE_READER_INFO] = new AsciiFileReaderInfo();

                    if (model.Extention.Equals(".xls"))
                        TaskManager.Bus[TaskManager.FILE_READER_INFO] = new ExcelFileReaderInfo();
                }

                model.FileInfoModel.Extention = TaskManager.Bus[TaskManager.EXTENTION].ToString();

                return PartialView(model);
            }

            return PartialView(new GetFileInformationModel());
        }
Esempio n. 5
0
        public ActionResult CancelUpload()
        {
            TaskManager = (TaskManager)Session["Taskmanager"];

            DataStructureType type = new DataStructureType();

            if (TaskManager.Bus.ContainsKey(TaskManager.DATASTRUCTURE_TYPE))
            {
                type = (DataStructureType)TaskManager.Bus[TaskManager.DATASTRUCTURE_TYPE];
            }

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

            return RedirectToAction("UploadWizard", "Submit", new RouteValueDictionary { { "area", "DCM" }, { "type", type } });
        }
Esempio n. 6
0
        /// <summary>
        /// returns true if Extention in the Bus will supported
        /// </summary>
        /// <param name="taskManager"></param>
        /// <returns></returns>
        private bool IsSupportedExtention(TaskManager taskManager)
        {
            if (taskManager.Bus.ContainsKey(TaskManager.EXTENTION))
            {
                string ext = taskManager.Bus[TaskManager.EXTENTION].ToString();
                DataStructureType type = (DataStructureType)taskManager.Bus[TaskManager.DATASTRUCTURE_TYPE];

                if (UploadWizardHelper.GetExtentionList(type).Contains(ext.ToLower())) return true;

            }

            return false;
        }
Esempio n. 7
0
        private void SetParametersToTaskmanager(long datasetId)
        {
            if (TaskManager == null)
                {
                    TaskManager = (TaskManager) Session["TaskManager"];
                }

                #region set dataset id & dataset title

                if (datasetId > 0)
                {
                    try
                    {
                        long datasetid = Convert.ToInt64(datasetId);
                        TaskManager.AddToBus(TaskManager.DATASET_ID, datasetid);

                        // get title
                        DatasetManager dm = new DatasetManager();
                        string title = "";
                        // is checkedIn?
                        if (dm.IsDatasetCheckedIn(datasetid))
                        {
                            title = XmlDatasetHelper.GetInformation(dm.GetDatasetLatestVersion(datasetid),
                                NameAttributeValues.title);
                        }

                        TaskManager.AddToBus(TaskManager.DATASET_TITLE, title);
                    }

                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }

                #endregion
        }
Esempio n. 8
0
        public ActionResult Validation(int index)
        {
            TaskManager = (TaskManager)Session["TaskManager"];
            //set current stepinfo based on index
            if (TaskManager != null)
            {
                TaskManager.SetCurrent(index);
                // remove if existing
                TaskManager.RemoveExecutedStep(TaskManager.Current());

                // set valid to false if exist
                if (TaskManager.Bus.ContainsKey(TaskManager.VALID))
                {
                    TaskManager.Bus.Remove(TaskManager.VALID);
                }
            }

            ValidationModel model = new ValidationModel();
            model.StepInfo = TaskManager.Current();

            return PartialView(model);
        }
        private void addSelectedDatasetToBus(long datasetId)
        {
            TaskManager = (TaskManager)Session["TaskManager"];
            DatasetManager datasetManager = new DatasetManager();

            if (datasetManager.GetDatasetVersionEffectiveTupleCount(datasetManager.GetDatasetLatestVersion(datasetId)) > 0)
            {
                TaskManager.AddToBus("DatasetStatus", "edit");
            }
            else
                TaskManager.AddToBus("DatasetStatus", "new");

            DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId);

            TaskManager.AddToBus(TaskManager.DATASET_ID, datasetId);

            //Add Metadata to Bus
            //TITLE
            TaskManager.AddToBus(TaskManager.DATASET_TITLE, XmlDatasetHelper.GetInformation(datasetVersion, NameAttributeValues.title));

            ResearchPlanManager rpm = new ResearchPlanManager();
            ResearchPlan rp = rpm.Repo.Get(datasetVersion.Dataset.ResearchPlan.Id);
            TaskManager.AddToBus(TaskManager.RESEARCHPLAN_ID, rp.Id);
            TaskManager.AddToBus(TaskManager.RESEARCHPLAN_TITLE, rp.Title);
        }
Esempio n. 10
0
        public ActionResult RefreshNavigation()
        {
            TaskManager = (TaskManager)Session["TaskManager"];

            return PartialView("_uploadWizardNav", TaskManager);
        }
Esempio n. 11
0
        public ActionResult ValidateFile()
        {
            DataStructureManager dsm = new DataStructureManager();

            try
            {
                BExIS.Dcm.UploadWizard.TaskManager TaskManager = (BExIS.Dcm.UploadWizard.TaskManager)Session["TaskManager"];
                ValidationModel model = new ValidationModel();
                model.StepInfo = TaskManager.Current();

                if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_ID) && TaskManager.Bus.ContainsKey(TaskManager.DATASTRUCTURE_ID))
                {
                    try
                    {
                        long id    = (long)Convert.ToInt32(TaskManager.Bus[TaskManager.DATASET_ID]);
                        long iddsd = (long)Convert.ToInt32(TaskManager.Bus[TaskManager.DATASTRUCTURE_ID]);
                        StructuredDataStructure sds = dsm.StructuredDataStructureRepo.Get(iddsd);
                        dsm.StructuredDataStructureRepo.LoadIfNot(sds.Variables);


                        if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".xlsm"))
                        {
                            // open FileStream
                            ExcelReader reader = new ExcelReader();
                            Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString());
                            reader.ValidateFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), sds, id);
                            model.ErrorList = reader.ErrorMessages;

                            if (TaskManager.Bus.ContainsKey(TaskManager.NUMBERSOFROWS))
                            {
                                TaskManager.Bus[TaskManager.NUMBERSOFROWS] = reader.NumberOfRows;
                            }
                            else
                            {
                                TaskManager.Bus.Add(TaskManager.NUMBERSOFROWS, reader.NumberOfRows);
                            }
                        }

                        if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".csv") ||
                            TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".txt"))
                        {
                            AsciiReader reader = new AsciiReader();
                            Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString());
                            reader.ValidateFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), (AsciiFileReaderInfo)TaskManager.Bus[TaskManager.FILE_READER_INFO], sds, id);
                            model.ErrorList = reader.ErrorMessages;

                            if (TaskManager.Bus.ContainsKey(TaskManager.NUMBERSOFROWS))
                            {
                                TaskManager.Bus[TaskManager.NUMBERSOFROWS] = reader.NumberOfRows;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        model.ErrorList.Add(new Error(ErrorType.Other, "Can not valid. :  " + ex.Message));
                        TaskManager.AddToBus(TaskManager.VALID, false);
                    }
                    finally
                    {
                        Stream.Close();
                    }
                }
                else
                {
                    model.ErrorList.Add(new Error(ErrorType.Dataset, "Dataset is not selected."));
                    TaskManager.AddToBus(TaskManager.VALID, false);
                }

                if (model.ErrorList.Count() == 0)
                {
                    model.Validated = true;
                    TaskManager.AddToBus(TaskManager.VALID, true);
                }

                return(PartialView(TaskManager.Current().GetActionInfo.ActionName, model));
            }
            finally
            {
                dsm.Dispose();
            }
        }
        public ActionResult GetFileInformation()
        {
            TaskManager = (TaskManager)Session["TaskManager"];
            TaskManager.Current().SetValid(false);

            if (TaskManager.Bus[TaskManager.IS_TEMPLATE].ToString().Equals("true"))
                TaskManager.Current().SetValid(true);

            if (TaskManager.Bus.ContainsKey(TaskManager.FILE_READER_INFO))
            {
                TaskManager.Current().SetValid(true);
            }
            else
            {
                GetFileInformationModel model = new GetFileInformationModel();
                model.StepInfo = TaskManager.Current();
                model.Extention = TaskManager.Bus[TaskManager.EXTENTION].ToString();
                model.FileInfoModel.Extention = TaskManager.Bus[TaskManager.EXTENTION].ToString();
                model.ErrorList.Add(new Error(ErrorType.Other, "File Infomartion not saved."));

                if (TaskManager.Bus.ContainsKey(TaskManager.FILE_READER_INFO))
                {
                    model.FileInfoModel = GetFileInfoModel((AsciiFileReaderInfo)TaskManager.Bus[TaskManager.FILE_READER_INFO], TaskManager.Bus[TaskManager.EXTENTION].ToString());
                }

                model.FileInfoModel.Extention = TaskManager.Bus[TaskManager.EXTENTION].ToString();

                return PartialView(model);
            }

            if (TaskManager.Current().IsValid())
            {
                TaskManager.AddExecutedStep(TaskManager.Current());
                TaskManager.GoToNext();
                Session["TaskManager"] = TaskManager;
                ActionInfo actionInfo = TaskManager.Current().GetActionInfo;
                return RedirectToAction(actionInfo.ActionName, actionInfo.ControllerName, new RouteValueDictionary { { "area", actionInfo.AreaName }, { "index", TaskManager.GetCurrentStepInfoIndex() } });
            }

            return PartialView();
        }
Esempio n. 13
0
        public ActionResult Validation(object[] data)
        {
            TaskManager = (TaskManager)Session["TaskManager"];
            ValidationModel model = new ValidationModel();

            if (TaskManager != null)
            {
                TaskManager.Current().SetValid(false);

                if (data != null) TaskManager.AddToBus(data);

                if (TaskManager.Bus.ContainsKey(TaskManager.VALID))
                {
                    bool valid = Convert.ToBoolean(TaskManager.Bus[TaskManager.VALID]);

                    if (valid)
                    {
                        TaskManager.Current().SetValid(true);
                    }
                    else
                    {
                        model.ErrorList.Add(new Error(ErrorType.Other, "Not Valid."));
                    }

                }
                else
                {
                    model.ErrorList.Add(new Error(ErrorType.Other, "Validation failed! Please check that the information you provided  in the previous steps conforms to your data FileStream."));
                    model.StepInfo = TaskManager.Current();
                }

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

            model.StepInfo = TaskManager.Current();

            return PartialView(model);
        }
Esempio n. 14
0
        public ActionResult SelectAFile(object[] data)
        {
            SelectFileViewModel model = new SelectFileViewModel();

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

            if (data != null) TaskManager.AddToBus(data);

            model.StepInfo = TaskManager.Current();

            TaskManager.Current().SetValid(false);

            if (TaskManager != null)
            {
                // is path of FileStream exist
                if (TaskManager.Bus.ContainsKey(TaskManager.FILEPATH))
                {
                    if (IsSupportedExtention(TaskManager))
                    {
                        try
                        {
                            if (GetDataStructureType().Equals(DataStructureType.Structured))
                            {
                                #region structured datastructure
                                    //try save FileStream
                                    string filePath = TaskManager.Bus[TaskManager.FILEPATH].ToString();
                                    //if extention like a makro excel FileStream
                                    if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".xlsm"))
                                    {
                                        // open FileStream
                                        ExcelReader reader = new ExcelReader();
                                        Stream = reader.Open(filePath);
                                        //Session["Stream"] = Stream;

                                        //check is it template

                                        if (reader.IsTemplate(Stream))
                                        {
                                            TaskManager.Current().SetValid(true);
                                            TaskManager.AddToBus(TaskManager.IS_TEMPLATE, "true");
                                        }
                                        else
                                        {
                                            model.ErrorList.Add(new Error(ErrorType.Other, "File is not a Template"));
                                            TaskManager.AddToBus(TaskManager.IS_TEMPLATE, "false");
                                        }

                                        Stream.Close();
                                    }
                                    else
                                    {
                                        TaskManager.AddToBus(TaskManager.IS_TEMPLATE, "false");
                                        // excel FileStream
                                        if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".xls"))
                                        {

                                            // open FileStream
                                            ExcelReader reader = new ExcelReader();
                                            Stream = reader.Open(filePath);
                                            //Session["Stream"] = Stream;
                                            TaskManager.Current().SetValid(true);

                                            Stream.Close();
                                        }
                                        // text ór csv FileStream
                                        else if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".csv") || TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".txt"))
                                        {
                                            // open FileStream
                                            AsciiReader reader = new AsciiReader();
                                            Stream = reader.Open(filePath);
                                            //Session["Stream"] = Stream;
                                            TaskManager.Current().SetValid(true);

                                            Stream.Close();
                                        }
                                    }
                                #endregion
                            }

                            if (GetDataStructureType().Equals(DataStructureType.Unstructured))
                            {
                                #region unstructured datastructure
                                //try save FileStream
                                string filePath = TaskManager.Bus[TaskManager.FILEPATH].ToString();

                                if(FileHelper.FileExist( filePath ))
                                {
                                    TaskManager.Current().SetValid(true);
                                }

                                #endregion
                            }

                        }
                        catch
                        {
                            model.ErrorList.Add(new Error(ErrorType.Other, "Cannot access FileStream on server."));
                        }
                    }
                    else
                    {
                        model.ErrorList.Add(new Error(ErrorType.Other, "File is not supported."));
                    }

                }
                else
                {
                    model.ErrorList.Add(new Error(ErrorType.Other, "No FileStream selected or submitted."));
                }

                if (TaskManager.Current().IsValid())
                {
                    TaskManager.AddExecutedStep(TaskManager.Current());
                    TaskManager.GoToNext();
                    Session["TaskManager"] = TaskManager;
                    ActionInfo actionInfo = TaskManager.Current().GetActionInfo;
                    return RedirectToAction(actionInfo.ActionName, actionInfo.ControllerName, new RouteValueDictionary { { "area", actionInfo.AreaName }, { "index", TaskManager.GetCurrentStepInfoIndex() } });
                }
            }

            model.serverFileList = GetServerFileList();
            //get datastuctureType
            model.DataStructureType = GetDataStructureType();
            model.SupportedFileExtentions = UploadWizardHelper.GetExtentionList(model.DataStructureType);

            return PartialView(model);
        }
Esempio n. 15
0
        public ActionResult RefreshTaskList()
        {
            TaskManager = (TaskManager)Session["TaskManager"];

            return PartialView("_taskListView", TaskManager.GetStatusOfStepInfos());
        }
        public ActionResult SpecifyDataset(object[] data)
        {
            TaskManager = (TaskManager)Session["TaskManager"];
            ChooseDatasetViewModel model = new ChooseDatasetViewModel();
            model.StepInfo = TaskManager.Current();

            if (TaskManager != null)
            {
                TaskManager.Current().SetValid(false);

                if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_ID))
                {
                    DatasetManager dm = new DatasetManager();
                    Dataset ds = new Dataset();
                    try
                    {
                        dm = new DatasetManager();
                        ds = dm.GetDataset((long)Convert.ToInt32(TaskManager.Bus[TaskManager.DATASET_ID]));

                        TaskManager.AddToBus(TaskManager.DATASTRUCTURE_ID, ((DataStructure)(ds.DataStructure.Self)).Id);
                        TaskManager.AddToBus(TaskManager.DATASTRUCTURE_TITLE, ((DataStructure)(ds.DataStructure.Self)).Name);

                        TaskManager.Current().SetValid(true);

                    }
                    catch
                    {
                        model.ErrorList.Add(new Error(ErrorType.Other, "Dataset not exist."));
                    }
                }
                else
                {
                    model.ErrorList.Add(new Error(ErrorType.Other, "Dataset not exist."));
                }

                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();
                    if ((List<ListViewItem>)Session["DatasetVersionViewList"] != null) model.DatasetsViewList = (List<ListViewItem>)Session["DatasetVersionViewList"];
              }
            }

            return PartialView(model);
        }
Esempio n. 17
0
        public ActionResult UploadWizard(DataStructureType type, long datasetid=0)
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Upload Data", this.Session.GetTenant());

            Session["TaskManager"] = null;

            if (TaskManager == null) TaskManager = (TaskManager)Session["TaskManager"];

            if (TaskManager == null)
            {
                try
                {

                    string path = "";

                    if (type == DataStructureType.Unstructured)
                        path = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "SubmitUnstructuredDataTaskInfo.xml");

                    if (type == DataStructureType.Structured)
                        path = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "SubmitTaskInfo.xml");

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

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

                    TaskManager = (TaskManager)Session["TaskManager"];
                    TaskManager.AddToBus(TaskManager.DATASTRUCTURE_TYPE, type);

                    Session["TaskManager"] = TaskManager;

                }
                catch (Exception e)
                {
                    ModelState.AddModelError(String.Empty, e.Message);
                }

                Session["Filestream"] = Stream;

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

                // get Lists of Dataset and Datastructure
                Session["DatasetVersionViewList"] = LoadDatasetVersionViewList(type);
                Session["DataStructureViewList"] = LoadDataStructureViewList(type);
                Session["ResearchPlanViewList"] = LoadResearchPlanViewList();

                // setparameters
                SetParametersToTaskmanager(datasetid);
            }

            return View((TaskManager)Session["TaskManager"]);
        }
        public ActionResult SpecifyDataset(int index)
        {
            TaskManager = (TaskManager)Session["TaskManager"];
            //set current stepinfo based on index
            if (TaskManager != null)
            {
                TaskManager.SetCurrent(index);

                // remove if existing
                TaskManager.RemoveExecutedStep(TaskManager.Current());
            }

            ChooseDatasetViewModel model = new ChooseDatasetViewModel();

            // jump back to this step
            // check if dataset selected
            if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_ID))
            {
                long datasetId = Convert.ToInt64(TaskManager.Bus[TaskManager.DATASET_ID]);

                if(datasetId > 0)
                {
                    // add title to model
                    model.DatasetTitle = TaskManager.Bus[TaskManager.DATASET_TITLE].ToString();
                    // add seleted dataset id to model
                    model.SelectedDatasetId = Convert.ToInt32(TaskManager.Bus[TaskManager.DATASET_ID]);
                    // add informations of dataset to Bus
                    addSelectedDatasetToBus(datasetId);
                }
            }
            model.StepInfo = TaskManager.Current();
            if ((List<ListViewItem>)Session["DatasetVersionViewList"] != null) model.DatasetsViewList = (List<ListViewItem>)Session["DatasetVersionViewList"];

            return PartialView(model);
        }
Esempio n. 19
0
        public ActionResult ValidateFile()
        {
            ViewData["SortedErrors"] = null;

            DataStructureManager dsm       = new DataStructureManager();
            IOUtility            iOUtility = new IOUtility();

            try
            {
                BExIS.Dcm.UploadWizard.TaskManager TaskManager = (BExIS.Dcm.UploadWizard.TaskManager)Session["TaskManager"];
                ValidationModel model = new ValidationModel();
                model.StepInfo = TaskManager.Current();

                if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_ID) && TaskManager.Bus.ContainsKey(TaskManager.DATASTRUCTURE_ID))
                {
                    try
                    {
                        long id    = (long)Convert.ToInt32(TaskManager.Bus[TaskManager.DATASET_ID]);
                        long iddsd = (long)Convert.ToInt32(TaskManager.Bus[TaskManager.DATASTRUCTURE_ID]);
                        StructuredDataStructure sds = dsm.StructuredDataStructureRepo.Get(iddsd);
                        dsm.StructuredDataStructureRepo.LoadIfNot(sds.Variables);

                        // Add Number of Variables to the BUS
                        if (sds != null)
                        {
                            TaskManager.AddToBus(TaskManager.NUMBERSOFVARIABLES, sds.Variables.Count);
                        }


                        if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".xlsm"))
                        {
                            // open FileStream
                            ExcelReader reader = new ExcelReader(sds, new ExcelFileReaderInfo());
                            Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString());
                            reader.ValidateTemplateFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), id);
                            model.ErrorList = reader.ErrorMessages;

                            TaskManager.AddToBus(TaskManager.NUMBERSOFROWS, reader.NumberOfRows);
                        }

                        if (iOUtility.IsSupportedExcelFile(TaskManager.Bus[TaskManager.EXTENTION].ToString()))
                        {
                            // open FileStream
                            ExcelReader reader = new ExcelReader(sds, (ExcelFileReaderInfo)TaskManager.Bus[TaskManager.FILE_READER_INFO]);
                            Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString());
                            reader.ValidateFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), id);
                            model.ErrorList = reader.ErrorMessages;

                            TaskManager.AddToBus(TaskManager.NUMBERSOFROWS, reader.NumberOfRows);
                        }


                        if (iOUtility.IsSupportedAsciiFile(TaskManager.Bus[TaskManager.EXTENTION].ToString()))
                        {
                            AsciiReader reader = new AsciiReader(sds, (AsciiFileReaderInfo)TaskManager.Bus[TaskManager.FILE_READER_INFO]);
                            Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString());
                            reader.ValidateFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), id);
                            model.ErrorList = reader.ErrorMessages;

                            TaskManager.AddToBus(TaskManager.NUMBERSOFROWS, reader.NumberOfRows);
                        }
                    }
                    catch (Exception ex)
                    {
                        model.ErrorList.Add(new Error(ErrorType.Other, "Can not valid. :  " + ex.Message));
                        TaskManager.AddToBus(TaskManager.VALID, false);
                    }
                    finally
                    {
                        Stream.Close();
                    }
                }
                else
                {
                    model.ErrorList.Add(new Error(ErrorType.Dataset, "Dataset is not selected."));
                    TaskManager.AddToBus(TaskManager.VALID, false);
                }

                if (model.ErrorList.Count() == 0)
                {
                    model.Validated = true;
                    TaskManager.AddToBus(TaskManager.VALID, true);
                }

                List <Error> errorList = new List <Error>();
                for (int i = 0; i < model.ErrorList.Count; i++)
                {
                    // Assume not duplicate.
                    bool duplicate = false;
                    for (int z = 0; z < i; z++)
                    {
                        if (model.ErrorList[z].ToString() == model.ErrorList[i].ToString())
                        {
                            // This is a duplicate.
                            duplicate = true;
                            break;
                        }
                    }
                    // If not duplicate, add to result.
                    if (!duplicate)
                    {
                        errorList.Add(model.ErrorList[i]);
                    }
                }

                model.ErrorList = errorList;

                if (errorList.Count > 0)
                {
                    // split up the error messages for a btter overview-- >
                    // set all value error with the same var name, datatypoe and issue-- >
                    // create a dictionary for error messages

                    // variable issues
                    var varNames  = errorList.Where(e => e.GetType().Equals(ErrorType.Value)).Select(e => e.getName()).Distinct();
                    var varIssues = errorList.Where(e => e.GetType().Equals(ErrorType.Value)).Select(e => e.GetMessage()).Distinct();

                    List <Tuple <string, int, string> > sortedErrors = new List <Tuple <string, int, string> >();

                    foreach (string vn in varNames)
                    {
                        foreach (string i in varIssues)
                        {
                            int c = errorList.Where(e => e.getName().Equals(vn) && e.GetMessage().Equals(i)).Count();

                            if (c > 0)
                            {
                                sortedErrors.Add(new Tuple <string, int, string>(vn, c, i));
                            }
                        }
                    }

                    if (sortedErrors.Count > 0)
                    {
                        ViewData["SortedValueErrors"] = sortedErrors;
                    }
                }

                return(PartialView(TaskManager.Current().GetActionInfo.ActionName, model));
            }
            finally
            {
                dsm.Dispose();
            }
        }