/// <summary> /// Calls template generation /// </summary> private async Task GenerateTemplate() { this.view.Hide(); BusyIndicatorManager.Enable(); string expectedFileNameExtension = ".txt"; byte[] templateDescriptionBytes = Encoding.UTF8.GetBytes(this.TemplateDescription); if (!Path.HasExtension(this.TemplateName) || (Path.HasExtension(this.TemplateName) && Path.GetExtension(this.TemplateName) != expectedFileNameExtension)) { this.TemplateName += expectedFileNameExtension; } try { this.GenerationContent = await Task.Run(() => CoreApi.GenerateTemplate( this.TemplateName, templateDescriptionBytes, this.ExtraStoragePath, string.Empty)); this.GenerationContent.Name = this.TemplateName; } catch (Exception e) { DialogManager.ShowErrorDialog(e.Message); } finally { BusyIndicatorManager.Disable(); } }
/// <summary> /// Runs template finalization /// </summary> private void OnFinilizeTemplate() { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (sender, args) => { string templateData = TemplateSerializer.TemplateToJson(this, false); string additionalPars = string.Empty; try { string templateName = Path.GetFileNameWithoutExtension(this.TemplateImageName) + "_template.omr"; FinalizationData finalizationResult = CoreApi.FinalizeTemplate(templateName, Encoding.UTF8.GetBytes(templateData), this.TemplateId, additionalPars); Application.Current.Dispatcher.Invoke(() => { this.ProcessFinalizationResponse(finalizationResult); }); } catch (Exception e) { DialogManager.ShowErrorDialog(e.Message); } }; worker.RunWorkerCompleted += (sender, args) => { BusyIndicatorManager.Disable(); }; BusyIndicatorManager.Enable(); worker.RunWorkerAsync(); }
/// <summary> /// Uploads selected images on cloud storage /// </summary> private async void OnUploadImages() { try { BusyIndicatorManager.Enable(); ControlHelper.HideAllChildViews(); Dictionary <string, byte[]> imagesData = new Dictionary <string, byte[]>(); string folderPath = string.IsNullOrEmpty(this.ExtraStoragePath) ? string.Empty : this.ExtraStoragePath + @"\"; foreach (FileToUpload item in this.ImagesToUpload) { imagesData.Add(string.Concat(folderPath, item.Name), File.ReadAllBytes(item.FullPath)); } await Task.Run(() => CoreApi.StorageUploadImages(imagesData)); if (this.ViewClosed != null) { this.ViewClosed(this.ExtraStoragePath); } this.view.Close(); } catch (Exception e) { DialogManager.ShowErrorDialog(e.Message); } finally { BusyIndicatorManager.Disable(); ControlHelper.RestoreHidderChildViews(); } }
/// <summary> /// Runs template correction /// </summary> private void OnCorrectTemplate() { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (sender, args) => { string templateData = TemplateSerializer.TemplateToJson(this, false); byte[] imageData = TemplateSerializer.CompressImage(this.TemplateImage, this.ImageSizeInBytes); //string imageData = TemplateConverter.CheckAndCompressImage(this.TemplateImage, this.ImageFileFormat, this.ImageSizeInBytes); string additionalPars = string.Empty; try { TemplateViewModel correctedTemplate = CoreApi.CorrectTemplate(this.TemplateImageName, imageData, templateData, this.WasUploaded, additionalPars); Application.Current.Dispatcher.Invoke(() => { this.ClearSelection(); this.PageQuestions.Clear(); this.AddQuestions(correctedTemplate.PageQuestions); this.TemplateId = correctedTemplate.TemplateId; this.FinalizationComplete = false; double koeff = this.TemplateImage.PixelWidth / correctedTemplate.PageWidth; ZoomKoefficient *= koeff; this.OnPropertyChanged(nameof(this.PageScale)); this.PageWidth = correctedTemplate.PageWidth; this.PageHeight = correctedTemplate.PageHeight; this.WasUploaded = true; this.Warnings.Add("Template correction complete!"); }); } catch (Exception e) { DialogManager.ShowErrorDialog(e.Message); } }; worker.RunWorkerCompleted += (sender, args) => { BusyIndicatorManager.Disable(); }; BusyIndicatorManager.Enable(); worker.RunWorkerAsync(); }