コード例 #1
0
ファイル: RapsController.cs プロジェクト: sahvishal/matrix
        private bool IsFileValid(RapsFileUploadEditModel model, out long count)
        {
            try
            {
                var archiveLocation = _mediaRepository.GetRapsUploadMediaFileLocation();
                _csvReader.Delimiter = _csvReader.GetFileDelimiter(archiveLocation.PhysicalPath + model.File.Path).ToString();
                var customerTable = _csvReader.ReadWithTextQualifier(archiveLocation.PhysicalPath + model.File.Path);
                count = customerTable.Rows.Count;
                if (customerTable.Rows.Count == 0)
                {
                    model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Uploaded file has no data.");
                    return(false);
                }

                var missingColumnNames = _rapsUploadHelper.CheckForColumns(customerTable.Rows[0]);
                if (!string.IsNullOrEmpty(missingColumnNames))
                {
                    model.FeedbackMessage =
                        FeedbackMessageModel.CreateFailureMessage("Missing Column Name(s) : " + missingColumnNames);
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                count = 0;
                IoC.Resolve <ILogManager>().GetLogger <Global>().Error("Raps Upload Validation Failure: " + ex.Message + "\n\t" + ex.StackTrace);
                return(false);
            }
        }
コード例 #2
0
ファイル: RapsController.cs プロジェクト: sahvishal/matrix
        // GET: /Medical/Raps/Upload
        public ActionResult Upload()
        {
            var uploadMediaLocation = _mediaRepository.GetRapsUploadMediaFileLocation();
            var model = new RapsFileUploadEditModel
            {
                UploadCsvMediaUrl = uploadMediaLocation.Url
            };

            System.Web.HttpContext.Current.Response.Headers.Remove("Refresh");
            return(View(model));
        }
コード例 #3
0
ファイル: RapsController.cs プロジェクト: sahvishal/matrix
        public JsonResult CreateResultArchive(string fileName, long fileSize)
        {
            var file = new File
            {
                Path       = fileName,
                Type       = FileType.Compressed,
                FileSize   = fileSize,
                UploadedBy = new OrganizationRoleUser(_session.UserSession.CurrentOrganizationRole.OrganizationRoleUserId),
                UploadedOn = DateTime.Now
            };

            file = _fileRepository.Save(file);

            var rapsUpload = new RapsUpload
            {
                FileId     = file.Id,
                UploadTime = DateTime.Now,
                StatusId   = (long)RapsUploadStatus.UploadStarted,
                UploadedBy = _session.UserSession.CurrentOrganizationRole.OrganizationRoleUserId
            };

            rapsUpload = _rapsUploadRepository.Save(rapsUpload);

            //update the file name
            file.Path = _fileHelper.AddPostFixToFileName(file.Path, rapsUpload.Id.ToString());
            _fileRepository.Save(file);


            var editModel = new RapsFileUploadEditModel
            {
                File = file,
                Id   = rapsUpload.Id
            };

            return(Json(editModel, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
ファイル: RapsController.cs プロジェクト: sahvishal/matrix
        public void ProcessUpload(RapsFileUploadEditModel rapsEditModel)
        {
            if (Request.Files.Count != 1)
            {
                throw new Exception("File count should not be empty!");
            }



            try
            {
                HttpPostedFileBase postedFile = Request.Files[0];

                decimal returnLength = 0;
                var     statuses     = new List <FileUploadStatusModel>();
                if (string.IsNullOrEmpty(Request.Headers["X-File-Name"]))
                {
                    UploadWholeFile(postedFile, rapsEditModel.File.Path, statuses);
                    returnLength = rapsEditModel.File.FileSize;
                }
                else
                {
                    returnLength = UploadPartialFile(postedFile, rapsEditModel.File.Path, statuses);
                }



                if (returnLength == rapsEditModel.File.FileSize || returnLength == 0)
                {
                    var resultArchive = _rapsUploadRepository.GetById(rapsEditModel.Id);
                    if (returnLength == rapsEditModel.File.FileSize)
                    {
                        long count = 0;
                        if (IsFileValid(rapsEditModel, out count))
                        {
                            resultArchive.TotalCount = count;
                            resultArchive.StatusId   = (long)RapsUploadStatus.Uploaded;
                        }
                        else
                        {
                            //statuses= new List<FileUploadStatusModel>();
                            //var fname = Path.GetFileName(postedFile.FileName);
                            //statuses.Add(new FileUploadStatusModel
                            //{
                            //    FileName = fname,
                            //    Url = "",
                            //    Size = 0,
                            //    DeleteUrl = "",   //maybe later..
                            //    Progress = "1.0",
                            //    Error = rapsEditModel.FeedbackMessage.Message
                            //});
                            var s = statuses.First();
                            s.Error = rapsEditModel.FeedbackMessage.Message;
                            //  throw new Exception(rapsEditModel.FeedbackMessage.Message);
                        }
                    }
                    else
                    {
                        resultArchive.StatusId = (long)RapsUploadStatus.UploadStarted;
                    }

                    _rapsUploadRepository.Save(resultArchive);
                }

                WriteJsonIframeSafe(statuses);
            }
            catch (Exception ex)
            {
                IoC.Resolve <ILogManager>().GetLogger <Global>().Error("Upload Failure! Message: " + ex.Message + "\n\t" + ex.StackTrace);
            }
        }