/// <summary> /// Gets or creates the <see cref="NamespaceMetadataState"/> node for the specified NamespaceUri. /// </summary> /// <param name="namespaceUri"></param> /// <returns></returns> public NamespaceMetadataState CreateNamespaceMetadataState(string namespaceUri) { NamespaceMetadataState namespaceMetadataState = FindNamespaceMetadataState(namespaceUri); if (namespaceMetadataState == null) { // find ServerNamespaces node NamespacesState serverNamespacesNode = FindPredefinedNode(ObjectIds.Server_Namespaces, typeof(NamespacesState)) as NamespacesState; if (serverNamespacesNode == null) { Utils.LogError("Cannot create NamespaceMetadataState for namespace '{0}'.", namespaceUri); return(null); } // create the NamespaceMetadata node namespaceMetadataState = new NamespaceMetadataState(serverNamespacesNode); namespaceMetadataState.BrowseName = new QualifiedName(namespaceUri, NamespaceIndex); namespaceMetadataState.Create(SystemContext, null, namespaceMetadataState.BrowseName, null, true); namespaceMetadataState.DisplayName = namespaceUri; namespaceMetadataState.SymbolicName = namespaceUri; namespaceMetadataState.NamespaceUri.Value = namespaceUri; // add node as child of ServerNamespaces and in predefined nodes serverNamespacesNode.AddChild(namespaceMetadataState); serverNamespacesNode.ClearChangeMasks(Server.DefaultSystemContext, true); AddPredefinedNode(SystemContext, namespaceMetadataState); } return(namespaceMetadataState); }
/// <summary> /// Creates the configuration node for the server. /// </summary> public void CreateServerConfiguration( ServerSystemContext systemContext, ApplicationConfiguration configuration) { // setup server configuration node m_serverConfigurationNode.ServerCapabilities.Value = configuration.ServerConfiguration.ServerCapabilities.ToArray(); m_serverConfigurationNode.ServerCapabilities.ValueRank = ValueRanks.OneDimension; m_serverConfigurationNode.ServerCapabilities.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> { 0 }); m_serverConfigurationNode.SupportedPrivateKeyFormats.Value = configuration.ServerConfiguration.SupportedPrivateKeyFormats.ToArray(); m_serverConfigurationNode.SupportedPrivateKeyFormats.ValueRank = ValueRanks.OneDimension; m_serverConfigurationNode.SupportedPrivateKeyFormats.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> { 0 }); m_serverConfigurationNode.MaxTrustListSize.Value = (uint)configuration.ServerConfiguration.MaxTrustListSize; m_serverConfigurationNode.MulticastDnsEnabled.Value = configuration.ServerConfiguration.MultiCastDnsEnabled; m_serverConfigurationNode.UpdateCertificate.OnCall = new UpdateCertificateMethodStateMethodCallHandler(UpdateCertificate); m_serverConfigurationNode.CreateSigningRequest.OnCall = new CreateSigningRequestMethodStateMethodCallHandler(CreateSigningRequest); m_serverConfigurationNode.ApplyChanges.OnCallMethod = new GenericMethodCalledEventHandler(ApplyChanges); m_serverConfigurationNode.GetRejectedList.OnCall = new GetRejectedListMethodStateMethodCallHandler(GetRejectedList); m_serverConfigurationNode.ClearChangeMasks(systemContext, true); // setup certificate group trust list handlers foreach (var certGroup in m_certificateGroups) { certGroup.Node.CertificateTypes.Value = certGroup.CertificateTypes; certGroup.Node.TrustList.Handle = new TrustList( certGroup.Node.TrustList, certGroup.TrustedStorePath, certGroup.IssuerStorePath, new TrustList.SecureAccess(HasApplicationSecureAdminAccess), new TrustList.SecureAccess(HasApplicationSecureAdminAccess) ); certGroup.Node.ClearChangeMasks(systemContext, true); } // find ServerNamespaces node and subscribe to StateChanged NamespacesState serverNamespacesNode = FindPredefinedNode(ObjectIds.Server_Namespaces, typeof(NamespacesState)) as NamespacesState; if (serverNamespacesNode != null) { serverNamespacesNode.StateChanged += ServerNamespacesChanged; } }
/// <summary> /// Finds the <see cref="NamespaceMetadataState"/> node for the specified NamespaceUri. /// </summary> /// <param name="namespaceUri"></param> /// <returns></returns> private NamespaceMetadataState FindNamespaceMetadataState(string namespaceUri) { try { // find ServerNamespaces node NamespacesState serverNamespacesNode = FindPredefinedNode(ObjectIds.Server_Namespaces, typeof(NamespacesState)) as NamespacesState; if (serverNamespacesNode == null) { Utils.LogError("Cannot find ObjectIds.Server_Namespaces node."); return(null); } IList <BaseInstanceState> serverNamespacesChildren = new List <BaseInstanceState>(); serverNamespacesNode.GetChildren(SystemContext, serverNamespacesChildren); foreach (var namespacesReference in serverNamespacesChildren) { // Find NamespaceMetadata node of NamespaceUri in Namespaces children NamespaceMetadataState namespaceMetadata = namespacesReference as NamespaceMetadataState; if (namespaceMetadata == null) { continue; } if (namespaceMetadata.NamespaceUri.Value == namespaceUri) { return(namespaceMetadata); } else { continue; } } IList <IReference> serverNamespacesReferencs = new List <IReference>(); serverNamespacesNode.GetReferences(SystemContext, serverNamespacesReferencs); foreach (IReference serverNamespacesReference in serverNamespacesReferencs) { if (serverNamespacesReference.IsInverse == false) { // Find NamespaceMetadata node of NamespaceUri in Namespaces references NodeId nameSpaceNodeId = ExpandedNodeId.ToNodeId(serverNamespacesReference.TargetId, Server.NamespaceUris); NamespaceMetadataState namespaceMetadata = FindNodeInAddressSpace(nameSpaceNodeId) as NamespaceMetadataState; if (namespaceMetadata == null) { continue; } if (namespaceMetadata.NamespaceUri.Value == namespaceUri) { return(namespaceMetadata); } } } return(null); } catch (Exception ex) { Utils.LogError(ex, "Error searching NamespaceMetadata for namespaceUri {0}.", namespaceUri); return(null); } }