/// <summary> /// On reload button clicked /// -- reload configuration and refresh UI accordingly /// <summary> private void btnReload_Button_Click(object sender, RoutedEventArgs e) { EnableSessionOpButtons(false); CloseSessionView_OpcuaClient(); m_sessionConfig = OpcuaSessionConfig.LoadFromJsonFile(m_sessionConfig_full_path); EndpointSelectorCTRL.IsEnabled = false; BrowseCTRL.IsEnabled = false; SessionsCTRL.IsEnabled = false; var ignored = Task.Run(OpenSessionView_OpcuaClient); }
public async Task <bool> SavePublishedNodes(string filePath = null) { bool isSuccess = false; try { string path = filePath; if (String.IsNullOrEmpty(path)) { path = DEFAULT_PUBLISHEDNODESPATH; } List <PublisherConfigurationFileEntry> publisherConfig = new List <PublisherConfigurationFileEntry>(sessionConfig.sessions.Count); foreach (var session in sessionConfig.sessions) { PublisherConfigurationFileEntry configEntry = new PublisherConfigurationFileEntry(); var settingpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, GetFullPath(SiteProfileId, session.profilePath)); var sessionSetting = OpcuaSessionConfig.LoadFromJsonFile(settingpath); configEntry.EndpointUri = sessionSetting.endpoint.EndpointUrl; configEntry.UseSecurity = (sessionSetting.endpoint.Description.SecurityMode != Opc.Ua.MessageSecurityMode.None); configEntry.OpcNodes = new List <OpcNodeOnEndpointUrl>(sessionSetting.monitoredlist.Count); foreach (var item in sessionSetting.monitoredlist) { OpcNodeOnEndpointUrl node = new OpcNodeOnEndpointUrl() { ExpandedNodeId = item.nodeid, Name = item.description, Tag = item.displayname }; configEntry.OpcNodes.Add(node); } publisherConfig.Add(configEntry); } // save session config isSuccess = await SerializationUtil.SaveToJsonFile(GetFullPath(SiteProfileId, path), publisherConfig); } catch (Exception ex) { Utils.Trace(ex, "SiteProfileManager.SavePublishedNodes() Exception: " + ex.Message); } return(isSuccess); }
// save to file in OpcPublisher legacy publishernodes format public async Task <bool> SavePublisherNodesLegacy(string filePath = null) { bool isSuccess = false; try { string path = filePath; if (String.IsNullOrEmpty(path)) { path = DEFAULT_PUBLISHEDNODESPATH; } List <PublishedNode> publisherNodes = new List <PublishedNode>(sessionConfig.sessions.Count); foreach (var session in sessionConfig.sessions) { var settingpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, GetFullPath(SiteProfileId, session.profilePath)); var sessionSetting = OpcuaSessionConfig.LoadFromJsonFile(settingpath); foreach (var item in sessionSetting.monitoredlist) { PublishedNode node = new PublishedNode() { EndpointUrl = sessionSetting.endpoint.EndpointUrl.ToString(), NodeId = new PublishedNodeId() { Identifier = item.nodeid }, Name = item.description, Tag = item.displayname, UseSecurity = (sessionSetting.endpoint.Description.SecurityMode != Opc.Ua.MessageSecurityMode.None) }; publisherNodes.Add(node); } } // save session config isSuccess = await SerializationUtil.SaveToJsonFile(GetFullPath(SiteProfileId, path), publisherNodes); } catch (Exception ex) { Utils.Trace(ex, "SiteProfileManager.SavePublisherNodesLegacy() Exception: " + ex.Message); } return(isSuccess); }
/// <summary> /// On page loaded /// </summary> protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); App.unclosedSession = this; sessionInfo = e.Parameter as SessionInfo; if (sessionInfo == null) { sessionMgmtAction = SESSIONMGMT_ACTION.NEW; sessionInfo = new SessionInfo(); sessionInfo.sessionName = ""; sessionInfo.profilePath = ""; sessionInfo.sourceType = ""; m_sessionConfig_full_path = ""; m_sessionConfig = null; } else { m_sessionConfig_full_path = Path.Combine(m_local, SiteProfileManager.GetFullPath(App.SiteProfileId, sessionInfo.profilePath)); // json configuration m_sessionConfig = OpcuaSessionConfig.LoadFromJsonFile(m_sessionConfig_full_path); } ApplicationInstance application = OpcuaSessionConfig.OpcuaApplication; ApplicationConfiguration configuration = application.ApplicationConfiguration; ServiceMessageContext context = configuration.CreateMessageContext(); if (!configuration.SecurityConfiguration.AutoAcceptUntrustedCertificates) { configuration.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation); } m_context = context; m_application = application; m_configuration = configuration; SessionsCTRL.Configuration = configuration; SessionsCTRL.MessageContext = context; SessionsCTRL.AddressSpaceCtrl = BrowseCTRL; SessionsCTRL.NodeSelected += SessionCtrl_NodeSelected; // disable cached endpoints from Opc.Ua.SampleClient.Config.xml //// get list of cached endpoints. //m_endpoints = m_configuration.LoadCachedEndpoints(true); m_endpoints = new ConfiguredEndpointCollection(); m_endpoints.DiscoveryUrls = configuration.ClientConfiguration.WellKnownDiscoveryUrls; // work around to fill Configuration and DiscoveryUrls if (m_sessionConfig != null) { m_sessionConfig.endpoint.Configuration = EndpointConfiguration.Create(m_configuration); m_sessionConfig.endpoint.Description.Server.DiscoveryUrls.Add(m_sessionConfig.endpoint.EndpointUrl.AbsoluteUri.ToString()); m_endpoints.Add(m_sessionConfig.endpoint); } // hook up endpoint selector EndpointSelectorCTRL.Initialize(m_endpoints, m_configuration); EndpointSelectorCTRL.ConnectEndpoint += EndpointSelectorCTRL_ConnectEndpoint; EndpointSelectorCTRL.EndpointsChanged += EndpointSelectorCTRL_OnChange; BrowseCTRL.SessionTreeCtrl = SessionsCTRL; BrowseCTRL.NodeSelected += BrowseCTRL_NodeSelected; btnDelSubscription.IsEnabled = false; btnAddSubscription.IsEnabled = false; btnDelSubscription.Click += ContextMenu_OnDelete; btnAddSubscription.Click += ContextMenu_OnReport; // exception dialog GuiUtils.ExceptionMessageDlg += ExceptionMessageDlg; EndpointSelectorCTRL.IsEnabled = false; BrowseCTRL.IsEnabled = false; SessionsCTRL.IsEnabled = false; txtSessionName.Text = sessionInfo.sessionName; if (sessionMgmtAction == SESSIONMGMT_ACTION.NEW) { txtSessionName.IsReadOnly = false; btnReload.IsEnabled = false; btnReload.Visibility = Visibility.Collapsed; EndpointSelectorCTRL.IsEnabled = true; } else { if (m_sessionConfig == null) { txtSessionName.IsReadOnly = true; EndpointSelectorCTRL.IsEnabled = true; btnReload.IsEnabled = false; } else { txtSessionName.IsReadOnly = true; btnReload.IsEnabled = false; var ignored = Task.Run(OpenSessionView_OpcuaClient); } } }