Пример #1
0
        public JsonResult UploadExcelFileBlackList()
        {
            string fileExcelBlackListName = $"FileExcelFileBlackList_{AbpSession.GetUserId()}";

            try
            {
                //Check input
                if (Request.Files.Count <= 0 || Request.Files[0] == null)
                {
                    throw new UserFriendlyException(L("Excel_File_Error"));
                }

                var file = Request.Files[0];
                //Delete old
                AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.TempFileDownloadFolder, fileExcelBlackListName);

                //Save new
                var fileInfo     = new FileInfo(file.FileName);
                var tempFileName = fileExcelBlackListName + fileInfo.Extension;
                var tempFilePath = Path.Combine(_appFolders.TempFileDownloadFolder, tempFileName);
                file.SaveAs(tempFilePath);
                return(Json(new AjaxResponse(new { fileName = tempFileName })));
            }
            catch (UserFriendlyException ex)
            {
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }
Пример #2
0
        public async Task UpdateLogo()
        {
            int TenantId = (int)AbpSession.TenantId;
            var data     = await TenantManager.GetByIdAsync(TenantId);

            if (data.LogoId != null)
            {
                try
                {
                    var files = await _binaryObjectManager.GetOrNullAsync((Guid)data.LogoId);

                    byte[] bytes = new byte[0];
                    bytes = files.Bytes;
                    var tempFileName = "LogoImage_" + data.Id + ".jpg";
                    if (!Directory.Exists(_appFolders.LogoPath))
                    {
                        Directory.CreateDirectory(_appFolders.LogoPath);
                    }
                    AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.LogoPath, tempFileName);

                    var tempFilePath = Path.Combine(_appFolders.LogoPath, tempFileName);

                    System.IO.File.WriteAllBytes(tempFilePath, bytes);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #3
0
        public async Task <ActionResult> UploadProfile()
        {
            var profile = Request.Form.Files.First();

            if (profile == null)
            {
                throw new Exception("Uploaded file is Empty !");
            }
            if (!Directory.Exists(_appFolders.TempFileDownloadFolder))
            {
                Directory.CreateDirectory(_appFolders.TempFileDownloadFolder);
            }
            byte[] fileBytes;
            using (var stream = profile.OpenReadStream())
            {
                fileBytes = stream.GetAllBytes();
            }

            if (!ImageFormatHelper.GetRawImageFormat(fileBytes).IsIn(ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Gif))
            {
                throw new Exception("Uploaded file is not an accepted image file !");
            }

            //Delete old temp profile pictures
            AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.TempFileDownloadFolder, "userProfileImage_" + AbpSession.GetUserId());

            //Save new picture
            var fileInfo     = new FileInfo(profile.FileName);
            var tempFileName = "userProfileImage_" + AbpSession.GetUserId() + fileInfo.Extension;
            var tempFilePath = Path.Combine(_appFolders.TempFileDownloadFolder, tempFileName);
            await System.IO.File.WriteAllBytesAsync(tempFilePath, fileBytes);

            return(new JsonResult(tempFileName));
        }
Пример #4
0
        public UploadProfilePictureOutput UploadProfilePicture()
        {
            try
            {
                var profilePictureFile = Request.Form.Files.First();

                //Check input
                if (profilePictureFile == null)
                {
                    throw new UserFriendlyException(L("ProfilePicture_Change_Error"));
                }

                if (profilePictureFile.Length > MaxProfilePictureSize)
                {
                    throw new UserFriendlyException(L("ProfilePicture_Warn_SizeLimit", AppConsts.MaxProfilPictureBytesUserFriendlyValue));
                }

                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }

                if (!ImageFormatHelper.GetRawImageFormat(fileBytes).IsIn(ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Gif))
                {
                    throw new Exception("Uploaded file is not an accepted image file !");
                }

                //Delete old temp profile pictures
                AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.TempFileDownloadFolder, "userProfileImage_" + AbpSession.GetUserId());

                //Save new picture
                var    fileInfo = new FileInfo(profilePictureFile.FileName);
                string ext      = fileInfo.Extension.ToLower().Trim();
                if (ext.Equals(".jpg") || ext.Equals(".png") || ext.Equals(".gif") || ext.Equals(".jpeg"))
                {
                    var tempFileName = "userProfileImage_" + AbpSession.GetUserId() + fileInfo.Extension;
                    var tempFilePath = Path.Combine(_appFolders.TempFileDownloadFolder, tempFileName);
                    System.IO.File.WriteAllBytes(tempFilePath, fileBytes);

                    using (var bmpImage = new Bitmap(tempFilePath))
                    {
                        return(new UploadProfilePictureOutput
                        {
                            FileName = tempFileName,
                            Width = bmpImage.Width,
                            Height = bmpImage.Height
                        });
                    }
                }
                else
                {
                    throw new UserFriendlyException("Uploaded file format is not correct !");
                }
            }
            catch (Exception ex)
            {
                return(new UploadProfilePictureOutput(new ErrorInfo(ex.Message)));
            }
        }
Пример #5
0
        public async Task Summafun()
        {
            var datas = UserManager.Users;

            foreach (var data in datas)
            {
                if (data.ProfilePictureId != null)
                {
                    try
                    {
                        var files = await _binaryObjectManager.GetOrNullAsync((Guid)data.ProfilePictureId);

                        byte[] bytes = new byte[0];
                        bytes = files.Bytes;
                        var tempFileName = "userProfileImage_" + data.Id + ".jpg";

                        AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.ProfilePath, tempFileName);

                        var tempFilePath = Path.Combine(_appFolders.ProfilePath, tempFileName);

                        System.IO.File.WriteAllBytes(tempFilePath, bytes);
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// 上传图片文件并上传至微信
        /// </summary>
        /// <returns></returns>
        public async Task <JsonResult> UploadMatialPic()
        {
            try
            {
                var profilePictureFile = Request.Form.Files.First();

                //Check input
                if (profilePictureFile == null)
                {
                    throw new UserFriendlyException(L("ProfilePicture_Change_Error"));
                }

                if (profilePictureFile.Length > 2097152) //2MB.
                {
                    throw new UserFriendlyException(L("ProfilePicture_Warn_SizeLimit"));
                }

                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }

                if (!ImageFormatHelper.GetRawImageFormat(fileBytes).IsIn(ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Gif))
                {
                    throw new Exception("上传文件非图片文件");
                }

                //Delete old temp profile pictures
                AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.TempFileDownloadFolder, "martialPic_" + AbpSession.GetUserId());

                //Save new picture
                var fileInfo     = new FileInfo(profilePictureFile.FileName);
                var tempFileName = "martialPic_" + AbpSession.GetUserId() + Guid.NewGuid().ToString() + fileInfo.Extension;
                var tempFilePath = Path.Combine(_appFolders.TempFileDownloadFolder, tempFileName);
                await System.IO.File.WriteAllBytesAsync(tempFilePath, fileBytes);

                var virtualPath = _matialFileService.MatialFileTempPath + tempFileName;


                var mediaId = "";
                try
                {
                    mediaId = await _wxMediaAppService.UploadMedia(tempFilePath, "");//上传至微信
                }
                catch (Exception e)
                {
                    Logger.Error("上传微信错误,错误信息:" + e.Message + ";错误堆栈:" + e.StackTrace);
                }

                //var mediaId = "测试";


                return(Json(new AjaxResponse(new { fileName = tempFileName, fileFullPath = tempFilePath, fileVirtualPath = virtualPath, mediaID = mediaId })));
            }
            catch (UserFriendlyException ex)
            {
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }
Пример #7
0
 public async Task CreateImageWhenEditEstimate(List <CreateImageDto> ListImage)
 {
     try
     {
         if (ListImage.Count > 0)
         {
             foreach (var item in ListImage)
             {
                 var image = ObjectMapper.Map <Models.Images>(item);
                 if (item.ImageName != null)
                 {
                     //Delete old document file
                     AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.AttachmentsFolder, item.ImageUrl);
                     var sourceFile = Path.Combine(_appFolders.TempFileDownloadFolder, item.ImageUrl);
                     var destFile   = Path.Combine(_appFolders.AttachmentsFolder, item.ImageUrl);
                     System.IO.File.Move(sourceFile, destFile);
                     var filePath = Path.Combine(_appFolders.AttachmentsFolder, item.ImageUrl);
                     image.ImageUrl    = filePath;
                     image.ImageName   = item.ImageName;
                     image.ImageSize   = item.ImageSize;
                     image.EstimatesId = item.EstimateID;
                     await _imageRepository.InsertAsync(image);
                 }
             }
             await CurrentUnitOfWork.SaveChangesAsync();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #8
0
        public async Task DeleteImageByIdWhenEdit(int id)
        {
            var ImageInDB = _imageRepository.Get(id);

            AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.AttachmentsFolder, ImageInDB.ImageName);
            await _imageRepository.DeleteAsync(id);
        }
Пример #9
0
 protected override void OnStartup(StartupEventArgs e)
 {
     AppFileHelper.ValidateApplicationFiles();
     Core.Enums.Theme userTheme = AppFileHelper.ReadUserThemeSettings();
     GlobalObjectHolder.CurrentTheme = userTheme;
     Resources.MergedDictionaries[0] = GetThemeResource(AppFileHelper.ReadUserThemeSettings());
     base.OnStartup(e);
 }
Пример #10
0
        public JsonResult UploadProfilePicture()
        {
            try
            {
                var profilePictureFile = Request.Form.Files.First();

                //Check input
                if (profilePictureFile == null)
                {
                    throw new UserFriendlyException(L("ProfilePicture_Change_Error"));
                }

                if (profilePictureFile.Length > 1048576) //1MB.
                {
                    throw new UserFriendlyException(L("ProfilePicture_Warn_SizeLimit"));
                }

                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }

                //Check file type & format
                using (var ms = new MemoryStream(fileBytes))
                {
                    var fileImage       = Image.FromStream(ms);
                    var acceptedFormats = new List <ImageFormat>
                    {
                        ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Gif
                    };

                    if (!acceptedFormats.Contains(fileImage.RawFormat))
                    {
                        throw new ApplicationException("Uploaded file is not an accepted image file !");
                    }
                }

                //Delete old temp profile pictures
                AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.TempFileDownloadFolder, "userProfileImage_" + AbpSession.GetUserId());

                //Save new picture
                var fileInfo     = new FileInfo(profilePictureFile.FileName);
                var tempFileName = "userProfileImage_" + AbpSession.GetUserId() + fileInfo.Extension;
                var tempFilePath = Path.Combine(_appFolders.TempFileDownloadFolder, tempFileName);
                System.IO.File.WriteAllBytes(tempFilePath, fileBytes);

                using (var bmpImage = new Bitmap(tempFilePath))
                {
                    return(Json(new AjaxResponse(new { fileName = tempFileName, width = bmpImage.Width, height = bmpImage.Height })));
                }
            }
            catch (UserFriendlyException ex)
            {
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }
Пример #11
0
        public JsonResult UploadProductSubGroupPicture(int ProductSubGroupId, string ImgPath)
        {
            try
            {
                var productSubGroupPictureFile = Request.Form.Files.First();

                //Check input
                if (productSubGroupPictureFile == null)
                {
                    throw new UserFriendlyException(L("ProductSubGroupPicture_Change_Error"));
                }

                if (productSubGroupPictureFile.Length > 1048576) //1MB.
                {
                    throw new UserFriendlyException(L("ProductSubGroupPicture_Warn_SizeLimit"));
                }

                byte[] fileBytes;
                using (var stream = productSubGroupPictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }

                if (!ImageFormatHelper.GetRawImageFormat(fileBytes).IsIn(ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Gif))
                {
                    throw new Exception("Uploaded file is not an accepted image file !");
                }

                var ProductSubGroup = _appFolders.ProductSubGroupFilePath;

                if (!Directory.Exists(ProductSubGroup))
                {
                    Directory.CreateDirectory(ProductSubGroup);
                }

                //Delete old ProductSubGroup pictures
                AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.FindFilePath, ImgPath);

                //Save new picture
                var fileInfo     = new FileInfo(productSubGroupPictureFile.FileName);
                var tempFileName = productSubGroupPictureFile.FileName + fileInfo.Extension;
                var tempFilePath = Path.Combine(ProductSubGroup, tempFileName);
                System.IO.File.WriteAllBytes(tempFilePath, fileBytes);

                using (var bmpImage = new Bitmap(tempFilePath))
                {
                    return(Json(new AjaxResponse(new { fileName = "Common/Images/ProductSubGroup/" + tempFileName, width = bmpImage.Width, height = bmpImage.Height })));
                }
            }
            catch (UserFriendlyException ex)
            {
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }
Пример #12
0
        public JsonResult UploadMultiTempProductPicture(int TempProductId)
        {
            try
            {
                var TempProductPictureFile = Request.Form.Files.First();

                //Check input
                if (TempProductPictureFile == null)
                {
                    throw new UserFriendlyException(L("ProductPicture_Change_Error"));
                }

                if (TempProductPictureFile.Length > 1048576) //1MB.
                {
                    throw new UserFriendlyException(L("ProductPicture_Warn_SizeLimit"));
                }

                byte[] fileBytes;
                using (var stream = TempProductPictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }

                if (!ImageFormatHelper.GetRawImageFormat(fileBytes).IsIn(ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Gif))
                {
                    throw new Exception("Uploaded file is not an accepted image file !");
                }
                var TempProducts = _appFolders.TempProductFilePath + @"\" + TempProductId;

                if (!Directory.Exists(TempProducts))
                {
                    Directory.CreateDirectory(TempProducts);
                }

                //Delete old temp product pictures
                AppFileHelper.DeleteFilesInFolderIfExists(TempProducts, TempProductPictureFile.FileName);

                //Save new picture
                var fileInfo     = new FileInfo(TempProductPictureFile.FileName);
                var tempFileName = TempProductPictureFile.FileName;
                var tempFilePath = Path.Combine(TempProducts, tempFileName);
                System.IO.File.WriteAllBytes(tempFilePath, fileBytes);

                using (var bmpImage = new Bitmap(tempFilePath))
                {
                    return(Json(new AjaxResponse(new { fileName = "Common/Images/TemporaryProduct/" + TempProductId + "/" + tempFileName, width = bmpImage.Width, height = bmpImage.Height })));
                }
            }
            catch (UserFriendlyException ex)
            {
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }
Пример #13
0
        public async Task UpdateProfilePicture(UpdateProfilePictureInput input)
        {
            var tempProfilePicturePath = Path.Combine(_appFolders.TempFileDownloadFolder, input.FileName);

            byte[] byteArray;

            using (var fsTempProfilePicture = new FileStream(tempProfilePicturePath, FileMode.Open))
            {
                using (var bmpImage = new Bitmap(fsTempProfilePicture))
                {
                    var width  = input.Width == 0 ? bmpImage.Width : input.Width;
                    var height = input.Height == 0 ? bmpImage.Height : input.Height;
                    var bmCrop = bmpImage.Clone(new Rectangle(input.X, input.Y, width, height), bmpImage.PixelFormat);

                    using (var stream = new MemoryStream())
                    {
                        bmCrop.Save(stream, bmpImage.RawFormat);
                        byteArray = stream.ToArray();
                    }
                }
            }

            if (byteArray.Length > 102400) //100 KB
            {
                throw new UserFriendlyException(L("ResizedProfilePicture_Warn_SizeLimit"));
            }

            var user = await UserManager.GetUserByIdAsync(AbpSession.GetUserId());

            if (user.ProfilePictureId.HasValue)
            {
                await _binaryObjectManager.DeleteAsync(user.ProfilePictureId.Value);
            }

            var fileInfo = new FileInfo(input.FileName);

            var file = fileInfo.Name + ".jpg";

            AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.ProfilePath, file);

            var tempFilePath = Path.Combine(_appFolders.ProfilePath, file);

            System.IO.File.WriteAllBytes(tempFilePath, byteArray);

            var storedFile = new BinaryObject(AbpSession.TenantId, byteArray);

            await _binaryObjectManager.SaveAsync(storedFile);

            user.ProfilePictureId = storedFile.Id;

            FileHelper.DeleteIfExists(tempProfilePicturePath);
            //await Summafun();
        }
Пример #14
0
        public JsonResult UploadChuKy(string maChuKy)
        {
            try
            {
                var userId = _session.UserId;
                //Check input
                if (Request.Files.Count <= 0 || Request.Files[0] == null)
                {
                    throw new UserFriendlyException(L("ProfilePicture_Change_Error"));
                }

                var file = Request.Files[0];

                if (file.ContentLength > 1048576) //1MB.
                {
                    throw new UserFriendlyException(L("ProfilePicture_Warn_SizeLimit"));
                }

                //Check file type & format
                var fileImage = System.Drawing.Image.FromStream(file.InputStream);

                var acceptedFormats = new List <ImageFormat>
                {
                    ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Gif
                };

                if (!acceptedFormats.Contains(fileImage.RawFormat))
                {
                    throw new ApplicationException("Uploaded file is not an accepted image file !");
                }

                //Delete old temp signatures
                AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.TempFileDownloadFolder, userId + "_" + maChuKy);

                //Save new picture
                var fileInfo     = new FileInfo(file.FileName);
                var tempFileName = userId + "_" + maChuKy + fileInfo.Extension;
                var tempFilePath = Path.Combine(_appFolders.TempFileDownloadFolder, tempFileName);
                file.SaveAs(tempFilePath);
                fileImage.Dispose();

                using (var bmpImage = new Bitmap(tempFilePath))
                {
                    return(Json(new AjaxResponse(new { fileName = tempFileName })));
                }
            }
            catch (UserFriendlyException ex)
            {
                Logger.Error($"{DateTime.Now.ToString("HH:mm:ss dd/MM/yyyy")} UploadChuKy {ex.Message} {JsonConvert.SerializeObject(ex)}");
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }
Пример #15
0
        public JsonResult UploadProfilePicture()
        {
            try
            {
                //Check input
                var files = Request.Form.Files;
                if (files.Count <= 0 || files[0] == null)
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "头像修改错误.");
                }

                var file = files[0];

                if (file.Length > 1048576) //1MB.
                {
                    throw new UserFriendlyException((int)ErrorCode.CodeValErr, "只能选择1mb内的JPG/JPEG图片,请重新选择头像文件.");
                }

                //Check file type & format 交给前端去处理
                //var fileImage = System.Drawing.  Image.FromStream(file.InputStream);
                //var acceptedFormats = new List<ImageFormat>
                //{
                //    ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Gif
                //};

                //if (!acceptedFormats.Contains(fileImage.RawFormat))
                //{
                //    throw new ApplicationException("Uploaded file is not an accepted image file !");
                //}

                //Delete old temp profile pictures
                AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.TempFileDownloadFolder, "userProfileImage_" + AbpSession.GetUserId());

                //Save new picture
                var fileInfo     = new FileInfo(file.FileName);
                var tempFileName = "userProfileImage_" + AbpSession.GetUserId() + fileInfo.Extension;
                var tempFilePath = Path.Combine(_appFolders.TempFileDownloadFolder, tempFileName);
                //file.sa(tempFilePath);

                using (FileStream fs = System.IO.File.Create(tempFilePath))
                {
                    file.CopyTo(fs);
                    fs.Flush();
                }
                return(Json(new AjaxResponse(new { fileName = tempFileName, })));
            }
            catch (UserFriendlyException ex)
            {
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }
        public UploadProfilePictureOutput UploadProfilePicture()
        {
            try
            {
                var profilePictureFile = Request.Form.Files.First();

                //Check input
                if (profilePictureFile == null)
                {
                    throw new UserFriendlyException(L("ProfilePicture_Change_Error"));
                }

                if (profilePictureFile.Length > MaxProfilePictureSize)
                {
                    throw new UserFriendlyException(L("ProfilePicture_Warn_SizeLimit", AppConsts.MaxProfilPictureBytesUserFriendlyValue));
                }

                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }

                //exception on linux
                // if (!fImageFormatHelper.GetRawImageFormat(fileBytes).IsIn(ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Gif))
                //{
                //   throw new Exception("Uploaded file is not an accepted image file !");
                //}

                //Delete old temp profile pictures
                AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.TempFileDownloadFolder, "userProfileImage_" + AbpSession.GetUserId());

                //Save new picture
                var fileInfo     = new FileInfo(profilePictureFile.FileName);
                var tempFileName = "userProfileImage_" + AbpSession.GetUserId() + fileInfo.Extension;
                var tempFilePath = Path.Combine(_appFolders.TempFileDownloadFolder, tempFileName);
                System.IO.File.WriteAllBytes(tempFilePath, fileBytes);

                return(new UploadProfilePictureOutput
                {
                    FileName = tempFileName,
                    Width = 0,
                    Height = 0
                });
            }
            catch (UserFriendlyException ex)
            {
                return(new UploadProfilePictureOutput(new ErrorInfo(ex.Message)));
            }
        }
Пример #17
0
        public GetLatestWebLogsOutput GetLatestWebLogs()
        {
            var directory = new DirectoryInfo(_appFolders.WebSiteLogsFolder);

            if (!directory.Exists)
            {
                return new GetLatestWebLogsOutput {
                           LatestWebLogLines = new List <string>()
                }
            }
            ;

            var lastLogFile = directory.GetFiles("*.txt", SearchOption.AllDirectories)
                              .OrderByDescending(f => f.LastWriteTime)
                              .FirstOrDefault();

            if (lastLogFile == null)
            {
                return(new GetLatestWebLogsOutput());
            }

            var lines        = AppFileHelper.ReadLines(lastLogFile.FullName).Reverse().Take(1000).ToList();
            var logLineCount = 0;
            var lineCount    = 0;

            foreach (var line in lines)
            {
                if (line.StartsWith("DEBUG") ||
                    line.StartsWith("INFO") ||
                    line.StartsWith("WARN") ||
                    line.StartsWith("ERROR") ||
                    line.StartsWith("FATAL"))
                {
                    logLineCount++;
                }

                lineCount++;

                if (logLineCount == 100)
                {
                    break;
                }
            }

            return(new GetLatestWebLogsOutput
            {
                LatestWebLogLines = lines.Take(lineCount).Reverse().ToList()
            });
        }
Пример #18
0
        public UploadProfilePictureOutput UploadProfilePicture()
        {
            try
            {
                var profilePictureFile = Request.Form.Files.First();

                //Check input
                if (profilePictureFile == null)
                {
                    throw new UserFriendlyException(L("ProfilePicture_Change_Error"));
                }

                if (profilePictureFile.Length > MaxProfilePictureSize)
                {
                    throw new UserFriendlyException(L("ProfilePicture_Warn_SizeLimit", AppConsts.MaxProfilPictureBytesUserFriendlyValue));
                }

                byte[] fileBytes;
                using (var stream = profilePictureFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }
                var fileInfo = new FileInfo(profilePictureFile.FileName);
                if (!new List <string> {
                    ".JPG", ".JPEG", ".JPE", ".BMP", ".GIF", ".PNG"
                }.Contains(fileInfo.Extension.ToUpperInvariant()))
                {
                    throw new Exception("Uploaded file is not an accepted image file !");
                }

                //Delete old temp profile pictures
                var fileNameWithoutExtension = "userProfileImage_" + AbpSession.GetUserId();
                AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.TempFileDownloadFolder, fileNameWithoutExtension);

                //Save new picture
                var tempFileName = fileNameWithoutExtension + fileInfo.Extension;
                var tempFilePath = Path.Combine(_appFolders.TempFileDownloadFolder, tempFileName);
                System.IO.File.WriteAllBytes(tempFilePath, fileBytes);

                return(new UploadProfilePictureOutput
                {
                    FileName = tempFileName,
                });
            }
            catch (UserFriendlyException ex)
            {
                return(new UploadProfilePictureOutput(new ErrorInfo(ex.Message)));
            }
        }
Пример #19
0
        public JsonResult UploadProfilePicture()
        {
            try
            {
                //Check input
                if (Request.Files.Count <= 0 || Request.Files[0] == null)
                {
                    throw new UserFriendlyException(L("ProfilePicture_Change_Error"));
                }

                var file = Request.Files[0];

                if (file.ContentLength > 1048576) //1MB.
                {
                    throw new UserFriendlyException(L("ProfilePicture_Warn_SizeLimit"));
                }

                //Check file type & format
                var fileImage       = Image.FromStream(file.InputStream);
                var acceptedFormats = new List <ImageFormat>
                {
                    ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Gif
                };

                if (!acceptedFormats.Contains(fileImage.RawFormat))
                {
                    throw new ApplicationException("Uploaded file is not an accepted image file !");
                }

                //Delete old temp profile pictures
                AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.TempFileDownloadFolder, "userProfileImage_" + AbpSession.GetUserId());

                //Save new picture
                var fileInfo     = new FileInfo(file.FileName);
                var tempFileName = "userProfileImage_" + AbpSession.GetUserId() + fileInfo.Extension;
                var tempFilePath = Path.Combine(_appFolders.TempFileDownloadFolder, tempFileName);
                file.SaveAs(tempFilePath);

                using (var bmpImage = new Bitmap(tempFilePath))
                {
                    return(Json(new AjaxResponse(new { fileName = tempFileName, width = bmpImage.Width, height = bmpImage.Height })));
                }
            }
            catch (UserFriendlyException ex)
            {
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }
Пример #20
0
        /// <summary>
        /// 保存上传物料图片
        /// </summary>
        /// <param name="filename">物料文件名(不含文件后缀)</param>
        public JsonResult UploadItemImage(string filename)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(filename))
                {
                    throw new ArgumentNullException("filename");
                }
                filename = filename.Trim();

                //Check input
                if (Request.Files.Count <= 0 || Request.Files[0] == null)
                {
                    throw new UserFriendlyException("图片上传失败!");
                }

                var file = Request.Files[0];
                if (file.ContentLength > 1024 * 1024) //1MB.
                {
                    throw new UserFriendlyException("图片尺寸过大(不得超过1M)。");
                }

                //Check file type & format
                var fileImage = Image.FromStream(file.InputStream);
                if (!fileImage.RawFormat.Equals(ImageFormat.Jpeg) &&
                    !fileImage.RawFormat.Equals(ImageFormat.Png) &&
                    !fileImage.RawFormat.Equals(ImageFormat.Bmp))
                {
                    throw new UserFriendlyException("图片格式不正确(jpeg、png、bmp)!");
                }

                //Delete exists pictures from ItemImagesFolder
                AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.ItemImagesFolder, filename);

                //Save new picture to ItemImagesFolder
                var fileInfo = new FileInfo(file.FileName);
                var fileNameWithExtension = filename + fileInfo.Extension;
                var filePath = Path.Combine(_appFolders.ItemImagesFolder, fileNameWithExtension);
                file.SaveAs(filePath);

                return(Json(new AjaxResponse(new { fileName = fileNameWithExtension })));
            }
            catch (UserFriendlyException ex)
            {
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }
Пример #21
0
        public JsonResult UploadTaiLieuSoHoa(string folderName = "TaiLieuSoHoa")
        {
            try
            {
                var userId = _session.UserId;

                //Check input
                if (Request.Files.Count <= 0 || Request.Files[0] == null)
                {
                    throw new UserFriendlyException(L("Excel_File_Error"));
                }

                var file                           = Request.Files[0];
                var fileExtension                  = Path.GetExtension(file.FileName);
                var fileNameNotExtension           = Path.GetFileNameWithoutExtension(file.FileName);
                var fileNameWithOutExtensionEncode = Base64Encode(fileNameNotExtension);

                var ngayTao  = DateTime.Now.ToString("yyyyMMdd_HHmmss");
                var fileName = RemoveUnicode(fileNameNotExtension).Replace(" ", "-") + "_" + ngayTao + fileExtension;
                fileName = HttpUtility.UrlEncode(fileName);


                var thuMucThang = DateTime.Now.ToString("yyyyMM");
                var pathName    = $"\\HCC_TAILIEUSO\\{folderName}\\{thuMucThang}\\";

                string HCC_FILE_PDF = GetUrlFileDefaut();
                var    folderPath   = Path.Combine(HCC_FILE_PDF, pathName);
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }

                //Delete old temp profile pictures
                AppFileHelper.DeleteFilesInFolderIfExists(folderPath, fileName);

                //Save new picture
                file.SaveAs(Path.Combine(folderPath, fileName));

                return(Json(new { fileName = pathName + fileName }, JsonRequestBehavior.AllowGet));
            }
            catch (UserFriendlyException ex)
            {
                Logger.Error($"{DateTime.Now.ToString("HH:mm:ss dd/MM/yyyy")} Upload [HCC_TAILIEUSO - {folderName}] {ex.Message} {JsonConvert.SerializeObject(ex)}");
                return(Json(new ErrorInfo(ex.Message), JsonRequestBehavior.AllowGet));
            }
        }
Пример #22
0
        public JsonResult UploadQuotationProduct()
        {
            string QuotationPath = _hostingEnvironment.WebRootPath + "\\Common\\Import\\";

            try
            {
                if (!Directory.Exists(QuotationPath))
                {
                    Directory.CreateDirectory(QuotationPath);
                }
                var productFile = Request.Form.Files.First();

                //Check input
                if (productFile == null)
                {
                    throw new UserFriendlyException(L("ProductSpecificationPicture_Change_Error"));
                }

                if (productFile.ContentType != "text/plain")
                {
                    throw new UserFriendlyException("Uploaded file is not an accepted text file !");
                }

                byte[] fileBytes;
                using (var stream = productFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }


                AppFileHelper.DeleteFilesInFolderIfExists(QuotationPath, productFile.FileName);

                //Save new file
                var fileInfo     = new FileInfo(productFile.FileName);
                var tempFileName = productFile.FileName;
                var tempFilePath = Path.Combine(QuotationPath, tempFileName);
                System.IO.File.WriteAllBytes(tempFilePath, fileBytes);

                return(Json(new AjaxResponse(new { fileName = QuotationPath + tempFileName, name = tempFileName })));
            }
            catch (UserFriendlyException ex)
            {
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }
Пример #23
0
        public GetLatestWebLogsOutput GetLatestWebLogs()
        {
            var directory   = new DirectoryInfo(_appFolders.WebLogsFolder);
            var lastLogFile = directory.GetFiles("*.txt", SearchOption.AllDirectories)
                              .OrderByDescending(f => f.LastWriteTime)
                              .FirstOrDefault();

            if (lastLogFile == null)
            {
                return(new GetLatestWebLogsOutput());
            }

            var lines = AppFileHelper.ReadLines(lastLogFile.FullName).Reverse().Take(100).Reverse().ToList();

            return(new GetLatestWebLogsOutput
            {
                LatesWebLogLines = lines
            });
        }
Пример #24
0
        public async Task GenerateProfilePicture()
        {
            try
            {
                long userid   = (long)AbpSession.UserId;
                int  TenantId = (int)(AbpSession.TenantId);

                using (_unitOfWorkManager.Current.SetTenantId(TenantId))
                {
                    var data = await UserManager.GetUserByIdAsync(userid);

                    if (data.ProfilePictureId != null)
                    {
                        try
                        {
                            var files = await _binaryObjectManager.GetOrNullAsync((Guid)data.ProfilePictureId);

                            byte[] bytes = new byte[0];
                            bytes = files.Bytes;
                            var tempFileName = "userProfileImage_" + data.Id + ".jpg";

                            AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.ProfilePath, tempFileName);

                            var tempFilePath = Path.Combine(_appFolders.ProfilePath, tempFileName);

                            System.IO.File.WriteAllBytes(tempFilePath, bytes);

                            data.ProfileImage = "Common/Profile/" + tempFileName;
                            await UserManager.UpdateAsync(data);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Пример #25
0
        public async Task<GetCountry> GetCountryForEdit(EntityDto input)
        {

            var datas = UserManager.Users.ToList();

            foreach (var data in datas)
            {
                if (data.ProfilePictureId != null)
                {
                    try
                    {
                        var files = await _binaryObjectManager.GetOrNullAsync((Guid)data.ProfilePictureId);
                        byte[] bytes = new byte[0];
                        bytes = files.Bytes;
                        var tempFileName = "userProfileImage_" + data.Id + ".jpg";

                        AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.ProfilePath, tempFileName);

                        var tempFilePath = Path.Combine(_appFolders.ProfilePath, tempFileName);

                        System.IO.File.WriteAllBytes(tempFilePath, bytes);
                    }
                    catch (Exception ex)
                    {

                    }

                }
            }
            var output = new GetCountry
            {
            };

            var persion = _countryRepository
                .GetAll().Where(p => p.Id == input.Id).FirstOrDefault();

            output.Countrys = persion.MapTo<CountryListDto>();
            return output;
        }
Пример #26
0
        public UploadProfilePictureOutput UploadProfile()
        {
            try
            {
                var proFile = Request.Form.Files.First();

                if (proFile == null)
                {
                    throw new UserFriendlyException(L("文件不存在"));
                }

                byte[] fileBytes;
                using (var stream = proFile.OpenReadStream())
                {
                    fileBytes = stream.GetAllBytes();
                }


                //Delete old temp profile pictures
                AppFileHelper.DeleteFilesInFolderIfExists(_appFolders.TempFileDownloadFolder, "Profile_" + AbpSession.GetUserId());

                //Save new picture
                var fileInfo     = new FileInfo(proFile.FileName);
                var tempFileName = "Profile_" + AbpSession.GetUserId() + fileInfo.Extension;
                var tempFilePath = Path.Combine(_appFolders.TempFileDownloadFolder, tempFileName);
                System.IO.File.WriteAllBytes(tempFilePath, fileBytes);

                return(new UploadProfilePictureOutput
                {
                    FileName = tempFileName,
                });
            }
            catch (UserFriendlyException ex)
            {
                return(new UploadProfilePictureOutput(new ErrorInfo(ex.Message)));
            }
        }
Пример #27
0
        public JsonResult UploadTaiLieuHoSo(string maThuTuc, string maSoThue, string strThuMucHoSo = "HOSO_0", string folderName = "tepdinhkem")
        {
            try
            {
                if (string.IsNullOrEmpty(maThuTuc))
                {
                    maThuTuc = "TT-unknown";
                }
                var userId = _session.UserId;

                //Check input
                if (Request.Files.Count <= 0 || Request.Files[0] == null)
                {
                    throw new UserFriendlyException(L("Excel_File_Error"));
                }

                //lấy tỉnh để tạo thêm thư mục
                var strTinh     = "unknown";
                var doanhnghiep = _doanhNghiepRepos.FirstOrDefault(x => x.MaSoThue == maSoThue);
                if (doanhnghiep != null)
                {
                    strTinh = !string.IsNullOrEmpty(doanhnghiep.Tinh) ? RemoveUnicode(doanhnghiep.Tinh).ToLower().Trim().Replace(" ", "-") : "unknown";
                }

                var file                           = Request.Files[0];
                var fileExtension                  = Path.GetExtension(file.FileName);
                var fileNameNotExtension           = Path.GetFileNameWithoutExtension(file.FileName);
                var fileNameWithOutExtensionEncode = Base64Encode(fileNameNotExtension);

                var ngayTao  = DateTime.Now.ToString("yyyyMMdd_HHmmss");
                var fileName = RemoveUnicode(fileNameNotExtension).Replace(" ", "-") + "_" + maSoThue + "_" + ngayTao + fileExtension;
                fileName = HttpUtility.UrlEncode(fileName);

                if (string.IsNullOrEmpty(strThuMucHoSo) || strThuMucHoSo == "HOSO_0")
                {
                    strThuMucHoSo = $"HOSO_0";
                }

                var pathName = $"{maThuTuc}\\{strTinh}\\{maSoThue}\\{strThuMucHoSo}\\{folderName}\\";

                string HCC_FILE_PDF = GetUrlFileDefaut();
                var    folderPath   = Path.Combine(HCC_FILE_PDF, pathName);
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }

                //Delete old temp profile pictures
                AppFileHelper.DeleteFilesInFolderIfExists(folderPath, fileName);

                //Save new picture
                file.SaveAs(Path.Combine(folderPath, fileName));

                //LogUploadFile
                LogUploadFile uploadObj = new LogUploadFile
                {
                    DuongDanTep = pathName + fileName,
                    DaTaiLen    = true
                };
                long _uploadFileId = _uploadFileRepos.InsertAndGetId(uploadObj);

                return(Json(new
                {
                    fileName = fileNameNotExtension + fileExtension,
                    filePath = pathName + fileName,
                    uploadFileId = _uploadFileId
                }, JsonRequestBehavior.AllowGet));
            }
            catch (UserFriendlyException ex)
            {
                Logger.Error($"{DateTime.Now.ToString("HH:mm:ss dd/MM/yyyy")} Upload [{strThuMucHoSo} - {folderName}] {ex.Message} {JsonConvert.SerializeObject(ex)}");
                return(Json(new ErrorInfo(ex.Message), JsonRequestBehavior.AllowGet));
            }
        }
        public void WriteDataToCSV(string name, string profileUrl, string memberID, string connection, string location, string industry, string headlineTitle, string currentTitle, string pastTitles, string currentCompany, string pastCompany, string skills, string numberOfConnections, string education, string email, string phoneNumber)
        {
            try
            {
                string loginId = string.Empty;
                GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Profile details saved in CSV file of profile URL : " + profileUrl + " ]");

                if (name.Trim() == string.Empty)
                {
                    name = "LinkedIn member";
                }
                if (profileUrl.Trim() == string.Empty)
                {
                    profileUrl = "--";
                }
                if (connection.Trim() == string.Empty)
                {
                    connection = "--";
                }
                if (location.Trim() == string.Empty)
                {
                    location = "--";
                }
                if (industry.Trim() == string.Empty)
                {
                    industry = "--";
                }
                if (headlineTitle.Trim() == string.Empty)
                {
                    headlineTitle = "--";
                }
                if (currentTitle.Trim() == string.Empty)
                {
                    currentTitle = "--";
                }
                if (pastTitles.Trim() == string.Empty)
                {
                    pastTitles = "--";
                }
                if (currentCompany.Trim() == string.Empty)
                {
                    currentCompany = "--";
                }
                if (pastCompany.Trim() == string.Empty)
                {
                    pastCompany = "--";
                }
                if (skills.Trim() == string.Empty)
                {
                    skills = "--";
                }
                if (numberOfConnections.Trim() == string.Empty)
                {
                    numberOfConnections = "--";
                }
                if (education.Trim() == string.Empty)
                {
                    education = "--";
                }
                if (email.Trim() == string.Empty)
                {
                    email = "--";
                }
                if (phoneNumber.Trim() == string.Empty)
                {
                    phoneNumber = "--";
                }


                string Header        = "Profile name" + "," + "Profile URL" + "," + "Member ID" + "," + "Degree of connection" + "," + "Location" + "," + "Industry" + "," + "Headline title" + "," + "Current title" + "," + "Past titles" + "," + "Current company" + "," + "Past company" + "," + "Skills" + "," + "Number of connections" + "," + "Education" + "," + "Email" + "," + "Phone number" + "," + "Account Used" + ",";
                string LDS_FinalData = name.Replace(",", ";") + "," + profileUrl.Replace(",", ";") + "," + memberID.Replace(",", ";") + "," + connection.Replace(",", ";") + "," + location.Replace(",", ";") + "," + industry.Replace(",", ";") + "," + headlineTitle.Replace(",", ";") + "," + currentTitle.Replace(",", ";") + "," + pastTitles.Replace(",", ";") + "," + currentCompany.Replace(",", ";") + "," + pastCompany.Replace(",", ";") + "," + skills.Replace(",", ";") + "," + numberOfConnections.Replace(",", ";") + "," + education.Replace(",", ";") + "," + email.Replace(",", ";") + "," + phoneNumber.Replace(",", ";") + "," + loginId.Replace(",", ";");
                string FileName      = "SalesNavigatorScraper";
                AppFileHelper.SalesNavigatorScraperWriteToCSV(LDS_FinalData, Header, FileName);
            }
            catch (Exception ex)
            {
            }
        }