IssuesWindow.xaml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 IQueryProviderFactory 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. private static Guid? _customerID = null;
  38. private static bool CheckCustomerID()
  39. {
  40. if (_customerID is not null)
  41. return true;
  42. var license = Client.Query(new Filter<License>().All(), Columns.None<License>().Add(x => x.Data))
  43. .ToObjects<License>().FirstOrDefault();
  44. if (license is not null && LicenseUtils.TryDecryptLicense(license.Data, out var result, out var error))
  45. {
  46. _customerID = result.CustomerID;
  47. return true;
  48. }
  49. return false;
  50. }
  51. private static RpcClientSocketTransport? _transport = null;
  52. private static bool CheckTransport()
  53. {
  54. if (_transport is not null)
  55. return true;
  56. var transport = new RpcClientSocketTransport(["remote.prsdigital.com.au:8006"]);
  57. var client = new RpcClient<Kanban>(transport);
  58. if(client.Validate("SYSTEM", "DO!pt%Qi!R0_h@LW", Guid.Empty).Status != InABox.Clients.ValidationStatus.VALID)
  59. return false;
  60. _transport = transport;
  61. return true;
  62. // var transport = new RpcClientSocketTransport(["127.0.0.1:8000"]);
  63. // var client = new RpcClient<Kanban>(transport);
  64. // if(client.Validate("frank", "frank", Guid.Empty).Status != InABox.Clients.ValidationStatus.VALID)
  65. // {
  66. // MessageWindow.ShowMessage("Could not connect to PRS digital database.", "Connection error.");
  67. // return;
  68. // }
  69. }
  70. public static bool Check()
  71. {
  72. if (!CheckCustomerID())
  73. return false;
  74. if (!CheckTransport())
  75. return false;
  76. var client = new RpcClient<Kanban>(_transport!);
  77. var waiting = client.Query(
  78. new Filter<Kanban>(x => x.Closed).IsEqualTo(Guid.Empty)
  79. .And(x => x.Status).IsEqualTo(KanbanStatus.Waiting)
  80. .And(x=>x.JobLink.Customer.ID).IsEqualTo(_customerID!.Value)
  81. .And(x=>x.CreatedBy).IsEqualTo(App.EmployeeName),
  82. Columns.None<Kanban>().Add(x => x.LastUpdate),
  83. new SortOrder<Kanban>(x => x.LastUpdate, SortDirection.Descending),
  84. CoreRange.Database(1)
  85. ).Rows.Any();
  86. return waiting;
  87. }
  88. public static void Execute()
  89. {
  90. if (!CheckCustomerID())
  91. {
  92. MessageWindow.ShowMessage("Could not load issues: no customer ID", "Error");
  93. return;
  94. }
  95. if (!CheckTransport())
  96. {
  97. MessageWindow.ShowMessage("Could not connect to PRS digital database.", "Connection error.");
  98. return;
  99. }
  100. var issues = new IssuesWindow();
  101. issues.Grid.CustomerID = _customerID!.Value;
  102. issues.ClientFactory = new _Factory(_transport!);
  103. issues.ShowDialog();
  104. }
  105. private class _Factory(IRpcClientTransport transport) : IQueryProviderFactory
  106. {
  107. public bool ExcludeCustomProperties => true;
  108. IRpcClientTransport Transport = transport;
  109. public InABox.Core.IQueryProvider Create(Type T)
  110. {
  111. var result = (IClient)Activator.CreateInstance(typeof(RpcClient<>).MakeGenericType(T), Transport);
  112. result.ExcludeCustomProperties = ExcludeCustomProperties;
  113. return result;
  114. }
  115. }
  116. }