private async void UpdateConvertedVideoMaterialAsync(long materialID, string processUrl) { if (_converter == null) { return; } // get Material from DataBase var material = _unitOfWork.MaterialRepository.Get(materialID); if (material == null || material.File == null) { return; } // get current path of the current Blob var sourcePath = _infrastructure.GetMaterialPath(material); // get the status of the convetsion var status = await _converter.GetStatusAsync(processUrl); if (status == null || !status.IsFinished || status.Output == null) { return; } // download conveted file var data = await _converter.DownloadAsync(processUrl); if (data == null) { return; } // change the filename with new extension string filename = material.File.FileName.Name.Replace(material.File.FileName.Extension, "." + status.Output.Extension); // create new Blob and attach it to the material material.ChangeFile(FileBlob.Create(material.Article.Code + "/", filename, "", data.Length)); // get new path of the new Blob (where to update converted file) var convertedPath = _infrastructure.GetMaterialPath(material); // update converted file _infrastructure.StorageService.SaveFile(convertedPath, data); // save changes to DataBase _unitOfWork.MaterialRepository.Update(material); _unitOfWork.SaveChanges(); // delete old file from Storage _infrastructure.StorageService.DeleteFile(sourcePath); }
public void AddFile() { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog().Value) { NameItemDialog nameDialog = new NameItemDialog(DialogOwner, "New File"); bool? dialogResult = nameDialog.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value) { FileBlob file = new FileBlob(UniverseVm.Model.Connection); file.Name = nameDialog.UserInput; file.FileName = Path.GetFileName(openFileDialog.FileName); file.UniverseId = UniverseVm.Model.id; string extension = Path.GetExtension(openFileDialog.FileName).ToLower(); if (extension == ".png") { file.FileType = FileBlob.FILE_TYPE_PNG; } else if (extension == ".jpg" || extension == ".jpeg") { file.FileType = FileBlob.FILE_TYPE_JPEG; } else if (extension == ".dotx") { file.FileType = FileBlob.FILE_TYPE_TEMPLATE; } else { file.FileType = FileBlob.FILE_TYPE_OTHER; } if (Files.Count > 0) { file.SortIndex = Files.Max(i => i.Model.SortIndex) + 1; } file.Create(); file.LoadFile(openFileDialog.FileName); FileBlobViewModel vm = new FileBlobViewModel(file, this); Files.Add(vm); } } }
public Material ImportMaterial(Article article, string filename, byte[] data, DateTime?date = null, string title = "", string comment = "") { if (article == null) { throw new CustomNotFoundException("Invalid Article specified!"); } var blob = FileBlob.Create(article.Code + "/", filename, CommonService.GetMD5(data), data.Length); //this.UnitOfWork.Create(blob); this.FileStorageService.SaveFile(blob.GetPath(), data); var material = article.AddMaterial(blob); material.ChangeInfo(date, title, comment); this.UnitOfWork.ArticleRepository.Update(article); this.UnitOfWork.MaterialRepository.Add(material); this.SaveChanges(); return(material); }