private static List <Model.File> GetFileList(string buildId, Software software, string browserVersion, Browser browser, string absolutePath, string fileFilter) { if (!Directory.Exists(absolutePath)) { return(new List <Model.File>()); } var files = Directory.GetFiles(absolutePath, fileFilter); var fileList = new List <Model.File>(); foreach (var file in files) { var fileZip = new Model.File { Name = Path.GetFileName(file) }; fileZip.Url = $"{DomainCdn}/vms/VMBuild_{buildId}/{software.SoftwareName}/{browserVersion}/{fileZip.Name}"; fileZip.MD5 = $"{DomainCdn}/vms/md5/VMBuild_{buildId}/{fileZip.Name}.md5.txt"; fileList.Add(fileZip); } Console.WriteLine($"Processed {files.Count()} files ({fileFilter.Substring(fileFilter.Length - 3, 3)}) in {absolutePath}"); return(fileList); }
public string GetFilePath(Model.File req) { string path = Path.Combine(BasePath, GetRelativeFilePath (req.FileType, req.UserId, req.FileId, req.suffix, req.version)); return(path); }
public ResponseBase ConfirmEditedMusic(Music music, Model.File WAVUpload, Model.File MP3Upload, ConfirmTypeAction confirmAction, string DeclineReason) { ResponseBase res = new ResponseBase(); try { // delete from confirmation table Confirmation conf = ((ConfirmationRepository)this._rep) .GetByEntityId(music.ID.ToString()); if (conf != null) { this._rep.Delete(conf); switch (confirmAction) { case ConfirmTypeAction.Ok: // update source music by music music.Status = MusicActiveStatus.Public; if (_MusicSrv.Update(music, music.SourceMusicId.Value, WAVUpload, MP3Upload).Success) { // Delete temp music _MusicSrv.DeleteBy(music.ID); } break; case ConfirmTypeAction.Decline: _MusicSrv.Update(music, music.ID, WAVUpload, MP3Upload); _emailService.DeclineNewUpdateMusic(music.Artist.User.Email, DeclineReason, music.HebrewName); break; case ConfirmTypeAction.Block: // Delete from temp _MusicSrv.DeleteBy(music.ID); // Set the source music as blocked var SourceMusic = _MusicRep.GetByID(music.SourceMusicId.Value); SourceMusic.Status = MusicActiveStatus.Blocked; _MusicRep.Update(SourceMusic); break; } this._uow.Commit(); res.Success = true; } else { res.Message = "לא הצלחנו לאתר נתונים"; res.Success = false; } } catch (Exception e) { res.Message = e.Message; res.Success = false; } return(res); }
public ActionResult UploadSketch(HttpPostedFileBase WAVUpload, HttpPostedFileBase MP3Upload, string ArtistNote, string AuctionId, string name) { if (ModelState.IsValid) { string ArtistId = User.Identity.GetUserId(); var auction = this._actionSrv.GetByID(AuctionId).Entity; if (auction != null) { // Create music obg var sketch = new Sketch() { Name = name, ArtistID = ArtistId, Comment = ArtistNote, CreateDate = DateTime.Now }; // Convert music to File Model.File mp3File = FileHelper. ConvertPostedFileToFile(MP3Upload, 0, ArtistId, null); Model.File wavFile = FileHelper. ConvertPostedFileToFile(WAVUpload, 0, ArtistId, null); // Add music to db and to file system var res = _musicSrv.AddSketchToAuction(auction, sketch, wavFile, mp3File); } } return(Redirect("~/Artist/OriginalMusic")); }
public string StoreImage(Model.File file, HttpPostedFileBase Httpfile) { string relativePath = GetRelativeFilePath(file.FileType, file.UserId, file.FileId, file.suffix, file.version); string path = Path.Combine(BasePath, relativePath); ValidateDirectory(Path.GetDirectoryName(path)); Httpfile.SaveAs(path); return(string.Format(FileNameFormat, file.FileId, 1, file.suffix)); }
/// <summary> /// /// </summary> /// <param name="file"></param> /// <returns></returns> public string StoreFile(Model.File file) { string relativePath = GetRelativeFilePath (file.FileType, file.UserId, file.FileId, file.suffix, file.version); string path = Path.Combine(BasePath, relativePath); ValidateDirectory(Path.GetDirectoryName(path)); System.IO.File.WriteAllBytes(path, file.Content); return(relativePath); }
public ResponseBase ConfirmNewMusic(Music music, Model.File WAVUpload, Model.File MP3Upload, ConfirmTypeAction confirmAction, string DeclineReason) { ResponseBase res = new ResponseBase(); try { // delete from confirmation table Confirmation conf = ((ConfirmationRepository)this._rep) .GetByEntityId(music.ID.ToString()); if (conf != null) { this._rep.Delete(conf); switch (confirmAction) { case ConfirmTypeAction.Ok: music.Status = MusicActiveStatus.Public; // update async artist report by updating his pdf file _pdfService.ArtistAddMusicAsync(DateTime.Now, music.HebrewName, music.MusicComposer, music.MusicPerformer, music.Exceptions, music.MusicWriter, music.ArtistID, WebConf.FSBaseRoute); break; case ConfirmTypeAction.Decline: _emailService.DeclineNewUpdateMusic(music.Artist.User.Email, DeclineReason, music.HebrewName); break; case ConfirmTypeAction.Block: music.Status = MusicActiveStatus.Blocked; break; } var resUpDateOK = _MusicSrv.Update(music, music.ID, WAVUpload, MP3Upload); this._uow.Commit(); res.Success = true; } else { res.Message = "לא הצלחנו לאתר נתונים"; res.Success = false; } } catch (Exception e) { res.Message = e.Message; res.Success = false; } return(res); }
public Project Substitute(Context ctx, Project project) { var processedFiles = new List <Model.File>(); if (project.ProcessedFiles != null) { processedFiles.AddRange(project.ProcessedFiles); } var tempCreatedFiles = project.CreatedFiles.ToList(); for (int i = 0; i < tempCreatedFiles.Count; i++) { // Replace templates in TEXT var file = tempCreatedFiles[i]; var text = System.IO.File.ReadAllText(file.Info.FullName); var processedText = ReplaceTemplates(text, ctx); System.IO.File.WriteAllText(file.Info.FullName, processedText); // Replace templates in DIRECTORY NAMES var processedDirectoryName = ReplaceTemplates(file.Info.Directory.FullName, ctx); if (file.Info.Directory.FullName != processedDirectoryName) { System.IO.Directory.Move(file.Info.Directory.FullName, processedDirectoryName); for (int j = 0; j < tempCreatedFiles.Count; j++) { tempCreatedFiles[j] = new Model.File { Info = new FileInfo( tempCreatedFiles[j].Info.FullName.Replace(file.Info.Directory.FullName, processedDirectoryName) ) }; } } // Replace templates in FILE NAMES var processedFileName = ReplaceTemplates(file.Info.FullName, ctx); if (file.Info.FullName != processedFileName) { System.IO.File.Move(Path.Combine(processedDirectoryName, file.Info.Name), processedFileName); file = new Model.File { Info = new FileInfo(processedFileName) }; } processedFiles.Add(file); } return(new Project { ProcessedFiles = processedFiles }); }
public Model.File GetFile(Model.File req) { string path = Path.Combine(BasePath, GetRelativeFilePath (req.FileType, req.UserId, req.FileId, req.suffix, req.version)); Model.File file = new Model.File() { FileId = Path.GetFileName(path), FileType = req.FileType, Content = System.IO.File.ReadAllBytes(path) }; return(file); }
public ActionResult GetFile(Model.File file, string FileName) { var res = service.GetFile(file); if (res.Success) { if (string.IsNullOrEmpty(FileName)) { return(File(res.Entity.Content, res.Entity.ContentType)); } return(File(res.Entity.Content, res.Entity.ContentType, FileName + file.suffix)); } return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); }
public EntityResponse <string> GetFilePath(Model.File req) { EntityResponse <string> res = new EntityResponse <string>(); try { res.Entity = this._rep.GetFilePath(req); res.Success = true; } catch (Exception e) { res.Message = e.Message; res.Success = false; } return(res); }
public ResponseBase AddSketchToAuction(Auction auction, Sketch sketch, Model.File WAVFile, Model.File MP3File) { var res = new ResponseBase(); sketch.CreateDate = DateTime.Now; res.Success = true; if (sketch.Artist == null && sketch.ArtistID != null) { sketch.Artist = _usersRep.GetByID(sketch.ArtistID)?.Artist; } if (res.Success && WAVFile != null) { WAVFile.UserId = sketch.Artist.Id; res = FsService.StoreFile(WAVFile); if (res.Success) { sketch.WAVFile = (res as EntityResponse <Model.File>).Entity; sketch.WAVFileID = sketch.WAVFile.FileId; } } if (res.Success && MP3File != null) { MP3File.UserId = sketch.Artist.Id; res = FsService.StoreFile(MP3File); if (res.Success) { sketch.MP3File = (res as EntityResponse <Model.File>).Entity; sketch.MP3FileID = sketch.MP3File.FileId; } } if (res.Success) { if (auction.Sketches == null) { auction.Sketches = new List <Sketch>(); } auction.Sketches.Add(sketch); return(_auctionSrv.Update(auction)); } return(res); }
public EntityResponse <Model.File> StoreFile(Model.File file) { var res = new EntityResponse <Model.File>(); try { var filePath = this._rep.StoreFile(file); res.Entity = file; res.Success = true; } catch (Exception e) { res.Message = e.ToString(); res.Success = false; } return(res); }
public SavePhotoResponse StorePhoto(HttpPostedFileBase file, PaskolUser user, string OldPhotoId = null) { SavePhotoResponse res = new SavePhotoResponse(); res.Success = true; try { if (file != null && file.ContentLength > 0) { var IsBitMap = ValidateImage(file); // If file is image if (IsBitMap) { var photo = new Model.File() { FileId = System.IO.Path.GetFileName(file.FileName), FileType = FileType.Photo, version = 1, UserId = user.Id }; string fi = this._rep.StoreImage(photo, file); res.PhotoId = fi; } else { res.Success = false; res.Message = "יש להעלות קובץ תמונה בלבד"; } } } catch (Exception e) { res.Message = e.Message; res.Success = false; throw; } return(res); }
public EntityResponse <Model.File> Get(string path) { EntityResponse <Model.File> res = new EntityResponse <Model.File>(); try { Model.File file = new Model.File() { FileId = Path.GetFileName(path), FileType = FileType.PDF, Content = System.IO.File.ReadAllBytes(path) }; res.Entity = file; res.Success = true; } catch (Exception e) { res.Success = false; res.Message = e.Message; } return(res); }
public static Model.File ConvertPostedFileToFile (HttpPostedFileBase postedFile, int version, string userId, string fileId) { Model.File resFile = null; if (postedFile != null) { resFile = new Model.File() { FileType = FileType.Music, suffix = System.IO.Path.GetExtension(postedFile.FileName), UserId = userId, version = version, }; if (!string.IsNullOrEmpty(fileId)) { resFile.FileId = fileId; } var wavLength = postedFile.InputStream.Length; resFile.Content = new byte[wavLength]; postedFile.InputStream.Read(resFile.Content, 0, (int)wavLength); } return(resFile); }
public void GetRange(Model.File file) { var res = service.GetFilePath(file); if (res.Success) { try { DownloadRange(res.Entity); } catch (HttpException e) { // The user cancel the request' it's OK } catch (Exception e) { throw new HttpException(500, e.ToString()); } } else { throw new HttpException(404, res.Message); } }
public ResponseBase Update(Music musicData, int musicId, Model.File WAVFile, Model.File MP3File) { ResponseBase res = this.GetByID(musicId); if (res.Success) { var dbMusic = (res as EntityResponse <Music>).Entity; dbMusic.UpdateDate = DateTime.Now; dbMusic.BPM = musicData.BPM; dbMusic.Comment = musicData.Comment; dbMusic.Copyrights = musicData.Copyrights; dbMusic.CostLevel = musicData.CostLevel; dbMusic.EnglishName = musicData.EnglishName; dbMusic.Exceptions = musicData.Exceptions; dbMusic.HebrewName = musicData.HebrewName; dbMusic.MusicComposer = musicData.MusicComposer; dbMusic.MusicLength = musicData.MusicLength; dbMusic.MusicPerformer = musicData.MusicPerformer; dbMusic.MusicWriter = musicData.MusicWriter; dbMusic.SongText = musicData.SongText; dbMusic.Status = musicData.Status; musicData.Tags = musicData.Tags ?? new List <Tag>(); var addTagList = musicData.Tags .Where(tg => !dbMusic.Tags.Any(dbTg => dbTg.ID == tg.ID)) ?.Select(tg => tg.ID); if (addTagList != null && addTagList.Any()) { res = TagService.GetTagList(addTagList); if (res.Success) { dbMusic.Tags.AddRange((res as EntityAllResponse <Tag>).Entities); } } if (res.Success) { dbMusic.Tags.RemoveAll(tg => !musicData.Tags.Any(x => x.ID == tg.ID)); if (WAVFile != null) { res = FsService.StoreFile(WAVFile); if (res.Success) { if (dbMusic.WAVFile != null) { dbMusic.WAVFile.version = (res as EntityResponse <Model.File>).Entity.version; } else { dbMusic.WAVFile = (res as EntityResponse <Model.File>).Entity; dbMusic.WAVFileID = dbMusic.WAVFile.FileId; } } } } if (res.Success && MP3File != null) { res = FsService.StoreFile(MP3File); if (res.Success) { if (dbMusic.MP3File != null) { dbMusic.MP3File.version = (res as EntityResponse <Model.File>).Entity.version; } else { dbMusic.MP3File = (res as EntityResponse <Model.File>).Entity; dbMusic.MP3FileID = dbMusic.MP3File.FileId; } } } if (res.Success) { res = base.Update(dbMusic); } } return(res); }
public ResponseBase SaveNewPurchase(int?MusicId, PaskolUser Buyer, double Total, Guid permId) { ResponseBase res = new ResponseBase(); try { Music music = null; if (MusicId != null && Buyer != null) { music = _musicRep.GetByID(MusicId.Value); if (music != null) { var file = new Model.File() { FileType = FileType.PDF, suffix = ".pdf", UserId = Buyer.Id, }; Purchase newPurchase = new Purchase(); newPurchase.Customer = Buyer; newPurchase.Music = music; newPurchase.PurchaseCost = Total; newPurchase.PurchaseStatus = PurchaseStatus.NotPaidToArtist; newPurchase.PurchaseDate = DateTime.Now; newPurchase.Permision = _permissionRep.GetByID(permId); newPurchase.CustomerReference = "";//TODO newPurchase.PurchaseAgreement = file; this._rep.Add(newPurchase); this._uow.Commit(); string pathToDownload = string.Format(CommonHelper.GetBaseUrl() + "/File/GetFile?FileId={0}&UserId={1}&FileType={2}&version={3}&suffix={4}&FileName={5}" , music.WAVFileID, music.ArtistID, FileType.Music, music.WAVFile.version, music.WAVFile.suffix, music.HebrewName); string permissions = string.Join(", ", newPurchase.Permision.PropertyValues .Where(pv => !pv.PermissionProperty.IsCostLevel) .Select(pv => pv.PermissionProperty.Name + " - " + pv.Name)); // Create Report _pdfService.PurchaseAgreement( WebConf.FSBaseRoute, Path.GetFileName(file.RelativePath), Buyer.Id, DateTime.Now, Buyer.UserName, Buyer.Email, music.HebrewName, music.MusicWriter, music.MusicComposer, music.MusicPerformer, permissions, newPurchase.PurchaseCost.HasValue ? newPurchase.PurchaseCost.Value : 0, newPurchase.CustomerReference, newPurchase.Music.Exceptions); // notify artist and customer this._emailSrv.AlertArtistPurchaseSuccess(newPurchase.Music.Artist.User.Email); this._emailSrv.AlertBuyerPurchaseSuccess(newPurchase.Customer.Email, pathToDownload); res.Success = true; } } if (music == null || Buyer == null) { res.Success = false; res.Message = "לא הצלחנו לזהות לקוח או מוזיקה"; } } catch (Exception e) { res.Message = e.Message; res.Success = false; } return(res); }
public ResponseBase ConfirmPhonePurchase(Purchase ConfPurchase, ConfirmTypeAction confirmAction) { ResponseBase res = new ResponseBase(); try { var purchase = this._purchasseRep.GetByID(ConfPurchase.PurchaseId); if (purchase != null) { // delete from confirmation table Confirmation conf = ((ConfirmationRepository)this._rep) .GetByEntityId(ConfPurchase.PurchaseId.ToString()); if (conf != null) { switch (confirmAction) { case ConfirmTypeAction.Ok: var file = new Model.File() { FileType = FileType.PDF, suffix = ".pdf", UserId = ConfPurchase.Customer.Id, }; // save that paid by customer but not paid to artist purchase.PurchaseStatus = PurchaseStatus.NotPaidToArtist; purchase.Note = " שולם.. " + ConfPurchase.Note; purchase.PurchaseCost = ConfPurchase.PurchaseCost; purchase.CustomerReference = ConfPurchase.CustomerReference; purchase.PurchaseAgreement = file; this._purchasseRep.Update(purchase); this._rep.Delete(conf); this._uow.Commit(); string pathToDownload = string.Format(CommonHelper.GetBaseUrl() + "/File/GetFile?FileId={0}&UserId={1}&FileType={2}&version={3}&suffix={4}&FileName={5}" , purchase.Music.WAVFileID, purchase.Music.ArtistID, FileType.Music, purchase.Music.WAVFile.version, purchase.Music.WAVFile.suffix, purchase.Music.HebrewName); string permissions = string.Join(", ", purchase.Permision.PropertyValues .Where(pv => !pv.PermissionProperty.IsCostLevel) .Select(pv => pv.PermissionProperty.Name + " - " + pv.Name)); // Create Report _pdfService.PurchaseAgreement( WebConf.FSBaseRoute, Path.GetFileName(file.RelativePath), purchase.Customer.Id, DateTime.Now, purchase.Customer.UserName, purchase.Customer.Email, purchase.Music.HebrewName, purchase.Music.MusicWriter, purchase.Music.MusicComposer, purchase.Music.MusicPerformer, permissions, purchase.PurchaseCost.HasValue ? purchase.PurchaseCost.Value : 0, purchase.CustomerReference, purchase.Music.Exceptions); // Send email _emailService.AlertArtistPurchaseSuccess(purchase.Music.Artist.User.Email); _emailService.AlertBuyerPurchaseSuccess(purchase.Customer.Email, pathToDownload); break; case ConfirmTypeAction.Decline: purchase.Note = " בוטל " + ConfPurchase.Note; this._purchasseRep.Update(purchase); this._uow.Commit(); break; } res.Success = true; } } else { res.Message = "הרכישה המבוקשת לעדכון לא נמצאה"; res.Success = false; } } catch (Exception e) { res.Message = e.Message; res.Success = false; } return(res); }
public ResponseBase Add(Music music, Model.File WAVFile, Model.File MP3File) { var res = new ResponseBase(); music.CreateDate = DateTime.Now; res.Success = true; if (music.Tags?.FirstOrDefault() != null) { var tgRes = TagService.GetAll(); res.Success = tgRes.Success; if (res.Success) { music.Tags = tgRes.Entities .Where(dbTag => music.Tags.Any(tag => tag.ID == dbTag.ID)) .ToList(); } else { res.Message = tgRes.Message; } } if (music.Artist?.User?.UserName != null) { music.Artist = _usersRep.GetArtistByName(music.Artist.User.UserName)?.Artist; if (music.Artist == null) { res.Success = false; res.Message = "לא נמצא אמן עם שם זה"; } } if (res.Success && WAVFile != null) { WAVFile.UserId = music.Artist.Id; res = FsService.StoreFile(WAVFile); if (res.Success) { music.WAVFile = (res as EntityResponse <Model.File>).Entity; music.WAVFileID = music.WAVFile.FileId; } } if (res.Success && MP3File != null) { MP3File.UserId = music.Artist.Id; res = FsService.StoreFile(MP3File); if (res.Success) { music.MP3File = (res as EntityResponse <Model.File>).Entity; music.MP3FileID = music.MP3File.FileId; } } if (res.Success) { if (music.MusicLength == TimeSpan.Zero) { res.Success = false; res.Message = "יש להזין אורך יצירה"; } } if (res.Success) { // update async artist report by updating his pdf file _pdfService.ArtistAddMusicAsync(DateTime.Now, music.HebrewName, music.MusicComposer, music.MusicPerformer, music.Exceptions, music.MusicWriter, music.Artist.Id, WebConf.FSBaseRoute); res = base.Add(music); } return(res); }