Ejemplo n.º 1
0
        public ActionResult Validation(object[] data)
        {
            TaskManager = (BExIS.Dcm.UploadWizard.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));
        }
Ejemplo n.º 2
0
        public ActionResult DefinePrimaryKey(object[] data)
        {
            TaskManager = (BExIS.Dcm.UploadWizard.TaskManager)Session["TaskManager"];
            PrimaryKeyViewModel model = new PrimaryKeyViewModel();

            model.StepInfo = TaskManager.Current();

            TaskManager.Current().SetValid(false);

            if (TaskManager.Bus.ContainsKey(TaskManager.PRIMARY_KEYS_UNIQUE))
            {
                TaskManager.Current().SetValid((bool)TaskManager.Bus[TaskManager.PRIMARY_KEYS_UNIQUE]);
            }

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

            // if step not valid load data if its not exist in the session for the model
            if (Session["VariableLableList"] == null)
            {
                model.VariableLableList      = LoadVariableLableList();
                Session["VariableLableList"] = model.VariableLableList;
            }
            else
            {
                model.VariableLableList = (List <ListViewItem>)Session["VariableLableList"];
            }

            // load maybe selected primary keys
            if (TaskManager.Bus.ContainsKey(TaskManager.PRIMARY_KEYS))
            {
                model.PK_Id_List = (List <long>)TaskManager.Bus[TaskManager.PRIMARY_KEYS];
            }

            // and add error to model
            model.ErrorList.Add(new Error(ErrorType.Other, "Define a primary key combination and check it please."));

            return(PartialView(model));
        }
Ejemplo n.º 3
0
        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());
        }
        public ActionResult SpecifyDataset(object[] data)
        {
            using (var unitOfWork = this.GetUnitOfWork())
            {
                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))
                    {
                        Dataset ds = new Dataset();
                        try
                        {
                            ds = unitOfWork.GetReadOnlyRepository <Dataset>().Get((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));
            }
        }
Ejemplo n.º 5
0
        public ActionResult SelectAFile(object[] data)
        {
            var 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
                                var filePath = TaskManager.Bus[TaskManager.FILEPATH].ToString();
                                //if extention like a makro excel FileStream
                                if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".xlsm"))
                                {
                                    // open FileStream
                                    var 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");
                                    }

                                    if (!ExcelReader.SUPPORTED_APPLICATIONS.Contains(reader.Application))
                                    {
                                        model.ErrorList.Add(new Error(ErrorType.Other, "The document was created in an application " + reader.Application + " that will currently not support"));
                                    }

                                    Stream.Close();
                                }
                                else
                                {
                                    TaskManager.AddToBus(TaskManager.IS_TEMPLATE, "false");
                                    // excel FileStream
                                    if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".xls"))
                                    {
                                        // open FileStream
                                        var 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
                                        var 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
                                var filePath = TaskManager.Bus[TaskManager.FILEPATH].ToString();

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


                                #endregion
                            }
                        }
                        catch (Exception ex)
                        {
                            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, this.Session.GetTenant());

            return(PartialView(model));
        }
        public ActionResult GetFileInformation()
        {
            IOUtility iOUtility = new IOUtility();

            TaskManager = (TaskManager)Session["TaskManager"];
            TaskManager.Current().SetValid(false);

            GetFileInformationModel model = new GetFileInformationModel();

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

            if (TaskManager.Bus.ContainsKey(TaskManager.FILE_READER_INFO))
            {
                FileReaderInfo fri = (FileReaderInfo)TaskManager.Bus[TaskManager.FILE_READER_INFO];

                if (fri is ExcelFileReaderInfo)
                {
                    ExcelFileReaderInfo efri = (ExcelFileReaderInfo)fri;
                    if (efri.VariablesStartRow == 0)
                    {
                        TaskManager.Current().SetValid(false);
                        model.ErrorList.Add(new Error(ErrorType.Other, "Header is not set."));
                    }

                    if (efri.DataStartRow == 0)
                    {
                        TaskManager.Current().SetValid(false);
                        model.ErrorList.Add(new Error(ErrorType.Other, "Data is not set."));
                    }

                    if (model.ErrorList.Count == 0)
                    {
                        TaskManager.Current().SetValid(true);
                    }
                }
                else
                {
                    TaskManager.Current().SetValid(true);
                }
            }

            if (!TaskManager.Current().IsValid())
            {
                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 Information not saved."));

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

                    if (iOUtility.IsSupportedExcelFile(model.Extention))
                    {
                        model.FileInfoModel = GetFileInfoModel((ExcelFileReaderInfo)TaskManager.Bus[TaskManager.FILE_READER_INFO], TaskManager.Bus[TaskManager.EXTENTION].ToString());
                    }
                }

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

                return(PartialView(model));
            }
            else
            {
                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() }
                }));
            }
        }