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


C# Session.AddSubscription方法代码示例

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


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

示例1: New

        /// <summary>
        /// Creates a new subscription.
        /// </summary>
        public Subscription New(Session session)
        {            
            if (session == null) throw new ArgumentNullException("session");

            Subscription subscription = new Subscription(session.DefaultSubscription);

            if (!new SubscriptionEditDlg().ShowDialog(subscription))
            {
                return null;
            }
            
            session.AddSubscription(subscription);    
            subscription.Create();

            Subscription duplicateSubscription = session.Subscriptions.FirstOrDefault(s => s.Id != 0 && s.Id.Equals(subscription.Id) && s != subscription);
            if (duplicateSubscription != null)
            {
                Utils.Trace("Duplicate subscription was created with the id: {0}", duplicateSubscription.Id);

                DialogResult result = MessageBox.Show("Duplicate subscription was created with the id: " + duplicateSubscription.Id + ". Do you want to keep it?", "Warning", MessageBoxButtons.YesNo);
                if (result == System.Windows.Forms.DialogResult.No)
                {
                    duplicateSubscription.Delete(false);
                    session.RemoveSubscription(subscription);

                    return null;
                }
            }

            Show(subscription);
            
            return subscription;
        }
开发者ID:OPCFoundation,项目名称:UA-.NET,代码行数:36,代码来源:SubscriptionDlg.cs

示例2: Initialize

    /// <summary>
    /// 
    /// </summary>
    /// <param name="Items"></param>
    public void Initialize(Session session)
    {

      Subscription subscription = new Subscription(session.DefaultSubscription);
      subscription.DisplayName = session.ToString() + ".AllSessions";
      bool bResult = session.AddSubscription(subscription);
      subscription.Create();
      Initialize(session, subscription);

    }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:14,代码来源:SessionCtrl.cs

示例3: New

        /// <summary>
        /// Creates a new subscription.
        /// </summary>
        public async Task<Subscription> New(Session session)
        {
            if (session == null) throw new ArgumentNullException("session");

            Subscription subscription = new Subscription(session.DefaultSubscription);
            SubscriptionEditDlg subscriptionEditDlg = new SubscriptionEditDlg();
            if (!await subscriptionEditDlg.ShowDialog(subscription))
            {
                return null;
            }

            session.AddSubscription(subscription);
            subscription.Create();

            Show(subscription);

            return subscription;
        }
开发者ID:OPCFoundation,项目名称:UA-.NETStandardLibrary,代码行数:21,代码来源:SubscriptionDlg.xaml.cs

示例4: CreateMonitoredItem

        public void CreateMonitoredItem(
            Session session, Subscription subscription, NodeId nodeId, MonitoringMode mode)
        {
            if (subscription == null)
            {
                subscription = session.DefaultSubscription;
                if (session.AddSubscription(subscription))
                    subscription.Create();
            }
            else
            {
                session.AddSubscription(subscription);
            }

            // add the new monitored item.
            MonitoredItem monitoredItem = new MonitoredItem(subscription.DefaultItem);

            monitoredItem.StartNodeId = nodeId;
            monitoredItem.AttributeId = Attributes.Value;
            monitoredItem.DisplayName = nodeId.Identifier.ToString();
            monitoredItem.MonitoringMode = mode;
            monitoredItem.SamplingInterval = mode == MonitoringMode.Sampling ? 1000 : 0;
            monitoredItem.QueueSize = 0;
            monitoredItem.DiscardOldest = true;

            monitoredItem.Notification += MonitoredItem_Notification;
            subscription.AddItem(monitoredItem);
            subscription.ApplyChanges();
        }
开发者ID:yuriik83,项目名称:UA-.UWP-Universal-Windows-Platform,代码行数:29,代码来源:ClientPage.xaml.cs

示例5: Server_ConnectComplete

        /// <summary>
        /// Updates the application after connecting to or disconnecting from the server.
        /// </summary>
        private void Server_ConnectComplete(object sender, EventArgs e)
        {
            try
            {
                m_session = ConnectServerCTRL.Session;

                if (m_session == null)
                {
                    StartBTN.Enabled = false;
                    return;
                }

                // set a suitable initial state.
                if (m_session != null && !m_connectedOnce)
                {
                    m_connectedOnce = true;
                }

                // this client has built-in knowledge of the information model used by the server.
                NamespaceTable wellKnownNamespaceUris = new NamespaceTable();
                wellKnownNamespaceUris.Append(Namespaces.Methods);

                string[] browsePaths = new string[] 
                {
                    "1:My Process/1:State",
                    "1:My Process",
                    "1:My Process/1:Start"
                };

                List<NodeId> nodes = ClientUtils.TranslateBrowsePaths(
                    m_session,
                    ObjectIds.ObjectsFolder,
                    wellKnownNamespaceUris,
                    browsePaths);

                // subscribe to the state if available.
                if (nodes.Count > 0 && !NodeId.IsNull(nodes[0]))
                {
                    m_subscription = new Subscription();

                    m_subscription.PublishingEnabled = true;
                    m_subscription.PublishingInterval = 1000;
                    m_subscription.Priority = 1;
                    m_subscription.KeepAliveCount = 10;
                    m_subscription.LifetimeCount = 20;
                    m_subscription.MaxNotificationsPerPublish = 1000;

                    m_session.AddSubscription(m_subscription);
                    m_subscription.Create();

                    MonitoredItem monitoredItem = new MonitoredItem();
                    monitoredItem.StartNodeId = nodes[0];
                    monitoredItem.AttributeId = Attributes.Value;
                    monitoredItem.Notification += new MonitoredItemNotificationEventHandler(MonitoredItem_Notification);
                    m_subscription.AddItem(monitoredItem);

                    m_subscription.ApplyChanges();
                }

                // save the object/method
                if (nodes.Count > 2)
                {
                    m_objectNode = nodes[1];
                    m_methodNode = nodes[2];
                }

                InitialStateTB.Text = "1";
                FinalStateTB.Text = "100";
                StartBTN.Enabled = true;
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
开发者ID:OPCFoundation,项目名称:UA-.NET,代码行数:78,代码来源:MainForm.cs

示例6: Server_ConnectComplete

        /// <summary>
        /// Updates the application after connecting to or disconnecting from the server.
        /// </summary>
        private void Server_ConnectComplete(object sender, EventArgs e)
        {
            try
            {
                m_session = ConnectServerCTRL.Session;

                // check for disconnect.
                if (m_session == null)
                {
                    if (m_auditEventForm != null)
                    {
                        m_auditEventForm.Close();
                        m_auditEventForm = null;
                    }

                    return;
                }

                // set a suitable initial state.
                if (m_session != null && !m_connectedOnce)
                {
                    m_connectedOnce = true;
                }

                // create the default subscription.
                m_subscription = new Subscription();

                m_subscription.DisplayName = null;
                m_subscription.PublishingInterval = 1000;
                m_subscription.KeepAliveCount = 10;
                m_subscription.LifetimeCount = 100;
                m_subscription.MaxNotificationsPerPublish = 1000;
                m_subscription.PublishingEnabled = true;
                m_subscription.TimestampsToReturn = TimestampsToReturn.Both;

                m_session.AddSubscription(m_subscription);
                m_subscription.Create();

                // must specify the fields that the form is interested in.
                m_filter.SelectClauses = m_filter.ConstructSelectClauses(
                    m_session,
                    NodeId.Parse("ns=2;s=4:2"),
                    NodeId.Parse("ns=2;s=4:1"),
                    ObjectTypeIds.DialogConditionType,
                    ObjectTypeIds.ExclusiveLimitAlarmType,
                    ObjectTypeIds.NonExclusiveLimitAlarmType);

                // create a monitored item based on the current filter settings.
                m_monitoredItem = m_filter.CreateMonitoredItem(m_session);

                // set up callback for notifications.
                m_monitoredItem.Notification += m_MonitoredItem_Notification;

                m_subscription.AddItem(m_monitoredItem);
                m_subscription.ApplyChanges();

                // send an initial refresh.
                Conditions_RefreshMI_Click(sender, e);

                ConditionsMI.Enabled = true;
                ViewMI.Enabled = true;
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:70,代码来源:MainForm.cs

示例7: Server_ConnectMI_Click

        /// <summary>
        /// Connects to a server.
        /// </summary>
        private void Server_ConnectMI_Click(object sender, EventArgs e)
        {            
            try
            {
                // disconnect any existing session.
                Server_DisconnectMI_Click(sender, e);

                InitialStateTB.Text = "1";
                FinalStateTB.Text = "100";

                // create the session.
                EndpointDescription endpointDescription = SelectEndpoint();
                EndpointConfiguration endpointConfiguration = EndpointConfiguration.Create(m_configuration);
                ConfiguredEndpoint endpoint = new ConfiguredEndpoint(null, endpointDescription, endpointConfiguration);
                
                m_session = Session.Create(
                    m_configuration,
                    endpoint,
                    true,
                    m_configuration.ApplicationName,
                    60000,
                    null,
                    null);

                // set up keep alive callback.
                m_session.KeepAliveInterval = 2000;
                m_session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive);

                // this client has built-in knowledge of the information model used by the server.
                NamespaceTable wellKnownNamespaceUris = new NamespaceTable();
                wellKnownNamespaceUris.Append(Namespaces.Methods);

                string[] browsePaths = new string[] 
                {
                    "1:My Process/1:State",
                    "1:My Process",
                    "1:My Process/1:Start"
                };

                List<NodeId> nodes = FormUtils.TranslateBrowsePaths(
                    m_session,
                    ObjectIds.ObjectsFolder,
                    wellKnownNamespaceUris,
                    browsePaths);
                
                // subscribe to the state if available.
                if (nodes.Count > 0 && !NodeId.IsNull(nodes[0]))
                {
                    m_subscription = new Subscription();

                    m_subscription.PublishingEnabled = true;
                    m_subscription.PublishingInterval = 1000;
                    m_subscription.Priority = 1;
                    m_subscription.KeepAliveCount = 10;
                    m_subscription.LifetimeCount = 20;
                    m_subscription.MaxNotificationsPerPublish = 1000;

                    m_session.AddSubscription(m_subscription);
                    m_subscription.Create();

                    MonitoredItem monitoredItem = new MonitoredItem();
                    monitoredItem.StartNodeId = nodes[0];
                    monitoredItem.AttributeId = Attributes.Value;
                    monitoredItem.Notification += new MonitoredItemNotificationEventHandler(MonitoredItem_Notification);
                    m_subscription.AddItem(monitoredItem);

                    m_subscription.ApplyChanges();
                }
                
                // save the object/method
                if (nodes.Count > 2)
                {
                    m_objectNode = nodes[1];
                    m_methodNode = nodes[2];
                }

                ConnectedLB.Text = "Connected";
                ServerUrlLB.Text = endpointDescription.EndpointUrl;
                LastKeepAliveTimeLB.Text = "---";
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:88,代码来源:MainForm.cs

示例8: 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

示例9: Start

        /// <summary>
        /// Starts the specified session.
        /// </summary>
        /// <param name="session">The session.</param>
        public void Start(Session session)
        {
            m_NotificationEventHandler = new NotificationEventHandler(Session_Notification);
            session.Notification += m_NotificationEventHandler;

            Subscription subscription = m_subscription = new Subscription();

            subscription.PublishingInterval = m_samplingRate;
            subscription.KeepAliveCount = 10;
            subscription.LifetimeCount = 100;
            subscription.MaxNotificationsPerPublish = 50000;
            subscription.PublishingEnabled = false;
            subscription.TimestampsToReturn = TimestampsToReturn.Neither;
            subscription.Priority = 1;
            subscription.DisableMonitoredItemCache = true;

            session.AddSubscription(subscription);
            subscription.Create();

            DateTime start = HiResClock.UtcNow;

            for (int ii = 0; ii < m_itemCount; ii++)
            {
                MonitoredItem monitoredItem = new MonitoredItem((uint)ii);

                monitoredItem.StartNodeId = new NodeId((uint)((1<<24) + ii), 2);
                monitoredItem.AttributeId = Attributes.Value;
                monitoredItem.SamplingInterval = -1;
                monitoredItem.Filter = null;
                monitoredItem.QueueSize = 0;
                monitoredItem.DiscardOldest = true;
                monitoredItem.MonitoringMode = MonitoringMode.Reporting;

                subscription.AddItem(monitoredItem);
            }

            subscription.ApplyChanges();
            DateTime end = HiResClock.UtcNow;

            ReportMessage("Time to add {1} items {0}ms.", (end - start).TotalMilliseconds, m_itemCount);

            start = HiResClock.UtcNow;
            subscription.SetPublishingMode(true);
            end = HiResClock.UtcNow;

            ReportMessage("Time to emable publishing {0}ms.", (end - start).TotalMilliseconds);
        }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:51,代码来源:Tester.cs

示例10: LoadItems

 public void LoadItems(Session session, List<DiagnosticListViewItem> items)
 {
   Subscription subscription = new Subscription(session.DefaultSubscription);
   bool bResult = session.AddSubscription(subscription);
   subscription.DisplayName = session.ToString();
   subscription.Create();
   LoadItems(session, items, subscription);
 }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:8,代码来源:DiagnosticCtrl.cs


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