123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- 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 Func<Type, IClient> ClientFactory
- {
- set => Grid.ClientFactory = value;
- }
- public IssuesWindow()
- {
- InitializeComponent();
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- Grid.Refresh(true, true);
- }
- public static void Execute()
- {
- var license = Client.Query(new Filter<License>().All(), Columns.None<License>().Add(x => x.Data))
- .ToObjects<License>().FirstOrDefault();
- var customerID = Guid.Empty;
- if(license is not null && LicenseUtils.TryDecryptLicense(license.Data, out var result, out var error))
- {
- customerID = result.CustomerID;
- }
- if(customerID == Guid.Empty)
- {
- MessageWindow.ShowMessage("Could not load issues: no customer ID", "Error");
- return;
- }
- var transport = new RpcClientSocketTransport(["remote.prsdigital.com.au:8006"]);
- var client = new RpcClient<Kanban>(transport);
- if(client.Validate("ADMIN", "admin", Guid.Empty).Status != InABox.Clients.ValidationStatus.VALID)
- {
- MessageWindow.ShowMessage("Could not connect to PRS digital database.", "Connection error.");
- return;
- }
- var issues = new IssuesWindow();
- // Save the old property if it exists.
- var prop = DatabaseSchema.Property(typeof(Kanban), IssuesGrid.CustomerProperty.Name) as CustomProperty;
- // Load the new property.
- DatabaseSchema.Load([IssuesGrid.CustomerProperty]);
- issues.Grid.CustomerID = customerID;
- issues.ClientFactory = x => (Activator.CreateInstance(typeof(RpcClient<>).MakeGenericType(x), transport) as IClient)!;
- issues.ShowDialog();
- // Return DB schema to what it was.
- DatabaseSchema.Unload([IssuesGrid.CustomerProperty]);
- if(prop is not null)
- {
- DatabaseSchema.Load([prop]);
- }
- }
- }
|