/// <summary> /// Loads template by specified path /// </summary> /// <param name="file">Path to template file</param> private void LoadTemplateFromFile(string file) { // return if there is active tabs and action was cancelled if (!this.CloseActiveTemplateTab()) { return; } if (!File.Exists(file)) { DialogManager.ShowErrorDialog("Failed to find file " + file + "."); return; } string directory = Path.GetDirectoryName(file); if (string.IsNullOrEmpty(directory)) { DialogManager.ShowErrorDialog("Failed to load template image."); return; } string templateName = Path.GetFileNameWithoutExtension(file); // find files with image extension and template name in the same directory List <string> imageFiles = DialogManager.GetImageFilesFromDirectory(directory) .Where(x => Path.GetFileNameWithoutExtension(x).Equals(templateName)).ToList(); if (imageFiles.Count < 1) { DialogManager.ShowErrorDialog("Failed to find template image."); return; } if (imageFiles.Count > 1) { DialogManager.ShowErrorDialog("Failed to load template image. Found several files with name: " + Path.GetFileNameWithoutExtension(file) + "."); return; } // load and deserialize template data string jsonString = File.ReadAllText(file); TemplateViewModel templateViewModel = TemplateSerializer.JsonToTemplate(jsonString); // if no name in template, use name of the file if (string.IsNullOrEmpty(templateViewModel.TemplateName)) { templateViewModel.TemplateName = Path.GetFileNameWithoutExtension(file); } // load image and check if it was loaded bool imageLoaded = templateViewModel.LoadTemplateImageFromFile(imageFiles[0]); if (!imageLoaded) { return; } templateViewModel.LoadedPath = file; templateViewModel.IsDirty = false; this.CloseActiveTemplateTab(); this.AddTab(templateViewModel); RecentMenuManager.AddFileNameToRecentList(this.RecentFiles, file); }
/// <summary> /// Initializes a new instance of the <see cref="BarcodeViewModel"/> class /// </summary> /// <param name="name">Name of the barcode</param> /// <param name="area">Area of the element</param> /// <param name="templateViewModel">The view model of parent template</param> public BarcodeViewModel(string name, Rect area, TemplateViewModel templateViewModel) { this.InitializeValues(name, area.Top, area.Left, area.Width, area.Height); this.ParentTemplate = templateViewModel; this.SelectedBarcodeType = BarcodeTypes.qr; }