/// <summary> /// Initializes a new instance of the <see cref="ComAeSubscriptionClient"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="configuration">The configuration.</param> /// <param name="cache">The cache for known types.</param> /// <param name="namespaceIndex">The namespace index for the event types.</param> /// <param name="manager">The manager.</param> /// <param name="monitoredItem">The monitored item.</param> public ComAeSubscriptionClient( ServerSystemContext context, ComAeClientConfiguration configuration, AeTypeCache cache, ushort namespaceIndex, ComAeClientManager manager, MonitoredItem monitoredItem) { m_defaultContext = context; m_separators = configuration.SeperatorChars; m_cache = cache; m_namespaceIndex = namespaceIndex; m_manager = manager; m_refreshComplete = new ManualResetEvent(false); m_monitoredItems = new List <MonitoredItem>(); m_monitoredItems.Add(monitoredItem); m_qualifiedName = null; m_isSource = false; NodeHandle handle = monitoredItem.ManagerHandle as NodeHandle; AeAreaState area = handle.Node as AeAreaState; if (area != null) { m_qualifiedName = area.QualifiedName; m_isSource = false; } else { AeSourceState source = handle.Node as AeSourceState; if (source != null) { m_qualifiedName = source.QualifiedName; m_isSource = true; } } }
/// <summary> /// Returns the next AE area or source. /// </summary> /// <returns>A DA element. Null if nothing left to browse.</returns> public BaseObjectState Next(ISystemContext context, ushort namespaceIndex) { // check if already completed. if (m_completed) { return(null); } // create the browser. if (base.Unknown == null) { base.Unknown = m_client.CreateAreaBrowser(); if (base.Unknown == null) { return(null); } if (!ChangeBrowsePosition(OPCAEBROWSEDIRECTION.OPCAE_BROWSE_TO, m_qualifiedName)) { return(null); } } // create the enumerator if not already created. if (m_enumerator == null) { m_enumerator = CreateEnumerator(false); m_sources = false; // a null indicates an error. if (m_enumerator == null) { m_completed = true; return(null); } } // need a loop in case errors occur fetching element metadata. BaseObjectState node = null; do { // fetch the next name. string name = m_enumerator.Next(); // a null indicates the end of list. if (name == null) { if (!m_sources) { m_enumerator.Dispose(); m_enumerator = CreateEnumerator(true); m_sources = true; continue; } m_completed = true; return(null); } // create the node. if (m_sources) { string qualifiedName = GetQualifiedSourceName(name); if (String.IsNullOrEmpty(qualifiedName)) { continue; } node = new AeSourceState(context, m_qualifiedName, qualifiedName, name, namespaceIndex); } else { string qualifiedName = GetQualifiedAreaName(name); if (String.IsNullOrEmpty(qualifiedName)) { continue; } node = new AeAreaState(context, qualifiedName, name, namespaceIndex); } break; }while (node == null); // return node. return(node); }
/// <summary> /// Returns the next AE area or source. /// </summary> /// <returns>A DA element. Null if nothing left to browse.</returns> public BaseObjectState Next(ISystemContext context, ushort namespaceIndex) { // check if already completed. if (m_completed) { return null; } // create the browser. if (base.Unknown == null) { base.Unknown = m_client.CreateAreaBrowser(); if (base.Unknown == null) { return null; } if (!ChangeBrowsePosition(OPCAEBROWSEDIRECTION.OPCAE_BROWSE_TO, m_qualifiedName)) { return null; } } // create the enumerator if not already created. if (m_enumerator == null) { m_enumerator = CreateEnumerator(false); m_sources = false; // a null indicates an error. if (m_enumerator == null) { m_completed = true; return null; } } // need a loop in case errors occur fetching element metadata. BaseObjectState node = null; do { // fetch the next name. string name = m_enumerator.Next(); // a null indicates the end of list. if (name == null) { if (!m_sources) { m_enumerator.Dispose(); m_enumerator = CreateEnumerator(true); m_sources = true; continue; } m_completed = true; return null; } // create the node. if (m_sources) { string qualifiedName = GetQualifiedSourceName(name); if (String.IsNullOrEmpty(qualifiedName)) { continue; } node = new AeSourceState(context, m_qualifiedName, qualifiedName, name, namespaceIndex); } else { string qualifiedName = GetQualifiedAreaName(name); if (String.IsNullOrEmpty(qualifiedName)) { continue; } node = new AeAreaState(context, qualifiedName, name, namespaceIndex); } break; } while (node == null); // return node. return node; }
/// <summary> /// Does any initialization required before the address space can be used. /// </summary> /// <remarks> /// The externalReferences is an out parameter that allows the node manager to link to nodes /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and /// should have a reference to the root folder node(s) exposed by this node manager. /// </remarks> public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences) { lock (Lock) { // check if the type model needs to be loaded. if (NamespaceIndexes.Length > 1) { LoadPredefinedNodes(SystemContext, externalReferences); } IList <IReference> references = null; // create the root node. string serverName = m_configuration.ServerName; if (String.IsNullOrEmpty(serverName)) { serverName = "ComAeServer"; } AeAreaState root = new AeAreaState(SystemContext, String.Empty, serverName, NamespaceIndex); root.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder); // link root to objects folder. if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references)) { externalReferences[ObjectIds.ObjectsFolder] = references = new List <IReference>(); } references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, root.NodeId)); // link root to server object. if (!externalReferences.TryGetValue(ObjectIds.Server, out references)) { externalReferences[ObjectIds.Server] = references = new List <IReference>(); } references.Add(new NodeStateReference(ReferenceTypeIds.HasNotifier, false, root.NodeId)); // create the status node. ComServerStatusState status = new ComServerStatusState(root); status.ReferenceTypeId = ReferenceTypeIds.Organizes; // get the type namepace for the browse name. int typeNamepaceIndex = Server.NamespaceUris.GetIndex(Namespaces.ComInterop); if (typeNamepaceIndex < 0) { typeNamepaceIndex = NamespaceIndex; } status.Create( SystemContext, AeModelUtils.ConstructIdForInternalNode("ServerStatus", NamespaceIndex), new QualifiedName("ServerStatus", (ushort)typeNamepaceIndex), null, true); root.AddChild(status); // store root folder in the pre-defined nodes. AddPredefinedNode(SystemContext, root); AddRootNotifier(root); // create the COM server. m_system.Initialize(SystemContext, m_configuration, status, Lock, OnServerReconnected); // create a template condition that can be used to initialize static metadata. m_templateAlarm = new AlarmConditionState(null); m_templateAlarm.SymbolicName = "TemplateAlarm"; m_templateAlarm.Create( SystemContext, null, new QualifiedName(m_templateAlarm.SymbolicName, NamespaceIndex), null, false); m_templateAlarm.Acknowledge.OnCall = OnAcknowledge; StartMetadataUpdates(DoMetadataUpdate, null, 5000, m_configuration.MaxReconnectWait); } }
/// <summary> /// Does any initialization required before the address space can be used. /// </summary> /// <remarks> /// The externalReferences is an out parameter that allows the node manager to link to nodes /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and /// should have a reference to the root folder node(s) exposed by this node manager. /// </remarks> public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences) { lock (Lock) { // check if the type model needs to be loaded. if (NamespaceIndexes.Length > 1) { LoadPredefinedNodes(SystemContext, externalReferences); } IList<IReference> references = null; // create the root node. string serverName = m_configuration.ServerName; if (String.IsNullOrEmpty(serverName)) { serverName = "ComAeServer"; } AeAreaState root = new AeAreaState(SystemContext, String.Empty, serverName, NamespaceIndex); root.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder); // link root to objects folder. if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references)) { externalReferences[ObjectIds.ObjectsFolder] = references = new List<IReference>(); } references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, root.NodeId)); // link root to server object. if (!externalReferences.TryGetValue(ObjectIds.Server, out references)) { externalReferences[ObjectIds.Server] = references = new List<IReference>(); } references.Add(new NodeStateReference(ReferenceTypeIds.HasNotifier, false, root.NodeId)); // create the status node. ComServerStatusState status = new ComServerStatusState(root); status.ReferenceTypeId = ReferenceTypeIds.Organizes; // get the type namepace for the browse name. int typeNamepaceIndex = Server.NamespaceUris.GetIndex(Namespaces.ComInterop); if (typeNamepaceIndex < 0) { typeNamepaceIndex = NamespaceIndex; } status.Create( SystemContext, AeModelUtils.ConstructIdForInternalNode("ServerStatus", NamespaceIndex), new QualifiedName("ServerStatus", (ushort)typeNamepaceIndex), null, true); root.AddChild(status); // store root folder in the pre-defined nodes. AddPredefinedNode(SystemContext, root); AddRootNotifier(root); // create the COM server. m_system.Initialize(SystemContext, m_configuration, status, Lock, OnServerReconnected); // create a template condition that can be used to initialize static metadata. m_templateAlarm = new AlarmConditionState(null); m_templateAlarm.SymbolicName = "TemplateAlarm"; m_templateAlarm.Create( SystemContext, null, new QualifiedName(m_templateAlarm.SymbolicName, NamespaceIndex), null, false); m_templateAlarm.Acknowledge.OnCall = OnAcknowledge; StartMetadataUpdates(DoMetadataUpdate, null, 5000, m_configuration.MaxReconnectWait); } }