本文整理汇总了C#中Subscription.AddItem方法的典型用法代码示例。如果您正苦于以下问题:C# Subscription.AddItem方法的具体用法?C# Subscription.AddItem怎么用?C# Subscription.AddItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subscription
的用法示例。
在下文中一共展示了Subscription.AddItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoReconnectTest
/// <summary>
/// Tests the session reconnect.
/// </summary>
private bool DoReconnectTest()
{
double increment = MaxProgress/6;
double position = 0;
bool success = true;
lock (m_messages)
{
m_messages.Clear();
}
int currentKeepAlive = Session.KeepAliveInterval;
List<Subscription> subscriptions = new List<Subscription>();
KeepAliveEventHandler keepAliveHandler = new KeepAliveEventHandler(Session_Reconnect);
NotificationEventHandler notificationHandler = new NotificationEventHandler(Session_Notification);
try
{
Session.KeepAlive += keepAliveHandler;
Session.Notification += notificationHandler;
for (int publishingInterval = 1000; publishingInterval <= 10000; publishingInterval += 1000)
{
Subscription subscription = new Subscription();
subscription.MaxMessageCount = 100;
subscription.LifetimeCount = 100;
subscription.KeepAliveCount = 10;
subscription.PublishingEnabled = true;
subscription.PublishingInterval = publishingInterval;
MonitoredItem monitoredItem = new MonitoredItem();
monitoredItem.StartNodeId = VariableIds.Server_ServerStatus_CurrentTime;
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.SamplingInterval = -1;
monitoredItem.QueueSize = 0;
monitoredItem.DiscardOldest = true;
subscription.AddItem(monitoredItem);
Session.AddSubscription(subscription);
subscription.Create();
subscriptions.Add(subscription);
}
m_keepAliveCount = 0;
Session.KeepAliveInterval = 1000;
Log("Setting keep alive interval to {0}ms.", Session.KeepAliveInterval);
int testDuration = 3000;
for (int ii = 0; ii < 6; ii++)
{
Session.Reconnect();
Log("Session reconnected. KeepAlives={0}", m_keepAliveCount);
if (m_errorEvent.WaitOne(testDuration, false))
{
Log("Unexpected error waiting for session keep alives. {0}", m_error.ToLongString());
return false;
}
position += increment;
ReportProgress(position);
}
}
finally
{
Session.RemoveSubscriptions(subscriptions);
Session.KeepAliveInterval = currentKeepAlive;
Session.KeepAlive -= keepAliveHandler;
Session.Notification -= notificationHandler;
}
ReportProgress(MaxProgress);
lock (m_messages)
{
foreach (KeyValuePair<uint,List<uint>> entry in m_messages)
{
entry.Value.Sort();
for (int ii = 0; ii < entry.Value.Count-1; ii++)
{
if (entry.Value[ii+1] - entry.Value[ii] > 1)
{
Log("Missing message. Subscription={0}, SequenceNumber={1}-{2}", entry.Key, entry.Value[ii]+1, entry.Value[ii+1]-1);
}
if (entry.Value[ii+1] == entry.Value[ii])
{
// Log("Duplicate message. Subscription={0}, SequenceNumber={1}", entry.Key, entry.Value[ii]);
}
}
}
//.........这里部分代码省略.........
示例2: 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);
}
}
示例3: DoKeepAliveTest
/// <summary>
/// Tests the session keep alive when there are no errors.
/// </summary>
private bool DoKeepAliveTest()
{
bool success = true;
double increment = MaxProgress/3;
double position = 0;
m_keepAliveCount = 0;
int currentKeepAlive = Session.KeepAliveInterval;
List<Subscription> subscriptions = new List<Subscription>();
KeepAliveEventHandler handler = new KeepAliveEventHandler(Session_KeepAlive);
try
{
Session.KeepAlive += handler;
// add several subscriptions with long publish intervals.
for (int publishingInterval = 10000; publishingInterval <= 20000; publishingInterval += 1000)
{
Subscription subscription = new Subscription();
subscription.MaxMessageCount = 100;
subscription.LifetimeCount = 100;
subscription.KeepAliveCount = 10;
subscription.PublishingEnabled = true;
subscription.PublishingInterval = publishingInterval;
MonitoredItem monitoredItem = new MonitoredItem();
monitoredItem.StartNodeId = VariableIds.Server_ServerStatus_CurrentTime;
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.SamplingInterval = -1;
monitoredItem.QueueSize = 0;
monitoredItem.DiscardOldest = true;
subscription.AddItem(monitoredItem);
Session.AddSubscription(subscription);
subscription.Create();
subscriptions.Add(subscription);
}
// get a value to read.
ReadValueId nodeToRead = new ReadValueId();
nodeToRead.NodeId = VariableIds.Server_ServerStatus;
nodeToRead.AttributeId = Attributes.Value;
ReadValueIdCollection nodesToRead = new ReadValueIdCollection();
nodesToRead.Add(nodeToRead);
int testDuration = 5000;
// make sure the keep alives come at the expected rate.
for (int keepAliveInterval = 500; keepAliveInterval < 2000; keepAliveInterval += 500)
{
m_keepAliveCount = 0;
DateTime start = DateTime.UtcNow;
DataValueCollection results = null;
DiagnosticInfoCollection diagnosticsInfos = null;
Session.Read(
null,
0,
TimestampsToReturn.Neither,
nodesToRead,
out results,
out diagnosticsInfos);
ClientBase.ValidateResponse(results, nodesToRead);
ClientBase.ValidateDiagnosticInfos(diagnosticsInfos, nodesToRead);
ServerStatusDataType status = ExtensionObject.ToEncodeable(results[0].Value as ExtensionObject) as ServerStatusDataType;
if (status == null)
{
Log("Server did not return a valid ServerStatusDataType structure. Value={0}, Status={1}", results[0].WrappedValue, results[0].StatusCode);
return false;
}
if ((DateTime.UtcNow - start).TotalSeconds > 1)
{
Log("Unexpected delay reading the ServerStatus structure. Delay={0}s", (DateTime.UtcNow - start).TotalSeconds);
return false;
}
Log("Setting keep alive interval to {0}ms.", keepAliveInterval);
Session.KeepAliveInterval = keepAliveInterval;
if (m_errorEvent.WaitOne(testDuration, false))
{
Log("Unexpected error waiting for session keep alives. {0}", m_error.ToLongString());
return false;
}
if (m_keepAliveCount < testDuration / keepAliveInterval)
//.........这里部分代码省略.........
示例4: BoilerCB_SelectedIndexChanged
private void BoilerCB_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (m_session == null)
{
return;
}
if (m_subscription != null)
{
m_session.RemoveSubscription(m_subscription);
m_subscription = null;
}
ReferenceDescription boiler = (ReferenceDescription)BoilerCB.SelectedItem;
if (boiler == null)
{
return;
}
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();
NamespaceTable wellKnownNamespaceUris = new NamespaceTable();
wellKnownNamespaceUris.Append(Namespaces.Boiler);
string[] browsePaths = new string[]
{
"1:PipeX001/1:FTX001/1:Output",
"1:DrumX001/1:LIX001/1:Output",
"1:PipeX002/1:FTX002/1:Output",
"1:LCX001/1:SetPoint",
};
List<NodeId> nodes = ClientUtils.TranslateBrowsePaths(
m_session,
(NodeId)boiler.NodeId,
wellKnownNamespaceUris,
browsePaths);
Control[] controls = new Control[]
{
InputPipeFlowTB,
DrumLevelTB,
OutputPipeFlowTB,
DrumLevelSetPointTB
};
for (int ii = 0; ii < nodes.Count; ii++)
{
controls[ii].Text = "---";
if (nodes[ii] != null)
{
MonitoredItem monitoredItem = new MonitoredItem();
monitoredItem.StartNodeId = nodes[ii];
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.Handle = controls[ii];
monitoredItem.Notification += new MonitoredItemNotificationEventHandler(MonitoredItem_Notification);
m_subscription.AddItem(monitoredItem);
}
}
m_subscription.ApplyChanges();
}
catch (Exception exception)
{
ClientUtils.HandleException(this.Text, exception);
}
}
示例5: Subscribe
/// <summary>
/// Adds a item to a subscription.
/// </summary>
private void Subscribe(Subscription subscription, ReferenceDescription reference)
{
MonitoredItem monitoredItem = new MonitoredItem(subscription.DefaultItem);
monitoredItem.DisplayName = subscription.Session.NodeCache.GetDisplayText(reference);
monitoredItem.StartNodeId = (NodeId)reference.NodeId;
monitoredItem.NodeClass = (NodeClass)reference.NodeClass;
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.SamplingInterval = 0;
monitoredItem.QueueSize = 1;
// add condition fields to any event filter.
EventFilter filter = monitoredItem.Filter as EventFilter;
if (filter != null)
{
monitoredItem.AttributeId = Attributes.EventNotifier;
monitoredItem.QueueSize = 0;
}
subscription.AddItem(monitoredItem);
subscription.ApplyChanges();
}
示例6: CreateSubscription
/// <summary>
/// Creates the subscription.
/// </summary>
private void CreateSubscription()
{
if (m_subscription != null)
{
m_subscription.Dispose();
m_subscription = null;
}
// get the current session.
Session session = m_server.Session;
if (session == null)
{
return;
}
// create the subscription.
m_subscription = new Subscription();
m_subscription.PublishingEnabled = Active;
m_subscription.PublishingInterval = (int)Math.Max(BufferTime, 1000);
m_subscription.KeepAliveCount = (uint)Math.Max(Math.Ceiling(((double)KeepAlive)/m_subscription.PublishingInterval), 10);
m_subscription.LifetimeCount = m_subscription.KeepAliveCount*3;
m_subscription.MaxNotificationsPerPublish = MaxSize;
m_subscription.TimestampsToReturn = TimestampsToReturn.Neither;
m_subscription.Priority = 0;
m_subscription.FastEventCallback = OnEventNotification;
m_subscription.DisableMonitoredItemCache = true;
session.AddSubscription(m_subscription);
m_subscription.Create();
// update the monitored items.
EventFilter filter = m_filter.GetFilter();
MonitoringMode monitoringMode = (Active)?MonitoringMode.Reporting:MonitoringMode.Disabled;
foreach (MonitoredItem monitoredItem in m_notifiers.Values)
{
monitoredItem.Filter = filter;
monitoredItem.MonitoringMode = monitoringMode;
m_subscription.AddItem(monitoredItem);
}
m_subscription.ApplyChanges();
}
示例7: CreateSubscription
/// <summary>
/// Creates the subscription.
/// </summary>
private void CreateSubscription()
{
m_subscription = new Subscription();
m_subscription.Handle = this;
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();
m_monitoredItem = new MonitoredItem();
m_monitoredItem.StartNodeId = m_areaId;
m_monitoredItem.AttributeId = Attributes.EventNotifier;
m_monitoredItem.SamplingInterval = 0;
m_monitoredItem.QueueSize = 1000;
m_monitoredItem.DiscardOldest = true;
ChangeFilter(m_filter, false);
m_monitoredItem.Notification += new MonitoredItemNotificationEventHandler(MonitoredItem_Notification);
m_subscription.AddItem(m_monitoredItem);
m_subscription.ApplyChanges();
}
示例8: DoDeadbandTest
//.........这里部分代码省略.........
filters[4] = filter;
lock (m_variables)
{
m_monitoredItems = new Dictionary<uint,TestVariable>();
for (int ii = 0; ii < m_variables.Count; ii++)
{
VariableNode variable = m_variables[ii].Variable;
for (int jj = 0; jj < filters.Length; jj++)
{
if (m_variables[ii].EURange == null && filters[jj].DeadbandType == (uint)DeadbandType.Percent)
{
continue;
}
MonitoredItem monitoredItem = new MonitoredItem();
monitoredItem.StartNodeId = variable.NodeId;
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.RelativePath = null;
monitoredItem.IndexRange = null;
monitoredItem.SamplingInterval = 100;
monitoredItem.QueueSize = 0;
monitoredItem.DiscardOldest = true;
monitoredItem.Filter = filters[jj];
monitoredItem.MonitoringMode = MonitoringMode.Reporting;
monitoredItem.Handle = m_variables[ii];
m_variables[ii].Notifications[monitoredItem.ClientHandle] = new List<Notification>();
m_monitoredItems[monitoredItem.ClientHandle] = m_variables[ii];
subscription.AddItem(monitoredItem);
}
}
}
subscription.ApplyChanges();
// check results.
foreach (MonitoredItem monitoredItem in subscription.MonitoredItems)
{
if (!CheckDeadbandError(monitoredItem))
{
success = false;
break;
}
}
}
// modify sampling interval.
if (success)
{
if (modifyDeadband)
{
if (!ModifyDeadband(subscription))
{
success = false;
}
}
}
// wait for first data change.
if (m_errorEvent.WaitOne(1000, false))
{
示例9: DoSamplingIntervalTest
//.........这里部分代码省略.........
{
lock (m_variables)
{
m_monitoredItems = new Dictionary<uint,TestVariable>();
for (int ii = 0; ii < m_variables.Count; ii++)
{
// servers that sample data values may not pick up boolean value changes.
if (m_variables[ii].DataType == BuiltInType.Boolean)
{
continue;
}
VariableNode variable = m_variables[ii].Variable;
for (int jj = 2000; jj <= 10000; jj += 1000)
{
MonitoredItem monitoredItem = new MonitoredItem();
monitoredItem.StartNodeId = variable.NodeId;
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.RelativePath = null;
monitoredItem.IndexRange = null;
monitoredItem.SamplingInterval = jj;
monitoredItem.QueueSize = 0;
monitoredItem.DiscardOldest = true;
monitoredItem.Filter = null;
monitoredItem.MonitoringMode = MonitoringMode.Reporting;
monitoredItem.Handle = m_variables[ii];
m_variables[ii].Notifications[monitoredItem.ClientHandle] = new List<Notification>();
m_monitoredItems[monitoredItem.ClientHandle] = m_variables[ii];
subscription.AddItem(monitoredItem);
}
}
}
subscription.ApplyChanges();
// check results.
foreach (MonitoredItem monitoredItem in subscription.MonitoredItems)
{
if (ServiceResult.IsBad(monitoredItem.Status.Error))
{
TestVariable variable = monitoredItem.Handle as TestVariable;
Log(
"Could not create MonitoredItem {0}. NodeId={1}, SamplingInterval={2}",
variable.Variable,
variable.Variable.NodeId,
monitoredItem.SamplingInterval);
success = false;
}
}
}
// modify sampling interval.
if (success)
{
if (modifySamplingInterval)
{
if (!ModifySamplingInterval(subscription))
{
success = false;
示例10: CreateSubscription
/// <summary>
/// Creates the subscription.
/// </summary>
private void CreateSubscription()
{
// 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();
// a table used to track event types.
m_eventTypeMappings = new Dictionary<NodeId, NodeId>();
NodeId knownEventId = ExpandedNodeId.ToNodeId(ObjectTypeIds.SystemCycleStatusEventType, m_session.NamespaceUris);
m_knownEventTypes = new Dictionary<NodeId, Type>();
m_knownEventTypes.Add(knownEventId, typeof(SystemCycleStatusEventState));
TypeDeclaration type = new TypeDeclaration();
type.NodeId = ExpandedNodeId.ToNodeId(ObjectTypeIds.SystemCycleStatusEventType, m_session.NamespaceUris);
type.Declarations = ClientUtils.CollectInstanceDeclarationsForType(m_session, type.NodeId);
// the filter to use.
m_filter = new FilterDeclaration(type, null);
// declate callback.
m_MonitoredItem_Notification = new MonitoredItemNotificationEventHandler(MonitoredItem_Notification);
// create a monitored item based on the current filter settings.
m_monitoredItem = new MonitoredItem();
m_monitoredItem.StartNodeId = Opc.Ua.ObjectIds.Server;
m_monitoredItem.AttributeId = Attributes.EventNotifier;
m_monitoredItem.SamplingInterval = 0;
m_monitoredItem.QueueSize = 1000;
m_monitoredItem.DiscardOldest = true;
m_monitoredItem.Filter = m_filter.GetFilter();
// set up callback for notifications.
m_monitoredItem.Notification += m_MonitoredItem_Notification;
m_subscription.AddItem(m_monitoredItem);
m_subscription.ApplyChanges();
}
示例11: AuditEventForm
/// <summary>
/// Initializes a new instance of the <see cref="AuditEventForm"/> class.
/// </summary>
/// <param name="session">The session.</param>
/// <param name="subscription">The subscription.</param>
public AuditEventForm(Session session, Subscription subscription)
{
InitializeComponent();
m_session = session;
m_subscription = subscription;
// a table used to track event types.
m_eventTypeMappings = new Dictionary<NodeId, NodeId>();
// the filter to use.
m_filter = new FilterDefinition();
m_filter.AreaId = ObjectIds.Server;
m_filter.Severity = EventSeverity.Min;
m_filter.IgnoreSuppressedOrShelved = true;
m_filter.EventTypes = new NodeId[] { ObjectTypeIds.AuditUpdateMethodEventType };
// find the fields of interest.
m_filter.SelectClauses = m_filter.ConstructSelectClauses(m_session, ObjectTypeIds.AuditUpdateMethodEventType);
// declate callback.
m_MonitoredItem_Notification = new MonitoredItemNotificationEventHandler(MonitoredItem_Notification);
// 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();
}
示例12: CreateSubscription
/// <summary>
/// Creates the subscription.
/// </summary>
private void CreateSubscription()
{
if (m_session == null)
{
return;
}
m_subscription = new Subscription();
m_subscription.Handle = this;
m_subscription.DisplayName = null;
m_subscription.PublishingInterval = 500;
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();
MonitoredItem monitoredItem = new MonitoredItem();
monitoredItem.StartNodeId = m_nodeId;
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.SamplingInterval = 1000;
monitoredItem.QueueSize = 1000;
monitoredItem.DiscardOldest = true;
monitoredItem.Notification += new MonitoredItemNotificationEventHandler(MonitoredItem_Notification);
m_subscription.AddItem(monitoredItem);
m_subscription.ApplyChanges();
// verify that the item was created successfully.
if (ServiceResult.IsBad(monitoredItem.Status.Error))
{
throw new ServiceResultException(monitoredItem.Status.Error);
}
}
示例13: CreateSubscription
/// <summary>
/// Creates the subscription.
/// </summary>
private void CreateSubscription()
{
if (m_session == null)
{
return;
}
m_subscription = new Subscription();
m_subscription.Handle = this;
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();
m_monitoredItem = new MonitoredItem();
m_monitoredItem.StartNodeId = m_nodeId;
m_monitoredItem.AttributeId = Attributes.Value;
m_monitoredItem.SamplingInterval = (int)SamplingIntervalNP.Value;
m_monitoredItem.QueueSize = 1000;
m_monitoredItem.DiscardOldest = true;
// specify aggregate filter.
if (AggregateCB.SelectedItem != null)
{
AggregateFilter filter = new AggregateFilter();
if (StartTimeCK.Checked)
{
filter.StartTime = StartTimeDP.Value.ToUniversalTime();
}
else
{
filter.StartTime = DateTime.UtcNow;
}
filter.ProcessingInterval = (double)ResampleIntervalNP.Value;
filter.AggregateType = ((AvailableAggregate)AggregateCB.SelectedItem).NodeId;
if (filter.AggregateType != null)
{
m_monitoredItem.Filter = filter;
}
}
m_monitoredItem.Notification += new MonitoredItemNotificationEventHandler(MonitoredItem_Notification);
m_subscription.AddItem(m_monitoredItem);
m_subscription.ApplyChanges();
SubscriptionStateChanged();
}
示例14: CreateItem
/// <summary>
/// Creates a new group item.
/// </summary>
public MonitoredItem CreateItem(Subscription subscription)
{
if (subscription == null) throw new ArgumentNullException("subscription");
MonitoredItem monitoredItem = new MonitoredItem(subscription.DefaultItem);
monitoredItem.QueueSize = 1;
if (!new MonitoredItemEditDlg().ShowDialog(subscription.Session, monitoredItem))
{
return null;
}
subscription.AddItem(monitoredItem);
subscription.ChangesCompleted();
return monitoredItem;
}
示例15: 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);
}
}