public async Task <bool> ExecuteForEntry(Guid entryId, string localFile, PerformContext context) { _setContext(context); Log($"Creating waveform for: {entryId} using {localFile}"); if (!string.IsNullOrEmpty(localFile) && !File.Exists(localFile)) { LogError($"FileNotFound: {localFile}"); return(false); } var entry = await _entryRepository.GetAsync(entryId); if (entry != null) { Log($"Generating waveform for: {entry.Id}"); var(dat, json, png) = !string.IsNullOrEmpty(localFile) ? await _waveFormGenerator.GenerateWaveformLocalFile(localFile) : await _waveFormGenerator.GenerateWaveformRemoteFile( entry.GetRawAudioUrl(_storageSettings.CdnUrl, _audioFileStorageSettings.ContainerName, "mp3") ); Log($"Dat: {dat}\nJSON: {json}\nPNG: {png}"); if (!string.IsNullOrEmpty(dat)) { Log("Uploading .dat"); await _fileUploader.UploadFile( dat, _waveformStorageSettings.ContainerName, $"{entry.Id}.dat", "application/x-binary", null); } if (!string.IsNullOrEmpty(json)) { Log("Uploading .json"); await _fileUploader.UploadFile( json, _waveformStorageSettings.ContainerName, $"{entry.Id}.json", "application/json", null); } if (!string.IsNullOrEmpty(png)) { Log("Uploading .png"); await _fileUploader.UploadFile( png, _waveformStorageSettings.ContainerName, $"{entry.Id}.png", "image/png", null); } entry.WaveformGenerated = true; Log("Updating context"); await _unitOfWork.CompleteAsync(); return(true); } return(false); }
public async Task <IActionResult> Createplatformrequest([FromForm] PlatformViewModel platformViewModel) { if (ModelState.IsValid) { var stylesheet = new ColorScheme() { SocialBarColor = platformViewModel.SocialBarColor, NavBarColor = platformViewModel.NavbarColor, BannerColor = platformViewModel.BannerColor, ButtonColor = platformViewModel.ButtonColor, ButtonTextColor = platformViewModel.ButtonTextColor, TextColor = platformViewModel.TextColor, BodyColor = platformViewModel.BodyColor, }; var logoFileName = Util.Util.GenerateDataStoreObjectName(platformViewModel.Name); var logoImageObj = new Media() { Name = logoFileName, Url = await _fileUploader.UploadFile(logoFileName, "platform-logos", platformViewModel.Logo), }; var bannerFileName = Util.Util.GenerateDataStoreObjectName(platformViewModel.Name); var bannerImageObj = new Media() { Name = bannerFileName, Url = await _fileUploader.UploadFile(bannerFileName, "platform-banners", platformViewModel.Banner), }; var platform = new Platform() { Name = platformViewModel.Name, Tenant = platformViewModel.Tenant, Logo = logoImageObj, Banner = bannerImageObj, Description = platformViewModel.Description, ColorScheme = stylesheet, }; var user = _userManager.GetUserAsync(User).Result; var platformRequest = new PlatformRequest() { Accept = false, Date = DateTime.Now, OrganisationName = user.FirmName, Reason = platformViewModel.PlatformReason, Treated = false, UserId = user.Id, Platform = platform }; _platformRequestManager.CreatePlatformRequest(platformRequest); // _platformManager.AddPlatform(platform); _unitOfWorkManager.Save(); return(Ok()); } return(StatusCode(400)); }
/// <summary> /// Uploads the file content to the remote document. /// </summary> /// <returns>The SHA-1 hash of the uploaded file content.</returns> /// <param name="localFile">Local file.</param> /// <param name="doc">Remote document.</param> /// <param name="transmissionManager">Transmission manager.</param> protected static byte[] UploadFile(IFileInfo localFile, IDocument doc, ActiveActivitiesManager transmissionManager) { byte[] hash = null; IFileUploader uploader = FileTransmission.ContentTaskUtils.CreateUploader(); FileTransmissionEvent transmissionEvent = new FileTransmissionEvent(FileTransmissionType.UPLOAD_MODIFIED_FILE, localFile.FullName); transmissionManager.AddTransmission(transmissionEvent); transmissionEvent.ReportProgress(new TransmissionProgressEventArgs { Started = true }); using (var hashAlg = new SHA1Managed()) { try { using (var file = localFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) { uploader.UploadFile(doc, file, transmissionEvent, hashAlg); hash = hashAlg.Hash; } } catch (Exception ex) { transmissionEvent.ReportProgress(new TransmissionProgressEventArgs { FailedException = ex }); throw; } } transmissionEvent.ReportProgress(new TransmissionProgressEventArgs { Completed = true }); return(hash); }
private APSIMJob BuildAPSIMJobAndStageFiles( Guid jobId, string apsimAppPkgVersion, string displayName, string modelZipFile, CancellationToken ct) { var job = new APSIMJob { DisplayName = displayName, StorageCredentials = _storageCredentials, BatchCredentials = _batchCredentials, PoolSettings = _poolSettings, ApsimApplicationPackageVersion = apsimAppPkgVersion, }; ct.ThrowIfCancellationRequested(); job.ModelZipFileSas = _fileUploader.UploadFile( modelZipFile, jobId.ToString(), Path.GetFileName(modelZipFile), ct); ct.ThrowIfCancellationRequested(); return(job); }
public async Task <bool> ProcessEntry(string url, string processId, PerformContext context) { var connection = new HubConnectionBuilder() .WithUrl($"{_appSettings.RealtimeUrl}/publicupdates") .Build(); await connection.StartAsync(); var fileName = $"{processId}.mp3"; var outputFile = Path.Combine(Path.GetTempPath(), fileName); var processResult = await _urlProcessService.DownloadAudioV2(processId, url, outputFile, (e) => { connection.InvokeAsync("SendMessage", processId, "processing", e); return(true); }); if (!processResult || !File.Exists(outputFile)) { return(false); } var info = await _downloader.GetInfo(url, string.Empty); var localImageFile = await HttpUtils.DownloadFile("https://cdn.podnoms.com/static/images/pn-back.jpg"); _tagger.CreateTags( outputFile, localImageFile, _downloader.RawProperties?.Title ?? "Downloaded by PodNoms", "Downloaded by PodNoms", "Downloaded By PodNoms", "Downloaded By PodNoms", "Downloaded By PodNoms"); var cdnFilename = $"processed/{fileName}"; var uploadResult = await _fileUploader.UploadFile( outputFile, "public", cdnFilename, "audio/mpeg", async (p, t) => { var progress = new ProcessingProgress(new TransferProgress { Percentage = p, TotalSize = t.ToString() }) { Progress = "Caching", ProcessingStatus = ProcessingStatus.Uploading.ToString() }; await connection.InvokeAsync("SendMessage", processId, "processing", progress); } ); var message = new ProcessingProgress(null) { Payload = Flurl.Url.Combine(_storageSettings.CdnUrl, "public", cdnFilename), Progress = "Processed", ProcessingStatus = ProcessingStatus.Processed.ToString() }; await connection.InvokeAsync("SendMessage", processId, "processing", message); return(true); }
public override async Task <bool> Execute(PerformContext context) { this._setContext(context); var entries = await this._entryRepository.GetAll() .Include(e => e.Podcast) .Include(e => e.Podcast.AppUser) .Where(e => e.MetadataStatus == 0) // .Take(10) .ToListAsync(); var count = entries.Count(); var i = 1; foreach (var entry in entries) { try { Log($"Processing {i++} of {count}"); Log($"Generating metadata for {entry.Title}"); var audioUrl = entry.GetAudioUrl($"{_storageOptions.CdnUrl}/{_audioStorageOptions.ContainerName}"); Log($"\tDownloading {audioUrl}"); var file = await HttpUtils.DownloadFile( audioUrl, System.IO.Path.Combine( System.IO.Path.GetTempPath(), $"{System.Guid.NewGuid()}.mp3")); if (!System.IO.File.Exists(file)) { continue; } if (!await this.ExecuteForEntry(entry, file, false, context)) { continue; } Log($"\tUploading {file}"); await _fileUploader.UploadFile( file, _audioStorageOptions.ContainerName, $"{entry.Id.ToString()}.mp3", "application/mpeg"); entry.MetadataStatus = 1; } catch (Exception ex) { entry.MetadataStatus = -1; LogError(ex.Message); } finally { await _unitOfWork.CompleteAsync(); } } Log("PREPARING SAVE!!"); return(false); }
private async Task _process(Guid entryId, string audioUrl, bool forceReprocess = false) { var audioExists = !string.IsNullOrEmpty(audioUrl) && await _fileUtils.CheckFileExists(audioUrl.Split('/')[0], audioUrl.Split('/')[1]); if (!audioExists || forceReprocess) { //TODO: This is all largely a duplicate of ProcessEntryJob, should call into that... Log($"_process: Missing audio for: {entryId}"); var localFile = Path.Combine(Path.GetTempPath(), $"{System.Guid.NewGuid()}.mp3"); var processed = await _processor.DownloadAudio(entryId, localFile); if (processed) { Log($"_process: Processed: {entryId}"); Log($"_process: Uploading audio for: {entryId}"); var uploaded = await _uploadService.UploadAudio(entryId, localFile); if (!uploaded) { LogError($"Error uploading audio from {entryId}"); } Log($"_process: Generating waveform for: {entryId}"); var(dat, json, png) = await _waveFormGenerator.GenerateWaveformLocalFile(localFile); if (!File.Exists(json)) { LogError($"_process: Error json does not exist {json}"); } else { Log($"_process: Uploading waveform for: {entryId}"); var result = await _fileUploader.UploadFile( json, _waveformStorageSettings.ContainerName, $"{entryId}.json", "application/x-binary", null); Log($"_process: Uploaded waveform for: {entryId}\n\tResult: {result}"); } Log($"_process: Completed processing of: {entryId}"); } else { LogError($"_process: Unable to process podcast entry: {entryId}"); } } else { Log($"_process: Audio exists, not processing"); } }
public async Task <IActionResult> ChangeImage(IFormFile imagefile) { var name = Guid.NewGuid().ToString() + imagefile.FileName; string Path = _hostEnvironment.ContentRootPath + "\\wwwroot\\images\\Users\\"; string ImagePath = "\\images\\Users\\" + name; _fileUploader.UploadFile(imagefile, Path, name); var result = await _account.ChangeImage(HttpContext.Session.GetString("AdminId"), ImagePath); if (result) { return(Ok(new { status = 1, Message = "Image Changed Successfuly" })); } return(BadRequest(new { status = 0, Message = "Error of Uploading Retry another time" })); }
/// <summary> /// Uploads the file content to the remote document. /// </summary> /// <returns>The SHA-1 hash of the uploaded file content.</returns> /// <param name="localFile">Local file.</param> /// <param name="doc">Remote document.</param> /// <param name="transmissionManager">Transmission manager.</param> /// <param name="transmissionEvent">File Transmission event.</param> protected byte[] UploadFile(IFileInfo localFile, IDocument doc, Transmission transmission) { using (var file = localFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) { byte[] hash = null; IFileUploader uploader = FileTransmission.ContentTaskUtils.CreateUploader(); using (var hashAlg = new SHA1Managed()) { try { uploader.UploadFile(doc, file, transmission, hashAlg); hash = hashAlg.Hash; } catch (Exception ex) { transmission.FailedException = ex; throw; } } transmission.Status = TransmissionStatus.FINISHED; return(hash); } }
public async Task <string> CacheImage(string imageUrl, string destUid) { // TODO: Need to convert everything to jpeg // PNG was a bad choice try { var sourceFile = await HttpUtils.DownloadFile(imageUrl); if (string.IsNullOrEmpty(sourceFile)) { return(string.Empty); } var extension = await HttpUtils.GetUrlExtension(imageUrl); if (!extension.Equals("jpg")) { if (extension.Equals("webp")) { (sourceFile, extension) = await ImageUtils.ConvertFileFromWebp(sourceFile, sourceFile, "jpg"); } else { (sourceFile, extension) = await ImageUtils.ConvertFile(sourceFile, sourceFile, "jpg"); } } var remoteFile = await _fileUploader.UploadFile( sourceFile, _imageFileStorageSettings.ContainerName, $"entry/{destUid}.jpg", "image/jpeg"); return(remoteFile); } catch (Exception ex) { _logger.LogError($"Error caching image: {ex.Message}"); } return(string.Empty); }
/// <summary> /// Performs the file import routine /// </summary> private void Import() { if (_openDialog.ShowDialog() == true) { try { var resolveKey = Path.GetExtension(_openDialog.FileName).Substring(1); _fileUploader = App.Container.Get <IFileUploader>(resolveKey); _fileUploader.OnEventLogged += LogEvent; _fileUploader.UploadFile(_openDialog.FileName); } catch (Exception ex) { LogEntries.Add(new LogEntry(DateTime.Now, ex.Message)); } finally { _fileUploader.OnEventLogged -= LogEvent; LogEvent(this, "File import complete."); } } }
private async Task <string> _commitImage(string id, IFormFile image, string subDirectory) { if (image is null) { throw new InvalidOperationException("Image in stream is null"); } if (image is null || image.Length == 0) { throw new InvalidOperationException("Image in stream has zero length"); } if (image.Length > _imageFileStorageSettings.MaxUploadFileSize) { throw new InvalidOperationException("Maximum file size exceeded"); } if (!_imageFileStorageSettings.IsSupported(image.FileName)) { throw new InvalidOperationException("Invalid file type"); } var cacheFile = await CachedFormFileStorage.CacheItem(System.IO.Path.GetTempPath(), image); var(finishedFile, extension) = await ImageUtils.ConvertFile(cacheFile, id); var destinationFile = $"{subDirectory}/{id}.{extension}"; await _fileUploader.UploadFile( finishedFile, _imageFileStorageSettings.ContainerName, destinationFile, "image/png", (p, t) => _logger.LogDebug($"Uploading image: {p} - {t}") ); return(destinationFile); }
public void UploadFile(string filePath, string destFileName, IBackgroundWorkContext context) { _fileUploader.UploadFile(filePath, destFileName, (i, s) => context.SetProgress(i, s)); }
/// <summary> /// Solve the specified situation by using localFile and remote object. /// </summary> /// <param name="localFileSystemInfo">Local filesystem info instance.</param> /// <param name="remoteId">Remote identifier or object.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { Stopwatch completewatch = new Stopwatch(); completewatch.Start(); Logger.Debug("Starting LocalObjectAdded"); string parentId = this.GetParentId(localFileSystemInfo, this.Storage); Guid uuid = this.WriteOrUseUuidIfSupported(localFileSystemInfo); ICmisObject addedObject; try { addedObject = this.AddCmisObject(localFileSystemInfo, parentId, this.Session); } catch (CmisPermissionDeniedException e) { OperationsLogger.Warn(string.Format("Permission denied while trying to Create the locally added object {0} on the server ({1}).", localFileSystemInfo.FullName, e.Message)); return; } OperationsLogger.Info(string.Format("Created remote {2} {0} for {1}", addedObject.Id, localFileSystemInfo.FullName, addedObject is IFolder ? "folder" : "document")); MappedObject mapped = new MappedObject( localFileSystemInfo.Name, addedObject.Id, localFileSystemInfo is IDirectoryInfo ? MappedObjectType.Folder : MappedObjectType.File, parentId, addedObject.ChangeToken) { Guid = uuid, LastRemoteWriteTimeUtc = addedObject.LastModificationDate, LastLocalWriteTimeUtc = localFileSystemInfo is IFileInfo && (localFileSystemInfo as IFileInfo).Length > 0 ? (DateTime?)null : (DateTime?)localFileSystemInfo.LastWriteTimeUtc, LastChangeToken = addedObject.ChangeToken, LastContentSize = localFileSystemInfo is IDirectoryInfo ? -1 : 0, ChecksumAlgorithmName = localFileSystemInfo is IDirectoryInfo ? null : "SHA-1", LastChecksum = localFileSystemInfo is IDirectoryInfo ? null : SHA1.Create().ComputeHash(new byte[0]) }; this.Storage.SaveMappedObject(mapped); var localFile = localFileSystemInfo as IFileInfo; if (localFile != null) { FileTransmissionEvent transmissionEvent = new FileTransmissionEvent(FileTransmissionType.UPLOAD_NEW_FILE, localFile.FullName); this.transmissionManager.AddTransmission(transmissionEvent); if (localFile.Length > 0) { Stopwatch watch = new Stopwatch(); OperationsLogger.Debug(string.Format("Uploading file content of {0}", localFile.FullName)); watch.Start(); IFileUploader uploader = ContentTaskUtils.CreateUploader(); using (SHA1 hashAlg = new SHA1Managed()) using (var fileStream = localFile.Open(FileMode.Open, FileAccess.Read)) { try { uploader.UploadFile(addedObject as IDocument, fileStream, transmissionEvent, hashAlg); } catch (Exception ex) { transmissionEvent.ReportProgress(new TransmissionProgressEventArgs { FailedException = ex }); throw; } mapped.ChecksumAlgorithmName = "SHA-1"; mapped.LastChecksum = hashAlg.Hash; } watch.Stop(); if (this.ServerCanModifyDateTimes) { (addedObject as IDocument).UpdateLastWriteTimeUtc(localFile.LastWriteTimeUtc); } mapped.LastContentSize = localFile.Length; mapped.LastChangeToken = addedObject.ChangeToken; mapped.LastRemoteWriteTimeUtc = addedObject.LastModificationDate; mapped.LastLocalWriteTimeUtc = localFileSystemInfo.LastWriteTimeUtc; if (mapped.RemoteObjectId != addedObject.Id) { this.Storage.RemoveObject(mapped); mapped.RemoteObjectId = addedObject.Id; } this.Storage.SaveMappedObject(mapped); OperationsLogger.Info(string.Format("Uploaded file content of {0} in [{1} msec]", localFile.FullName, watch.ElapsedMilliseconds)); } transmissionEvent.ReportProgress(new TransmissionProgressEventArgs { Completed = true }); } completewatch.Stop(); Logger.Debug(string.Format("Finished LocalObjectAdded after [{0} msec]", completewatch.ElapsedMilliseconds)); }
public IActionResult PostIdeationReply([FromForm] IdeationReplyDTO ideationReplyDto) { // return Created("/ideation/overview/1", null); //log test 1 Ideation ideation = _ideationManager.GetIdeationWithQuestions(ideationReplyDto.IdeationId); //log test 2 User user = _usermanager.GetUserAsync(User).Result; //log test 3 if (ideation == null || user == null) { return(NotFound()); } //log test 4 IdeationReply newReply = new IdeationReply() { Ideation = ideation, Title = ideationReplyDto.Title, Answers = new List <Answer>(), Votes = new List <Vote>(), Comments = new List <Comment>(), Created = DateTime.Now, User = user, Reports = new List <IdeationReport>() }; //log test 5 int index = 0; ideationReplyDto.Answers.ForEach(dto => { Answer newAnswer = null; switch (dto.FieldType) { case FieldType.OpenText: newAnswer = new OpenTextAnswer() { QuestionIndex = dto.QuestionIndex, Value = dto.OpenAnswer }; break; case FieldType.Image: case FieldType.Video: string fileName = Util.Util.GenerateDataStoreObjectName(dto.FileAnswer.FileName); string pathName = _fileUploader.UploadFile(fileName, "ideationReply", dto.FileAnswer).Result; newAnswer = new MediaAnswer() { QuestionIndex = dto.QuestionIndex, Value = new Media() { Name = dto.FileAnswer.FileName, Url = pathName } }; break; case FieldType.SingleChoice: case FieldType.DropDown: newAnswer = new SingleChoiceAnswer() { QuestionIndex = dto.QuestionIndex, SelectedChoice = dto.SingleAnswer }; break; case FieldType.MultipleChoice: newAnswer = new MultipleChoiceAnswer() { QuestionIndex = dto.QuestionIndex, SelectedChoices = dto.MultipleAnswer }; break; case FieldType.Location: newAnswer = new LocationAnswer() { QuestionIndex = dto.QuestionIndex, Value = new Location() { Latitude = dto.LocationAnswer.Latitude, Longitude = dto.LocationAnswer.Longitude, ZoomLevel = dto.LocationAnswer.ZoomLevel, } }; break; default: throw new ArgumentOutOfRangeException(); } newAnswer.OrderIndex = index++; newReply.Answers.Add(newAnswer); }); //log test 6 _ideationManager.AddIdeationReply(newReply); //log test 7 // Create activity var activity = CreateActivity(ActivityType.IdeationReply, user); activity.IdeationReply = newReply; _activityManager.AddActivity(activity); //log test 8 // Save everything _unitOfWorkManager.Save(); //log test 9 // Push activity var activityVm = new ActivityViewModel(activity); //log test 10 PushWebsockets(activityVm).Wait(); //log test 11 return(Created("/ideation/view/" + newReply.IdeationReplyId, new { id = newReply.IdeationReplyId })); }
public async Task <IActionResult> Create([FromForm] PlatformViewModel platformViewModel, [FromServices] UserManager <User> userManager) { if (ModelState.IsValid) { var stylesheet = new ColorScheme() { SocialBarColor = platformViewModel.SocialBarColor, NavBarColor = platformViewModel.NavbarColor, BannerColor = platformViewModel.BannerColor, ButtonColor = platformViewModel.ButtonColor, ButtonTextColor = platformViewModel.ButtonTextColor, TextColor = platformViewModel.TextColor, BodyColor = platformViewModel.BodyColor, }; Media logoImageObj = null; if (platformViewModel.Logo != null) { var logoFileName = Util.Util.GenerateDataStoreObjectName(platformViewModel.Logo.FileName); logoImageObj = new Media() { Name = logoFileName, Url = await _fileUploader.UploadFile(logoFileName, "platform-logos", platformViewModel.Logo), }; } Media bannerImageObj = null; if (platformViewModel.Banner != null) { var bannerFileName = Util.Util.GenerateDataStoreObjectName(platformViewModel.Banner.FileName); bannerImageObj = new Media() { Name = bannerFileName, Url = await _fileUploader.UploadFile(bannerFileName, "platform-banners", platformViewModel.Banner), }; } var platform = new Platform() { Name = platformViewModel.Name, Tenant = platformViewModel.Tenant, Logo = logoImageObj, Banner = bannerImageObj, Description = platformViewModel.Description, ColorScheme = stylesheet, }; List <User> admins = userManager.GetUsersForClaimAsync(new Claim(platform.Tenant, "Admin")).Result.ToList(); foreach (User admin in admins) { await userManager.ReplaceClaimAsync(admin, new Claim(platform.Tenant, "Admin"), new Claim(platform.Tenant, "User")); } if (platformViewModel.Admins != null) { foreach (string AdminUserName in platformViewModel.Admins) { User newAdmin = userManager.FindByNameAsync(AdminUserName).Result; //Kijken of user al bestaat op het platform var claimsForSubdomain = userManager.GetClaimsAsync(newAdmin).Result.FirstOrDefault(c => c.Type == platform.Tenant); //Subdomain is het subdomain waarop je zit if (claimsForSubdomain == null) { //User heeft nog geen claim op dit platform => claim toewijzen dus! EN DIRECT ADMIN TOEWIJZEN await userManager.AddClaimAsync(newAdmin, new Claim(platform.Tenant, "Admin")); } else { //User heeft al een claim op dit platform -> Claim verwijderen is Admin Vervangen door User /*await userManager.ReplaceClaimAsync(newAdmin, new Claim(claimsForSubdomain.Type, claimsForSubdomain.Value), * new Claim(claimsForSubdomain.Type, "User"));*/ //User heeft al een claim op dit platform en wordt nu admin -> Claim verwijderen is User Vervangen door Admin await userManager.ReplaceClaimAsync(newAdmin, new Claim(claimsForSubdomain.Type, claimsForSubdomain.Value), new Claim(claimsForSubdomain.Type, "Admin")); } } } _platformManager.AddPlatform(platform); _unitOfWorkManager.Save(); return(Ok()); } return(StatusCode(400)); }
public async Task <bool> UploadAudio(Guid entryId, string localFile) { _logger.LogInformation($"Starting to upload audio for {entryId} - {localFile}"); var entry = await _repository.GetAsync(entryId); if (entry == null) { _logger.LogError($"Unable to find entry with id: {entryId.ToString()}"); return(false); } var userId = entry.Podcast.AppUser.Id.ToString(); entry.ProcessingStatus = ProcessingStatus.Uploading; await _sendProgressUpdate( userId, entry.Id.ToString(), new ProcessingProgress( _mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry)) { ProcessingStatus = ProcessingStatus.Uploading.ToString() } ); await _unitOfWork.CompleteAsync(); _logger.LogInformation($"Updated item status {entryId} - {localFile}"); try { // TODO // bit messy but can't figure how to pass youtube-dl job result to this job // so using AudioUrl as a proxy if (File.Exists(localFile)) { _logger.LogInformation($"Local item exists {entryId} - {localFile}"); var fileInfo = new FileInfo(localFile); var fileName = $"{entry.Id.ToString()}{fileInfo.Extension}"; await _fileUploader.UploadFile( localFile, _audioStorageSettings.ContainerName, fileName, "application/mpeg", async (p, t) => { if (p % 1 != 0) { return; } try { await _sendProgressUpdate( userId, entry.Id.ToString(), new ProcessingProgress(new TransferProgress { Percentage = p, TotalSize = t.ToString() }) { ProcessingStatus = ProcessingStatus.Uploading.ToString() }); } catch (Exception e) { _logger.LogError($"Error sending progress update.\n\t{e.Message}"); _logger.LogError($"p:\np\n\n\n"); _logger.LogError($"t:\n{ObjectDumper.Dump(t)}\n\n\n"); _logger.LogError(ObjectDumper.Dump(entry)); } }); entry.Processed = true; entry.ProcessingStatus = ProcessingStatus.Processed; entry.AudioUrl = entry.GetAudioUrl(_appSettings.AudioUrl); _logger.LogDebug($"AudioUrl is: {entry.AudioUrl}"); entry.AudioFileSize = fileInfo.Length; await _unitOfWork.CompleteAsync(); var vm = _mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry); await _sendProgressUpdate( userId, entry.Id.ToString(), new ProcessingProgress(entry) { ProcessingStatus = ProcessingStatus.Processed.ToString(), Payload = vm }); return(true); } _logger.LogError($"Error uploading audio file: {entry.AudioUrl} does not exist"); entry.ProcessingStatus = ProcessingStatus.Failed; entry.ProcessingPayload = $"Unable to find {entry.AudioUrl}"; await _unitOfWork.CompleteAsync(); await _sendProgressUpdate( userId, entry.Id.ToString(), new ProcessingProgress(_mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry)) { ProcessingStatus = ProcessingStatus.Failed.ToString() }); } catch (Exception ex) { _logger.LogError($"Error uploading audio file: {ex.Message}"); entry.ProcessingStatus = ProcessingStatus.Failed; entry.ProcessingPayload = ex.Message; await _unitOfWork.CompleteAsync(); await _sendProgressUpdate( userId, entry.Id.ToString(), new ProcessingProgress(entry) { ProcessingStatus = ProcessingStatus.Failed.ToString() }); } return(false); }
/// <summary> /// Solve the specified situation by using the storage, localFile and remoteId. /// Uploads the file content if content has been changed. Otherwise simply saves the /// last modification date. /// </summary> /// <param name="localFileSystemInfo">Local filesystem info instance.</param> /// <param name="remoteId">Remote identifier or object.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { if (!localFileSystemInfo.Exists) { throw new ArgumentException("Given local path does not exists: " + localFileSystemInfo.FullName); } // Match local changes to remote changes and updated them remotely IMappedObject mappedObject = null; try { string ea = localFileSystemInfo.GetExtendedAttribute(MappedObject.ExtendedAttributeKey); Guid guid; if (Guid.TryParse(ea, out guid)) { mappedObject = this.Storage.GetObjectByGuid(guid); } } catch (Exception) { } if (mappedObject == null) { mappedObject = this.Storage.GetObjectByLocalPath(localFileSystemInfo); } if (mappedObject == null) { throw new ArgumentException(string.Format("Could not find db entry for {0} => invoke crawl sync", localFileSystemInfo.FullName)); } IFileInfo localFile = localFileSystemInfo as IFileInfo; if (localFile != null && localFile.IsContentChangedTo(mappedObject, scanOnlyIfModificationDateDiffers: true)) { Logger.Debug(string.Format("\"{0}\" is different from {1}", localFile.FullName, mappedObject.ToString())); OperationsLogger.Debug(string.Format("Local file \"{0}\" has been changed", localFile.FullName)); IFileUploader uploader = FileTransmission.ContentTaskUtils.CreateUploader(); var doc = remoteId as IDocument; FileTransmissionEvent transmissionEvent = new FileTransmissionEvent(FileTransmissionType.UPLOAD_MODIFIED_FILE, localFile.FullName); this.transmissionManager.AddTransmission(transmissionEvent); transmissionEvent.ReportProgress(new TransmissionProgressEventArgs { Started = true }); using (var hashAlg = new SHA1Managed()) using (var file = localFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) { try { uploader.UploadFile(doc, file, transmissionEvent, hashAlg); } catch (Exception ex) { transmissionEvent.ReportProgress(new TransmissionProgressEventArgs { FailedException = ex }); if (ex.InnerException is CmisPermissionDeniedException) { OperationsLogger.Warn(string.Format("Local changed file \"{0}\" has been not been uploaded: PermissionDenied", localFile.FullName)); return; } throw; } mappedObject.LastChecksum = hashAlg.Hash; } mappedObject.LastChangeToken = doc.ChangeToken; mappedObject.LastRemoteWriteTimeUtc = doc.LastModificationDate; mappedObject.LastLocalWriteTimeUtc = localFile.LastWriteTimeUtc; mappedObject.LastContentSize = localFile.Length; OperationsLogger.Info(string.Format("Local changed file \"{0}\" has been uploaded", localFile.FullName)); transmissionEvent.ReportProgress(new TransmissionProgressEventArgs { Completed = true }); } if (this.ServerCanModifyDateTimes) { try { if (remoteId is IDocument) { (remoteId as IDocument).UpdateLastWriteTimeUtc(localFileSystemInfo.LastWriteTimeUtc); mappedObject.LastRemoteWriteTimeUtc = localFileSystemInfo.LastWriteTimeUtc; } else if (remoteId is IFolder) { (remoteId as IFolder).UpdateLastWriteTimeUtc(localFileSystemInfo.LastWriteTimeUtc); mappedObject.LastRemoteWriteTimeUtc = localFileSystemInfo.LastWriteTimeUtc; } } catch (CmisPermissionDeniedException) { Logger.Debug(string.Format("Locally changed modification date \"{0}\"is not uploaded to the server: PermissionDenied", localFileSystemInfo.LastWriteTimeUtc)); } } mappedObject.LastLocalWriteTimeUtc = localFileSystemInfo.LastWriteTimeUtc; this.Storage.SaveMappedObject(mappedObject); }
public async Task <IActionResult> Post([FromForm] ProjectDTO projectDto) { if (ModelState.IsValid) { var phases = new List <Phase>(); projectDto.Phases.ForEach(phaseDto => { var phase = new Phase() { Number = phaseDto.Number, Title = phaseDto.Title, Description = phaseDto.Description, }; phases.Add(phase); }); var fileName = Util.Util.GenerateDataStoreObjectName(projectDto.Logo.FileName); var imageObj = new Media() { Name = fileName, Url = await _fileUploader.UploadFile(fileName, "project-logos", projectDto.Logo), }; var platform = _platformManager.GetPlatformByTenant(projectDto.PlatformTenant); var project = new Project() { Title = projectDto.Title, Goal = projectDto.Goal, Logo = imageObj, Phases = phases, Platform = platform, StartDate = projectDto.StartDate, EndDate = projectDto.EndDate, CurrentPhaseNumber = projectDto.CurrentPhase }; if (projectDto.CurrentPhase > projectDto.Phases.Count) { project.CurrentPhaseNumber = 0; } if (projectDto.Moderators != null) { foreach (string moderatorUserName in projectDto.Moderators) { User mod = _userManager.FindByNameAsync(moderatorUserName).Result; if (mod != null) { ProjectModerator moderator = new ProjectModerator() { Project = project, User = mod }; project.Moderators.Add(moderator); } } } platform.Projects.Add(project); _projectManager.AddProject(project); _unitOfWorkManager.Save(); return(Created("/project/details/" + project.ProjectId, new { id = project.ProjectId })); } return(StatusCode(400)); }
public async Task <Unit> Handle(UploadFileFromContextRequest request, CancellationToken cancellationToken) { await _fileUploader.UploadFile(request.Request); return(Unit.Value); }