diff --git a/multiwindow-demo/MultiWindowDemo/MainWindow.xaml.cs b/multiwindow-demo/MultiWindowDemo/MainWindow.xaml.cs
index fe3eba3..9b3eadf 100644
--- a/multiwindow-demo/MultiWindowDemo/MainWindow.xaml.cs
+++ b/multiwindow-demo/MultiWindowDemo/MainWindow.xaml.cs
@@ -1,43 +1,24 @@
-using DOT.Core.Extensions;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading;
+using System;
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.Navigation;
-using System.Windows.Shapes;
+using DOT.Core.Extensions;
using Tick42;
using Tick42.AppManager;
using Tick42.StartingContext;
using Tick42.Windows;
+using static MultiWindowDemo.ChartWindow;
namespace MultiWindowDemo
{
///
- /// Interaction logic for MainWindow.xaml
+ /// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
- public Glue42 glue42_;
+ private const string ChartWindowAppName = "ChartChild";
+ private const string ColorWindowAppName = "ColorChild";
- // The shape of the state that will be saved and restored with the window
- public class AppState
- {
- public int SelectedIndex { get; set; }
- }
-
- public string TabGroupId { get; set; }
-
- private readonly string ColorWindowAppName = "ColorChild";
- private readonly string ChartWindowAppName = "ChartChild";
+ private Glue42 glue42_;
public MainWindow()
{
@@ -45,17 +26,17 @@ public MainWindow()
var initializeOptions = new InitializeOptions();
initializeOptions.SetSaveRestoreStateEndpoint(_ =>
- // Returning the state that has to be saved when the applicaiton is saved in a layout
- // In this case the app saves the selected color from the dropdown
- new AppState
- {
- SelectedIndex = ColorSelector.SelectedIndex
- }.AsCompletedTask(), null, Dispatcher);
+ // Returning the state that has to be saved when the applicaiton is saved in a layout
+ // In this case the app saves the selected color from the dropdown
+ new AppState
+ {
+ SelectedIndex = ColorSelector.SelectedIndex
+ }.AsCompletedTask(), null, Dispatcher);
Task g = Glue42.InitializeGlue(initializeOptions);
// Registering the main window and then continuing with the registration of the additional applications
- RegisterMainWindow(g).ContinueWith(r =>
+ RegisterMainWindow(g).ContinueWith(async r =>
{
// glue will be initialized with the registration of the main window
glue42_ = g.Result;
@@ -63,108 +44,122 @@ public MainWindow()
var appState = glue42_.GetRestoreState();
ColorSelector.SelectedIndex = appState?.SelectedIndex ?? -1;
- RegisterColorApp();
- RegisterChartApp();
+ await RegisterChartApp().ConfigureAwait(false);
+ await RegisterColorApp().ConfigureAwait(false);
}, TaskScheduler.FromCurrentSynchronizationContext());
}
- private void Color_Click(object sender, RoutedEventArgs e)
- {
- var currColor = "#FFFFFF"; // white is the default color
-
- if (ColorSelector.SelectedItem != null)
- {
- currColor = ((SolidColorBrush)((Rectangle)ColorSelector.SelectedItem).Fill).Color.ToString();
- }
-
- var colorWindow = new ColorWindow(currColor);
- var synchronizationContext = SynchronizationContext.Current;
+ public string TabGroupId { get; set; }
- // First the window is registered as a GlueWindow and then an instance of the application which corresponds to the window is registered
- RegisterColorWindow(colorWindow).ContinueWith(r =>
+ private async void Color_Click(object sender, RoutedEventArgs e)
+ {
+ var cxt = AppManagerContext.CreateNew();
+ cxt.SetObject(new ColorWindow.State
{
- glue42_.AppManager.RegisterInstance(ColorWindowAppName, r.Result.Id, colorWindow, synchronizationContext);
- });
- // Too see how to do it in one invocation please see Chart_Click
+ RectangleColor = "#AAAAAA"
+ }, glue42_.AGMObjectSerializer);
+ await (await glue42_.AppManager.AwaitApplication(app => app.Name == ColorWindowAppName)).Start(cxt);
}
- private void Chart_Click(object sender, RoutedEventArgs e)
+ private void AssociateWindowToAppInstance()
{
var chartWindow = new ChartWindow();
- var synchronizationContext = SynchronizationContext.Current;
- var placement = new GlueWindowScreenPlacement().WithTabGroupId(TabGroupId); // Adding the tab group id so the chart window appears in the same tab group as the main window
+ var placement =
+ new GlueWindowScreenPlacement()
+ .WithTabGroupId(
+ TabGroupId); // Adding the tab group id so the chart window appears in the same tab group as the main window
// With the RegisterAppWindow invocation both the window and an instance of the application are being registered
glue42_.GlueWindows.RegisterAppWindow(chartWindow, chartWindow, ChartWindowAppName,
builder => builder
- .WithPlacement(placement)
- .WithType(GlueWindowType.Tab)
- .WithTitle(ChartWindowAppName));
+ .WithPlacement(placement)
+ .WithType(GlueWindowType.Tab)
+ .WithTitle(ChartWindowAppName));
+
+ // alternatively if you have a GlueWindow you can use glue42_.AppManager.RegisterInstance to bind it as an application instance
+ }
+
+ private async void Chart_Click(object sender, RoutedEventArgs e)
+ {
+ var cxt = AppManagerContext.CreateNew();
+ cxt.SetObject(new SymbolState
+ {
+ ActiveSymbol = "FIRST.L"
+ }, glue42_.AGMObjectSerializer);
+ await (await glue42_.AppManager.AwaitApplication(app => app.Name == ChartWindowAppName)).Start(
+ cxt);
}
private Task RegisterMainWindow(Task initGlueTask)
{
TabGroupId = Guid.NewGuid().ToString();
return initGlueTask.RegisterWindow(this, gwo =>
- {
- gwo.WithChannelSupport(true).WithTitle("MultiWindowWPF").WithType(GlueWindowType.Tab);
-
- // Making sure that the TabGroupId is correct, so the windows can be opened in the same tab group when started from the MainWindow
- if (gwo.Placement is GlueWindowScreenPlacement placement && placement.TabGroupId == null)
- {
- placement.WithTabGroupId(TabGroupId);
- }
- else if (gwo.Placement == null)
- {
- gwo.Placement = new GlueWindowScreenPlacement().WithTabGroupId(TabGroupId);
- }
- else if (gwo.Placement is GlueWindowScreenPlacement screenPlacement && screenPlacement.TabGroupId != null)
- {
- TabGroupId = screenPlacement.TabGroupId;
- }
- });
+ {
+ gwo.WithChannelSupport(true).WithTitle("MultiWindowWPF").WithType(GlueWindowType.Tab);
+
+ // Making sure that the TabGroupId is correct, so the windows can be opened in the same tab group when started from the MainWindow
+ if (gwo.Placement is GlueWindowScreenPlacement placement && placement.TabGroupId == null)
+ {
+ placement.WithTabGroupId(TabGroupId);
+ }
+ else if (gwo.Placement == null)
+ {
+ gwo.Placement = new GlueWindowScreenPlacement().WithBounds(new GlueWindowBounds(0, 0, 600, 600))
+ .WithTabGroupId(TabGroupId);
+ }
+ else if (gwo.Placement is GlueWindowScreenPlacement screenPlacement &&
+ screenPlacement.TabGroupId != null)
+ {
+ TabGroupId = screenPlacement.TabGroupId;
+ }
+ });
}
- private void RegisterColorApp()
+ private async Task RegisterColorApp()
{
- // Registering the WPF window as a Glue application and providing the shape of its state
- glue42_.AppManager.RegisterWPFApp(app =>
+ var baseApp = await glue42_.AppManager
+ .AwaitApplication(app => app.Name == ChartWindowAppName).ConfigureAwait(false);
+
+ var baseDefinition = await baseApp.GetFullConfig().ConfigureAwait(false);
+ try
{
- app.WithName(ColorWindowAppName)
- .WithTitle(ColorWindowAppName)
- .WithContext(this)
- .WithType(GlueWindowType.Tab);
- });
+ await glue42_.AppManager
+ .RegisterWPFAppAsync(
+ app =>
+ {
+ app.WithAppDefinitionModifier(appDef =>
+ {
+ baseDefinition.Title = ColorWindowAppName;
+ baseDefinition.Name = ColorWindowAppName;
+ baseDefinition.Details.Owner = glue42_.InitializeOptions.ApplicationName;
+ baseDefinition.Details.WindowStyle = null;
+ baseDefinition.Type = ApplicationType.ChildWindow;
+ return baseDefinition;
+ });
+ }).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e);
+ }
}
- private void RegisterChartApp()
+ private Task RegisterChartApp()
{
// Registering the WPF window as a Glue application and providing the shape of its state
- glue42_.AppManager.RegisterWPFApp((app) =>
+ return glue42_.AppManager.RegisterWPFAppAsync(app =>
{
app.WithName(ChartWindowAppName)
- .WithTitle(ChartWindowAppName)
- .WithContext(this)
- .WithType(GlueWindowType.Tab);
+ .WithTitle(ChartWindowAppName)
+ .WithContext(this)
+ .WithType(GlueWindowType.Tab);
});
}
- private Task RegisterColorWindow(Window colorWindow)
+ // The shape of the state that will be saved and restored with the window
+ public class AppState
{
- return glue42_.AsCompletedTask().RegisterWindow(colorWindow, gwo =>
- {
- gwo.WithTitle(ColorWindowAppName).WithType(GlueWindowType.Tab);
-
- // Making sure the TabGroupId is correct, so the windows can be opened in the same tab group when started from the MainWindow
- if (gwo.Placement is GlueWindowScreenPlacement placement && placement.TabGroupId == null)
- {
- placement.WithTabGroupId(TabGroupId);
- }
- else if (gwo.Placement == null)
- {
- gwo.Placement = new GlueWindowScreenPlacement().WithTabGroupId(TabGroupId);
- }
- });
+ public int SelectedIndex { get; set; }
}
}
-}
+}
\ No newline at end of file
diff --git a/multiwindow-demo/MultiWindowDemo/MultiWindowDemo.csproj b/multiwindow-demo/MultiWindowDemo/MultiWindowDemo.csproj
index c4ad696..6d40038 100644
--- a/multiwindow-demo/MultiWindowDemo/MultiWindowDemo.csproj
+++ b/multiwindow-demo/MultiWindowDemo/MultiWindowDemo.csproj
@@ -34,8 +34,8 @@
4
-
- ..\packages\Glue42.2018.2174.0.0\lib\net45\Glue42.dll
+
+ ..\packages\io.Connect.NET.1.27.0.0\lib\net45\ioConnectNET.dll
..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll
diff --git a/multiwindow-demo/MultiWindowDemo/packages.config b/multiwindow-demo/MultiWindowDemo/packages.config
index ddfcd76..76fac92 100644
--- a/multiwindow-demo/MultiWindowDemo/packages.config
+++ b/multiwindow-demo/MultiWindowDemo/packages.config
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file