当前位置: 首页>>代码示例>>C#>>正文


C# Session.FetchTypeTree方法代码示例

本文整理汇总了C#中Opc.Ua.Client.Session.FetchTypeTree方法的典型用法代码示例。如果您正苦于以下问题:C# Session.FetchTypeTree方法的具体用法?C# Session.FetchTypeTree怎么用?C# Session.FetchTypeTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Opc.Ua.Client.Session的用法示例。


在下文中一共展示了Session.FetchTypeTree方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnSessionCreated

        /// <summary>
        /// Called when a session is created with a server.
        /// </summary>
        private void OnSessionCreated(Session session)
        {
            string commonAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
            string configFileName = Utils.Format(@"{0}\OPC Foundation\ComPseudoServers\{1}.internal.xml", commonAppDataPath, m_clsid);

            lock (m_lock)
            {
                try
                {
                    m_session = null;
                    m_Subscription = null;
                    m_AreaNodes.Clear();

                    m_session = session;

                    // load the config file.
                    if (File.Exists(configFileName))
                    {
                        XmlSerializer ser = new XmlSerializer(typeof(Configuration));
                        TextReader reader = new StreamReader(configFileName);
                        m_configFile = (Configuration)ser.Deserialize(reader);
                        reader.Close();

                        // set the ActualDataType property
                        for (int ii = 0; ii < m_configFile.Attributes.Length - 1; ii++)
                        {
                            NodeId nodeid = new NodeId(m_configFile.Attributes[ii].strDataTypeNodeId);
                            m_configFile.Attributes[ii].ActualDataType = DataTypes.GetSystemType(nodeid, EncodeableFactory.GlobalFactory);
                        }
                    }
                    else
                    {
                        InitConfigInfo(configFileName);
                    }

                    // Obtain the current server table, generate index mapping tables (client->server, server->client)
                    // and update the client side namespace table if necessary due to server changes
                    GenerateNamespaceIndexMappings(m_clsid);

                    // The client side namespace table may have been updated if the server namespace table
                    // has changed therefore save the updated client table.
                    SaveConfigInfo(configFileName);
                    
                    // fetch type tree.
                    m_session.FetchTypeTree(Opc.Ua.ObjectTypeIds.BaseEventType);
                    m_session.FetchTypeTree(Opc.Ua.ReferenceTypeIds.References);
                    
                    //Create UA Event Subscription if none configured in the registry
                    m_Subscription = new Opc.Ua.Client.Subscription(m_session.DefaultSubscription);
                    m_Subscription.PublishingEnabled = true;
                    m_Subscription.PublishingInterval = m_configFile.ProxySubscriptionSettings.PublishingInterval;
                    m_Subscription.KeepAliveCount = m_configFile.ProxySubscriptionSettings.KeepAliveCount;
                    m_Subscription.LifetimeCount = m_configFile.ProxySubscriptionSettings.LifetimeCount;
                    m_Subscription.Priority = m_configFile.ProxySubscriptionSettings.Priority;
                    m_Subscription.MaxNotificationsPerPublish = m_configFile.ProxySubscriptionSettings.MaxNotificationsPerPublish;

                    m_session.AddSubscription(m_Subscription);
                    m_Subscription.Create();
                    m_KeepAliveInterval = (int)(m_Subscription.CurrentPublishingInterval * m_Subscription.CurrentKeepAliveCount);

                    // Add Server object as the only monitored item to this subscription

                    NodeId nodeId_Server = new NodeId(Opc.Ua.Objects.Server);

                    MonitoredItem monitoredItem = CreateMonitoredItemForEvents(nodeId_Server);
                    m_Subscription.AddItem(monitoredItem);
                    m_Subscription.ApplyChanges();

                    AreaNode areaNode = new AreaNode();
                    areaNode.AreaName = "/";
                    ++areaNode.RefCount;
                    areaNode.MonitoredItem = monitoredItem;
                    m_notifiers.Add(monitoredItem.ClientHandle, areaNode);
                    m_AreaNodes.Add("/", areaNode);

                    m_Subscription.Session.Call(
                        Opc.Ua.ObjectTypes.ConditionType,
                        Methods.ConditionType_ConditionRefresh,
                        m_Subscription.Id);
                }
                catch (Exception e)
                {
                    Utils.Trace(e, "Initializing server after create.");
                    throw ComUtils.CreateComException(e);
                }
            }
        }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:90,代码来源:ComAeProxy.cs

示例2: CreateSession

        /// <summary>
        /// Creates a new session.
        /// </summary>
        private Session CreateSession(Guid clsid)
        {
            // lookup the cached configuration information.
            ConfiguredEndpoint endpoint = null;
            bool previouslyConnected = true;

            if (!m_verifiedEndpoints.TryGetValue(clsid, out endpoint))
            {
                endpoint = LoadConfiguredEndpoint(clsid);

                if (endpoint != null)
                {
                    Utils.Trace("Loaded endpoint with URL: {0}", endpoint.EndpointUrl);
                    previouslyConnected = false;
                }
            } 
            
            if (endpoint == null)
            { 
                endpoint = m_endpointCache.Create(DefaultServerUrl);
            }
            
            // Initialize the client configuration.
            // Fetch the current configuration information by connecting to the server's discovery endpoint.
            // This method assumes that the discovery endpoint can be constructed by appending "/discovery" to the URL.
            if (endpoint.UpdateBeforeConnect && !previouslyConnected)
            {
                endpoint.UpdateFromServer(BindingFactory.Default);
                Utils.Trace("Updated endpoint from server: {0}", endpoint.EndpointUrl);
            }

            // Need to specify that the server is trusted by the client application.
            if (!previouslyConnected)
            {
                m_configuration.SecurityConfiguration.AddTrustedPeer(endpoint.Description.ServerCertificate);
            }

            // Set the session keep alive to 600 seconds.
            m_configuration.ClientConfiguration.DefaultSessionTimeout = 600000;

            ServiceMessageContext messageContext = m_configuration.CreateMessageContext();

            // Initialize the channel which will be created with the server.
            ITransportChannel channel = SessionChannel.Create(
                m_configuration,
                endpoint.Description,
                endpoint.Configuration,
                m_configuration.SecurityConfiguration.ApplicationCertificate.Find(true),
                messageContext);

              // Wrap the channel with the session object.
            Session session = new Session(channel, m_configuration, endpoint, null);
            session.ReturnDiagnostics = DiagnosticsMasks.SymbolicId;
            
            // The user login credentials must be provided when opening a session.
            IUserIdentity identity = null;

            if (endpoint.UserIdentity != null)
            {
                identity = new Opc.Ua.UserIdentity(endpoint.UserIdentity);
            }

            // Create the session. This actually connects to the server.
            session.Open("COM Client Session", identity);
        
            // need to fetch the references in order use the node cache.
            session.FetchTypeTree(ReferenceTypeIds.References);

            // save the updated information.
            if (!previouslyConnected)
            {
                try
                {
                    SaveConfiguredEndpoint(clsid, endpoint);
                }
                catch (Exception e)
                {
                    Utils.Trace(e, "Could not save SaveConfiguredEndpoint in registry."); 
                }

                m_verifiedEndpoints.Add(clsid, endpoint);
            }
            
            return session;
        }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:88,代码来源:Com.Da.Server.cs


注:本文中的Opc.Ua.Client.Session.FetchTypeTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。