IssuesWindow.xaml.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Comal.Classes;
  2. using InABox.Clients;
  3. using InABox.Core;
  4. using InABox.Rpc;
  5. using InABox.Wpf;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Shapes;
  19. namespace PRSDesktop.Forms.Issues;
  20. /// <summary>
  21. /// Interaction logic for IssuesWindow.xaml
  22. /// </summary>
  23. public partial class IssuesWindow : Window
  24. {
  25. public Func<Type, IClient> ClientFactory
  26. {
  27. set => Grid.ClientFactory = value;
  28. }
  29. public IssuesWindow()
  30. {
  31. InitializeComponent();
  32. }
  33. private void Window_Loaded(object sender, RoutedEventArgs e)
  34. {
  35. Grid.Refresh(true, true);
  36. }
  37. public static void Execute()
  38. {
  39. var license = Client.Query(new Filter<License>().All(), Columns.None<License>().Add(x => x.Data))
  40. .ToObjects<License>().FirstOrDefault();
  41. var customerID = Guid.Empty;
  42. if(license is not null && LicenseUtils.TryDecryptLicense(license.Data, out var result, out var error))
  43. {
  44. customerID = result.CustomerID;
  45. }
  46. if(customerID == Guid.Empty)
  47. {
  48. MessageWindow.ShowMessage("Could not load issues: no customer ID", "Error");
  49. return;
  50. }
  51. var transport = new RpcClientSocketTransport(["remote.prsdigital.com.au:8006"]);
  52. var client = new RpcClient<Kanban>(transport);
  53. if(client.Validate("ADMIN", "admin", Guid.Empty).Status != InABox.Clients.ValidationStatus.VALID)
  54. {
  55. MessageWindow.ShowMessage("Could not connect to PRS digital database.", "Connection error.");
  56. return;
  57. }
  58. var issues = new IssuesWindow();
  59. // Save the old property if it exists.
  60. var prop = DatabaseSchema.Property(typeof(Kanban), IssuesGrid.CustomerProperty.Name) as CustomProperty;
  61. // Load the new property.
  62. DatabaseSchema.Load([IssuesGrid.CustomerProperty]);
  63. issues.Grid.CustomerID = customerID;
  64. issues.ClientFactory = x => (Activator.CreateInstance(typeof(RpcClient<>).MakeGenericType(x), transport) as IClient)!;
  65. issues.ShowDialog();
  66. // Return DB schema to what it was.
  67. DatabaseSchema.Unload([IssuesGrid.CustomerProperty]);
  68. if(prop is not null)
  69. {
  70. DatabaseSchema.Load([prop]);
  71. }
  72. }
  73. }