From a0c243ebe3924fd85b402b7490c70438374c24a4 Mon Sep 17 00:00:00 2001 From: Erich Barnstedt Date: Fri, 15 Jul 2016 09:46:42 +0200 Subject: [PATCH] Added application message dialog for .Net Forms and Console apps. --- .../ApplicationInstance.cs | 1 + .../Samples/Client.Net4/Program.cs | Bin 6920 -> 7070 bytes .../Configuration/Common (OLD)/MessageDlg.cs | 62 ++++++++++++++++++ .../UA Client Controls.csproj | 1 + .../Common (OLD)/MessageDlg.xaml.cs | 7 +- .../NetCoreConsolePublisher/Program.cs | 35 ++++++++++ .../Samples/NetCoreConsoleServer/Program.cs | 35 ++++++++++ .../Samples/Publisher.Net4/Program.cs | Bin 5886 -> 6098 bytes .../Samples/Server.Net4/Program.cs | 2 + 9 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 SampleApplications/Samples/ClientControls.Net4/Configuration/Common (OLD)/MessageDlg.cs diff --git a/SampleApplications/SDK/Opc.Ua.Configuration/ApplicationInstance.cs b/SampleApplications/SDK/Opc.Ua.Configuration/ApplicationInstance.cs index f06da38cd1..4a881ca633 100644 --- a/SampleApplications/SDK/Opc.Ua.Configuration/ApplicationInstance.cs +++ b/SampleApplications/SDK/Opc.Ua.Configuration/ApplicationInstance.cs @@ -142,6 +142,7 @@ namespace Opc.Ua.Configuration /// /// If true the application will not be visible to the GDS local agent after installation. public bool NoGdsAgentAdmin { get; set; } + public static IApplicationMessageDlg MessageDlg { get; set; } #endregion diff --git a/SampleApplications/Samples/Client.Net4/Program.cs b/SampleApplications/Samples/Client.Net4/Program.cs index 537d4bd830a538fe60745b6db48c30dedb87108a..2c8c1e5f14b544c420f292841350e4c95212e9df 100644 GIT binary patch delta 76 zcmeA$n`gd(OITEo!IvSGp%@4g8Pb6)7ls^$^vR0Cs*+g588jF)8LTHy6cn8tAjC2G MkD%D*UqXBw0F5^hzW@LL delta 12 TcmbPd-eI ShowAsync() + { + DialogResult result = MessageBox.Show(message, "OPC UA", buttons); + return await Task.FromResult((result == DialogResult.OK) || (result == DialogResult.Yes)); + } + } +} + diff --git a/SampleApplications/Samples/ClientControls.Net4/UA Client Controls.csproj b/SampleApplications/Samples/ClientControls.Net4/UA Client Controls.csproj index da5631cd80..14a97c46b2 100644 --- a/SampleApplications/Samples/ClientControls.Net4/UA Client Controls.csproj +++ b/SampleApplications/Samples/ClientControls.Net4/UA Client Controls.csproj @@ -504,6 +504,7 @@ DateTimeValueEditDlg.cs + UserControl diff --git a/SampleApplications/Samples/ClientControls/Common (OLD)/MessageDlg.xaml.cs b/SampleApplications/Samples/ClientControls/Common (OLD)/MessageDlg.xaml.cs index 24ccb1665b..faaca62972 100644 --- a/SampleApplications/Samples/ClientControls/Common (OLD)/MessageDlg.xaml.cs +++ b/SampleApplications/Samples/ClientControls/Common (OLD)/MessageDlg.xaml.cs @@ -27,7 +27,6 @@ * http://opcfoundation.org/License/MIT/1.00/ * ======================================================================*/ - using Windows.UI.Xaml.Controls; using Windows.UI.Xaml; using System.Threading.Tasks; @@ -39,6 +38,7 @@ namespace Opc.Ua.Client.Controls public class ApplicationMessageDlg:IApplicationMessageDlg { private MessageDlg dialog = new MessageDlg(""); + public override void Message(string text, bool ask) { if (ask) @@ -50,6 +50,7 @@ namespace Opc.Ua.Client.Controls dialog.MessageText(text); } } + public override async Task ShowAsync() { return await dialog.ShowAsync() == MessageDlgButton.Yes; @@ -98,8 +99,7 @@ namespace Opc.Ua.Client.Controls Left = left; Right = right; } - - + public async Task ShowAsync() { // configure dialog @@ -137,6 +137,5 @@ namespace Opc.Ua.Client.Controls dialogPopup.IsOpen = false; } } - } diff --git a/SampleApplications/Samples/NetCoreConsolePublisher/Program.cs b/SampleApplications/Samples/NetCoreConsolePublisher/Program.cs index 512ede7319..32d1a04313 100644 --- a/SampleApplications/Samples/NetCoreConsolePublisher/Program.cs +++ b/SampleApplications/Samples/NetCoreConsolePublisher/Program.cs @@ -36,6 +36,40 @@ namespace NetCoreConsolePublisher } } + public class ApplicationMessageDlg : IApplicationMessageDlg + { + private string message = string.Empty; + private bool ask = false; + + public override void Message(string text, bool ask) + { + this.message = text; + this.ask = ask; + } + + public override async Task ShowAsync() + { + if (ask) + { + message += " (y/n, default y): "; + Console.Write(message); + } + else + { + Console.WriteLine(message); + } + if (ask) + { + ConsoleKeyInfo result = Console.ReadKey(); + return await Task.FromResult((result.KeyChar == 'y') || (result.KeyChar == 'Y') || (result.KeyChar == '\r')); + } + else + { + return await Task.FromResult(true); + } + } + } + public class Program { private static AmqpConnectionCollection m_publishers = null; @@ -46,6 +80,7 @@ namespace NetCoreConsolePublisher public static void Main(string[] args) { + ApplicationInstance.MessageDlg = new ApplicationMessageDlg(); ApplicationInstance application = new ApplicationInstance(); application.ApplicationName = "UA AMQP Publisher"; application.ApplicationType = ApplicationType.ClientAndServer; diff --git a/SampleApplications/Samples/NetCoreConsoleServer/Program.cs b/SampleApplications/Samples/NetCoreConsoleServer/Program.cs index c366558c4d..666b101af1 100644 --- a/SampleApplications/Samples/NetCoreConsoleServer/Program.cs +++ b/SampleApplications/Samples/NetCoreConsoleServer/Program.cs @@ -18,12 +18,47 @@ using System.Threading.Tasks; namespace NetCoreConsoleServer { + public class ApplicationMessageDlg : IApplicationMessageDlg + { + private string message = string.Empty; + private bool ask = false; + + public override void Message(string text, bool ask) + { + this.message = text; + this.ask = ask; + } + + public override async Task ShowAsync() + { + if (ask) + { + message += " (y/n, default y): "; + Console.Write(message); + } + else + { + Console.WriteLine(message); + } + if (ask) + { + ConsoleKeyInfo result = Console.ReadKey(); + return await Task.FromResult((result.KeyChar == 'y') || (result.KeyChar == 'Y') || (result.KeyChar == '\r')); + } + else + { + return await Task.FromResult(true); + } + } + } + public class Program { public static void Main(string[] args) { try { + ApplicationInstance.MessageDlg = new ApplicationMessageDlg(); ApplicationInstance application = new ApplicationInstance(); application.ApplicationName = "UA Sample Server"; application.ApplicationType = ApplicationType.Server; diff --git a/SampleApplications/Samples/Publisher.Net4/Program.cs b/SampleApplications/Samples/Publisher.Net4/Program.cs index 3483b3499189ba472e48e76dfa92ceb844b3e443..224f185003e6a63f5784bdc3a8a849f3be7d009e 100644 GIT binary patch delta 107 zcmeyTdr5zT0?*`U+%nQR44Dk640#MC40;UC4EbPI5s=PdDBdi|^PWjmkHHtHpcn`f l8Pb6)7ob%7WO;s7aV+8t8Vs6~*Ne$d{>3Y{`3D~x2LQY{8e#wd delta 17 Zcmcbl|4(;=0?+0+o)=7;@9=+P2LMN22de-8 diff --git a/SampleApplications/Samples/Server.Net4/Program.cs b/SampleApplications/Samples/Server.Net4/Program.cs index a54c46d8dd..3894602641 100644 --- a/SampleApplications/Samples/Server.Net4/Program.cs +++ b/SampleApplications/Samples/Server.Net4/Program.cs @@ -30,6 +30,7 @@ using System; using System.Windows.Forms; using Opc.Ua.Configuration; +using Opc.Ua.Client.Controls; namespace Opc.Ua.Sample { @@ -44,6 +45,7 @@ namespace Opc.Ua.Sample Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); + ApplicationInstance.MessageDlg = new ApplicationMessageDlg(); ApplicationInstance application = new ApplicationInstance(); application.ApplicationName = "UA Sample Server"; application.ApplicationType = ApplicationType.Server;