Skip to content

Commit

Permalink
Update examples for 8.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
john-ciq committed May 16, 2024
1 parent b72ca2b commit 7d414e7
Show file tree
Hide file tree
Showing 26 changed files with 194 additions and 103 deletions.
4 changes: 2 additions & 2 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.3.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.9.3\lib\net452\Finsemble.dll</HintPath>
<Reference Include="Finsemble, Version=8.11.0.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.11.0\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 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.3" targetFramework="net452" />
<package id="Finsemble" version="8.11.0" 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
4 changes: 2 additions & 2 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.3.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.9.3\lib\net452\Finsemble.dll</HintPath>
<Reference Include="Finsemble, Version=8.11.0.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.11.0\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 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.3" targetFramework="net452" />
<package id="Finsemble" version="8.11.0" 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
1 change: 1 addition & 0 deletions MultiWindowExample/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public static void Main(string[] args)
application = new App();
application.InitializeComponent();
mutex.ReleaseMutex();
// Blocks main thread
application.Run();

// Allow single instance code to perform cleanup operations
Expand Down
7 changes: 3 additions & 4 deletions MultiWindowExample/IIntegrateable.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System.Windows;
using ChartIQ.Finsemble;
using ChartIQ.Finsemble;

namespace MultiWindowExample
{
/// <summary>
/// Interface for windows that can be integrated with Finsemble.
/// </summary>
interface IIntegratable
{
{
/// <summary>
/// Sets the instance of Finsemble to be used by this object.
/// </summary>
/// <param name="fsbl">The instance of Finsemble</param>
void SetFinsemble(Finsemble fsbl);
}
}
}
4 changes: 2 additions & 2 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.3.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.9.3\lib\net452\Finsemble.dll</HintPath>
<Reference Include="Finsemble, Version=8.11.0.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.11.0\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 Down
70 changes: 24 additions & 46 deletions MultiWindowExample/SingleInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Remoting;
Expand Down Expand Up @@ -188,7 +189,6 @@ public static string[] CommandLineToArgvW(string cmdLine)
// Assert.AreEqual(IntPtr.Zero, p);
}
}

}

public interface ISingleInstanceApp
Expand Down Expand Up @@ -250,18 +250,6 @@ public static class SingleInstance<TApplication>

#endregion

#region Public Properties

/// <summary>
/// Gets list of command line arguments for the application.
/// </summary>
public static IList<string> CommandLineArgs
{
get { return commandLineArgs; }
}

#endregion

#region Public Methods

/// <summary>
Expand All @@ -274,19 +262,19 @@ public static bool InitializeAsFirstInstance(string uniqueName)
commandLineArgs = GetCommandLineArgs(uniqueName);

// Build unique application Id and the IPC channel name.
string applicationIdentifier = uniqueName + Environment.UserName;
string applicationIdentifier = $"{uniqueName}{Environment.UserName}";

string channelName = String.Concat(applicationIdentifier, Delimiter, ChannelNameSuffix);
string channelName = string.Concat(applicationIdentifier, Delimiter, ChannelNameSuffix);

// Create mutex based on unique application Id to check if this is the first instance of the application.
bool firstInstance;
singleInstanceMutex = new Mutex(true, applicationIdentifier, out firstInstance);
singleInstanceMutex = new Mutex(true, applicationIdentifier, out bool firstInstance);
if (firstInstance)
{
CreateRemoteService(channelName);
}
else
{
Trace.TraceInformation($"Send message to the Main instance: {string.Join(", ", commandLineArgs)}");
SignalFirstInstance(channelName, commandLineArgs);
}

Expand All @@ -298,11 +286,8 @@ public static bool InitializeAsFirstInstance(string uniqueName)
/// </summary>
public static void Cleanup()
{
if (singleInstanceMutex != null)
{
singleInstanceMutex.Close();
singleInstanceMutex = null;
}
singleInstanceMutex?.Close();
singleInstanceMutex = null;

if (channel != null)
{
Expand All @@ -321,7 +306,7 @@ public static void Cleanup()
/// <returns>List of command line arg strings.</returns>
private static IList<string> GetCommandLineArgs(string uniqueApplicationName)
{
string[] args = null;
string[] args = new string[] { };
if (AppDomain.CurrentDomain.ActivationContext == null)
{
// The application was not clickonce deployed, get args from standard API's
Expand All @@ -333,7 +318,7 @@ private static IList<string> GetCommandLineArgs(string uniqueApplicationName)
// Clickonce deployed apps cannot recieve traditional commandline arguments
// As a workaround commandline arguments can be written to a shared location before
// the app is launched and the app can obtain its commandline arguments from the
// shared location
// shared location
string appFolderPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), uniqueApplicationName);

Expand All @@ -349,18 +334,14 @@ private static IList<string> GetCommandLineArgs(string uniqueApplicationName)

File.Delete(cmdLinePath);
}
catch (IOException)
catch (IOException ex)
{
Trace.TraceError($"Failed to read file: {cmdLinePath}. The error: {ex.Message}");
}
}
}

if (args == null)
{
args = new string[] { };
}

return new List<string>(args);
return args;
}

/// <summary>
Expand All @@ -371,11 +352,12 @@ private static void CreateRemoteService(string channelName)
{
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Dictionary<string, string>();

props["name"] = channelName;
props["portName"] = channelName;
props["exclusiveAddressUse"] = "false";
IDictionary props = new Dictionary<string, string>()
{
{ "name", channelName },
{"portName", channelName },
{ "exclusiveAddressUse", "false"}
};

// Create the IPC Server channel with the channel properties
channel = new IpcServerChannel(props, serverProvider);
Expand All @@ -402,19 +384,16 @@ private static void SignalFirstInstance(string channelName, IList<string> args)
IpcClientChannel secondInstanceChannel = new IpcClientChannel();
ChannelServices.RegisterChannel(secondInstanceChannel, true);

string remotingServiceUrl = IpcProtocol + channelName + "/" + RemoteServiceName;
string remotingServiceUrl = $"{IpcProtocol}{channelName}/{RemoteServiceName}";

// Obtain a reference to the remoting service exposed by the server i.e the first instance of the application
IPCRemoteService firstInstanceRemoteServiceReference = (IPCRemoteService)RemotingServices.Connect(typeof(IPCRemoteService), remotingServiceUrl);
var firstInstanceRemoteServiceReference = RemotingServices.Connect(typeof(IPCRemoteService), remotingServiceUrl) as IPCRemoteService;

// Check that the remote service exists, in some cases the first instance may not yet have created one, in which case
// the second instance should just exit
if (firstInstanceRemoteServiceReference != null)
{
// Invoke a method of the remote service exposed by the first instance passing on the command line
// arguments and causing the first instance to activate itself
firstInstanceRemoteServiceReference.InvokeFirstInstance(args);
}
// Invoke a method of the remote service exposed by the first instance passing on the command line
// arguments and causing the first instance to activate itself
firstInstanceRemoteServiceReference?.InvokeFirstInstance(args);
}

/// <summary>
Expand All @@ -425,8 +404,7 @@ private static void SignalFirstInstance(string channelName, IList<string> args)
private static object ActivateFirstInstanceCallback(object arg)
{
// Get command line args to be passed to first instance
IList<string> args = arg as IList<string>;
ActivateFirstInstance(args);
ActivateFirstInstance(arg as IList<string>);
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion MultiWindowExample/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.3" targetFramework="net452" />
<package id="Finsemble" version="8.11.0" 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
44 changes: 43 additions & 1 deletion WPFExample/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using ChartIQ.Finsemble.FDC3.Types;
using Microsoft.IdentityModel.Tokens;
using System.Windows.Interop;
using ChartIQ.Finsemble.FDC3.Interfaces;
using System.Diagnostics;

namespace WPFExample
{
Expand Down Expand Up @@ -60,7 +62,16 @@ private async void SpawnComponent_Click(object sender, RoutedEventArgs e)
}
});

var appId = await FSBL.FDC3Client.DesktopAgentClient.Open(componentName, context);
// Check if the component able to receive the context
var contextToSend = await ShouldSendContextToComponent(context, componentName) ? context : null;
try
{
var appId = await FSBL.FDC3Client.DesktopAgentClient.Open(componentName, contextToSend);
}
catch(Exception ex)
{
Trace.TraceError($"Failed to open the app: {ex.Message}");
}

//Intent
//var context = new Context(new JObject
Expand Down Expand Up @@ -371,6 +382,18 @@ await FSBL.getDispatcher().Invoke(async delegate //main thread
//});

WindowReady?.Invoke(this, EventArgs.Empty);

_ = Task.Run(async () =>
{
await Task.Delay(5000);
Dispatcher.Invoke(delegate
{
Width = 1600;
Height = 60;
Top = 200;
Left = 200;
});
});
}

private void Logger_OnLog(object sender, JObject e)
Expand Down Expand Up @@ -553,5 +576,24 @@ private void Subscribe_to_pubsub()
}
});
}

/// <summary>
/// check if the component able to receive the context
/// </summary>
private async Task<bool> ShouldSendContextToComponent(IContext context, string componentName)
{
var componentConfig = (await FSBL.ConfigClient.Get(new[] { "finsemble", "components", componentName }))?.response;
var intents = componentConfig?["appConfig"]?["interop"]?["intents"]?["listensFor"]?.Children();

foreach (var intent in intents)
{
if (intent?.First?["contexts"]?.ToString().Contains(context.Type) == true)
{
return true;
}
}

return false;
}
}
}
4 changes: 2 additions & 2 deletions WPFExample/WPFExample.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.3.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.9.3\lib\net452\Finsemble.dll</HintPath>
<Reference Include="Finsemble, Version=8.11.0.0, Culture=neutral, PublicKeyToken=9df516fcbc4ebe73, processorArchitecture=MSIL">
<HintPath>..\packages\Finsemble.8.11.0\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 Down
2 changes: 1 addition & 1 deletion WPFExample/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.3" targetFramework="net452" />
<package id="Finsemble" version="8.11.0" 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
28 changes: 27 additions & 1 deletion WPFExampleCore/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
Expand Down Expand Up @@ -405,7 +406,16 @@ private async void SpawnComponent_Click(object sender, RoutedEventArgs e)
}
});

var appId = await FSBL.Clients.Fdc3Client.DesktopAgentClient.Open(componentName, context);
// Check if the component able to receive the context
var contextToSend = await ShouldSendContextToComponent(context, componentName) ? context : null;
try
{
var appId = await FSBL.Clients.Fdc3Client.DesktopAgentClient.Open(componentName, contextToSend);
}
catch (Exception ex)
{
Trace.TraceError($"Failed to open the app: {ex.Message}");
}
}
else
{
Expand All @@ -414,6 +424,22 @@ private async void SpawnComponent_Click(object sender, RoutedEventArgs e)
}
}

private async Task<bool> ShouldSendContextToComponent(Context context, string componentName)
{
var componentConfig = (await FSBL.Clients.ConfigClient.Get(new[] { "finsemble", "components", componentName }))?.response;
var intents = componentConfig?["appConfig"]?["interop"]?["intents"]?["listensFor"]?.Children();

foreach (var intent in intents)
{
if (intent?.First?["contexts"]?.ToString().Contains(context.Type) == true)
{
return true;
}
}

return false;
}

private void Send_Click(object sender, RoutedEventArgs e)
{
if (FSBL.Clients.Fdc3Client is object)
Expand Down
Loading

0 comments on commit 7d414e7

Please sign in to comment.