Browse Source

PRSLogikal Improvements

frogsoftware 9 months ago
parent
commit
ef75cb5b07

+ 1 - 0
prs.desktop/Panels/Jobs/LogikalProjectImport.xaml.cs

@@ -35,6 +35,7 @@ public partial class LogikalProjectImport : Window
                     Projects.Items = 
                         client.ProjectList()?.OfType<LogikalProject>().ToList() 
                         ?? new List<LogikalProject>();
+                    Projects.Refresh(true,true);
                 }
             }
         }

+ 4 - 0
prs.logikal/App.config

@@ -61,6 +61,10 @@
         <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
         <bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
       </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
+      </dependentAssembly>
     </assemblyBinding>
   </runtime>
 </configuration>

+ 1 - 1
prs.logikal/LogikalListener.cs

@@ -90,7 +90,7 @@ namespace PRSLogikal
         {
             var _response = new LogikalLoginResponse()
             {
-                Status = Server.Login(request.UserID, request.Password)
+                Status = Server.Login(request.WindowHandle /* request.UserID, request.Password */ )
             };
             _server.WriteAsync(_response.ToMessage());
         }

+ 36 - 20
prs.logikal/LogikalServer.cs

@@ -1,13 +1,16 @@
 using System;
 using System.Collections.Generic;
 using System.Data.SQLite;
+using System.Diagnostics;
 using System.Dynamic;
 using System.IO;
 using System.Linq;
 using System.Windows;
+using System.Windows.Interop;
 using System.Windows.Threading;
 using InABox.Logikal;
 using Ofcas.Lk.Api.Client.Core;
+using Ofcas.Lk.Api.Client.Ui;
 using Ofcas.Lk.Api.Shared;
 
 namespace PRSLogikal
@@ -28,46 +31,53 @@ namespace PRSLogikal
     
     public class LogikalServer : IDisposable
     {
-        
-        //private readonly List<String> _log = new List<String>();
-        //public String[] Log => _log.ToArray();
-
-
-        
         public event LogikalLogEvent Log;
         private void DoLog(String message) => Log?.Invoke(this, new LogikalLogArguments(message));
         
-        private IServiceProxyResult _proxy;
+        private IServiceProxyUiResult _proxy;
         private ICoreObjectResult<ILoginScope> _login;
 
         public LogikalStatus Connect(string path)
         {
-            Disconnect();
+            if (_proxy != null)
+                Disconnect();
+            
+            // Check that LogiKal is actually running from the folder we have specified
+            var _driveLetter = Path.GetPathRoot(path)?.Split(':').FirstOrDefault()?.ToLower() ?? "c";
+            var _processes = Process.GetProcessesByName("LogiKal");
+            var _running = _processes.Any(x => x.MainModule?.FileName.ToLower().Contains($"{_driveLetter}\\common\\bin\\logikal.exe") == true);
+            if (!_running)
+            {
+                DoLog($"LogiKal is not running at [{path}]");
+                return LogikalStatus.Error;
+            }
 
-            var _p = ServiceProxyFactory.CreateServiceProxy(path);
-            var _status = _p.ServiceProxy.Start();
+            var _p = ServiceProxyUiFactory.CreateServiceProxy(path,"erp");
+            var _status = _p.ServiceProxyUi.Start();
             if (_status.OperationCode != OperationCode.Accepted)
             {
-                DoLog($"Unable to connect to Logikal at [{path}]: {_status}");
+                DoLog($"Unable to connect to LogiKal at [{path}]: {_status}");
                 return LogikalStatus.Error;
             }
 
+            DoLog("LogiKal connected successfully!");
             _proxy = _p;
             return LogikalStatus.Ok;
         }
 
         public LogikalStatus Disconnect()
         {
-            Logout();
+            if (_login != null)
+                Logout();
 
             if (_proxy != null)
             {
-                _proxy.ServiceProxy.Stop();
+                _proxy.ServiceProxyUi.Stop();
                 _proxy.Dispose();
             }
 
+            DoLog("LogiKal disconnected successfully!");
             _proxy = null;
-
             return LogikalStatus.Ok;
         }
 
@@ -76,23 +86,24 @@ namespace PRSLogikal
             
         }
 
-        public LogikalStatus Login(string username, string password)
+        public LogikalStatus Login(IntPtr windowHandle)
         {
             Dictionary<string, object> _parameters = new Dictionary<string, object>()
             {
                 { WellKnownParameterKey.Login.ProgramMode, "erp" },
-                { WellKnownParameterKey.Login.UserName, username },
-                { WellKnownParameterKey.Login.Password, password },
+                { WellKnownParameterKey.Login.ApplicationHandle, windowHandle },
+                //{ WellKnownParameterKey.Login.UserName, username },
+                //{ WellKnownParameterKey.Login.Password, password },
 
             };
 
             if (_proxy == null)
             {
-                DoLog($"Logikal is not connected");
+                DoLog($"LogiKal is not connected");
                 return LogikalStatus.Error;
             }
 
-            var _check = _proxy.ServiceProxy.CanLogin(_parameters);
+            var _check = _proxy.ServiceProxyUi.CanLogin(_parameters);
             if (!_check.CanExecute)
             {
                 DoLog($"Login not allowed: {_check}!");
@@ -101,14 +112,17 @@ namespace PRSLogikal
 
             try
             {
-                var _l = _proxy.ServiceProxy.Login(_parameters);
+                var _l = _proxy.ServiceProxyUi.Login(_parameters);
                 if (_l.OperationCode != OperationCode.Accepted)
                 {
                     DoLog($"Login failed: {_l}");
                     _login = null;
                 }
                 else
+                {
+                    DoLog($"Login succeeded: {_l}");
                     _login = _l;
+                }
             }
             catch (Exception e)
             {
@@ -123,6 +137,7 @@ namespace PRSLogikal
             if (_login != null)
                 _login.Dispose();
             _login = null;
+            DoLog($"Logout succeeded!");
             return LogikalStatus.Ok;
         }
 
@@ -151,6 +166,7 @@ namespace PRSLogikal
                             };
                             _result.Add(_summary);
                         }
+                        DoLog($"GetProjects() returns {_result.Count} records!");
                     }
                 }
                 else

+ 6 - 3
prs.logikal/MainWindow.xaml

@@ -9,8 +9,9 @@
     <Grid Margin="5">
             
         <Grid.RowDefinitions>
-            <RowDefinition Height="40" />
-            <RowDefinition Height="40" />
+            <RowDefinition Height="0" />
+            <RowDefinition Height="0" />
+            <RowDefinition Height="0" />
             <RowDefinition Height="*"/>
         </Grid.RowDefinitions>
         
@@ -30,6 +31,8 @@
         <TextBox Grid.Row="1" Grid.Column="2"  x:Name="_password" Text="" Margin="5,5,0,0" IsEnabled="False" VerticalContentAlignment="Center" />
         <Button Grid.Row="1" Grid.Column="3"  x:Name="_logout" Content="Logout" Margin="5,5,0,0" Click="_logout_OnClick" IsEnabled="False"/>
         
-        <TextBox x:Name="_Log" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" Margin="0,5,0,0" />
+        <Button Grid.Row="2" Grid.Column="0" x:Name="_projects" Content="Projects" Margin="0,5,0,0" Click="_projects_OnClick" IsEnabled="False"/>
+        
+        <TextBox x:Name="_Log" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" Margin="0,5,0,0" />
     </Grid>
 </Window>

+ 14 - 2
prs.logikal/MainWindow.xaml.cs

@@ -2,6 +2,7 @@
 using System.Diagnostics;
 using System.Linq;
 using System.Windows;
+using System.Windows.Interop;
 using H.Formatters;
 using H.Pipes;
 using H.Pipes.Extensions;
@@ -60,18 +61,20 @@ namespace PRSLogikal
                 _userid.IsEnabled = true;
                 _password.IsEnabled = true;
                 _logout.IsEnabled = false;
+                _projects.IsEnabled = false;
             }
         }
         
         private void _login_OnClick(object sender, RoutedEventArgs e)
         {
-            if (_logikal.Login((_userid).Text, _password.Text) == LogikalStatus.Ok)
+            if (_logikal.Login( new WindowInteropHelper(this).Handle /*_userid.Text, _password.Text */ ) == LogikalStatus.Ok)
             {
                 _disconnect.IsEnabled = false;
                 _login.IsEnabled = false;
                 _userid.IsEnabled = false;
                 _password.IsEnabled = false;
                 _logout.IsEnabled = true;
+                _projects.IsEnabled = true;
             }
         }
 
@@ -84,6 +87,7 @@ namespace PRSLogikal
                 _userid.IsEnabled = true;
                 _password.IsEnabled = true;
                 _logout.IsEnabled = false;
+                _projects.IsEnabled = false;
             }
         }
         
@@ -97,9 +101,17 @@ namespace PRSLogikal
                 _login.IsEnabled = false;
                 _userid.IsEnabled = false;
                 _password.IsEnabled = false;
+                _projects.IsEnabled = false;
             }
         }
 
-        
+        private void _projects_OnClick(object sender, RoutedEventArgs e)
+        {
+            var projects = _logikal.GetProjects();
+            foreach (var _project in projects)
+            {
+                Log($"Project: {_project.Name}: {_project.Path}");
+            }
+        }
     }
 }

+ 18 - 36
prs.logikal/PRSLogikal.csproj

@@ -20,7 +20,7 @@
         <DebugSymbols>true</DebugSymbols>
         <DebugType>full</DebugType>
         <Optimize>false</Optimize>
-        <OutputPath>..\prs.desktop\bin\Debug\net8.0-windows\PRSLogikal</OutputPath>
+        <OutputPath>p:\</OutputPath>
         <DefineConstants>DEBUG;TRACE</DefineConstants>
         <ErrorReport>prompt</ErrorReport>
         <WarningLevel>4</WarningLevel>
@@ -35,25 +35,7 @@
         <WarningLevel>4</WarningLevel>
     </PropertyGroup>
     <ItemGroup>
-        <Reference Include="H.Formatters, Version=2.0.59.0, Culture=neutral, PublicKeyToken=155b585918bc2f0b, processorArchitecture=MSIL">
-          <HintPath>..\packages\H.Formatters.2.0.59\lib\net451\H.Formatters.dll</HintPath>
-        </Reference>
-        <Reference Include="H.Formatters.BinaryFormatter, Version=2.0.59.0, Culture=neutral, PublicKeyToken=155b585918bc2f0b, processorArchitecture=MSIL">
-          <HintPath>..\packages\H.Formatters.BinaryFormatter.2.0.59\lib\net451\H.Formatters.BinaryFormatter.dll</HintPath>
-        </Reference>
-        <Reference Include="H.Formatters.Newtonsoft.Json, Version=13.0.59.0, Culture=neutral, PublicKeyToken=155b585918bc2f0b, processorArchitecture=MSIL">
-          <HintPath>..\packages\H.Formatters.Newtonsoft.Json.13.0.59\lib\net451\H.Formatters.Newtonsoft.Json.dll</HintPath>
-        </Reference>
-        <Reference Include="H.Pipes, Version=2.0.59.0, Culture=neutral, PublicKeyToken=155b585918bc2f0b, processorArchitecture=MSIL">
-          <HintPath>..\packages\H.Pipes.2.0.59\lib\net462\H.Pipes.dll</HintPath>
-        </Reference>
-        <Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
-          <HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
-        </Reference>
         <Reference Include="mscorlib" />
-        <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
-          <HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
-        </Reference>
         <Reference Include="Ofcas.Lk.Api.Client.Core">
           <HintPath>..\..\Users\frank.vandenbos\.nuget\packages\ofcas.lk.api.client.core\3.0.2.8\lib\net452\Ofcas.Lk.Api.Client.Core.dll</HintPath>
         </Reference>
@@ -63,15 +45,6 @@
         <Reference Include="System"/>
         <Reference Include="System.Core"/>
         <Reference Include="System.Data"/>
-        <Reference Include="System.Data.SQLite, Version=1.0.118.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
-          <HintPath>..\..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.118.0\lib\net46\System.Data.SQLite.dll</HintPath>
-        </Reference>
-        <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
-          <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
-        </Reference>
-        <Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
-          <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
-        </Reference>
         <Reference Include="System.Xml"/>
         <Reference Include="System.Xaml">
             <RequiredTargetFramework>4.0</RequiredTargetFramework>
@@ -119,7 +92,6 @@
     </ItemGroup>
     <ItemGroup>
         <None Include="App.config"/>
-        <None Include="packages.config" />
     </ItemGroup>
     <ItemGroup>
       <ProjectReference Include="..\..\inabox\InABox.Logikal\InABox.Logikal.csproj">
@@ -127,12 +99,22 @@
         <Name>InABox.Logikal</Name>
       </ProjectReference>
     </ItemGroup>
+    <ItemGroup>
+      <PackageReference Include="H.Formatters" Version="2.0.59" />
+      <PackageReference Include="H.Formatters.BinaryFormatter" Version="2.0.59" />
+      <PackageReference Include="H.Formatters.Newtonsoft.Json" Version="13.0.59" />
+      <PackageReference Include="H.Pipes" Version="2.0.59" />
+      <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
+      <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
+      <PackageReference Include="Ofcas.Framework.Translation" Version="1.0.0.397" />
+      <PackageReference Include="Ofcas.Lk.Api.Client.Core" Version="3.0.2.8" />
+      <PackageReference Include="Ofcas.Lk.Api.Client.Ui" Version="3.0.2.8" />
+      <PackageReference Include="Ofcas.Lk.Api.Core" Version="3.0.0.98" />
+      <PackageReference Include="Ofcas.Lk.Api.Ui" Version="3.0.0.98" />
+      <PackageReference Include="Stub.System.Data.SQLite.Core.NetFramework" Version="1.0.118" />
+      <PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" />
+      <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.3" />
+      <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
+    </ItemGroup>
     <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
-    <Import Project="..\..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.118.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets" Condition="Exists('..\..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.118.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets')" />
-    <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
-      <PropertyGroup>
-        <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
-      </PropertyGroup>
-      <Error Condition="!Exists('..\..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.118.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.118.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets'))" />
-    </Target>
 </Project>

+ 0 - 13
prs.logikal/packages.config

@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
-  <package id="H.Formatters" version="2.0.59" targetFramework="net48" />
-  <package id="H.Formatters.BinaryFormatter" version="2.0.59" targetFramework="net48" />
-  <package id="H.Formatters.Newtonsoft.Json" version="13.0.59" targetFramework="net48" />
-  <package id="H.Pipes" version="2.0.59" targetFramework="net48" />
-  <package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net48" />
-  <package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
-  <package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.118.0" targetFramework="net472" />
-  <package id="System.Data.SQLite.Core" version="1.0.118.0" targetFramework="net472" />
-  <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net48" />
-  <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
-</packages>