diff --git a/AuthenticationExample/App.xaml.cs b/AuthenticationExample/App.xaml.cs index 0d19081..0c5b9f5 100644 --- a/AuthenticationExample/App.xaml.cs +++ b/AuthenticationExample/App.xaml.cs @@ -1,25 +1,38 @@ using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; using System.Diagnostics; -using System.Linq; -using System.Threading.Tasks; using System.Windows; namespace AuthenticationExample { - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - protected override void OnStartup(StartupEventArgs e) - { + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + protected override void OnStartup(StartupEventArgs e) + { #if DEBUG Debugger.Launch(); #endif - var mainWindow = new MainWindow(e.Args); - } - } + +#if LOGGING && TRACE + TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log"); + logger.TraceOutputOptions = TraceOptions.DateTime; + + Trace.Listeners.Add(logger); + Trace.AutoFlush = true; + Trace.TraceInformation("Logging started"); +#endif + try + { + var mainWindow = new MainWindow(e.Args); // send command line arguments to main window. + } + catch (Exception ex) + { + Trace.TraceError(ex.ToString()); + Trace.TraceInformation("Shutting down"); + this.Shutdown(); + } + } + } } diff --git a/AuthenticationExample/AuthenticationExample.csproj b/AuthenticationExample/AuthenticationExample.csproj index dc0241e..a090b7d 100644 --- a/AuthenticationExample/AuthenticationExample.csproj +++ b/AuthenticationExample/AuthenticationExample.csproj @@ -21,7 +21,7 @@ full false bin\Debug\ - DEBUG;TRACE + DEBUG;TRACE;LOGGING prompt 4 @@ -30,7 +30,7 @@ pdbonly true bin\Release\ - TRACE + TRACE;LOGGING prompt 4 @@ -49,8 +49,8 @@ ..\packages\DotNetZip.1.16.0\lib\net40\DotNetZip.dll - - ..\packages\Finsemble.7.1.1\lib\net452\Finsemble.dll + + ..\packages\Finsemble.7.2.0\lib\net452\Finsemble.dll ..\packages\Microsoft.IdentityModel.Logging.6.16.0\lib\net45\Microsoft.IdentityModel.Logging.dll @@ -64,12 +64,26 @@ ..\packages\PInvoke.Windows.Core.0.6.49\lib\net20\PInvoke.Windows.Core.dll + + ..\packages\Polly.7.2.3\lib\netstandard1.1\Polly.dll + ..\packages\SuperSocket.ClientEngine.Core.0.10.0\lib\net45\SuperSocket.ClientEngine.dll + + ..\packages\System.Collections.Immutable.1.7.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll + diff --git a/AuthenticationExample/packages.config b/AuthenticationExample/packages.config index 5adc8c7..e5cbb78 100644 --- a/AuthenticationExample/packages.config +++ b/AuthenticationExample/packages.config @@ -1,12 +1,46 @@  - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FDC3WPFExample/App.xaml.cs b/FDC3WPFExample/App.xaml.cs index 9e78f7f..4dc12a2 100644 --- a/FDC3WPFExample/App.xaml.cs +++ b/FDC3WPFExample/App.xaml.cs @@ -1,36 +1,50 @@ using ChartIQ.Finsemble; +using System; using System.Diagnostics; using System.Windows; namespace FDC3WPFExample { - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - private MainWindow mainWindow = null; - - protected override void OnStartup(StartupEventArgs e) - { - Debug.Print("OnStartup"); + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + private MainWindow mainWindow = null; + protected override void OnStartup(StartupEventArgs e) + { #if DEBUG Debugger.Launch(); #endif - mainWindow = new MainWindow(e.Args); // send command line arguments to main window. - } - private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) - { -#if DEBUG - Debugger.Launch(); +#if LOGGING && TRACE + TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log"); + logger.TraceOutputOptions = TraceOptions.DateTime; + + Trace.Listeners.Add(logger); + Trace.AutoFlush = true; + Trace.TraceInformation("Logging started"); #endif + try + { + mainWindow = new MainWindow(e.Args); // send command line arguments to main window. + } + catch (Exception ex) + { + Trace.TraceError(ex.ToString()); + Trace.TraceInformation("Shutting down"); + this.Shutdown(); + } + } - Finsemble.DispatcherUnhandledException(mainWindow, e); + private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) + { + Finsemble.DispatcherUnhandledException(mainWindow, e); - Debug.Print($"An Unhandled Exception has occurred. Exception: {e.Exception}"); - Shutdown(); - } - } + Trace.TraceError($"An Unhandled Exception has occurred. Exception: {e.Exception}"); + Trace.TraceInformation("Shutting down"); + Shutdown(); + } + } } diff --git a/FDC3WPFExample/FDC3WPFExample.csproj b/FDC3WPFExample/FDC3WPFExample.csproj index 02e0a86..a10f32d 100644 --- a/FDC3WPFExample/FDC3WPFExample.csproj +++ b/FDC3WPFExample/FDC3WPFExample.csproj @@ -21,7 +21,7 @@ full false bin\Debug\ - DEBUG;TRACE + DEBUG;TRACE;LOGGING prompt 4 @@ -30,7 +30,7 @@ pdbonly true bin\Release\ - TRACE + TRACE;LOGGING prompt 4 @@ -49,8 +49,8 @@ ..\packages\DotNetZip.1.16.0\lib\net40\DotNetZip.dll - - ..\packages\Finsemble.7.1.1\lib\net452\Finsemble.dll + + ..\packages\Finsemble.7.2.0\lib\net452\Finsemble.dll ..\packages\Microsoft.IdentityModel.Logging.6.16.0\lib\net45\Microsoft.IdentityModel.Logging.dll @@ -64,11 +64,23 @@ ..\packages\PInvoke.Windows.Core.0.6.49\lib\net20\PInvoke.Windows.Core.dll - - ..\packages\SuperSocket.ClientEngine.Core.0.10.0\lib\net45\SuperSocket.ClientEngine.dll + + ..\packages\Polly.7.2.3\lib\netstandard1.1\Polly.dll + + ..\packages\System.Collections.Immutable.1.7.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll + @@ -80,9 +92,6 @@ - - ..\packages\WebSocket4Net.0.15.2\lib\net45\WebSocket4Net.dll - diff --git a/FDC3WPFExample/packages.config b/FDC3WPFExample/packages.config index fcf5567..4e32424 100644 --- a/FDC3WPFExample/packages.config +++ b/FDC3WPFExample/packages.config @@ -1,11 +1,44 @@  - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MultiWindowExample/App.xaml.cs b/MultiWindowExample/App.xaml.cs index 5800167..2c46c21 100644 --- a/MultiWindowExample/App.xaml.cs +++ b/MultiWindowExample/App.xaml.cs @@ -44,39 +44,49 @@ public static void Main(string[] args) #if DEBUG Debugger.Launch(); #endif - // create a global mutex - using (var mutex = new Mutex(false, "Finsemble")) - { - var mutexAcquired = false; - try - { - // acquire the mutex (or timeout after 60 seconds) - // will return false if it timed out - mutexAcquired = mutex.WaitOne(60000); - } - catch (AbandonedMutexException) - { - // abandoned mutexes are still acquired, we just need - // to handle the exception and treat it as acquisition - mutexAcquired = true; - } - - // if it wasn't acquired, it timed out, so can handle that how ever we want - if (!mutexAcquired) - { - Console.WriteLine("I have timed out acquiring the mutex and can handle that somehow"); - return; - } - - // otherwise, we've acquired the mutex and should do what we need to do, - // then ensure that we always release the mutex - if (SingleInstance.InitializeAsFirstInstance(Unique)) - { - application = new App(); - - // If window type passed for initial launch, add listener to launch window when connected. - var argsList = args.ToList(); - IEnumerable nonFSBLArgs = GetNonFinsembleArgs(argsList); + +#if LOGGING && TRACE + TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log"); + logger.TraceOutputOptions = TraceOptions.DateTime; + + Trace.Listeners.Add(logger); + Trace.AutoFlush = true; + Trace.TraceInformation("Logging started"); +#endif + + // create a global mutex + using (var mutex = new Mutex(false, "Finsemble")) + { + var mutexAcquired = false; + try + { + // acquire the mutex (or timeout after 60 seconds) + // will return false if it timed out + mutexAcquired = mutex.WaitOne(60000); + } + catch (AbandonedMutexException) + { + // abandoned mutexes are still acquired, we just need + // to handle the exception and treat it as acquisition + mutexAcquired = true; + } + + // if it wasn't acquired, it timed out, so can handle that how ever we want + if (!mutexAcquired) + { + Console.WriteLine("I have timed out acquiring the mutex and can handle that somehow"); + return; + } + + // otherwise, we've acquired the mutex and should do what we need to do, + // then ensure that we always release the mutex + if (SingleInstance.InitializeAsFirstInstance(Unique)) + { + application = new App(); + + // If window type passed for initial launch, add listener to launch window when connected. + var argsList = args.ToList(); + IEnumerable nonFSBLArgs = GetNonFinsembleArgs(argsList); if ((nonFSBLArgs != null) && nonFSBLArgs.Any()) { // Non-finsemble arguments passed, launch window @@ -92,13 +102,13 @@ public static void Main(string[] args) } application.InitializeComponent(); - mutex.ReleaseMutex(); - application.Run(); + mutex.ReleaseMutex(); + application.Run(); - // Allow single instance code to perform cleanup operations - SingleInstance.Cleanup(); - } - } + // Allow single instance code to perform cleanup operations + SingleInstance.Cleanup(); + } + } } /// @@ -148,7 +158,7 @@ private static bool LaunchWindow(IList args) if (window == null) { - Debug.Print($"Could not create window: {name}"); + Trace.TraceWarning($"Could not create window: {name}"); } else { @@ -160,7 +170,7 @@ private static bool LaunchWindow(IList args) IIntegratable fsblWin = window as IIntegratable; if (fsblWin == null) { - Debug.Print($"The window \"{name}\" is not a window that can be integrated into Finsemble."); + Trace.TraceWarning($"The window \"{name}\" is not a window that can be integrated into Finsemble."); } else { @@ -173,9 +183,9 @@ private static bool LaunchWindow(IList args) // Dispose of Finsemble object when window is closed. window.Closed += (s, e) => { - Debug.WriteLine("disposing window from app.xaml"); + Trace.TraceInformation("disposing window from app.xaml"); fsbl.Dispose(); - Debug.WriteLine("dispose completed"); + Trace.TraceInformation("dispose completed"); }; fsbl.Connect("MultiWindowExample", JWK); diff --git a/MultiWindowExample/MultiWindowExample.csproj b/MultiWindowExample/MultiWindowExample.csproj index 56b82ac..a11152b 100644 --- a/MultiWindowExample/MultiWindowExample.csproj +++ b/MultiWindowExample/MultiWindowExample.csproj @@ -21,7 +21,7 @@ full false bin\Debug\ - DEBUG;TRACE + DEBUG;TRACE;LOGGING prompt 4 @@ -30,7 +30,7 @@ pdbonly true bin\Release\ - TRACE + TRACE;LOGGING prompt 4 @@ -49,8 +49,8 @@ ..\packages\DotNetZip.1.16.0\lib\net40\DotNetZip.dll - - ..\packages\Finsemble.7.1.1\lib\net452\Finsemble.dll + + ..\packages\Finsemble.7.2.0\lib\net452\Finsemble.dll ..\packages\Microsoft.IdentityModel.Logging.6.16.0\lib\net45\Microsoft.IdentityModel.Logging.dll @@ -64,13 +64,27 @@ ..\packages\PInvoke.Windows.Core.0.6.49\lib\net20\PInvoke.Windows.Core.dll + + ..\packages\Polly.7.2.3\lib\netstandard1.1\Polly.dll + ..\packages\SuperSocket.ClientEngine.Core.0.10.0\lib\net45\SuperSocket.ClientEngine.dll + + ..\packages\System.Collections.Immutable.1.7.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll + diff --git a/MultiWindowExample/packages.config b/MultiWindowExample/packages.config index 5adc8c7..e5cbb78 100644 --- a/MultiWindowExample/packages.config +++ b/MultiWindowExample/packages.config @@ -1,12 +1,46 @@  - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WPFExample/App.xaml.cs b/WPFExample/App.xaml.cs index a4238c2..2506c70 100644 --- a/WPFExample/App.xaml.cs +++ b/WPFExample/App.xaml.cs @@ -15,23 +15,38 @@ public partial class App : Application protected override void OnStartup(StartupEventArgs e) { - Debug.Print("OnStartup"); - #if DEBUG - Debugger.Launch(); + Debugger.Launch(); +#endif + +#if LOGGING && TRACE + TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log"); + logger.TraceOutputOptions = TraceOptions.DateTime; + + Trace.Listeners.Add(logger); + Trace.AutoFlush = true; + Trace.TraceInformation("Logging started"); #endif - mainWindow = new MainWindow(e.Args); // send command line arguments to main window. + + try + { + mainWindow = new MainWindow(e.Args); // send command line arguments to main window. + } + catch (Exception ex) + { + Trace.TraceError(ex.ToString()); + Trace.TraceInformation("Shutting down"); + this.Shutdown(); + } } private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { -#if DEBUG - Debugger.Launch(); -#endif LogUnhandledException(e.Exception); Finsemble.DispatcherUnhandledException(mainWindow, e); - Debug.Print($"An Unhandled Exception has occurred. Exception: {e.Exception}"); + Trace.TraceError($"An Unhandled Exception has occurred. Exception: {e.Exception}"); + Trace.TraceInformation("Shutting down"); Shutdown(); } diff --git a/WPFExample/WPFExample.csproj b/WPFExample/WPFExample.csproj index 64d8372..cc8d098 100644 --- a/WPFExample/WPFExample.csproj +++ b/WPFExample/WPFExample.csproj @@ -21,7 +21,7 @@ full false bin\Debug\ - DEBUG;TRACE + TRACE;DEBUG;LOGGING prompt 4 @@ -30,7 +30,7 @@ pdbonly true bin\Release\ - TRACE + TRACE;LOGGING prompt 4 @@ -49,8 +49,8 @@ ..\packages\DotNetZip.1.16.0\lib\net40\DotNetZip.dll - - ..\packages\Finsemble.7.1.1\lib\net452\Finsemble.dll + + ..\packages\Finsemble.7.2.0\lib\net452\Finsemble.dll ..\packages\Microsoft.IdentityModel.Logging.6.16.0\lib\net45\Microsoft.IdentityModel.Logging.dll @@ -64,11 +64,23 @@ ..\packages\PInvoke.Windows.Core.0.6.49\lib\net20\PInvoke.Windows.Core.dll - - ..\packages\SuperSocket.ClientEngine.Core.0.10.0\lib\net45\SuperSocket.ClientEngine.dll + + ..\packages\Polly.7.2.3\lib\netstandard1.1\Polly.dll + + ..\packages\System.Collections.Immutable.1.7.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll + @@ -80,9 +92,6 @@ - - ..\packages\WebSocket4Net.0.15.2\lib\net45\WebSocket4Net.dll - diff --git a/WPFExample/packages.config b/WPFExample/packages.config index fcf5567..4e32424 100644 --- a/WPFExample/packages.config +++ b/WPFExample/packages.config @@ -1,11 +1,44 @@  - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WPFExampleCore/App.xaml.cs b/WPFExampleCore/App.xaml.cs index be1406a..8329d0c 100644 --- a/WPFExampleCore/App.xaml.cs +++ b/WPFExampleCore/App.xaml.cs @@ -10,39 +10,54 @@ namespace WPFExampleCore /// public partial class App : Application { - private MainWindow mainWindow = null; - - protected override void OnStartup(StartupEventArgs e) - { - Debug.Print("OnStartup"); + private MainWindow mainWindow = null; + protected override void OnStartup(StartupEventArgs e) + { #if DEBUG - Debugger.Launch(); + Debugger.Launch(); #endif - mainWindow = new MainWindow(e.Args); // send command line arguments to main window. - } - private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) - { -#if DEBUG - Debugger.Launch(); +#if LOGGING && TRACE + TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log"); + logger.TraceOutputOptions = TraceOptions.DateTime; + + Trace.Listeners.Add(logger); + Trace.AutoFlush = true; + Trace.TraceInformation("Logging started"); #endif - LogUnhandledException(e.Exception); - Debug.Print($"An Unhandled Exception has occurred. Exception: {e.Exception}"); - Shutdown(); - } - - private void LogUnhandledException(Exception e) - { - using (StreamWriter sw = new StreamWriter("Critical exceptions.log", true)) - { - sw.WriteLine($"{DateTime.Now.ToUniversalTime()} - {e.Message}"); - sw.WriteLine(e.StackTrace); - sw.WriteLine(); - sw.Close(); - } - - if (e.InnerException != null) LogUnhandledException(e.InnerException); - } - } + + try + { + mainWindow = new MainWindow(e.Args); // send command line arguments to main window. + } + catch (Exception ex) + { + Trace.TraceError(ex.ToString()); + Trace.TraceInformation("Shutting down"); + this.Shutdown(); + } + } + + private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) + { + LogUnhandledException(e.Exception); + Trace.TraceError($"An Unhandled Exception has occurred. Exception: {e.Exception}"); + Trace.TraceInformation("Shutting down"); + Shutdown(); + } + + private void LogUnhandledException(Exception e) + { + using (StreamWriter sw = new StreamWriter("Critical exceptions.log", true)) + { + sw.WriteLine($"{DateTime.Now.ToUniversalTime()} - {e.Message}"); + sw.WriteLine(e.StackTrace); + sw.WriteLine(); + sw.Close(); + } + + if (e.InnerException != null) LogUnhandledException(e.InnerException); + } + } } diff --git a/WPFExampleCore/WPFExampleCore.csproj b/WPFExampleCore/WPFExampleCore.csproj index e9ff662..60d2053 100644 --- a/WPFExampleCore/WPFExampleCore.csproj +++ b/WPFExampleCore/WPFExampleCore.csproj @@ -8,12 +8,28 @@ 7.1.1 + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + - + diff --git a/WPFMultiWindowExampleCore/AppStartup.cs b/WPFMultiWindowExampleCore/AppStartup.cs index 6ffc028..086d0f2 100644 --- a/WPFMultiWindowExampleCore/AppStartup.cs +++ b/WPFMultiWindowExampleCore/AppStartup.cs @@ -28,6 +28,16 @@ public static void Main(string[] args) #if DEBUG Debugger.Launch(); #endif + +#if LOGGING && TRACE + TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log"); + logger.TraceOutputOptions = TraceOptions.DateTime; + + Trace.Listeners.Add(logger); + Trace.AutoFlush = true; + Trace.TraceInformation("Logging started"); +#endif + // create a global mutex using (var mutex = new Mutex(false, "Finsemble")) { @@ -139,7 +149,7 @@ private static Window CreateWindow(string[] args) default: { // Unknown window, ignore - Debug.Print($"Could not create window: {name}"); + Trace.TraceError($"Could not create window: {name}"); break; } } @@ -165,10 +175,7 @@ private static IEnumerable GetNonFinsembleArgs(IList args) /// private static void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { -#if DEBUG - Debugger.Launch(); -#endif - Debug.Print($"An Unhandled Exception has occurred. {e.Exception.Message}"); + Trace.TraceError($"An Unhandled Exception has occurred. {e.Exception.Message}"); MessageBox.Show("An Unhandled Exception has occurred. Please Check your event Logs."); } } diff --git a/WPFMultiWindowExampleCore/MainWindow.xaml.cs b/WPFMultiWindowExampleCore/MainWindow.xaml.cs index f532f6a..2c4e58a 100644 --- a/WPFMultiWindowExampleCore/MainWindow.xaml.cs +++ b/WPFMultiWindowExampleCore/MainWindow.xaml.cs @@ -69,7 +69,7 @@ private async void ConnectToFinsemble(string[] args) private void Finsemble_Connected(object sender, EventArgs e) { - Debug.WriteLine("FSBL connected"); + Trace.TraceInformation("FSBL connected"); Application.Current.Dispatcher.Invoke(() => { @@ -109,7 +109,7 @@ private void Finsemble_Connected(object sender, EventArgs e) Show(); }); - Debug.Print($"The window \"{this.LabelWindowName.Content}\" is connected to Finsemble."); + Trace.TraceInformation($"The window \"{this.LabelWindowName.Content}\" is connected to Finsemble."); } } } diff --git a/WPFMultiWindowExampleCore/SingleInstance.cs b/WPFMultiWindowExampleCore/SingleInstance.cs index bffc4d9..5c46e22 100644 --- a/WPFMultiWindowExampleCore/SingleInstance.cs +++ b/WPFMultiWindowExampleCore/SingleInstance.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO.Pipes; using System.Text.Json; using System.Threading; @@ -162,7 +163,7 @@ private static void CreateRemoteService(string channelName) } catch (Exception ex) { - System.Diagnostics.Debug.Print(ex.Message); + Trace.TraceError(ex.Message); } finally { @@ -204,7 +205,7 @@ private static void SignalFirstInstance(string channelName, IList args) } catch (Exception ex) { - System.Diagnostics.Debug.Print(ex.Message); + Trace.TraceError(ex.Message); } } diff --git a/WPFMultiWindowExampleCore/WPFMultiWindowExampleCore.csproj b/WPFMultiWindowExampleCore/WPFMultiWindowExampleCore.csproj index 845b586..100f052 100644 --- a/WPFMultiWindowExampleCore/WPFMultiWindowExampleCore.csproj +++ b/WPFMultiWindowExampleCore/WPFMultiWindowExampleCore.csproj @@ -9,8 +9,24 @@ 7.1.1 + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + - + diff --git a/WindowlessExample.Core/Program.cs b/WindowlessExample.Core/Program.cs index 77eb2ba..13ea4f6 100644 --- a/WindowlessExample.Core/Program.cs +++ b/WindowlessExample.Core/Program.cs @@ -1,7 +1,6 @@ using System; +using System.Diagnostics; using System.Threading; -using Finsemble.Core; -using Finsemble.Core.Clients.Router; using Finsemble.Core.Events; using Microsoft.IdentityModel.Tokens; using Newtonsoft.Json.Linq; @@ -26,11 +25,20 @@ class Program Q = "4R0RUlCnmZRzEw9sqjwxMuvNM1BTSubvMvG0VIlBkYbCn9MOdwurBPxrYqnUcbw-q-qzQy6st6a4L-EAZSnfD3FEEFKeINOJK06l0EwjcLeP8B4YQ-bxd9UroXpl9ACiMqHzyvJCNOpw8A22nbjKVnVhW1E17F-LFAJoWBetYA0", QI = "PODgpJrXxPAp72v_O0fNfAhWjHLeTk9TfLARl9lzPpYIoYR5tgP1Y_A-3feH_xtCfkzcCskfXIerQlY9lVmqs-eGEYjfuuPVYIruN4OsskMY1nz-h_14clyUmUwfCQJDV4qjcAzf80IMu53jYEW1BydRf90snRjk1dYgSq_qtTQ", }; - + static void Main(string[] args) { #if DEBUG - System.Diagnostics.Debugger.Launch(); + Debugger.Launch(); +#endif + +#if LOGGING && TRACE + TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log"); + logger.TraceOutputOptions = TraceOptions.DateTime; + + Trace.Listeners.Add(logger); + Trace.AutoFlush = true; + Trace.TraceInformation("Logging started"); #endif FSBL = new Finsemble.Core.Finsemble(args, null); @@ -46,6 +54,10 @@ private static void OnConnected(object sender, EventArgs e) { FSBL.Clients.Logger.Log("Windowless example Core connected to Finsemble."); + // If the appd config contains ` "appService": true, "waitForInitialization": true `, + // signal to Finsemble that appService initialization is complete + FSBL.PublishReady(); + // Send log message every 5 seconds timer.Interval = 5 * 1000; timer.AutoReset = true; @@ -55,7 +67,8 @@ private static void OnConnected(object sender, EventArgs e) //Search provider example FSBL.Clients.SearchClient.Register( "Windowless example Core", - (o, args) => { + (o, args) => + { FSBL.Clients.Logger.Log("Received query", args.response?["data"]?["text"]); JArray results = new JArray{ new JObject { @@ -67,11 +80,13 @@ private static void OnConnected(object sender, EventArgs e) }; args.sendQueryMessage(new FinsembleEventResponse(results, null)); }, - (o, args) => { + (o, args) => + { FSBL.Clients.Logger.Log("Search result action clicked on", args.response["item"], "action:", args.response["action"]); args.sendQueryMessage(new FinsembleEventResponse("Performed search result action", null)); }, - (o, args) => { + (o, args) => + { FSBL.Clients.Logger.Log("Search provider title was click on"); args.sendQueryMessage(new FinsembleEventResponse("Performed search provider action", null)); }, diff --git a/WindowlessExample.Core/WindowlessExample.Core.csproj b/WindowlessExample.Core/WindowlessExample.Core.csproj index ff1781f..b28382d 100644 --- a/WindowlessExample.Core/WindowlessExample.Core.csproj +++ b/WindowlessExample.Core/WindowlessExample.Core.csproj @@ -7,8 +7,24 @@ 7.1.1 + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + - + diff --git a/WindowlessExample/Program.cs b/WindowlessExample/Program.cs index 0874a5b..dafc1bb 100644 --- a/WindowlessExample/Program.cs +++ b/WindowlessExample/Program.cs @@ -1,5 +1,6 @@ using System; using System.Threading; +using System.Diagnostics; using ChartIQ.Finsemble; using ChartIQ.Finsemble.Events; using ChartIQ.Finsemble.Router; @@ -32,6 +33,14 @@ static void Main(string[] args) #if DEBUG System.Diagnostics.Debugger.Launch(); #endif +#if LOGGING && TRACE + TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log"); + logger.TraceOutputOptions = TraceOptions.DateTime; + + Trace.Listeners.Add(logger); + Trace.AutoFlush = true; + Trace.TraceInformation("Logging started"); +#endif // Initialize Finsemble //Ensure that your window has been created (so that its window handle exists) before connecting to Finsemble. @@ -39,7 +48,7 @@ static void Main(string[] args) FSBL.Connected += OnConnected; FSBL.Disconnected += OnShutdown; FSBL.Connect("WindowlessExample", JWK); - + // Block main thread until worker is finished. autoEvent.WaitOne(); } @@ -48,6 +57,10 @@ private static void OnConnected(object sender, EventArgs e) { FSBL.Logger.Log("Windowless example connected to Finsemble."); + // If the appd config contains ` "appService": true, "waitForInitialization": true `, + // signal to Finsemble that appService initialization is complete + FSBL.PublishReady(); + // Send log message every 5 seconds timer.Interval = 5 * 1000; timer.AutoReset = true; @@ -56,8 +69,9 @@ private static void OnConnected(object sender, EventArgs e) //Search provider example FSBL.SearchClient.Register( - "Windowless example", - (object o, FinsembleQueryArgs args) => { + "Windowless example", + (object o, FinsembleQueryArgs args) => + { FSBL.Logger.Log("Received query", args.response?["data"]?["text"]); JArray results = new JArray{ new JObject { @@ -69,22 +83,25 @@ private static void OnConnected(object sender, EventArgs e) }; args.sendQueryMessage(new FinsembleEventResponse(results, null)); }, - (object o, FinsembleQueryArgs args) => { + (object o, FinsembleQueryArgs args) => + { FSBL.Logger.Log("Search result action clicked on", args.response["item"], "action:", args.response["action"]); args.sendQueryMessage(new FinsembleEventResponse("Performed search result action", null)); }, - (object o, FinsembleQueryArgs args) => { + (object o, FinsembleQueryArgs args) => + { FSBL.Logger.Log("Search provider title was click on"); args.sendQueryMessage(new FinsembleEventResponse("Performed search provider action", null)); }, - "Windowless example search provider", + "Windowless example search provider", (object o, FinsembleEventArgs args) => { if (args.error != null) { FSBL.Logger.Error("Error returned when registering as a search provider", args.error); - } else - { + } + else + { FSBL.Logger.Log("Registered search provider"); } } diff --git a/WindowlessExample/WindowlessExample.csproj b/WindowlessExample/WindowlessExample.csproj index 3483aed..ab7f952 100644 --- a/WindowlessExample/WindowlessExample.csproj +++ b/WindowlessExample/WindowlessExample.csproj @@ -21,7 +21,7 @@ full false bin\Debug\ - DEBUG;TRACE + DEBUG;TRACE;LOGGING prompt 4 @@ -30,7 +30,7 @@ pdbonly true bin\Release\ - TRACE + TRACE;LOGGING prompt 4 @@ -46,8 +46,8 @@ bin\x64\Release\ - - ..\packages\Finsemble.7.1.1\lib\net452\Finsemble.dll + + ..\packages\Finsemble.7.2.0\lib\net452\Finsemble.dll @@ -62,15 +62,26 @@ ..\packages\PInvoke.Windows.Core.0.6.49\lib\net20\PInvoke.Windows.Core.dll - - ..\packages\SuperSocket.ClientEngine.Core.0.10.0\lib\net45\SuperSocket.ClientEngine.dll + + ..\packages\Polly.7.2.3\lib\netstandard1.1\Polly.dll + + ..\packages\System.Collections.Immutable.1.7.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + + - - ..\packages\WebSocket4Net.0.15.2\lib\net45\WebSocket4Net.dll + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll + + diff --git a/WindowlessExample/packages.config b/WindowlessExample/packages.config index 304f972..7c6b013 100644 --- a/WindowlessExample/packages.config +++ b/WindowlessExample/packages.config @@ -1,10 +1,43 @@  - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WinformExample/FormExample.cs b/WinformExample/FormExample.cs index 84842ce..9a9f421 100644 --- a/WinformExample/FormExample.cs +++ b/WinformExample/FormExample.cs @@ -238,7 +238,7 @@ private void CreateLinkerPills(JArray allChannels) { if (!LinkerGroups.ContainsKey(channel["name"].ToString())) { - var label = channel["label"].ToString(); + var label = channel["label"]?.ToString() ?? channel["name"].ToString(); var button = new RoundedButton() { diff --git a/WinformExample/Program.cs b/WinformExample/Program.cs index 3ebb05f..de64ecf 100644 --- a/WinformExample/Program.cs +++ b/WinformExample/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using System.Threading; using System.Windows.Forms; @@ -14,6 +15,14 @@ static class Program [STAThread] static void Main() { +#if LOGGING && TRACE + TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log"); + logger.TraceOutputOptions = TraceOptions.DateTime; + + Trace.Listeners.Add(logger); + Trace.AutoFlush = true; + Trace.TraceInformation("Logging started"); +#endif string[] args = Environment.GetCommandLineArgs(); Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException); @@ -28,17 +37,20 @@ static void Main() static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { LogUnhandledException(e.Exception); + Trace.TraceInformation("Shutting down"); Application.Exit(); } static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { LogUnhandledException(e.ExceptionObject as Exception); + Trace.TraceInformation("Shutting down"); Application.Exit(); } static void LogUnhandledException(Exception e) { + Trace.TraceError(e.Message); using (StreamWriter sw = new StreamWriter("Critical exceptions.log", true)) { sw.WriteLine($"{DateTime.Now.ToUniversalTime()} - {e.Message}"); diff --git a/WinformExample/WinformExample.csproj b/WinformExample/WinformExample.csproj index 49b8043..cd8ddcc 100644 --- a/WinformExample/WinformExample.csproj +++ b/WinformExample/WinformExample.csproj @@ -22,7 +22,7 @@ full false bin\Debug\ - DEBUG;TRACE + DEBUG;TRACE;LOGGING prompt 4 @@ -31,7 +31,7 @@ pdbonly true bin\Release\ - TRACE + TRACE;LOGGING prompt 4 @@ -50,8 +50,8 @@ ..\packages\DotNetZip.1.16.0\lib\net40\DotNetZip.dll - - ..\packages\Finsemble.7.1.1\lib\net452\Finsemble.dll + + ..\packages\Finsemble.7.2.0\lib\net452\Finsemble.dll ..\packages\Microsoft.IdentityModel.Logging.6.16.0\lib\net45\Microsoft.IdentityModel.Logging.dll @@ -74,14 +74,26 @@ ..\packages\PInvoke.Windows.Core.0.6.49\lib\net20\PInvoke.Windows.Core.dll + + ..\packages\Polly.7.2.3\lib\netstandard1.1\Polly.dll + - - ..\packages\SuperSocket.ClientEngine.Core.0.10.0\lib\net45\SuperSocket.ClientEngine.dll - + + ..\packages\System.Collections.Immutable.1.7.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll + @@ -93,9 +105,6 @@ - - ..\packages\WebSocket4Net.0.15.2\lib\net45\WebSocket4Net.dll - diff --git a/WinformExample/packages.config b/WinformExample/packages.config index 3e8868e..2139411 100644 --- a/WinformExample/packages.config +++ b/WinformExample/packages.config @@ -1,14 +1,47 @@  - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WinformExampleCore/MainForm.cs b/WinformExampleCore/MainForm.cs index bcff1a3..ad0eb11 100644 --- a/WinformExampleCore/MainForm.cs +++ b/WinformExampleCore/MainForm.cs @@ -65,7 +65,7 @@ private async void ConnectToFinsemble() private async void Finsemble_Connected(object sender, EventArgs e) { - Debug.Print("FSBL Ready."); + Trace.TraceInformation("FSBL Ready."); _bridge.Clients.Logger.OnLog += Logger_OnLog; _bridge.Clients.Logger.Log(new JToken[] { "Winform Example Core connected to Finsemble." }); @@ -75,14 +75,27 @@ private async void Finsemble_Connected(object sender, EventArgs e) _bridge.Clients.RouterClient.Subscribe("Finsemble.WorkspaceService.groupUpdate", HandleWindowGrouping); #region FDC3 - // Listen to Fdc3Client state change to render connected channels - _bridge.Clients.Fdc3Client.StateChanged += Fdc3Client_StateChanged; ; - // Show joined channels - Fdc3Client_StateChanged(null, _bridge.Clients.Fdc3Client.LastStateChangedArgs); + if (_bridge.Clients.Fdc3Client != null) + { + // Listen to Fdc3Client state change to render connected channels + _bridge.Clients.Fdc3Client.StateChanged += Fdc3Client_StateChanged; + // Show joined channels + Fdc3Client_StateChanged(null, _bridge.Clients.Fdc3Client.LastStateChangedArgs); - // Example for Fdc3Client subscribe to specific context. The "*" for subscription to all contexts. - _contextListenter = _bridge.Clients.Fdc3Client.DesktopAgentClient.AddContextListener("fdc3.instrument", HandleContext); + // Example for Fdc3Client subscribe to specific context. The "*" for subscription to all contexts. + _contextListenter = _bridge.Clients.Fdc3Client.DesktopAgentClient.AddContextListener("fdc3.instrument", HandleContext); + } + #endregion + + #region Linker Client + if (_bridge.Clients.LinkerClient != null) + { + // Listen to Linker state change to render connected channels + _bridge.Clients.LinkerClient.OnStateChange(Fdc3Client_StateChanged); + // Example for LinkerClient subscribe + _bridge.Clients.LinkerClient.Subscribe("symbol", HandleLinkerData); + } #endregion //Example for Handling PubSub data @@ -238,6 +251,24 @@ private async void HandleComponentsList() } } + private void HandleLinkerData(object sender, FinsembleEventArgs response) + { + this.Invoke(new Action(() => + { + if (response.error != null) + { + _bridge.Clients.Logger.Error(new JToken[] { "Error when receiving linker data: ", response.error.ToString() }); + } + else if (response.response != null) + { + string value = response.response?["data"]?.ToString(); + DataLabel.Text = value; + SourceLabel.Text = "via Linker"; + DataToSendInput.Text = value; + } + })); + } + private void HandleContext(Context context) { _bridge.Clients.Logger.Debug($"Context received: {context.Value}"); @@ -352,7 +383,7 @@ private void CreateLinkerPills(JArray allChannels) { if (!LinkerGroups.ContainsKey(channel["name"].ToString())) { - var label = channel["label"].ToString(); + var label = channel["label"]?.ToString() ?? channel["name"].ToString(); var button = new Controls.RoundedButton() { @@ -454,7 +485,6 @@ private void HandleWindowGrouping(object sender, FinsembleEventArgs args) private void Logger_OnLog(object sender, JObject e) { - Debug.Print($"Logged message: {e.ToString()}"); MessagesRichBox.Invoke(new Action(() => { MessagesRichBox.Text += e + "\n\n"; @@ -488,21 +518,39 @@ private void LoadAndSetButtonsFont() private void LinkerButton_Click(object sender, EventArgs e) { - _bridge.Clients.Util.OpenLinkerWindow(); + if (_bridge.Clients.LinkerClient != null) + { + _bridge.Clients.LinkerClient.OpenLinkerWindow(); + } + else + { + _bridge.Clients.Util.OpenLinkerWindow(); + } } private void SendButton_Click(object sender, EventArgs e) { - var param = new JObject + if (_bridge.Clients.LinkerClient != null) { - ["type"] = "fdc3.instrument", - ["name"] = DataToSendInput.Text, - ["id"] = new JObject + _bridge.Clients.LinkerClient.Publish(new JObject { - ["ticker"] = DataToSendInput.Text - } - }; - _bridge.Clients.Fdc3Client.DesktopAgentClient.Broadcast(new Context(param)); + ["dataType"] = "symbol", + ["data"] = DataToSendInput.Text + }); + } + else + { + var param = new JObject + { + ["type"] = "fdc3.instrument", + ["name"] = DataToSendInput.Text, + ["id"] = new JObject + { + ["ticker"] = DataToSendInput.Text + } + }; + _bridge.Clients.Fdc3Client.DesktopAgentClient.Broadcast(new Context(param)); + } } private void UpdateAlwaysOnTopButton(bool isAlwaysOnTop) diff --git a/WinformExampleCore/Program.cs b/WinformExampleCore/Program.cs index 7b67c6a..851f064 100644 --- a/WinformExampleCore/Program.cs +++ b/WinformExampleCore/Program.cs @@ -14,6 +14,18 @@ static class Program [STAThread] static void Main() { +#if DEBUG + Debugger.Launch(); +#endif + +#if LOGGING && TRACE + TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log"); + logger.TraceOutputOptions = TraceOptions.DateTime; + + Trace.Listeners.Add(logger); + Trace.AutoFlush = true; + Trace.TraceInformation("Logging started"); +#endif Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); @@ -22,11 +34,6 @@ static void Main() Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); -#if DEBUG - Debugger.Launch(); - Debug.Print("OnStartup"); -#endif - string[] args = Environment.GetCommandLineArgs(); Application.Run(new MainForm(args)); } @@ -34,18 +41,20 @@ static void Main() static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { LogUnhandledException(e.Exception); - Debug.Print($"An Unhandled Exception has occurred. Exception: {e.Exception}"); + Trace.TraceInformation("Shutting down"); Application.Exit(); } static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { LogUnhandledException(e.ExceptionObject as Exception); + Trace.TraceInformation("Shutting down"); Application.Exit(); } static void LogUnhandledException(Exception e) { + Trace.TraceError(e.Message); using (StreamWriter sw = new StreamWriter("Critical exceptions.log", true)) { sw.WriteLine($"{DateTime.Now.ToUniversalTime()} - {e.Message}"); diff --git a/WinformExampleCore/WinformExampleCore.csproj b/WinformExampleCore/WinformExampleCore.csproj index 536b50a..88199c3 100644 --- a/WinformExampleCore/WinformExampleCore.csproj +++ b/WinformExampleCore/WinformExampleCore.csproj @@ -8,6 +8,22 @@ 7.1.1 + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + @@ -23,7 +39,7 @@ - + diff --git a/WinformMultiWindowExample/Program.cs b/WinformMultiWindowExample/Program.cs index de1c05f..aa21606 100644 --- a/WinformMultiWindowExample/Program.cs +++ b/WinformMultiWindowExample/Program.cs @@ -8,6 +8,7 @@ using System.Diagnostics; using System.Linq; using System.Windows.Forms; + using System.Diagnostics; internal static class Program { @@ -22,6 +23,15 @@ internal static void Main(string[] args) Debugger.Launch(); #endif +#if LOGGING && TRACE + TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log"); + logger.TraceOutputOptions = TraceOptions.DateTime; + + Trace.Listeners.Add(logger); + Trace.AutoFlush = true; + Trace.TraceInformation("Logging started"); +#endif + ApplicationContext app = new ApplicationContext(args); app.Run(args); } @@ -55,7 +65,7 @@ public ApplicationContext(string[] args) var fsbl = new Finsemble(args.ToArray(), form); fsbl.Connected += (s, e) => { - Debug.WriteLine("FSBL connected"); + Trace.TraceInformation("FSBL connected"); IIntegratable fsblForm = form as IIntegratable; if (fsblForm != null) @@ -67,9 +77,9 @@ public ApplicationContext(string[] args) // Dispose of Finsemble object when window is closed. form.Closed += (s, e) => { - Debug.WriteLine("disposing window from app.xaml"); + Trace.TraceInformation("disposing window from app.xaml"); fsbl.Dispose(); - Debug.WriteLine("dispose completed"); + Trace.TraceInformation("dispose completed"); }; fsbl.Connect("WinformMultiWindowExample", JWK); this.MainForm = form; @@ -88,7 +98,7 @@ protected override void OnStartupNextInstance(StartupNextInstanceEventArgs event var fsbl = new Finsemble(eventArgs.CommandLine.ToArray(), form); fsbl.Connected += (s, e) => { - Debug.WriteLine("FSBL connected"); + Trace.TraceInformation("FSBL connected"); IIntegratable fsblForm = form as IIntegratable; if (fsblForm != null) { @@ -99,9 +109,9 @@ protected override void OnStartupNextInstance(StartupNextInstanceEventArgs event // Dispose of Finsemble object when window is closed. form.Closed += (s, e) => { - Debug.WriteLine("disposing window from app.xaml"); + Trace.TraceInformation("disposing window from app.xaml"); fsbl.Dispose(); - Debug.WriteLine("dispose completed"); + Trace.TraceInformation("dispose completed"); }; fsbl.Connect("WinformMultiWindowExample", JWK); form.Show(); diff --git a/WinformMultiWindowExample/WinformMultiWindowExample.csproj b/WinformMultiWindowExample/WinformMultiWindowExample.csproj index b8e3dec..66eedca 100644 --- a/WinformMultiWindowExample/WinformMultiWindowExample.csproj +++ b/WinformMultiWindowExample/WinformMultiWindowExample.csproj @@ -21,7 +21,7 @@ full false bin\Debug\ - DEBUG;TRACE + DEBUG;TRACE;LOGGING prompt 4 @@ -30,7 +30,7 @@ pdbonly true bin\Release\ - TRACE + TRACE;LOGGING prompt 4 @@ -50,8 +50,8 @@ ..\packages\DotNetZip.1.16.0\lib\net40\DotNetZip.dll - - ..\packages\Finsemble.7.1.1\lib\net452\Finsemble.dll + + ..\packages\Finsemble.7.2.0\lib\net452\Finsemble.dll ..\packages\Microsoft.IdentityModel.Logging.6.16.0\lib\net45\Microsoft.IdentityModel.Logging.dll @@ -75,12 +75,24 @@ ..\packages\PInvoke.Windows.Core.0.6.49\lib\net20\PInvoke.Windows.Core.dll - - ..\packages\SuperSocket.ClientEngine.Core.0.10.0\lib\net45\SuperSocket.ClientEngine.dll + + ..\packages\Polly.7.2.3\lib\netstandard1.1\Polly.dll + + ..\packages\System.Collections.Immutable.1.7.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll + @@ -90,9 +102,6 @@ - - ..\packages\WebSocket4Net.0.15.2\lib\net45\WebSocket4Net.dll - diff --git a/WinformMultiWindowExample/packages.config b/WinformMultiWindowExample/packages.config index bc6abfe..ad95ad9 100644 --- a/WinformMultiWindowExample/packages.config +++ b/WinformMultiWindowExample/packages.config @@ -1,14 +1,47 @@  - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WinformMultiWindowExampleCore/FinsembleForm.cs b/WinformMultiWindowExampleCore/FinsembleForm.cs index 64ef17f..e40bea8 100644 --- a/WinformMultiWindowExampleCore/FinsembleForm.cs +++ b/WinformMultiWindowExampleCore/FinsembleForm.cs @@ -47,9 +47,9 @@ protected override void SetVisibleCore(bool value) private void FinsembleForm_FormClosed(object sender, FormClosedEventArgs e) { - Debug.WriteLine("disposing Finsemble bridge"); + Trace.TraceInformation("disposing Finsemble bridge"); FSBL.Dispose(); - Debug.WriteLine("dispose completed"); + Trace.TraceInformation("dispose completed"); } /// @@ -65,7 +65,7 @@ private async void ConnectToFinsemble(string[] args) private void Finsemble_Connected(object sender, EventArgs e) { - Debug.WriteLine("FSBL connected"); + Trace.TraceInformation("FSBL connected"); //show the form this.allowshowdisplay = true; this.Visible = true; diff --git a/WinformMultiWindowExampleCore/Program.cs b/WinformMultiWindowExampleCore/Program.cs index dccdb6c..8766dad 100644 --- a/WinformMultiWindowExampleCore/Program.cs +++ b/WinformMultiWindowExampleCore/Program.cs @@ -23,6 +23,15 @@ static void Main() #if DEBUG Debugger.Launch(); #endif +#if LOGGING && TRACE + TextWriterTraceListener logger = new TextWriterTraceListener("Finsemble.log"); + logger.TraceOutputOptions = TraceOptions.DateTime; + + Trace.Listeners.Add(logger); + Trace.AutoFlush = true; + Trace.TraceInformation("Logging started"); +#endif + Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); @@ -50,7 +59,7 @@ static void Main() // if it wasn't acquired, it timed out, so can handle that how ever we want if (!mutexAcquired) { - Debug.Print("I have timed out acquiring the mutex and can handle that somehow"); + Trace.TraceError("I have timed out acquiring the mutex and can handle that somehow"); return; } @@ -97,9 +106,8 @@ private static void SingleInstance_MessageReceived(string[] args) private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { -#if DEBUG - Debug.Print($"An Unhandled Exception has occurred. Exception: {e.Exception}"); -#endif + Trace.TraceError($"An Unhandled Exception has occurred. Exception: {e.Exception}"); + Trace.TraceInformation("Shutting down"); Application.Exit(); } diff --git a/WinformMultiWindowExampleCore/SingleInstance.cs b/WinformMultiWindowExampleCore/SingleInstance.cs index 33e4a36..e95d8be 100644 --- a/WinformMultiWindowExampleCore/SingleInstance.cs +++ b/WinformMultiWindowExampleCore/SingleInstance.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using System.Text.Json.Serialization; using System.Text.Json; +using System.Diagnostics; namespace WinformMultiWindowExampleCore { @@ -126,7 +127,7 @@ private static void CreateRemoteService(string channelName) } catch (Exception ex) { - System.Diagnostics.Debug.Print(ex.Message); + Trace.TraceError(ex.Message); } finally { @@ -169,7 +170,7 @@ private static void SignalFirstInstance(string channelName, string[] args) } catch (Exception ex) { - System.Diagnostics.Debug.Print(ex.Message); + Trace.TraceError(ex.Message); } } } diff --git a/WinformMultiWindowExampleCore/WinformMultiWindowExampleCore.csproj b/WinformMultiWindowExampleCore/WinformMultiWindowExampleCore.csproj index 0551acd..54326c9 100644 --- a/WinformMultiWindowExampleCore/WinformMultiWindowExampleCore.csproj +++ b/WinformMultiWindowExampleCore/WinformMultiWindowExampleCore.csproj @@ -8,8 +8,24 @@ 7.1.1 + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + + + TRACE;LOGGING;$(DefineConstants) + + - +