private void btnAdd_Click(object sender, EventArgs e) { try { this.dlgFile.InitialDirectory = this.TargetPath; this.dlgFile.DefaultExt = "blueprint"; if (this.dlgFile.ShowDialog() == DialogResult.OK) { var s = this.dlgFile.FileName; var bp = BlueprintFile.Load(s); bp.LoadBlocks(); this.AddColorPalettePanel(bp.Colors, true); var fi = new FileInfo(this.dlgFile.FileName); this.TargetPath = fi.DirectoryName; this.ColorPalettes.ColorPalettes.Add(new ColorPalette() { Colors = bp.Colors }); } } catch (Exception ex) { MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } }
private async Task DeleteResizedFilesAsync(BlueprintFile blueprintFile) { _logger.LogInformation($"Start DeleteResizedFilesAsync"); var connection = _sqlConnectionFactory.GetNewConnection(); const string getQuery = @"SELECT Id, FilePath FROM BlueprintFile WHERE OriginalId = @Id"; const string removeQuery = @"DELETE BlueprintFile WHERE OriginalId = @Id"; var query = await connection.QueryAsync <DeletedBlueprintFile>(getQuery, new { blueprintFile.Id }); var blueprintFiles = query.ToList(); blueprintFiles.ForEach(f => { if (File.Exists(f.FilePath)) { File.Delete(f.FilePath); } }); await connection.ExecuteAsync(removeQuery, new { blueprintFile.Id }); connection.Dispose(); }
private async Task ProcessFile(BlueprintFile blueprintFile) { _logger.LogInformation($"Call to {nameof(ProcessFile)} with Id: {blueprintFile.Id}"); // Delay 100ms to avoid blocking at the method "ReadImage" await Task.Delay(100); try { _logger.LogInformation($"Reading image {blueprintFile.FilePath} ..."); FileStream fileStream = _imageService.ReadImage(blueprintFile.FilePath); if (fileStream != null) { using (fileStream) { string fileExtension = blueprintFile.Extension.Contains(".") ? blueprintFile.Extension.ToLower() : $".{blueprintFile.Extension.ToLower()}"; (int height, int width)dimentions = await _imageService.GetImageDimentions(fileStream, fileExtension, CancellationToken.None); _logger.LogInformation($"Saving dimentions info for ImgId: {blueprintFile.Id} - {blueprintFile.OriginalFileName} with width/height: {dimentions.width}/{dimentions.height} ..."); var connection = _sqlConnectionFactory.GetNewConnection(); const string updateQuery = @"UPDATE [dbo].[BlueprintFile] SET Width = @Width, Height=@Height WHERE Id = @Id"; await connection.ExecuteAsync(updateQuery, new { Width = dimentions.width, Height = dimentions.height, blueprintFile.Id }); connection.Dispose(); _logger.LogInformation($"Update successfully for ImgId: {blueprintFile.Id}."); } } } catch (Exception ex) { _logger.LogError(ex, $"Failed {nameof(ProcessFile)} with ImgId: {blueprintFile.Id}"); } }
private void listView1_DoubleClick(object sender, EventArgs e) { var bpi = (BlueprintItem)this.bpListView.SelectedItems[0].Tag; var bp = BlueprintFile.Load(bpi.Path); var f = new Form2(); f.Blueprint = bp; f.Show(); }
public void TestReadBlueprintFile() { BlueprintFile blueprints = new BlueprintFile(); using (var s = File.OpenRead("Resources\\Saves\\formulas.gst")) { blueprints.Read(s); } }
private async Task UpdateFileAsync(BlueprintFile blueprintFile) { _logger.LogInformation($"Start UpdateFileAsync"); var connection = _sqlConnectionFactory.GetNewConnection(); const string updateQuery = @"UPDATE [dbo].[BlueprintFile] SET BackgroudProcessingStatus = @BackgroudProcessingStatus, ModifiedBy=@ModifiedBy, ModifiedDate=@ModifiedDate WHERE Id = @Id"; await connection.ExecuteAsync(updateQuery, new { BackgroudProcessingStatus = BackgroudProcessingStatus.Processed, ModifiedBy = nameof(System), ModifiedDate = DateTime.UtcNow, blueprintFile.Id }); connection.Dispose(); }
private async Task InsertFile(BlueprintFile blueprintFile) { _logger.LogInformation($"Saving blueprintFile to DB for Img: {blueprintFile.FilePath}"); var connection = _sqlConnectionFactory.GetNewConnection(); const string insertQuery = @"INSERT INTO [dbo].[BlueprintFile] ([OriginalId], [OriginalFileName], [Width], [Height], [CompanyId], [FilePath], [ThumbnailPath], [Extension], [FileType], [Source], [CloudUrl], [FileData], [CreatedBy], [CreatedDate], [ModifiedBy], [ModifiedDate]) VALUES (@OriginalId, @OriginalFileName, @Width, @Height, @CompanyId, @FilePath, @ThumbnailPath, @Extension, @FileType, @Source, @CloudUrl, @FileData, @CreatedBy, @CreatedDate, @ModifiedBy, @ModifiedDate)"; await connection.ExecuteAsync(insertQuery, blueprintFile); connection.Dispose(); }
private void LoadJsonData() { //使用文件系统打开Json filepath = EditorUtility.OpenFilePanel("选择Json文件", Application.streamingAssetsPath, "json"); if (!string.IsNullOrEmpty(filepath)) { string dataAsJson = File.ReadAllText(filepath); /// Debug.Log(JsonUtility.FromJson<Blueprint>(dataAsJson)); bpf = JsonUtility.FromJson <BlueprintFile>(dataAsJson); } }
private Task CleanUpDataForOriginalFile(BlueprintFile blueprintFile) { _logger.LogInformation($"Start {nameof(CleanUpDataForOriginalFile)} with Id: {blueprintFile.Id}"); if (File.Exists(blueprintFile.FilePath)) { File.Delete(blueprintFile.FilePath); } return(Task.CompletedTask); }
public async Task Handle(DomainEventNotification <PreGenerateResizedImagesEvent> notification, CancellationToken cancellationToken) { var domainEvent = notification.DomainEvent; _logger.LogInformation("Handling Domain Event: {DomainEvent}", domainEvent.GetType().Name); BlueprintFile blueprintFile = await _fileRepository.GetByIdAsync(domainEvent.Id); if (blueprintFile != null) { await _preGeneratorService.PreGenerateResizedImages(blueprintFile); } }
/// <summary> /// ブロック削除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void blockEraseToolStripMenuItem_Click(object sender, EventArgs e) { if (this.bpListView.SelectedIndices.Count == 0) { return; } var bpi = (BlueprintItem)this.bpListView.SelectedItems[0].Tag; var f = new FormBlockErase(); var bp = BlueprintFile.Load(bpi.Path); f.Blueprint = bp; f.ShowDialog(); }
private void ViewHistory(BlueprintItem bpi) { this.histroyListView.BeginUpdate(); this.histroyListView.Clear(); var related = bpi.Path.Substring(this.backupMgr.TargetPath.Length); var dirPath = related.Substring(0, related.Length - ".blueprint".Length); var bkDirPath = this.backupMgr.BackupPath + dirPath; var bkDir = new DirectoryInfo(bkDirPath); if (!bkDir.Exists) { this.histroyListView.EndUpdate(); return; } this.histroyListView.Columns.Clear(); this.histroyListView.Columns.Add("Name").Width = 200; this.histroyListView.Columns.Add("Version"); this.histroyListView.Columns.Add("Game Version"); this.histroyListView.Columns.Add("Last Update Date").Width = 150; foreach (var f in bkDir.GetFiles()) { var bp = BlueprintFile.Load(f.FullName); if (bp == null) { continue; } var item = new ListViewItem(f.Name); item.SubItems.Add("v" + bp.Version.ToString()); item.SubItems.Add(bp.Blueprint.GameVersion); item.SubItems.Add(f.LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss")); item.Tag = new BlueprintItem() { Path = f.FullName, }; this.histroyListView.Items.Add(item); //Task.Factory.StartNew<ListViewItem>(() => //{ // return item; //}).ContinueWith(res => //{ // if (res.Result != null) // { // } //}, TaskScheduler.FromCurrentSynchronizationContext()); } this.histroyListView.EndUpdate(); }
public FileBuilder BuildFileInfo(BlueprintFile file) { _file.CreatedDate = file.CreatedDate; _file.CreatedBy = file.CreatedBy; _file.FileType = file.FileType; _file.Height = file.Height; _file.Width = file.Width; _file.OriginalFileName = file.OriginalFileName; _file.Source = file.Source; _file.OriginalId = file.OriginalId; _file.CompanyId = file.CompanyId; _file.Extension = file.Extension; return(this); }
private void LoadBlueprintsAsCharacter(string grimDawnSavesDirectory, Action <string> stateChangeCallback) { var recipesFilePath = Path.Combine(grimDawnSavesDirectory, formulasFilename); stateChangeCallback("Loading " + recipesFilePath); var recipes = new BlueprintFile(); using (var s = File.OpenRead(recipesFilePath)) { recipes.Read(s); } _characters.Add(recipes.ToCharacterFile()); }
public async Task <Unit> Handle(DeleteFileCommand request, CancellationToken cancellationToken) { Guard.AgainstNull(nameof(DeleteFileCommand), request); BlueprintFile blueprintFile = await _fileRepository.GetByIdAsync(request.FileId); Guard.AgainstNull(nameof(blueprintFile), blueprintFile); // Deletes file from forder _fileSystemService.Delete(blueprintFile.FilePath); await _fileRepository.DeleteAsync(blueprintFile); await _fileRepository.CommitAsync(); return(Unit.Value); }
private async Task ResizeImageAsync(BlueprintFile blueprintFile, FileStream fileStream, int newWidth, int newHeight) { _logger.LogInformation($"Start ResizeImageAsync: {blueprintFile.Id} - {blueprintFile.OriginalFileName} with width/height: {blueprintFile.Width}/{blueprintFile.Height} and newWidth/newHeight: {newWidth}/{newHeight}"); var oldFileName = Path.GetFileName(blueprintFile.FilePath); string fileExtension = Path.GetExtension(blueprintFile.FilePath); var imagePath = Path.GetDirectoryName(blueprintFile.FilePath); var newFileName = string.Concat(Path.GetFileNameWithoutExtension(oldFileName), newWidth == 0 ? "" : $"_w{newWidth}", newHeight == 0 ? "" : $"_h{newHeight}", fileExtension); string cloudPath = PathHelper.CombineUrl(imagePath.Replace(_configuration.RootDataFolder, _configuration.CloudDataUrl), string.Empty); if (File.Exists(Path.Combine(imagePath, newFileName))) { File.Delete(Path.Combine(imagePath, newFileName)); } using (FileStream outputStream = new FileStream(Path.Combine(imagePath, newFileName), FileMode.CreateNew)) { (int width, int height)dimentions = await _imageService.ResizeImage(fileStream, (newWidth, newHeight), fileExtension, outputStream); var filebuilder = new FileBuilder(); var newFile = filebuilder.BuildCloudUrl(cloudPath, newFileName) .BuildFilePath(imagePath, newFileName) .BuildFileInfo(new BlueprintFile { CreatedDate = DateTime.UtcNow, CreatedBy = nameof(System), FileType = blueprintFile.FileType, Height = dimentions.height, Width = dimentions.width, OriginalFileName = newFileName, Source = blueprintFile.Source, OriginalId = blueprintFile.Id, Extension = blueprintFile.Extension, CompanyId = blueprintFile.CompanyId, FileName = null }) .Build(); await InsertFile(newFile); } }
private void colorPaletteToolStripMenuItem_Click(object sender, EventArgs e) { if (this.bpListView.SelectedIndices.Count == 0) { return; } var bpi = (BlueprintItem)this.bpListView.SelectedItems[0].Tag; var bp = BlueprintFile.Load(bpi.Path); if (string.IsNullOrEmpty(colorPaletteForm.TargetPath)) { colorPaletteForm.TargetPath = this.targetInput.Text; } colorPaletteForm.Blueprint = bp; colorPaletteForm.ShowDialog(); }
private async Task PreGenerateForOriginalFile(BlueprintFile blueprintFile) { _logger.LogInformation($"Start {nameof(PreGenerateForOriginalFile)} with Id: {blueprintFile.Id}"); await DeleteResizedFilesAsync(blueprintFile); FileStream fileStream = _imageService.ReadImage(blueprintFile.FilePath); if (fileStream != null) { using (fileStream) { foreach (int newWidth in _configuration.PreGeneratedWidthRange) { if (newWidth >= blueprintFile.Width) { continue; } await ResizeImageAsync(blueprintFile, fileStream, newWidth, 0); fileStream.Position = 0; } foreach (int newHeight in _configuration.PreGeneratedHeightRange) { if (newHeight >= blueprintFile.Height) { continue; } await ResizeImageAsync(blueprintFile, fileStream, 0, newHeight); fileStream.Position = 0; } } } await UpdateFileAsync(blueprintFile); }
private void ViewList(string path) { this.bpListView.BeginUpdate(); this.bpListView.Clear(); this.bpListView.Columns.Clear(); this.bpListView.Columns.Add("Name").Width = 200; this.bpListView.Columns.Add("Version"); this.bpListView.Columns.Add("Game Version"); this.bpListView.Columns.Add("Last Update Date").Width = 150; this.bpListView.EndUpdate(); var dir = new DirectoryInfo(path); foreach (var f in dir.GetFiles("*.blueprint")) { Task.Factory.StartNew <ListViewItem>(() => { var bp = BlueprintFile.Load(f.FullName); var item = new ListViewItem(f.Name); item.SubItems.Add("v" + bp.Version.ToString()); item.SubItems.Add(bp.Blueprint.GameVersion); item.SubItems.Add(f.LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss")); item.Tag = new BlueprintItem() { Path = f.FullName, }; return(item); }).ContinueWith(res => { this.bpListView.BeginUpdate(); this.bpListView.Items.Add(res.Result); this.bpListView.EndUpdate(); }, TaskScheduler.FromCurrentSynchronizationContext()); } }
/// <summary> /// Pregenerates resized images. /// </summary> /// <param name="blueprintFile">The blueprintFile.</param> /// <returns>Task.</returns> public async Task PreGenerateResizedImages(BlueprintFile blueprintFile) { await PreGenerateForOriginalFile(blueprintFile); }
private void CreateNewJson() { filepath = ""; bpf = new BlueprintFile(); }
private void Reset() { _file = new BlueprintFile(); }
public ProjectFileViewModel(BlueprintFile blueprintFile) { this.ProjectFileName = blueprintFile.Path; this.BlueprintManager = blueprintFile.BlueprintManager; }
private void UpdateFileData(BlueprintFile file) { }