Beispiel #1
0
 public ClientSiteController(IConfiguration configuration)
 {
     clientSiteRepo    = new ClientSiteRepo(configuration);
     fileUploadService = new FileUploadService(configuration);
     _configuration    = configuration;
     auditLogService   = new AuditLogService(HttpContext, configuration);
 }
Beispiel #2
0
 public AvoidedPlannedMaintenanceController(IConfiguration configuration)
 {
     avoidPlannedMaintRepo = new AvoidPlannedMaintenanceRepo(configuration);
     _configuration        = configuration;
     fileUploadService     = new FileUploadService(configuration);
     auditLogService       = new AuditLogService(HttpContext, configuration);
 }
 public FileUploadController(IConfiguration configuration)
 {
     _configuration    = configuration;
     lookupRepo        = new LookupsRepo(configuration);
     appConfigRepo     = new ApplicationConfigurationRepo(configuration);
     fileUploadService = new FileUploadService(configuration);
 }
Beispiel #4
0
        public ActionResult ViewPostDetails(Post post, List <HttpPostedFileBase> postedFile)
        {
            if (ModelState.IsValid)
            {
                //New Files

                foreach (var file in postedFile)
                {
                    FileUploadService service = new FileUploadService();
                    if (file != null && file.ContentLength > 0)
                    {
                        FileDetail fileDetail = new FileDetail()
                        {
                            FileName    = Path.GetFileName(file.FileName),
                            ContentType = file.ContentType,
                            Data        = service.ConvertToBytes(file),
                            PostId      = post.PostId
                        };
                        db.Entry(fileDetail).State = EntityState.Added;
                    }
                }
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];
                post.ModifyBy        = session.Username;
                post.ModifyDate      = DateTime.Now;
                db.Entry(post).State = EntityState.Modified;
                db.SaveChanges();
                ViewBag.EditPost = "This post has been edited successfully!";
                return(RedirectToAction("ViewListPost", new { id = post.TopicId }));
            }
            return(View(post));
        }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "MajorId,Name,MetaTitle,Description,CreateDate,CreateBy,ModifyDate,ModifyBy")] Major major, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];
                FileUploadService service = new FileUploadService();
                if (uploadFile != null)
                {
                    db.FileDetails.Add(new FileDetail
                    {
                        FileName    = Path.GetFileName(uploadFile.FileName),
                        ContentType = uploadFile.ContentType,
                        Data        = service.ConvertToBytes(uploadFile),
                        MajorId     = major.MajorId
                    });
                }
                major.CreateBy   = session.Username;
                major.CreateDate = DateTime.Now;
                db.Majors.Add(major);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(major));
        }
        public async Task FileUploadService_UploadFile_ReturnsCurropted()
        {
            var wc  = new Mock <IWorkContext>();
            var cId = 123;

            wc.Setup(w => w.CurrentUserId).Returns(cId);
            var ah = new Mock <AuditHelper>(wc.Object);

            var vFactory = new Mock <IFileHandlerFactory>();

            vFactory.Setup(v => v.IsSupportedExtension(It.IsAny <string>())).Returns(() => true);
            vFactory.Setup(v => v.Validate(It.IsAny <string>(), It.IsAny <byte[]>())).Returns(() => FileStatusCode.Corrupted);

            var uReq = new FileUploadRequest
            {
                FileName = "ttt.txt",
                Bytes    = new byte[] { 1, 1, 1, 1, 1 }
            };

            var sessionRepo = new Mock <IFileUploadSessionRepository>();

            sessionRepo.Setup(s => s.Create(It.IsAny <FileUploadSessionModel>()))
            .Callback <FileUploadSessionModel>(n => n.Id = 123);

            var uMgr  = new FileUploadService(vFactory.Object, null, null, null, sessionRepo.Object, null, ah.Object);
            var upRes = await uMgr.UploadAsync(new[] { uReq });

            var res = upRes.First();

            res.Status.ShouldBe(FileStatusCode.Corrupted);
            res.WasUploaded.ShouldBeFalse();
        }
        public async Task HandleValidSubmitAsync()
        {
            await FileUploadService.UploadAsync(file, Model.FileGuid);

            var plugin = PluginTester.LoadPlugin(Model.FileGuid);

            if (plugin == null)
            {
                Toaster.Error("Vložený soubor není platná knihovna.");
                return;
            }

            try
            {
                PluginTester.TestImplementation(plugin);
            }
            catch (Exception e)
            {
                Toaster.Error(e.Message, "Chyba implementace");
                return;
            }

            await PlayerService.InsertNewPlayerAsync(new PlayerVM
            {
                Name     = Model.Name,
                Password = Model.Password,
                FileGuid = Model.FileGuid,
                League   = (League)Convert.ToInt32(Model.League)
            });

            Toaster.Info("Nový hráč vložen.");
            NavigationManager.NavigateTo("/players");
        }
Beispiel #8
0
        public async Task <HttpResponseMessage> DeleteAsync(int id)
        {
            try
            {
                FileUploadService    svc   = new FileUploadService();
                FileUploadAddRequest model = new FileUploadAddRequest();
                model = svc.SelectById(id);
                var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/upload"), model.SystemFileName);
                try
                {
                    var deleteObjectRequest = new DeleteObjectRequest
                    {
                        BucketName = bucketname,
                        Key        = model.SystemFileName
                    };
                    await awsS3Client.DeleteObjectAsync(deleteObjectRequest);
                }
                catch (AmazonS3Exception e)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
                }

                if (File.Exists(fileSavePath))
                {
                    File.Delete(fileSavePath);
                }
                svc.Delete(id);
                SuccessResponse resp = new SuccessResponse();
                return(Request.CreateResponse(HttpStatusCode.OK, resp));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Beispiel #9
0
        public async Task <ActionResult> UploadChunk(string key, int id, string fileType, string imageName, int numberOfBlocks)
        {
            var service = new FileUploadService(new Logger());

            HttpPostedFileBase request = Request.Files["Slice"];

            byte[] chunk = new byte[request.ContentLength];
            request.InputStream.Read(chunk, 0, Convert.ToInt32(request.ContentLength));

            await service.UploadFileChunk(id, imageName, chunk);

            if (id == numberOfBlocks)
            {
                var blockList = Enumerable
                                .Range(1, numberOfBlocks)
                                .ToList <int>()
                                .ConvertAll(rangeElement =>
                                            Convert.ToBase64String(Encoding.UTF8.GetBytes(
                                                                       string.Format(CultureInfo.InvariantCulture, "{0:D4}", rangeElement))));

                await service.CommintBlockList(blockList, imageName, fileType);

                var context = GlobalHost.ConnectionManager.GetHubContext <ClippHub>();
                context.Clients.Group(key).notifyUploaded();

                return(Json(new
                {
                    error = false,
                    isLastBlock = true,
                    message = "upload complete"
                }));
            }

            return(Json(new { error = false, isLastBlock = false, message = string.Empty }));
        }
 public WorkNotificationController(IConfiguration configuration)
 {
     _configuration       = configuration;
     worknotificationRepo = new WorkNotificationRepo(configuration);
     fileUploadService    = new FileUploadService(configuration);
     lookupRepo           = new LookupsRepo(configuration);
 }
        public HttpResponseMessage FileUpload(EncodedImage encodedImage)
        {
            try
            {
                FileUploadService fSvc = new FileUploadService();


                byte[]     newBytes = Convert.FromBase64String(encodedImage.EncodedImageFile);;
                UploadFile model    = new UploadFile();
                model.FileUploadName = "img";
                model.ByteArray      = newBytes;
                model.Extension      = encodedImage.FileExtension;
                model.Location       = "TestImages";

                int fileId = fSvc.Insert(model);

                ItemResponse <int> resp = new ItemResponse <int>();
                resp.Item = fileId;

                return(Request.CreateResponse(HttpStatusCode.OK, resp));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Beispiel #12
0
 public ActionResult Edit([Bind(Include = "MajorId,Name,MetaTitle,Description,CreateDate,CreateBy,ModifyDate,ModifyBy")] Major major, HttpPostedFileBase uploadFile)
 {
     if (ModelState.IsValid)
     {
         FileUploadService service = new FileUploadService();
         var session = (UserLogin)Session[CommonConstants.USER_SESSION];
         if (uploadFile != null)
         {
             FileDetail file = db.FileDetails.ToList().Find(x => x.MajorId == major.MajorId);
             if (file != null)
             {
                 file.FileName        = Path.GetFileName(uploadFile.FileName);
                 file.ContentType     = uploadFile.ContentType;
                 file.Data            = service.ConvertToBytes(uploadFile);
                 db.Entry(file).State = EntityState.Modified;
             }
             else
             {
                 db.FileDetails.Add(new FileDetail
                 {
                     FileName    = Path.GetFileName(uploadFile.FileName),
                     ContentType = uploadFile.ContentType,
                     Data        = service.ConvertToBytes(uploadFile),
                     MajorId     = major.MajorId
                 });
             }
         }
         major.ModifyBy        = session.Username;
         major.ModifyDate      = DateTime.Now;
         db.Entry(major).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(major));
 }
Beispiel #13
0
        public ActionResult Mody(UserInfo user)
        {
            OperationResult result = null;
            var             old    = unitOfWork.DUserInfo.GetByID(user.ID);
            List <string>   list   = new List <string>();

            list.AddRange(this.Request.Form.AllKeys.AsEnumerable());
            string    uploadsFolder = Request.ApplicationPath.TrimEnd('/') + "/File/User/" + user.ID + "/";//附件路径文件
            MFileInfo fl            = new FileUploadService().FileUpload(uploadsFolder);

            if (fl != null)
            {
                user.Photo = fl.Path;
                list.Add("Photo");
            }
            new DBLogService().insert(ActionClick.Mody, user);
            unitOfWork.DUserInfo.Update(old, user, list);
            result = unitOfWork.Save();
            CacheHelper.RemoveAllCache("UserInfo" + user.ID);
            var isSave = unitOfWork.SaveRMsg();

            if (result.ResultType == OperationResultType.Success)
            {
                return(Json(new { r = true }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { r = false, m = "操作失败\n" + result.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public async Task FileUploadService_UploadFile_ReturnsEmptyResult()
        {
            var service = new FileUploadService(null, null, null, null, null, null, null);
            var res     = await service.UploadAsync(new List <FileUploadRequest>());

            res.Count().ShouldBe(0);
        }
 public FailureReportController(IConfiguration configuration)
 {
     failurereportRepo = new FailureReportRepo(configuration);
     _configuration    = configuration;
     fileUploadService = new FileUploadService(configuration);
     auditLogService   = new AuditLogService(HttpContext, configuration);
 }
Beispiel #16
0
        public ActionResult Create([Bind(Include = "TopicId,Name,MetaTitle,Description,DisplayOrder,ClosureDate,CreateDate,CreateBy,ModifyDate,ModifyBy,Status,MajorId")] Topic topic, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];
                FileUploadService service = new FileUploadService();
                if (uploadFile != null)
                {
                    db.FileDetails.Add(new FileDetail
                    {
                        FileName    = Path.GetFileName(uploadFile.FileName),
                        ContentType = uploadFile.ContentType,
                        Data        = service.ConvertToBytes(uploadFile),
                        TopicId     = topic.TopicId
                    });
                }
                topic.CreateBy   = session.Username;
                topic.CreateDate = DateTime.Now;
                db.Topics.Add(topic);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MajorId = new SelectList(db.Majors, "MajorId", "Name", topic.MajorId);
            return(View(topic));
        }
Beispiel #17
0
 public FileUpload(FileHelper fileHelper, IMapper mapper, FileUploadService fileUploadService, FileUploadRepository fileUploadRepo, PaginatedMetaService paginatedMetaService)
 {
     _fileUploadService    = fileUploadService;
     _fileUploadRepo       = fileUploadRepo;
     _paginatedMetaService = paginatedMetaService;
     _mapper     = mapper;
     _fileHelper = fileHelper;
 }
Beispiel #18
0
        public ActionResult ListFiles(string key)
        {
            var service = new FileUploadService(new Logger());

            var files = service.ListFiles(key);

            return(Json(files));
        }
        public ExpiredFilesCleanupJob(FileUploadService fileUploadService, ILogger <ExpiredFilesCleanupJob> logger)
        {
            _logger = logger;
            DefaultTusConfiguration config = fileUploadService.CreateTusConfiguration();

            _expirationStore = (ITusExpirationStore)config.Store;
            _expiration      = config.Expiration;
        }
 public UploadController(IOptions <Settings> settings,
                         IOptions <S3Settings> s3Settings,
                         IOptions <FileUploadService> fileUploadService)
 {
     Settings          = settings.Value;
     S3Settings        = s3Settings.Value;
     FileUploadService = fileUploadService.Value;
 }
Beispiel #21
0
        public void SendText(string key, string text)
        {
            Clients.OthersInGroup(key).pushText(text);

            var service = new FileUploadService(new Logger());

            service.StoreText(key, text);
        }
 public AgentService(IUnitOfWork uow,
                     IHostingEnvironment environment,
                     FileUploadService fileUploadService)
 {
     Database               = uow;
     this.environment       = environment;
     this.fileUploadService = fileUploadService;
 }
Beispiel #23
0
        public ActionResult SetMetadata(string key, string fileName)
        {
            var service = new FileUploadService(new Logger());

            string imageName = service.CreateBlockBlob(key, fileName);

            return(Json(imageName));
        }
Beispiel #24
0
 public CommentsController(ApplicationDbContext context, IHostingEnvironment environment,
                           FileUploadService fileUploadService, UserManager <ApplicationUser> userManager)
 {
     _context           = context;
     _environment       = environment;
     _fileUploadService = fileUploadService;
     _userManager       = userManager;
 }
Beispiel #25
0
 public ReportFeederController(IConfiguration configuration)
 {
     _configuration    = configuration;
     jobRepo           = new JobRepo(configuration);
     reportFeederRepo  = new ReportFeederRepo(configuration);
     fileUploadService = new FileUploadService(configuration);
     auditLogService   = new AuditLogService(HttpContext, configuration);
 }
Beispiel #26
0
        public ActionResult editProfile([Bind(Include = "UserId,Name,Email,Username,Password,Phone,Address,DateOfBirth,CreateDate,CreateBy,ModifyDate,ModifyBy,AccountStatus,GroupId,MajorId")] User user, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                FileUploadService service = new FileUploadService();
                var session = (UserLogin)Session[CommonConstants.USER_SESSION];
                if (uploadFile != null)
                {
                    FileDetail file = db.FileDetails.ToList().Find(x => x.UserId == user.UserId);
                    if (file != null)
                    {
                        file.FileName        = Path.GetFileName(uploadFile.FileName);
                        file.ContentType     = uploadFile.ContentType;
                        file.Data            = service.ConvertToBytes(uploadFile);
                        db.Entry(file).State = EntityState.Modified;
                    }
                    else
                    {
                        db.FileDetails.Add(new FileDetail
                        {
                            FileName    = Path.GetFileName(uploadFile.FileName),
                            ContentType = uploadFile.ContentType,
                            Data        = service.ConvertToBytes(uploadFile),
                            UserId      = user.UserId
                        });
                    }
                }
                user.ModifyBy   = session.Username;
                user.ModifyDate = DateTime.Now;
                var Password = Request["Password"];
                ViewBag.GroupId = new SelectList(db.GroupMembers, "GroupId", "Name", user.GroupId);
                ViewBag.MajorId = new SelectList(db.Majors, "MajorId", "Name", user.MajorId);


                var email          = Request["Email"];
                var checkEmailNull = db.Users.Where(x => x.UserId.Equals(user.UserId) && x.Email.Equals(email)).Count();
                if (checkEmailNull <= 0)
                {
                    var isEmailExist = db.Users.Where(s => s.Email == email).Count();
                    if (isEmailExist > 0)
                    {
                        ModelState.AddModelError("", "Email already exists.");
                        return(View(user));
                    }
                }

                var checkPass = db.Users.Where(x => x.UserId == user.UserId && x.Password == Password).Count();
                if (checkPass <= 0)
                {
                    user.Password = Encryptor.GetMD5(Password);
                }

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Profile", new { id = user.UserId }));
            }
            return(View(user));
        }
 public InstitutionsController(ApplicationDbContext context, FileUploadService fileUploadService,
                               IHostingEnvironment environment, IMemoryCache memoryCache, IStringLocalizer <Institution> localizer)
 {
     _localizer         = localizer;
     _cache             = memoryCache;
     _environment       = environment;
     _context           = context;
     _fileUploadService = fileUploadService;
 }
 public EquipmentController(IConfiguration configuration)
 {
     equipmentRepo     = new EquipmentRepo(configuration);
     _configuration    = configuration;
     lookupRepo        = new LookupsRepo(configuration);
     appConfigRepo     = new ApplicationConfigurationRepo(configuration);
     fileUploadService = new FileUploadService(configuration);
     auditLogService   = new AuditLogService(HttpContext, configuration);
 }
Beispiel #29
0
 public ActionResult Create([Bind(Include = "UserId,Name,Email,Username,Password,Phone,Address,DateOfBirth,CreateDate,CreateBy,ModifyDate,ModifyBy,AccountStatus,GroupId,MajorId")] User user, FileDetail fileDetail, HttpPostedFileBase uploadFile)
 {
     if (ModelState.IsValid)
     {
         var session       = (UserLogin)Session[CommonConstants.USER_SESSION];
         var checkEmail    = db.Users.FirstOrDefault(s => s.Email == user.Email);
         var checkUsername = db.Users.FirstOrDefault(s => s.Username == user.Username);
         ViewBag.GroupId = new SelectList(db.GroupMembers, "GroupId", "Name", user.GroupId);
         ViewBag.MajorId = new SelectList(db.Majors, "MajorId", "Name", user.MajorId);
         if (checkEmail != null)
         {
             ModelState.AddModelError("", "Email already exists.");
             return(View());
         }
         else if (checkUsername != null)
         {
             ModelState.AddModelError("", "Username already exists.");
             return(View());
         }
         else
         {
             FileUploadService service = new FileUploadService();
             if (uploadFile != null)
             {
                 db.FileDetails.Add(new FileDetail
                 {
                     FileName    = Path.GetFileName(uploadFile.FileName),
                     ContentType = uploadFile.ContentType,
                     Data        = service.ConvertToBytes(uploadFile),
                     UserId      = user.UserId
                 });
             }
             if (user.GroupId == "Admin" || user.GroupId == "Manager")
             {
                 user.MajorId = null;
             }
             user.CreateBy   = session.Username;
             user.CreateDate = DateTime.Now;
             user.Password   = Encryptor.GetMD5(user.Password);
             db.Configuration.ValidateOnSaveEnabled = false;
             db.Users.Add(user);
             var result = db.SaveChanges();
             if (result > 0)
             {
                 ViewBag.Success = "Create Successfully!";
                 return(View());
             }
             else
             {
                 ModelState.AddModelError("", "Create unsuccessfully! Please try again.");
                 return(View());
             }
         }
     }
     return(View(user));
 }
 public ServerApiController(IOwnerRepository ownerData, IOwnerTokenCodec ownerTokenCodec, IOptionsMonitor <ManageOption> manageOption,
                            IFileTokenCodec fileTokenCodec, IStorageService storageSvce, IFileRepository fileRepo, FileUploadService fileUpdSvce) : base(manageOption)
 {
     _ownerData       = ownerData;
     _ownerTokenCodec = ownerTokenCodec;
     _fileTokenCodec  = fileTokenCodec;
     _storageSvce     = storageSvce;
     _fileRepo        = fileRepo;
     _fileUpdSvce     = fileUpdSvce;
 }
 public FileUploadController(FileUploadService fileUploadService)
 {
     this.fileUploadService = fileUploadService;
 }
Beispiel #32
0
 /// <summary>
 /// 取附件列表
 /// </summary>
 /// <param name="formid">表单ID</param>
 /// <returns>string</returns>
 public static string GetAttachList(string formid)
 {
     FileUploadService fileuploadClient = new FileUploadService();
     StringBuilder stringBuilder = new StringBuilder();
     var attach = fileuploadClient.GetFileListByOnlyApplicationID(formid);
     stringBuilder.Append("<AttachList>");
     if (attach.FileList != null)
     {
         for (int i = 0; i < attach.FileList.Count(); i++)
         {
             string path = attach.FileList[i].FILEURL;
             string filename = path.Substring(path.LastIndexOf('\\') + 1);
             string filepath = HttpUtility.UrlEncode(attach.FileList[i].FILEURL + "\\" + attach.FileList[i].FILENAME);
             string url = attach.DownloadUrl + "?filename=" + filepath;//文件地址
             //sb.Append("<a href=\"" + url + "\" >" + filename + "</a>");
             stringBuilder.Append("<Atrribute Name=\"" + attach.FileList[i].FILENAME + "\" Url=\"" + url + "\" />");
         }
     }
     stringBuilder.Append("</AttachList>");
     return stringBuilder.ToString();
 }