| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.Rpc;
- using InABox.Wpf;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- namespace PRSDesktop.Forms.Issues;
- /// <summary>
- /// Interaction logic for IssuesWindow.xaml
- /// </summary>
- public partial class IssuesWindow : Window
- {
- public IQueryProviderFactory ClientFactory
- {
- set => Grid.ClientFactory = value;
- }
- public IssuesWindow()
- {
- InitializeComponent();
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- Grid.Refresh(true, true);
- }
-
- private static Guid? _customerID = null;
- private static bool CheckCustomerID()
- {
- if (_customerID is not null)
- return true;
-
- var license = Client.Query(new Filter<License>().All(), Columns.None<License>().Add(x => x.Data))
- .ToObjects<License>().FirstOrDefault();
- if (license is not null && LicenseUtils.TryDecryptLicense(license.Data, out var result, out var error))
- {
- _customerID = result.CustomerID;
- return true;
- }
- return false;
- }
-
- private static RpcClientSocketTransport? _transport = null;
- private static bool CheckTransport()
- {
- if (_transport is not null)
- return true;
-
- var transport = new RpcClientSocketTransport(["remote.prsdigital.com.au:8006"]);
- var client = new RpcClient<Kanban>(transport);
- if(client.Validate("SYSTEM", "DO!pt%Qi!R0_h@LW", Guid.Empty).Status != InABox.Clients.ValidationStatus.VALID)
- return false;
-
- _transport = transport;
- return true;
- // var transport = new RpcClientSocketTransport(["127.0.0.1:8000"]);
- // var client = new RpcClient<Kanban>(transport);
- // if(client.Validate("frank", "frank", Guid.Empty).Status != InABox.Clients.ValidationStatus.VALID)
- // {
- // MessageWindow.ShowMessage("Could not connect to PRS digital database.", "Connection error.");
- // return;
- // }
- }
- public static bool Check()
- {
- if (!CheckCustomerID())
- return false;
- if (!CheckTransport())
- return false;
- var client = new RpcClient<Kanban>(_transport!);
- var waiting = client.Query(
- new Filter<Kanban>(x => x.Closed).IsEqualTo(Guid.Empty)
- .And(x => x.Status).IsEqualTo(KanbanStatus.Waiting)
- .And(x=>x.JobLink.Customer.ID).IsEqualTo(_customerID!.Value)
- .And(x=>x.CreatedBy).IsEqualTo(App.EmployeeName),
- Columns.None<Kanban>().Add(x => x.LastUpdate),
- new SortOrder<Kanban>(x => x.LastUpdate, SortDirection.Descending),
- CoreRange.Database(1)
- ).Rows.Any();
-
- return waiting;
- }
- public static void Execute()
- {
- if (!CheckCustomerID())
- {
- MessageWindow.ShowMessage("Could not load issues: no customer ID", "Error");
- return;
- }
- if (!CheckTransport())
- {
- MessageWindow.ShowMessage("Could not connect to PRS digital database.", "Connection error.");
- return;
- }
-
- var issues = new IssuesWindow();
- issues.Grid.CustomerID = _customerID!.Value;
- issues.ClientFactory = new _Factory(_transport!);
- issues.ShowDialog();
- }
- private class _Factory(IRpcClientTransport transport) : IQueryProviderFactory
- {
- public bool ExcludeCustomProperties => true;
-
- IRpcClientTransport Transport = transport;
- public InABox.Core.IQueryProvider Create(Type T)
- {
- var result = (IClient)Activator.CreateInstance(typeof(RpcClient<>).MakeGenericType(T), Transport);
- result.ExcludeCustomProperties = ExcludeCustomProperties;
- return result;
- }
- }
- }
|