mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-28 22:55:49 +08:00
Added application message dialog for .Net Forms and Console apps.
This commit is contained in:
@@ -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<bool> 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;
|
||||
|
||||
Reference in New Issue
Block a user