MainWindowViewModel.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using Avalonia.Controls;
  2. using Avalonia.Platform.Storage;
  3. using EdTestEmulator.Models;
  4. using EdTestEmulator.Services;
  5. using ReactiveUI;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Diagnostics;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Threading.Tasks;
  14. namespace EdTestEmulator.ViewModels
  15. {
  16. public class MainWindowViewModel : ViewModelBase
  17. {
  18. public string Greeting => "Welcome to Avalonia!";
  19. public ObservableCollection<ProcedureRow> Procedures { get; }
  20. public ObservableCollection<MessageRow> Messages { get; }
  21. public Dictionary<MessageRow,string> XmlMessages { get; }
  22. public MessageRow SelectedMessage { get; set; }
  23. public ProcedureRow SelectedProcedure { get; set; }
  24. public string ExchangePath { get; set; } = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/InputDir";
  25. private MessageProcessingService _service;
  26. public MainWindowViewModel()
  27. {
  28. Procedures = new() { new ProcedureRow() { Type = "DT", DateStart = DateTime.Today, DeclarantName = "TestName", ProcedureUUID = Guid.NewGuid().ToString(), Organization = "OOO Roga i Kopita" } };
  29. Messages = new();
  30. XmlMessages = new();
  31. _service = new MessageProcessingService(Procedures, Messages, XmlMessages, ExchangePath);
  32. this.RaisePropertyChanged(nameof(Procedures));
  33. }
  34. public void SelectMessageManual(Window window)
  35. {
  36. Task.Run(async () =>
  37. {
  38. var storageProvider = ((Window)window).StorageProvider;
  39. var initPath = String.Empty;
  40. FilePickerFileType xmlFilter = new("XML")
  41. {
  42. Patterns = new[] { "*.xml"}
  43. };
  44. var folderPickerOpenOptions = new FilePickerOpenOptions()
  45. {
  46. AllowMultiple = false,
  47. FileTypeFilter = new List<FilePickerFileType>() { xmlFilter },
  48. SuggestedStartLocation = await storageProvider.TryGetFolderFromPathAsync(initPath)
  49. };
  50. var result = await storageProvider.OpenFilePickerAsync(folderPickerOpenOptions);
  51. if (result is null || result.Count != 1 || result.First().Path.AbsolutePath == String.Empty)
  52. return;
  53. var xmlFilePath = result.First().Path.LocalPath;
  54. File.Copy(xmlFilePath, ExchangePath + "/" + Path.GetFileName(xmlFilePath));
  55. });
  56. }
  57. public void OpenExchangeFolder()
  58. {
  59. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() { FileName = ExchangePath, UseShellExecute = true });
  60. }
  61. public void OpenXmlMessage()
  62. {
  63. var vm = new DocumentWindowViewModel();
  64. vm.XmlString = XmlMessages[SelectedMessage];
  65. vm.Title = SelectedMessage.Description;
  66. vm.XlstPath = "C:\\Users\\Veloe\\source\\repos\\EdTestEmulator\\EdTestEmulator\\Assets\\EdVersions\\xslt_out_5_21_0\\1006107E_ESADout_CU.xslt";
  67. vm.ConvertToHtml();
  68. var window = new DocumentWindow();
  69. window.DataContext = vm;
  70. window.Show();
  71. }
  72. }
  73. }