public ActionResult UploadFiles(Models.FileModel model)
 {
     if (ModelState.IsValid)
     {
         if (AppSettings.ValidProjectKeys.Contains(model.ProjectCode))
         {
             model.DownloadFiles = new List <SavedImage>();
             //iterating through multiple file collection
             foreach (HttpPostedFileBase file in model.Files)
             {
                 if (file != null)
                 {
                     var newFiles = m_ImageService.SaveFiles(model.ProjectCode, model.InternalPath, model.ImageSize, file, model.CreateNewFile);
                     if (newFiles.Count > 0)
                     {
                         model.DownloadFiles.AddRange(newFiles);
                     }
                 }
             }
             model.UploadStatus = model.Files.Count().ToString() + " files uploaded successfully.";
         }
         else
         {
             ModelState.AddModelError("ProjectCode", "Project key is not valid.");
             model.UploadStatus = "Check Project key.";
             model.Files        = null;
         }
     }
     return(View(model));
 }
 // GET: Home
 public ActionResult UploadFiles()
 {
     Models.FileModel model = new Models.FileModel();
     model.ProjectCode  = AppSettings.ValidProjectKeys.First();
     model.InternalPath = AppSettings.DefaultContentFolder;
     model.ImageSize    = AppSettings.DefaultSize;
     return(View(model));
 }
예제 #3
0
        public override async Task <AddArticleContentRequest> HandleAsync(AddArticleContentRequest command, CancellationToken cancellationToken = new CancellationToken())
        {
            if (string.IsNullOrWhiteSpace(command.Language))
            {
                var library = await _libraryRepository.GetLibraryById(command.LibraryId, cancellationToken);

                if (library == null)
                {
                    throw new BadRequestException();
                }

                command.Language = library.Language;
            }

            var issue = await _issueRepository.GetIssue(command.LibraryId, command.PeriodicalId, command.VolumeNumber, command.IssueNumber, cancellationToken);

            if (issue == null)
            {
                throw new BadRequestException();
            }

            var article = await _articleRepository.GetArticleById(command.LibraryId, command.PeriodicalId, command.VolumeNumber, command.IssueNumber, command.ArticleId, cancellationToken);

            if (article != null)
            {
                var name      = GenerateChapterContentUrl(command.PeriodicalId, command.IssueNumber, command.ArticleId, command.Language, command.MimeType);
                var actualUrl = await _fileStorage.StoreTextFile(name, command.Contents, cancellationToken);

                var fileModel = new Models.FileModel {
                    MimeType = command.MimeType, FilePath = actualUrl, IsPublic = issue.IsPublic, FileName = name
                };
                var file = await _fileRepository.AddFile(fileModel, cancellationToken);

                var issueContent = new ArticleContentModel
                {
                    PeriodicalId = command.PeriodicalId,
                    IssueId      = issue.Id,
                    ArticleId    = command.ArticleId,
                    Language     = command.Language,
                    MimeType     = command.MimeType,
                    FileId       = file.Id
                };

                command.Result = await _articleRepository.AddArticleContent(command.LibraryId, issueContent, cancellationToken);

                if (file.IsPublic)
                {
                    var url = await ImageHelper.TryConvertToPublicFile(file.Id, _fileRepository, cancellationToken);

                    command.Result.ContentUrl = url;
                }
            }

            return(await base.HandleAsync(command, cancellationToken));
        }
 public ActionResult Settings(int id)
 {
     Models.FileModel file = new Models.FileModel(Logic.GetFileById(id));
     file.AccessedUsers = new List <User>(Logic.GetAllowedUsers(file.ID));
     if (User.Identity.Name.Equals(file.OwnerName) || User.IsInRole("Admin"))
     {
         return(View(file));
     }
     else
     {
         return(Redirect("~/"));
     }
 }
예제 #5
0
        private static bool CheckForMultiImport(Models.FileModel file)
        {
            // add more raw extensions here
            // example: if a masklist exists in the filelist, ignore all files in the subdirectory
            // named the same as masklist but with extension mlmask
            var directory = new FileInfo(file.FullName).Directory;

            if (directory.Name.Contains($".{ERedExtension.mlmask}"))
            {
                return(false);
            }

            return(true);
        }
예제 #6
0
        private async Task LoggerDownload(ApplicationIdentityUser user, Models.FileModel fileModel)
        {
            string ip     = HttpContext.Request.HttpContext.Connection.RemoteIpAddress.ToString();
            Guid?  userId = user?.Id;
            var    ipInfo = await new IpDataServlet(ip).GetIpInfo();

            LoggerDownloadModel logDown = new LoggerDownloadModel
            {
                CreationDateTime = DateTime.UtcNow,
                Id            = Guid.NewGuid(),
                UserId        = userId,
                Size          = fileModel.Size,
                Name          = fileModel.TrustedName,
                StorageName   = fileModel.UntrustedName,
                Type          = fileModel.Type,
                Asn           = ipInfo.Asn,
                AsnDomain     = ipInfo.AsnDomain,
                AsnName       = ipInfo.AsnName,
                AsnRoute      = ipInfo.AsnRoute,
                AsnType       = ipInfo.AsnType,
                CallingCode   = ipInfo.CallingCode,
                City          = ipInfo.City,
                ContinentCode = ipInfo.ContinentCode,
                ContinentName = ipInfo.ContinentName,
                CountryCode   = ipInfo.CountryCode,
                CountryName   = ipInfo.CountryName,
                Ip            = ipInfo.Ip,
                Latitude      = ipInfo.Latitude,
                Longitude     = ipInfo.Longitude,
                Organisation  = ipInfo.Organisation,
                Postal        = ipInfo.Postal,
                Region        = ipInfo.Region,
                RegionCode    = ipInfo.RegionCode,
                TimeZone      = ipInfo.TimeZone,
                Languages     = ipInfo.Languages,
                Error         = ipInfo.Error
            };

            await _context.LoggerDownload.AddAsync(logDown);

            await _context.SaveChangesAsync();
        }
예제 #7
0
        public async Task <IActionResult> DownloadFileStream(Models.FileModel fileModel)
        {
            if (System.IO.File.Exists(fileModel.Path))
            {
                FileStream              sourceStream            = new FileStream(fileModel.Path, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read, BufferSize, FileOptions.Asynchronous | FileOptions.SequentialScan);
                ThrottledStream         destinationStreamStream = null;
                ApplicationIdentityUser user = null;
                if (HttpContext.User != null)
                {
                    user = await _userManager.GetUserAsync(HttpContext.User);

                    if (user != null)
                    {
                        destinationStreamStream = new ThrottledStream(sourceStream, kbpsLogged);
                    }
                }

                if (destinationStreamStream == null)
                {
                    destinationStreamStream = new ThrottledStream(sourceStream, kbps);
                }

                await LoggerDownload(user, fileModel);

                FileStreamResult fileStreamResult = new FileStreamResult(destinationStreamStream, FindMimeHelpers.GetMimeFromFile(fileModel.Path));
                fileStreamResult.FileDownloadName = fileModel.TrustedName;
                fileStreamResult.LastModified     = fileModel.UploadDT;

                return(fileStreamResult);
            }
            else
            {
                ModelState.AddModelError("Error", $"The request couldn't be processed (Error 0).");
                return(NotFound(ModelState));
            }
        }
예제 #8
0
        public ActionResult Index(Models.FileModel model, Models.FolderModel fmodel)
        {
            //services = new Models.RepoManagerServices();

            if (fmodel.folderName != null)
            {
                Thread t1 = new Thread(() => { Directory.CreateDirectory(Session["fPath"].ToString() + @"\" + fmodel.folderName); });

                t1.Start();
            }

            //var path = Server.MapPath("~/wwroot/");

            if (model.file != null || model.filePath != null)
            {
                Thread t = new Thread(() => { services.UploadFile(model.file, Session["fPath"].ToString()); });

                t.Start();
            }

            folderModel.folderPath = Session["fPath"].ToString();

            return(View(folderModel));
        }
예제 #9
0
 public CsvDataReaderWriter(Models.FileModel fileParameters = null, int notifyAfter = 200_000)
 {
     FileParameters = fileParameters ?? new Models.FileModel();
     NotifyAfter    = notifyAfter;
 }
예제 #10
0
        public ActionResult UploadCkEditor()
        {
            int    lastid   = new int();
            string fileName = "";

            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFileBase file = Request.Files[i]; //Uploaded file
                                                            //Use the following properties to get file's name, size and MIMEType
                int fileSize = file.ContentLength;
                fileName = file.FileName;
                string           mimeType    = file.ContentType;
                System.IO.Stream fileContent = file.InputStream;

                lastid = this.filemodel.Upload(fileName);
                DateTime temptime  = this.filemodel.mTime;
                String[] temparray = this.filemodel.temp_str_array;
                this.filemodel = new Models.FileModel();
                this.filemodel.Upload_2(lastid, temptime);

                bool dir = false;
                dir = Directory.Exists(@"C:\www\cf\UpLoadFile\" + temparray[0]);
                if (!dir)
                {
                    Directory.CreateDirectory(@"C:\www\cf\UpLoadFile\" + temparray[0]);
                }

                dir = Directory.Exists(@"C:\www\cf\UpLoadFile\" + temparray[0] + "\\" + temparray[0] + "-" + temparray[1]);
                if (!dir)
                {
                    Directory.CreateDirectory(@"C:\www\cf\UpLoadFile\" + temparray[0] + "\\" + temparray[0] + "-" + temparray[1]);
                }

                dir = Directory.Exists(@"C:\www\cf\UpLoadFile\" + temparray[0] + "\\" + temparray[0] + "-" + temparray[1] + "\\" + temparray[0] + "-" + temparray[1] + "-" + temparray[2]);
                if (!dir)
                {
                    Directory.CreateDirectory(@"C:\www\cf\UpLoadFile\" + temparray[0] + "\\" + temparray[0] + "-" + temparray[1] + "\\" + temparray[0] + "-" + temparray[1] + "-" + temparray[2]);
                }

                //To save file, use SaveAs method
                file.SaveAs(Server.MapPath("/UpLoadFile/" + temparray[0] + "/" + temparray[0] + "-" + temparray[1] + "/" + temparray[0] + "-" + temparray[1] + "-" + temparray[2]) + "/" + lastid.ToString() + ".file"); //File will be saved in application root

                this.filemodel = new Models.FileModel();
                string path = Server.MapPath(this.filemodel.DownLoad(lastid));
                this.filemodel = new Models.FileModel();
                this.filemodel.Upload_3(lastid, temptime, path);
            }

            if (!string.IsNullOrEmpty(Session["murl"] as string))
            {
                this.mUrl = Session["murl"].ToString();
            }

            //String cKEditorFuncNum = Request.Form["CKEditorFuncNum"]; POST值
            String cKEditorFuncNum = Request.QueryString["CKEditorFuncNum"];//GET值

            if (cKEditorFuncNum == "")
            {
                cKEditorFuncNum = "2";
            }
            String sb = "";

            if (String.IsNullOrEmpty(Request.QueryString["CKEditorFuncNum"]))
            {
                sb = sb + "{";
                sb = sb + "\"CKEditorFuncNum\": 2 , ";
                sb = sb + "\"uploaded\":" + "true" + " , ";
                sb = sb + "\"fileName\":\"" + fileName + "\" , ";
                sb = sb + "\"url\":\"" + this.mUrl + "file/show/" + lastid.ToString() + "\"";
                sb = sb + "}";
                return(Content(sb));
            }
            else
            {
                return(Content("<script>window.parent.CKEDITOR.tools.callFunction(1,'" + this.mUrl + "file/show/" + lastid.ToString() + "','');</script>"));
            }

            return(Content(sb));
        }
예제 #11
0
        public ActionResult Upload()
        {
            int    lastid   = new int();
            string fileName = "";

            int p_id = Int32.Parse(Request.QueryString["p_id"]);//GET值

            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFileBase file = Request.Files[i]; //Uploaded file
                                                            //Use the following properties to get file's name, size and MIMEType
                int fileSize = file.ContentLength;
                fileName = file.FileName;
                string           mimeType    = file.ContentType;
                System.IO.Stream fileContent = file.InputStream;

                lastid = this.filemodel.Upload(fileName);
                DateTime temptime  = this.filemodel.mTime;
                String[] temparray = this.filemodel.temp_str_array;
                this.filemodel = new Models.FileModel();
                this.filemodel.Upload_2(lastid, temptime);

                bool dir = false;
                dir = Directory.Exists(@"C:\www\cf\UpLoadFile\" + temparray[0]);
                if (!dir)
                {
                    Directory.CreateDirectory(@"C:\www\cf\UpLoadFile\" + temparray[0]);
                }

                dir = Directory.Exists(@"C:\www\cf\UpLoadFile\" + temparray[0] + "\\" + temparray[0] + "-" + temparray[1]);
                if (!dir)
                {
                    Directory.CreateDirectory(@"C:\www\cf\UpLoadFile\" + temparray[0] + "\\" + temparray[0] + "-" + temparray[1]);
                }

                dir = Directory.Exists(@"C:\www\cf\UpLoadFile\" + temparray[0] + "\\" + temparray[0] + "-" + temparray[1] + "\\" + temparray[0] + "-" + temparray[1] + "-" + temparray[2]);
                if (!dir)
                {
                    Directory.CreateDirectory(@"C:\www\cf\UpLoadFile\" + temparray[0] + "\\" + temparray[0] + "-" + temparray[1] + "\\" + temparray[0] + "-" + temparray[1] + "-" + temparray[2]);
                }

                //To save file, use SaveAs method
                file.SaveAs(Server.MapPath("/UpLoadFile/" + temparray[0] + "/" + temparray[0] + "-" + temparray[1] + "/" + temparray[0] + "-" + temparray[1] + "-" + temparray[2]) + "/" + lastid.ToString() + ".file"); //File will be saved in application root

                this.filemodel = new Models.FileModel();
                string path = Server.MapPath(this.filemodel.DownLoad(lastid));
                this.filemodel = new Models.FileModel();
                this.filemodel.Upload_3(lastid, temptime, path);
                this.filemodel = new Models.FileModel();
                this.homemodel.DraftRunPP(p_id, lastid, "image", temptime);
            }

            //String cKEditorFuncNum = Request.Form["CKEditorFuncNum"]; POST值
            String cKEditorFuncNum = Request.QueryString["CKEditorFuncNum"];//GET值

            if (cKEditorFuncNum == "")
            {
                cKEditorFuncNum = "2";
            }
            String sb = "";

            sb = sb + "{";
            sb = sb + "\"CKEditorFuncNum\": 2 , ";
            sb = sb + "\"uploaded\":" + "true" + " , ";
            sb = sb + "\"fileName\":\"" + fileName + "\" , ";
            sb = sb + "\"url\":\"" + "~/" + "file/show/" + lastid.ToString() + "\"";
            sb = sb + "}";

            return(Content(sb));
        }
 public ActionResult Settings(int id)
 {
     Models.FileModel file = new Models.FileModel(Logic.GetFileById(id));
     file.AccessedUsers = new List<User>(Logic.GetAllowedUsers(file.ID));
     if (User.Identity.Name.Equals(file.OwnerName) || User.IsInRole("Admin"))
         return View(file);
     else
         return Redirect("~/");
 }
예제 #13
0
        //public delegate FileContentResult func(byte[] data, string fileName);

        public FileResult DownloadFile(Models.FileModel model)
        {
            return(File(System.IO.File.ReadAllBytes(model.filePath), System.Net.Mime.MediaTypeNames.Application.Octet, model.fileName));
        }
 public CsvDataReaderWriter(Models.FileModel fileParameters = null)
 {
     FileParameters = fileParameters ?? new Models.FileModel();
 }