Skip to content

Commit

Permalink
Update examples for 8.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
NinjaManatee committed Sep 27, 2023
1 parent d1c6c2a commit b72ca2b
Show file tree
Hide file tree
Showing 26 changed files with 870 additions and 141 deletions.
6 changes: 3 additions & 3 deletions AuthenticationExample/AuthenticationExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<Reference Include="DotNetZip, Version=1.16.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.16.0\lib\net40\DotNetZip.dll</HintPath>
</Reference>
<Reference Include="Finsemble, Version=8.9.0.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.9.0\lib\net452\Finsemble.dll</HintPath>
<Reference Include="Finsemble, Version=8.9.3.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.9.3\lib\net452\Finsemble.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Logging, Version=6.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Logging.6.16.0\lib\net45\Microsoft.IdentityModel.Logging.dll</HintPath>
Expand All @@ -59,7 +59,7 @@
<HintPath>..\packages\Microsoft.IdentityModel.Tokens.6.16.0\lib\net45\Microsoft.IdentityModel.Tokens.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PInvoke.Windows.Core, Version=0.6.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.Windows.Core.0.6.49\lib\net20\PInvoke.Windows.Core.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion AuthenticationExample/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip" version="1.16.0" targetFramework="net452" />
<package id="Finsemble" version="8.9.0" targetFramework="net452" />
<package id="Finsemble" version="8.9.3" targetFramework="net452" />
<package id="Microsoft.IdentityModel.Logging" version="6.16.0" targetFramework="net452" />
<package id="Microsoft.IdentityModel.Tokens" version="6.16.0" targetFramework="net452" />
<package id="Microsoft.NETCore.Platforms" version="6.0.6" targetFramework="net452" />
Expand Down
6 changes: 3 additions & 3 deletions FDC3WPFExample/FDC3WPFExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<Reference Include="DotNetZip, Version=1.16.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.16.0\lib\net40\DotNetZip.dll</HintPath>
</Reference>
<Reference Include="Finsemble, Version=8.9.0.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.9.0\lib\net452\Finsemble.dll</HintPath>
<Reference Include="Finsemble, Version=8.9.3.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.9.3\lib\net452\Finsemble.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Logging, Version=6.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Logging.6.16.0\lib\net45\Microsoft.IdentityModel.Logging.dll</HintPath>
Expand All @@ -59,7 +59,7 @@
<HintPath>..\packages\Microsoft.IdentityModel.Tokens.6.16.0\lib\net45\Microsoft.IdentityModel.Tokens.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PInvoke.Windows.Core, Version=0.6.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.Windows.Core.0.6.49\lib\net20\PInvoke.Windows.Core.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion FDC3WPFExample/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip" version="1.16.0" targetFramework="net452" />
<package id="Finsemble" version="8.9.0" targetFramework="net452" />
<package id="Finsemble" version="8.9.3" targetFramework="net452" />
<package id="Microsoft.IdentityModel.Logging" version="6.16.0" targetFramework="net452" />
<package id="Microsoft.IdentityModel.Tokens" version="6.16.0" targetFramework="net452" />
<package id="Microsoft.NETCore.Platforms" version="6.0.6" targetFramework="net452" />
Expand Down
189 changes: 95 additions & 94 deletions MultiWindowExample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Threading;

namespace MultiWindowExample
Expand All @@ -15,8 +17,6 @@ namespace MultiWindowExample
/// </summary>
public partial class App : Application, ISingleInstanceApp
{
private static readonly object lockObj = new object();

private const string Unique = "6bea6fc4-5d9c-4961-b39d-89addcd65a73";

private static App application = null;
Expand All @@ -35,14 +35,18 @@ public partial class App : Application, ISingleInstanceApp
QI = "PODgpJrXxPAp72v_O0fNfAhWjHLeTk9TfLARl9lzPpYIoYR5tgP1Y_A-3feH_xtCfkzcCskfXIerQlY9lVmqs-eGEYjfuuPVYIruN4OsskMY1nz-h_14clyUmUwfCQJDV4qjcAzf80IMu53jYEW1BydRf90snRjk1dYgSq_qtTQ",
};

private static TaskCompletionSource<bool> ParentInstanceReadyTCS;

private static SemaphoreSlim SemaphoreSync = new SemaphoreSlim(1, 1);

/// <summary>
///
/// </summary>
[STAThread]
public static void Main(string[] args)
{
#if DEBUG
Debugger.Launch();
Debugger.Launch();
#endif

#if LOGGING && TRACE
Expand Down Expand Up @@ -82,25 +86,28 @@ public static void Main(string[] args)
// then ensure that we always release the mutex
if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
{
application = new App();

// If window type passed for initial launch, add listener to launch window when connected.
var argsList = args.ToList();
IEnumerable<string> nonFSBLArgs = GetNonFinsembleArgs(argsList);
if ((nonFSBLArgs != null) && nonFSBLArgs.Any())
{
// Non-finsemble arguments passed, launch window
LaunchWindow(args.ToList());
}
else
// initialize the parent instance
if (FSBL == null)
{
ParentInstanceReadyTCS = new TaskCompletionSource<bool>();

// Register with Finsemble as a windowless component so the application will close when Finsemble is closed.
//Ensure that your window has been created (so that its window handle exists) before connecting to Finsemble.
var fsbl = new Finsemble(args.ToArray(), null);
FSBL = new Finsemble(args, null);
FSBL.Connected += FSBL_Connected;
// Subscribe on Disconnected event to close the Application
FSBL.Disconnected += OnShutdown;
FSBL.Connect("MultiWindowExample", JWK);
}

fsbl.Connect("MultiWindowExample", JWK);
// If window type passed for initial launch, add listener to launch window when connected.
var newWindowName = GetWindowNameToLaunch(args);
if (!string.IsNullOrEmpty(newWindowName))
{
_ = LaunchWindow(newWindowName, args);
}

// start application
application = new App();
application.InitializeComponent();
mutex.ReleaseMutex();
application.Run();
Expand All @@ -111,121 +118,90 @@ public static void Main(string[] args)
}
}

/// <summary>
/// Giving a list of arguments, returns an enumerable of non-Finsemble arguments (no =)
/// </summary>
/// <param name="args">List of arguments</param>
/// <returns>Enumerable of non-Finsemble arguments</returns>
private static IEnumerable<string> GetNonFinsembleArgs(IList<string> args)
{
var nonFSBLArgs = args.Where(str => !str.Contains("=") && !str.Contains(".exe"));

return nonFSBLArgs;
}

/// <summary>
/// Launches a Finsemble aware window with the passed arguments.
/// </summary>
/// <param name="args">The arguments passed to the process.</param>
/// <returns>Always true?</returns>
private static bool LaunchWindow(IList<string> args)
/// <param name="windowName">The name of the window to be launched.</param>
/// <param name="args">Command line args for launched window.</param>
private static async Task<Window> LaunchWindow(string windowName, IEnumerable<string> args)
{
#if DEBUG
Debugger.Launch();
#endif

if (!args.Any())
{
// Invalid number of arguments
return true;
}
TaskCompletionSource<Window> tcs = new TaskCompletionSource<Window>();

var nonFSBLArgs = GetNonFinsembleArgs(args);
if ((nonFSBLArgs == null) || !nonFSBLArgs.Any())
if (string.IsNullOrEmpty(windowName))
{
// no non-finsemble arguments. Cannot launch window.
return true;
// Invalid window name
throw new ArgumentNullException("windowName", "Invalid window name");
}

string name = nonFSBLArgs.First();

// handle command line arguments of second instance
Window window = null;
Current.Dispatcher.Invoke(() =>
{
window = CreateWindow(name);
window = CreateWindow(windowName);
});

if (window == null)
{
Trace.TraceWarning($"Could not create window: {name}");
Trace.TraceWarning($"Could not create window: {windowName}");
tcs.SetResult(window);
}
else if (!(window is IIntegratable fsblWindow))
{
Trace.TraceWarning($"The window \"{windowName}\" is not a window that can be integrated into Finsemble.");
tcs.SetResult(window);
}
else
{
Current.Dispatcher.Invoke(() =>
{
// Ensure that your window has been created (so that its window handle exists) before connecting to Finsemble.
new WindowInteropHelper(window).EnsureHandle();
});

// Wait until the parent instance connects to Finsemble
await ParentInstanceReadyTCS.Task;

// Register with Finsemble
//Ensure that your window has been created (so that its window handle exists) before connecting to Finsemble.
var fsbl = new Finsemble(args.ToArray(), window);
var fsbl = new Finsemble(args?.ToArray(), window);
fsbl.Connected += (s, e) =>
{
IIntegratable fsblWin = window as IIntegratable;
if (fsblWin == null)
{
Trace.TraceWarning($"The window \"{name}\" is not a window that can be integrated into Finsemble.");
}
else
{
fsblWin.SetFinsemble(fsbl);
}
fsblWindow.SetFinsemble(fsbl);
Current.Dispatcher.Invoke(window.Show);
// releases the Task when the child window connected to Finsemble
tcs.SetResult(window);
};

// Dispose of Finsemble object when window is closed.
window.Closed += (s, e) =>
{
Trace.TraceInformation("disposing window from app.xaml");
fsbl.Dispose();
Trace.TraceInformation("dispose completed");
Trace.TraceInformation($"The window {windowName} has been closed");
};

fsbl.Connect("MultiWindowExample", JWK);
}

return true;
return await tcs.Task;
}

private static void OnShutdown(object sender, EventArgs e)
private static void FSBL_Connected(object sender, EventArgs e)
{
if (FSBL != null)
{
lock (lockObj)
{
if (FSBL != null)
{
try
{
// Dispose of Finsemble.
FSBL.Dispose();
}
catch { }
finally
{
FSBL = null;
}
}
// Uncomment a row below if the parent app is appService and the config contains "waitForInitialization": true
// FSBL.PublishReady();
ParentInstanceReadyTCS.SetResult(true);
}

}
}
private static void OnShutdown(object sender, EventArgs e)
{
FSBL = null;

try
{
// Release main thread so application can exit.
Current.Dispatcher.Invoke(application.Shutdown);
}
catch
catch (Exception ex)
{
// An error occurred, but I don't care as long as it exits.
;
Trace.TraceError($"Couldn't shutdown the apllication. Exception: {ex.Message}");
}
}

Expand Down Expand Up @@ -277,7 +253,27 @@ private static Window CreateWindow(string name)
/// <returns></returns>
public bool SignalExternalCommandLineArgs(IList<string> args)
{
return LaunchWindow(args);
var newWindowName = GetWindowNameToLaunch(args);
Task.Run(async () =>
{
try
{
// The SemaphoreSync object will guarantee that only one child window will be created per time.
// Use TimeSpan as parameter to prevent an infinite waiting while SemaphoreSync is released.
await SemaphoreSync.WaitAsync(TimeSpan.FromMinutes(5));
await LaunchWindow(newWindowName, args);
}
catch(Exception ex)
{
Trace.TraceError($"Couldn't launch child window because {ex.Message}");
}
finally
{
SemaphoreSync.Release();
}
});
return true;
}
#endregion

Expand All @@ -288,11 +284,16 @@ public bool SignalExternalCommandLineArgs(IList<string> args)
/// <param name="e"></param>
private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
#if DEBUG
Debugger.Launch();
#endif
MessageBox.Show($"An Unhandled Exception has occurred. Please Check your event Logs. \n {e.Exception.Message}");
}

MessageBox.Show("An Unhandled Exception has occurred. Please Check your event Logs.");
/// <summary>
/// Returns the window name which should be created
/// </summary>
/// <param name="args">command line arguments passed to application</param>
private static string GetWindowNameToLaunch(IEnumerable<string> args)
{
return args?.FirstOrDefault(str => !str.Contains("=") && !str.Contains(".exe"));
}
}
}
6 changes: 3 additions & 3 deletions MultiWindowExample/MultiWindowExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
<Reference Include="DotNetZip, Version=1.16.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.16.0\lib\net40\DotNetZip.dll</HintPath>
</Reference>
<Reference Include="Finsemble, Version=8.9.0.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.9.0\lib\net452\Finsemble.dll</HintPath>
<Reference Include="Finsemble, Version=8.9.3.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.9.3\lib\net452\Finsemble.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Logging, Version=6.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IdentityModel.Logging.6.16.0\lib\net45\Microsoft.IdentityModel.Logging.dll</HintPath>
Expand All @@ -59,7 +59,7 @@
<HintPath>..\packages\Microsoft.IdentityModel.Tokens.6.16.0\lib\net45\Microsoft.IdentityModel.Tokens.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PInvoke.Windows.Core, Version=0.6.0.0, Culture=neutral, PublicKeyToken=9e300f9f87f04a7a, processorArchitecture=MSIL">
<HintPath>..\packages\PInvoke.Windows.Core.0.6.49\lib\net20\PInvoke.Windows.Core.dll</HintPath>
Expand Down
Loading

0 comments on commit b72ca2b

Please sign in to comment.