private async void BrowseBTN_Click(object sender, EventArgs e) { try { Browser browser = new Browser(m_browser.Session); browser.BrowseDirection = BrowseDirection.Forward; browser.NodeClassMask = (int)NodeClass.View | (int)NodeClass.Object; browser.ReferenceTypeId = ReferenceTypeIds.Organizes; browser.IncludeSubtypes = true; ReferenceDescription reference = new SelectNodeDlg().ShowDialog(browser, Objects.ViewsFolder); if (reference != null) { if (reference.NodeClass != NodeClass.View) { MessageDlg dialog = new MessageDlg("Please select a valid view node id."); await dialog.ShowAsync(); return; } ViewIdTB.Text = Utils.Format("{0}", reference.NodeId); } } catch (Exception exception) { GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception); } }
private async void OkBTN_Click(object sender, EventArgs e) { NodeId viewId = null; try { viewId = NodeId.Parse(ViewIdTB.Text); } catch (Exception) { MessageDlg dialog = new MessageDlg("Please enter a valid node id for the view id."); await dialog.ShowAsync(); } try { ViewDescription view = null; if (!NodeId.IsNull(viewId) || ((bool)ViewTimestampCK.IsChecked || (bool)ViewVersionCK.IsChecked)) { view = new ViewDescription(); view.ViewId = viewId; view.Timestamp = DateTime.MinValue; view.ViewVersion = 0; if ((bool)ViewTimestampCK.IsChecked && (ViewTimestampDP.Date > ViewTimestampDP.MinYear)) { view.Timestamp = Convert.ToDateTime(ViewTimestampDP.Date); } if ((bool)ViewVersionCK.IsChecked) { view.ViewVersion = (uint)ViewVersionNC.Value; } } m_browser.View = view; m_browser.MaxReferencesReturned = (uint)MaxReferencesReturnedNC.Value; m_browser.BrowseDirection = (BrowseDirection)BrowseDirectionCB.SelectedItem; m_browser.NodeClassMask = (int)NodeClass.View | (int)NodeClass.Object; m_browser.ReferenceTypeId = ReferenceTypeCTRL.SelectedTypeId; m_browser.IncludeSubtypes = (bool)IncludeSubtypesCK.IsChecked; m_browser.NodeClassMask = 0; int nodeClassMask = 0; foreach (NodeClass nodeClass in NodeClassList.Items) { nodeClassMask |= (int)nodeClass; } m_browser.NodeClassMask = nodeClassMask; } catch (Exception exception) { GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception); } }
async void ExceptionMessageDlg(string message) { await Dispatcher.RunAsync( CoreDispatcherPriority.Normal, async() => { MessageDlg dialog = new MessageDlg(message); await dialog.ShowAsync(); }); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { ApplicationInstance.MessageDlg = new ApplicationMessageDlg(); ApplicationInstance application = new ApplicationInstance(); application.ApplicationName = "UA Sample Client"; application.ApplicationType = ApplicationType.ClientAndServer; application.ConfigSectionName = "Opc.Ua.SampleClient"; // set empty page for MessageDlg Window.Current.Content = new ClientPage(); // Ensure the current window is active Window.Current.Activate(); try { // load the application configuration. await application.LoadApplicationConfiguration(false); // allow UA servers to use the same certificate for HTTPS validation. ApplicationInstance.SetUaValidationForHttps(application.ApplicationConfiguration.CertificateValidator); // run the application interactively. Window.Current.Content = new ClientPage(application.ApplicationConfiguration.CreateMessageContext(), application, null, application.ApplicationConfiguration); // Ensure the current window is active Window.Current.Activate(); } catch (ServiceResultException ex) { Utils.Trace("ServiceResultException:" + ex.Message); MessageDlg dialog = new MessageDlg("Client not started. Exit.\r\n" + ex.Message); await dialog.ShowAsync(); Application.Current.Exit(); return; } try { // check the application certificate. await application.CheckApplicationInstanceCertificate(false, 0); // start the server. await application.Start(new SampleServer()); } catch (ServiceResultException ex) { Utils.Trace("ServiceResultException:" + ex.Message); MessageDlg dialog = new MessageDlg("Client ok but Server has not started.\r\n" + ex.Message); await dialog.ShowAsync(); } }
/// <summary> /// Show a message for approval and return result. /// </summary> /// <param name="message"></param> /// <param name="silent"></param> /// <returns>True if approved, false otherwise.</returns> private async Task <bool> ApproveMessage(string message, bool silent) { if (!silent && MessageDlg != null) { MessageDlg.Message(message, true); return(await MessageDlg.ShowAsync().ConfigureAwait(false)); } else { Utils.LogError(message); return(false); } }
/// <summary> /// Show a message for approval and return result. /// </summary> /// <param name="message"></param> /// <param name="silent"></param> /// <returns>True if approved, false otherwise.</returns> private static async Task <bool> ApproveMessage(string message, bool silent) { if (!silent && MessageDlg != null) { MessageDlg.Message(message, true); return(await MessageDlg.ShowAsync()); } else { Utils.Trace(message); return(false); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs args) { ApplicationInstance.MessageDlg = new ApplicationMessageDlg(); ApplicationInstance application = new ApplicationInstance(); application.ApplicationName = "UA Sample Server"; application.ApplicationType = ApplicationType.Server; application.ConfigSectionName = "Opc.Ua.SampleServer"; // helper to let Opc.Ua Utils find the localFolder in the environment StorageFolder localFolder = ApplicationData.Current.LocalFolder; Utils.DefaultLocalFolder = localFolder.Path; // set empty page for MessageDlg Window.Current.Content = new ServerPage(); // Ensure the current window is active Window.Current.Activate(); // Allow the current window to activate since the stack initialization below can take some time // and the app can be terminated by the runtime if this takes too long await Task.Delay(1); try { // load the application configuration. await application.LoadApplicationConfiguration(false); // check the application certificate. await application.CheckApplicationInstanceCertificate(false, 0); // start the server. await application.Start(new Opc.Ua.Sample.SampleServer()); // run the application interactively. Window.Current.Content = new ServerPage(application); } catch (Exception ex) { Utils.Trace("Exception:" + ex.Message); MessageDlg dialog = new MessageDlg(ex.Message); await dialog.ShowAsync(); Application.Current.Exit(); } }
/// <summary> /// Loads the configuration. /// </summary> public async Task <ApplicationConfiguration> LoadAppConfig( bool silent, Stream stream, ApplicationType applicationType, Type configurationType, bool applyTraceSettings, ICertificatePasswordProvider certificatePasswordProvider = null) { Utils.LogInfo("Loading application from stream."); try { // load the configuration file. ApplicationConfiguration configuration = await ApplicationConfiguration.Load( stream, applicationType, configurationType, applyTraceSettings, certificatePasswordProvider) .ConfigureAwait(false); if (configuration == null) { return(null); } return(configuration); } catch (Exception e) { Utils.LogError(e, "Could not load configuration from stream."); // warn user. if (!silent) { if (MessageDlg != null) { MessageDlg.Message("Load Application Configuration: " + e.Message); await MessageDlg.ShowAsync().ConfigureAwait(false); } throw; } return(null); } }
/// <summary> /// Loads the configuration. /// </summary> public static async Task <ApplicationConfiguration> LoadAppConfig( bool silent, string filePath, ApplicationType applicationType, Type configurationType, bool applyTraceSettings, ICertificatePasswordProvider certificatePasswordProvider = null) { Utils.Trace(Utils.TraceMasks.Information, "Loading application configuration file. {0}", filePath); try { // load the configuration file. ApplicationConfiguration configuration = await ApplicationConfiguration.Load( new System.IO.FileInfo(filePath), applicationType, configurationType, applyTraceSettings, certificatePasswordProvider) .ConfigureAwait(false); if (configuration == null) { return(null); } return(configuration); } catch (Exception e) { Utils.Trace(e, "Could not load configuration file. {0}", filePath); // warn user. if (!silent) { if (MessageDlg != null) { MessageDlg.Message("Load Application Configuration: " + e.Message); await MessageDlg.ShowAsync().ConfigureAwait(false); } throw; } return(null); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs args) { ApplicationInstance.MessageDlg = new ApplicationMessageDlg(); ApplicationInstance application = new ApplicationInstance(); application.ApplicationName = "UA Sample Server"; application.ApplicationType = ApplicationType.Server; application.ConfigSectionName = "Opc.Ua.SampleServer"; // set empty page for MessageDlg Window.Current.Content = new ServerPage(); // Ensure the current window is active Window.Current.Activate(); try { // load the application configuration. await application.LoadApplicationConfiguration(false); // This call registers the certificate with HTTP.SYS // It must be called once after installation if the HTTPS endpoint is enabled. // HttpAccessRule.SetHttpsCertificate(c.SecurityConfiguration.ApplicationCertificate.Find(true), 51212, false); // check the application certificate. await application.CheckApplicationInstanceCertificate(false, 0); // start the server. await application.Start(new Opc.Ua.Sample.SampleServer()); // run the application interactively. Window.Current.Content = new ServerPage(application); // Ensure the current window is active Window.Current.Activate(); } catch (ServiceResultException ex) { Utils.Trace("ServiceResultException:" + ex.Message); MessageDlg dialog = new MessageDlg("Server not started. Exit.\r\n" + ex.Message); await dialog.ShowAsync(); Application.Current.Exit(); } }
private async void Browser_MoreReferences(Browser sender, BrowserEventArgs e) { try { AddReferences(m_nodeToBrowse, e.References); e.References.Clear(); MessageDlg dialog = new MessageDlg("More references exist. Continue?", MessageDlgButton.Yes, MessageDlgButton.No); MessageDlgButton result = await dialog.ShowAsync(); if (result != MessageDlgButton.Yes) { e.Cancel = true; } } catch (Exception exception) { GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { ApplicationInstance.MessageDlg = new ApplicationMessageDlg(); ApplicationInstance application = new ApplicationInstance(); application.ApplicationName = "UA Sample Client"; application.ApplicationType = ApplicationType.ClientAndServer; application.ConfigSectionName = "Opc.Ua.SampleClient"; // set empty page for MessageDlg Window.Current.Content = new ClientPage(); // Ensure the current window is active Window.Current.Activate(); // Allow the current window to activate since the stack initialization below can take some time // and the app can be terminated by the runtime if this takes too long await Task.Delay(1); try { // load the application configuration. await application.LoadApplicationConfiguration(false); // check the application certificate. await application.CheckApplicationInstanceCertificate(false, 0); // run the application interactively. Window.Current.Content = new ClientPage(application.ApplicationConfiguration.CreateMessageContext(), application, null, application.ApplicationConfiguration); // start the server. await application.Start(new SampleServer()); } catch (Exception ex) { Utils.Trace("Exception:" + ex.Message); MessageDlg dialog = new MessageDlg(ex.Message); await dialog.ShowAsync(); Application.Current.Exit(); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs args) { ApplicationInstance.MessageDlg = new ApplicationMessageDlg(); ApplicationInstance application = new ApplicationInstance(); application.ApplicationName = "UA Sample Server"; application.ApplicationType = ApplicationType.Server; application.ConfigSectionName = "Opc.Ua.SampleServer"; // set empty page for MessageDlg Window.Current.Content = new ServerPage(); // Ensure the current window is active Window.Current.Activate(); try { // load the application configuration. await application.LoadApplicationConfiguration(false); // check the application certificate. await application.CheckApplicationInstanceCertificate(false, 0); // start the server. await application.Start(new Opc.Ua.Sample.SampleServer()); // run the application interactively. Window.Current.Content = new ServerPage(application); // Ensure the current window is active Window.Current.Activate(); } catch (ServiceResultException ex) { Utils.Trace("ServiceResultException:" + ex.Message); MessageDlg dialog = new MessageDlg("Server not started. Exit.\r\n" + ex.Message); await dialog.ShowAsync(); Application.Current.Exit(); } }
async void Window_PageClosing(object sender, RoutedEventArgs e) { if (m_masterPage == null && m_pages.Count > 0) { MessageDlg dialog = new MessageDlg("Close all sessions?", MessageDlgButton.Yes, MessageDlgButton.No); MessageDlgButton result = await dialog.ShowAsync(); if (result != MessageDlgButton.Yes) { return; } } BrowseCTRL.Clear(); for (int ii = 0; ii < m_pages.Count; ii++) { if (Object.ReferenceEquals(m_pages[ii], sender)) { m_pages.RemoveAt(ii); break; } } }
/// <summary> /// Provides a user defined method. /// </summary> protected virtual async void DoTest(Session session) { MessageDlg dialog = new MessageDlg("A handy place to put test code."); await dialog.ShowAsync(); }