Przeglądaj źródła

Using Forms webBrowser, instead of WPF; added a caption to the MYOb poster

Kenric Nugteren 1 rok temu
rodzic
commit
19659eac9a

+ 1 - 0
InABox.Poster.MYOB/IMYOBPoster.cs

@@ -7,6 +7,7 @@ using System.Threading.Tasks;
 
 namespace InABox.Poster.MYOB;
 
+[Caption("MYOB")]
 public interface IMYOBPoster<TPostable> : IPoster<TPostable, MYOBPosterSettings>, IGlobalSettingsPoster<MYOBGlobalPosterSettings>
     where TPostable : Entity, IPostable, IRemotable, IPersistent, new()
 {

+ 1 - 0
InABox.Poster.MYOB/InABox.Poster.MYOB.csproj

@@ -5,6 +5,7 @@
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
 	  <UseWpf>true</UseWpf>
+	  <UseWindowsForms>true</UseWindowsForms>
   </PropertyGroup>
 
   <ItemGroup>

+ 11 - 7
InABox.Poster.MYOB/MYOBPosterEngine.cs

@@ -15,7 +15,7 @@ using System.Windows.Controls;
 
 namespace InABox.Poster.MYOB;
 
-public class MYOBConnectionData(ApiConfiguration configuration, CompanyFileService cfService)
+public class MYOBConnectionData(ApiConfiguration configuration, CompanyFileService cfService, IOAuthKeyService authKey)
 {
     public ApiConfiguration Configuration { get; set; } = configuration;
 
@@ -26,6 +26,8 @@ public class MYOBConnectionData(ApiConfiguration configuration, CompanyFileServi
     public CompanyFileCredentials? CompanyFileCredentials { get; set; }
 
     public CompanyFileWithResources? ActiveCompanyFile { get; set; }
+
+    public IOAuthKeyService AuthKey { get; set; } = authKey;
 }
 
 public partial class MYOBPosterEngine<TPostable> :
@@ -56,25 +58,27 @@ public partial class MYOBPosterEngine<TPostable> :
         var window = new Window
         {
             Width = 800,
-            Height = 600
+            Height = 600,
+            Title = "Sign in to MYOB"
         };
 
         string? resultCode = null;
-        var browser = new WebBrowser();
-        browser.Navigated += (o, e) =>
+        var browser = new System.Windows.Forms.WebBrowser();
+        browser.DocumentTitleChanged += (o, e) =>
         {
-            dynamic doc = browser.Document;
-            var htmlText = doc.documentElement.InnerHtml as string;
+            var htmlText = browser.DocumentText;
             if(htmlText is not null)
             {
                 var match = CodeRegex().Match(htmlText);
                 if (match.Success)
                 {
                     resultCode = match.Groups[1].Value;
+                    window.DialogResult = true;
                     window.Close();
                 }
             }
         };
+
         browser.Navigate(url);
         window.Content = browser;
         if(window.ShowDialog() == true)
@@ -115,7 +119,7 @@ public partial class MYOBPosterEngine<TPostable> :
 
         var cfService = new CompanyFileService(configuration, null, keystore);
 
-        _connectionData = new MYOBConnectionData(configuration, cfService);
+        _connectionData = new MYOBConnectionData(configuration, cfService, keystore);
 
         return _connectionData;
     }