public override ResultModel <DownloadFileViewModel> GetFileById(Guid id) { if (id == Guid.Empty) { return(ExceptionMessagesEnum.NullParameter.ToErrorModel <DownloadFileViewModel>()); } var dbFileResult = _context.FilesBox.FirstOrDefault(x => (x.Id == id) & (x.IsDeleted == false)); if (dbFileResult == null) { return(ExceptionMessagesEnum.FileNotFound.ToErrorModel <DownloadFileViewModel>()); } var filePath = Path.Combine(_hostingEnvironment.WebRootPath, FileRootPath, dbFileResult.Path); var dto = new DownloadFileViewModel { Path = filePath, FileExtension = dbFileResult.FileExtension, FileName = dbFileResult.Name }; return(new ResultModel <DownloadFileViewModel> { IsSuccess = true, Result = dto }); }
public DownloadFileViewModel DownloadEmissionTestImage(int id) { var response = new DownloadFileViewModel(); try { var emissionTestReportRecord = _db.VehicleEmissiontTests.FirstOrDefault(t => t.Id == id); var imagePath = emissionTestReportRecord.GetVehicleEmissionTestImagePath(config); byte[] fileContents = null; MemoryStream ms = new MemoryStream(); using (FileStream fs = File.OpenRead(imagePath)) { fs.CopyTo(ms); fileContents = ms.ToArray(); ms.Dispose(); response.FileData = fileContents; } response.FileName = emissionTestReportRecord.Attachment; } catch (Exception ex) { logger.LogError(ex.ToString()); } return(response); }
public override ResultModel <DownloadFileViewModel> GetFileById(Guid id) { if (id == Guid.Empty) { return(ExceptionMessagesEnum.NullParameter.ToErrorModel <DownloadFileViewModel>()); } var dbFileResult = _context.Files.FirstOrDefault(x => (x.Id == id) & (x.IsDeleted == false)); if (dbFileResult == null) { return(ExceptionMessagesEnum.FileNotFound.ToErrorModel <DownloadFileViewModel>()); } var dto = new DownloadFileViewModel { EncryptedFile = dbFileResult.Hash, FileExtension = dbFileResult.FileExtension, FileName = dbFileResult.Name }; return(new ResultModel <DownloadFileViewModel> { IsSuccess = true, Result = dto }); }
public IActionResult DownloadFile([FromRoute] DownloadFileViewModel model) { try { var fileModel = _mapper.Map <DownloadFileViewModel, DownloadFileDto>(model); var fileType = _contentService.GetFileType(fileModel); return(PhysicalFile(model.FilePath, fileType, model.FileName)); } catch { return(BadRequest()); } }
public IFormFile GetFileFromByte([FromBody] DownloadFileViewModel downloadFile) { var file = fileService.DownloadById(downloadFile.IdRequest, downloadFile.IdFile); try { using (var fileStream = new FileStream(downloadFile.FileName, FileMode.Create, FileAccess.Write)) { fileStream.Write(file.Content, 0, file.Content.Length); } } catch (Exception e) { OperationResult.FromException(e, 0); } return(null); }
//public void AddUrl(string temp, string folder = "", string title = "") //{ // var list = temp.Split('\n'); // foreach (var item in list) // { // Uri uriResult; // var list2 = item.Split('\t'); // string url = list2[0]; // bool result = Uri.TryCreate(url, UriKind.Absolute, out uriResult); // if (result == false) // { // continue; // } // if (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps) // { // //string ext = Util.GetExtension(url); // //if (Util.IsMovie(ext) || Util.IsPicture(ext)) // { // //Console.WriteLine(temp); // _dispatcher.BeginInvoke(new Action(() => // { // string protocol = "HTTP"; // string ext = Util.GetExtension(url); // if(Util.IsLive(ext)) // { // protocol = "LIVE"; // } // DownloadData data = new DownloadData // { // URL = url, // Folder = folder, // Title = title, // Protocol = protocol // }; // viewmodel.AddFile(data); // }), (DispatcherPriority)10); // } // } // } //} public MainWindow() { InitializeComponent(); this.Closing += MainWindow_Closing; viewmodel = DownloadFileViewModel.SharedViewModel();; this.DataContext = viewmodel; viewmodel.DownloadFolder = Directory.GetCurrentDirectory() + "\\Download"; IPCTestServer.IPCTestServer.SetWindow(this); new Thread(() => { var server = new MyServer(); }).Start(); //if (false) //{ // cbw = new ClipBoardWatcher(); // cbw.DrawClipBoard += (sender, e) => // { // if (Clipboard.ContainsText()) // { // string temp = Clipboard.GetText(); // AddUrl(temp); // } // }; //} System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += dispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 1); dispatcherTimer.Start(); }
public MainWindow() { InitializeComponent(); this.DataContext = DownloadFileViewModel.SharedViewModel(); }
public IHttpActionResult Download(string path) { var downloadFileInfo = new DownloadFileViewModel(path); return(new FileActionResult(downloadFileInfo)); }
public DownloadFileViewModel DownloadUserImage(int id, int type) { var response = new DownloadFileViewModel(); try { var imagePath = string.Empty; var userRecord = _db.Users.FirstOrDefault(t => t.Id == id); switch (type) { case (int)UserPhotoType.UserImage: { imagePath = userRecord.GetUserImagePath(_config); response.FileName = userRecord.Image; } break; case (int)UserPhotoType.NicBack: { imagePath = userRecord.GetUserNICBackImagePath(_config); response.FileName = userRecord.NicfrontImage; } break; case (int)UserPhotoType.NicFront: { imagePath = userRecord.GetUserNICFrontImagePath(_config); response.FileName = userRecord.NicbackImage; } break; case (int)UserPhotoType.DrivingLicenceFront: { imagePath = userRecord.GetUserDrivingLicenceFrontImagePath(_config); response.FileName = userRecord.DrivingLicenceFrontImage; } break; case (int)UserPhotoType.DrivingLicenceBack: { imagePath = userRecord.GetUserDrivingLicenceBackImagePath(_config); response.FileName = userRecord.DrivingLicenceBackImage; } break; } byte[] fileContents = null; MemoryStream ms = new MemoryStream(); using (FileStream fs = File.OpenRead(imagePath)) { fs.CopyTo(ms); fileContents = ms.ToArray(); ms.Dispose(); response.FileData = fileContents; } } catch (Exception ex) { _logger.LogError(ex.ToString()); } return(response); }
/// <summary> /// /// </summary> /// <param name="info"></param> public FileActionResult(DownloadFileViewModel info) { DownloadFile = info; }