Manages a session with a server.
Inheritance: SessionClient, IDisposable
Example #1
0
 /// <summary>
 /// Updates the list of references.
 /// </summary>
 private void UpdateList(Session session, NodeId nodeId)
 {
     m_nodeId = nodeId;
     ReferencesLV.Items.Clear();
     List<ReferenceDescription> references = Browse(session, nodeId);
     DisplayReferences(session, references);
 }
        /// <summary>
        /// Prompts the user to specify the browse options.
        /// </summary>
        public bool ShowDialog(Session session, MonitoredItem monitoredItem)
        {
            if (monitoredItem == null) throw new ArgumentNullException("monitoredItem");

            DataChangeFilter filter = monitoredItem.Filter as DataChangeFilter;

            if (filter == null)
            {
                filter = new DataChangeFilter();

                filter.Trigger       = DataChangeTrigger.StatusValue;
                filter.DeadbandValue = 0;
                filter.DeadbandType  = (uint)(int)DeadbandType.None;
            }

            TriggerCB.SelectedItem      = filter.Trigger;
            DeadbandTypeCB.SelectedItem = (DeadbandType)(int)filter.DeadbandType;
            DeadbandNC.Value            = (decimal)filter.DeadbandValue;
            
            if (ShowDialog() != DialogResult.OK)
            {
                return false;
            }

            filter.Trigger       = (DataChangeTrigger)TriggerCB.SelectedItem;
            filter.DeadbandType  = Convert.ToUInt32(DeadbandTypeCB.SelectedItem);
            filter.DeadbandValue = (double)DeadbandNC.Value;

            monitoredItem.Filter = filter;

            return true;
        }
Example #3
0
        /// <summary>
        /// Initializes the test with session, configuration and logger.
        /// </summary>
        public TestBase(
            string name,
            Session session,
            ServerTestConfiguration configuration,
            ReportMessageEventHandler reportMessage,
            ReportProgressEventHandler reportProgress,
            TestBase template)
        {
            m_name = name;
            m_session = session;
            m_configuration = configuration;
            m_reportMessage = reportMessage;
            m_reportProgress = reportProgress;

            if (template != null && Object.ReferenceEquals(session, template.m_session))
            {
                m_blockSize = template.BlockSize;
                m_availableNodes = template.m_availableNodes;
                m_writeableVariables = template.m_writeableVariables;
            }
            else
            {
                m_blockSize = 1000;
                m_availableNodes = new NodeIdDictionary<Node>();
                m_writeableVariables = new List<VariableNode>();
            }
        }
Example #4
0
        public void Show(Session session, NodeId nodeId)
        {
            m_session = session;
            m_nodeId = nodeId;

            Show();
        }
Example #5
0
        /// <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();
        }
Example #6
0
        /// <summary>
        /// Sets the nodes in the control.
        /// </summary>
        public void Initialize(Session session, NodeIdCollection nodeIds, NodeClass nodeClassMask)
        {
            if (session == null) throw new ArgumentNullException("session");
            
            Clear();
            
            m_session       = session;
            m_nodeIds       = nodeIds;
            m_nodeClassMask = (nodeClassMask == 0)?(NodeClass)Byte.MaxValue:nodeClassMask;

            if (nodeIds == null)
            {
                return;                
            }

            foreach (NodeId nodeId in nodeIds)
            {
                INode node = m_session.NodeCache.Find(nodeId);

                if (node != null && (m_nodeClassMask & node.NodeClass) != 0)
                {
                    AddItem(node, "Property", -1);
                }
            }

            AdjustColumns();
        }
Example #7
0
        /// <summary>
        /// Displays the available areas in a tree view.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns></returns>
        public NodeId ShowDialog(Session session)
        {
            m_session = session;

            TreeNode root = new TreeNode(BrowseNames.Server);
            root.Nodes.Add(new TreeNode());
            BrowseTV.Nodes.Add(root);
            root.Expand();

            // display the dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return null;
            }

            // ensure selection is valid.
            if (BrowseTV.SelectedNode == null)
            {
                return null;
            }

            // get the selection.
            ReferenceDescription reference = (ReferenceDescription)BrowseTV.SelectedNode.Tag;

            if (reference == null)
            {
                return ObjectIds.Server;
            }

            // return the result.
            return (NodeId)reference.NodeId;
        }
Example #8
0
 public static ReferenceDescriptionCollection Browse(Session session, BrowseDescription nodeToBrowse, bool throwOnError)
 {
     try
       {
     var descriptionCollection = new ReferenceDescriptionCollection();
     var nodesToBrowse = new BrowseDescriptionCollection { nodeToBrowse };
     BrowseResultCollection results;
     DiagnosticInfoCollection diagnosticInfos;
     session.Browse(null, null, 0U, nodesToBrowse, out results, out diagnosticInfos);
     ClientBase.ValidateResponse(results, nodesToBrowse);
     ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse);
     while (!StatusCode.IsBad(results[0].StatusCode))
     {
       for (var index = 0; index < results[0].References.Count; ++index)
     descriptionCollection.Add(results[0].References[index]);
       if (results[0].References.Count == 0 || results[0].ContinuationPoint == null)
     return descriptionCollection;
       var continuationPoints = new ByteStringCollection();
       continuationPoints.Add(results[0].ContinuationPoint);
       session.BrowseNext(null, false, continuationPoints, out results, out diagnosticInfos);
       ClientBase.ValidateResponse(results, continuationPoints);
       ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints);
     }
     throw new ServiceResultException(results[0].StatusCode);
       }
       catch (Exception ex)
       {
     if (throwOnError)
       throw new ServiceResultException(ex, 2147549184U);
     return null;
       }
 }
Example #9
0
        /// <summary>
        /// Prompts the user to edit a value.
        /// </summary>
        public Variant ShowDialog(Session session, NodeId nodeId)
        {
            m_session = session;
            m_nodeId = nodeId;

            #region Task #B2 - Write Value
            // generate a default value based on the data type.
            m_value = Variant.Null;
            m_sourceType = GetExpectedType(session, nodeId);

            if (m_sourceType != null)
            {
                m_value = new Variant(TypeInfo.GetDefaultValue(m_sourceType.BuiltInType), m_sourceType);
            }

            // cast the value to a string.
            ValueTB.Text = (string)TypeInfo.Cast(m_value.Value, m_value.TypeInfo, BuiltInType.String);
            #endregion

            if (ShowDialog() != DialogResult.OK)
            {
                return Variant.Null;
            }

            return m_value;
        }
Example #10
0
        /// <summary>
        /// Displays the dialog.
        /// </summary>
        public void Show(Session session, NodeId objectId, NodeId methodId)
        {
            if (session == null)  throw new ArgumentNullException("session");
            if (methodId == null) throw new ArgumentNullException("methodId");
            
            if (m_session != null)
            {
                m_session.SessionClosing -= m_SessionClosing;
            }

            m_session = session;
            m_session.SessionClosing += m_SessionClosing;
        
            m_objectId = objectId;            
            m_methodId = methodId;

            InputArgumentsCTRL.Update(session, methodId, true);     
            OutputArgumentsCTRL.Update(session, methodId, false);
            
            Node target = session.NodeCache.Find(objectId) as Node;
            Node method = session.NodeCache.Find(methodId) as Node;

            if (target != null && method != null)
            {
                Text = String.Format("Call {0}.{1}", target, method);
            }

            Show();
            BringToFront();
        }
Example #11
0
        /// <summary>
        /// Prompts the user to specify the browse options.
        /// </summary>
        public bool ShowDialog(Session session, ReadValueId valueId)
        {
            if (session == null) throw new ArgumentNullException("session");
            if (valueId == null) throw new ArgumentNullException("valueId");

            NodeIdCTRL.Browser = new Browser(session);

            INode node = session.NodeCache.Find(valueId.NodeId);

            if (node != null)
            {
                DisplayNameTB.Text = node.ToString();
            }

            NodeIdCTRL.Identifier      = valueId.NodeId;
            AttributeIdCB.SelectedItem = Attributes.GetBrowseName(valueId.AttributeId);
            IndexRangeTB.Text          = valueId.IndexRange;
            EncodingCB.Text            = (valueId.DataEncoding != null)?valueId.DataEncoding.Name:null;
         
            if (ShowDialog() != DialogResult.OK)
            {
                return false;
            }

            valueId.NodeId      = NodeIdCTRL.Identifier;
            valueId.AttributeId = Attributes.GetIdentifier((string)AttributeIdCB.SelectedItem);
            valueId.IndexRange  = IndexRangeTB.Text;            
         
            if (String.IsNullOrEmpty(EncodingCB.Text))
            {
                valueId.DataEncoding = new QualifiedName(EncodingCB.Text);
            }

            return true;
        }
Example #12
0
        /// <summary>
        /// Updates the list control.
        /// </summary>
        private void UpdateList(Session session, Argument[] arguments, string browseName)
        {
            for (int ii = 0; ii < arguments.Length; ii++)
            {
                Argument argument = arguments[ii];
                Variant defaultValue = new Variant(TypeInfo.GetDefaultValue(argument.DataType, argument.ValueRank));

                ListViewItem item = new ListViewItem(arguments[ii].Name);

                if (browseName == BrowseNames.InputArguments)
                {
                    item.SubItems.Add("IN");
                    m_firstOutputArgument++;
                }
                else
                {
                    item.SubItems.Add("OUT");
                }

                string dataType = session.NodeCache.GetDisplayText(arguments[ii].DataType);

                if (arguments[ii].ValueRank >= 0)
                {
                    dataType += "[]";
                }

                item.SubItems.Add(defaultValue.ToString());
                item.SubItems.Add(dataType);
                item.SubItems.Add(Utils.Format("{0}", arguments[ii].Description));
                item.Tag = defaultValue;

                ArgumentsLV.Items.Add(item);
            }
        }
Example #13
0
        /// <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;
        }
Example #14
0
        /// <summary>
        /// Prompts the user to specify the browse options.
        /// </summary>
        public bool ShowDialog(Session session, WriteValue value)
        {
            if (session == null) throw new ArgumentNullException("session");
            if (value == null)   throw new ArgumentNullException("value");

            
            NodeIdCTRL.Browser = new Browser(session);

            INode node = session.NodeCache.Find(value.NodeId);

            if (node != null)
            {
                DisplayNameTB.Text = node.ToString();
            }

            NodeIdCTRL.Identifier      = value.NodeId;
            AttributeIdCB.SelectedItem = Attributes.GetBrowseName(value.AttributeId);
            IndexRangeTB.Text          = value.IndexRange;
         
            if (ShowDialog() != DialogResult.OK)
            {
                return false;
            }

            value.NodeId      = NodeIdCTRL.Identifier;
            value.AttributeId = Attributes.GetIdentifier((string)AttributeIdCB.SelectedItem);
            value.IndexRange  = IndexRangeTB.Text;            
         
            return true;
        }
        /// <summary>
        /// Sets the nodes in the control.
        /// </summary>
        public void Initialize(Session session, ExpandedNodeId nodeId)
        {
            if (session == null) throw new ArgumentNullException("session");
            
            Clear();

            if (nodeId == null)
            {
                return;                
            }
            
            m_session = session;
            m_nodeId  = (NodeId)nodeId;

            INode node = m_session.NodeCache.Find(m_nodeId);

            if (node != null && (node.NodeClass & (NodeClass.Variable | NodeClass.Object)) != 0)
            {
                AddReferences(ReferenceTypeIds.HasTypeDefinition, BrowseDirection.Forward);
                AddReferences(ReferenceTypeIds.HasModellingRule,  BrowseDirection.Forward);
            }

            AddAttributes();
            AddProperties();
        }
Example #16
0
        /// <summary>
        /// Browses up.
        /// </summary>
        /// <param name="session">The session.</param>
        public void BrowseUp(Session session)
        {
            TraceState("BrowseUp");

            // find the id of the current node.
            string itemId = null;
                       
            lock (m_lock)
            {
                // check if already at root.
                if (m_browsePosition == null || String.IsNullOrEmpty(m_browsePosition.ItemId))
                {
                    throw ComUtils.CreateComException(ResultIds.E_FAIL);
                }

                itemId = m_browsePosition.ItemId;
            }

            // find the parent - revert to root if parent does not exist.
            ComDaBrowseElement parent = m_cache.FindParent(session, itemId);
            
            lock (m_lock)
            {
                m_browsePosition = parent; 
            }
        }
Example #17
0
        /// <summary>
        /// Displays the address space with the specified view
        /// </summary>
        public void Show(Session session, NodeId startId)
        {   
            if (session == null) throw new ArgumentNullException("session");
            
            if (m_session != null)
            {
                m_session.SessionClosing -= m_SessionClosing;
            }

            m_session = session;            
            m_session.SessionClosing += m_SessionClosing;
            
            Browser browser  = new Browser(session);

            browser.BrowseDirection = BrowseDirection.Both;
            browser.ContinueUntilDone = true;
            browser.ReferenceTypeId = ReferenceTypeIds.References;

            BrowseCTRL.Initialize(browser, startId);
            
            UpdateNavigationBar();

            Show();
            BringToFront();
        }
Example #18
0
        /// <summary>
        /// Prompts the user to view or edit the value.
        /// </summary>
        public object ShowDialog(
            Session session, 
            NodeId nodeId,
            uint attributeId,
            string name, 
            object value, 
            bool readOnly,
            string caption)
        {
            if (!String.IsNullOrEmpty(caption))
            {
                this.Text = caption;
            }

            OkBTN.Visible = !readOnly;

            ValueCTRL.ChangeSession(session);
            ValueCTRL.ShowValue(nodeId, attributeId, name, value, readOnly);

            if (base.ShowDialog() != DialogResult.OK)
            {
                return null;
            }

            return ValueCTRL.GetValue();
        }
Example #19
0
        /// <summary>
        /// Creates the monitored item based on the current definition.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns>The monitored item.</returns>
        public MonitoredItem CreateMonitoredItem(Session session)
        {
            // choose the server object by default.
            if (AreaId == null)
            {
                AreaId = ObjectIds.Server;
            }

            // create the item with the filter.
            MonitoredItem monitoredItem = new MonitoredItem();

            monitoredItem.DisplayName = null;
            monitoredItem.StartNodeId = AreaId;
            monitoredItem.RelativePath = null;
            monitoredItem.NodeClass = NodeClass.Object;
            monitoredItem.AttributeId = Attributes.EventNotifier;
            monitoredItem.IndexRange = null;
            monitoredItem.Encoding = null;
            monitoredItem.MonitoringMode = MonitoringMode.Reporting;
            monitoredItem.SamplingInterval = 0;
            monitoredItem.QueueSize = UInt32.MaxValue;
            monitoredItem.DiscardOldest = true;
            monitoredItem.Filter = ConstructFilter(session);

            // save the definition as the handle.
            monitoredItem.Handle = this;

            return monitoredItem;
        }
Example #20
0
        /// <summary>
        /// Prompts the user to edit an annotation.
        /// </summary>
        public Annotation ShowDialog(Session session, Annotation annotation, string caption)
        {
            if (caption != null)
            {
                this.Text = caption;
            }

            m_session = session;

            if (annotation == null)
            {
                annotation = new Annotation();
                annotation.AnnotationTime = DateTime.UtcNow;
                annotation.UserName = Environment.GetEnvironmentVariable("USERNAME");
                annotation.Message = "<insert your message here>";
            }

            AnnotationTimeDP.Value = annotation.AnnotationTime;
            UserNameTB.Text = annotation.UserName;
            CommentTB.Text = annotation.Message;

            if (ShowDialog() != DialogResult.OK)
            {
                return null;
            }

            annotation = new Annotation();
            annotation.AnnotationTime = AnnotationTimeDP.Value;
            annotation.UserName = UserNameTB.Text;
            annotation.Message = CommentTB.Text;

            return annotation;
        }
Example #21
0
 /// <summary>
 /// Initializes the control with a root and a set of hierarchial reference types to follow. 
 /// </summary>
 /// <param name="session">The session.</param>
 /// <param name="rootId">The root of the hierarchy to browse.</param>
 /// <param name="referenceTypeIds">The reference types to follow.</param>
 public void Initialize(
     Session session,
     NodeId rootId,
     params NodeId[] referenceTypeIds)
 {
     BrowseCTRL.Initialize(session, rootId, referenceTypeIds);
 }
Example #22
0
        public void Show(Session session, NodeId objectId, NodeId methodId)
        {
            m_session = session;
            m_objectId = objectId;
            m_methodId = methodId;

            Show();
        }
 private void Session_Closing(object sender, EventArgs e)
 {
     if (Object.ReferenceEquals(sender, m_session))
     {
         m_session.SessionClosing -= m_SessionClosing;
         m_session = null;
     }
 }
        /// <summary>
        /// Initializes the object with default values.
        /// </summary>
        public NodeCache(Session session)
        {
            if (session == null) throw new ArgumentNullException("session");

            m_session  = session;
            m_typeTree = new TypeTable(m_session.NamespaceUris);
            m_nodes    = new NodeTable(m_session.NamespaceUris, m_session.ServerUris, m_typeTree);
        }
Example #25
0
 /// <summary>
 /// Creates the test object.
 /// </summary>
 public TranslatePathTest(
     Session session,
     ServerTestConfiguration configuration,
     ReportMessageEventHandler reportMessage,
     ReportProgressEventHandler reportProgress,
     TestBase template)
 : 
     base("TranslatePath", session, configuration, reportMessage, reportProgress, template)
 {
 }
Example #26
0
        /// <summary>
        /// Displays a dialog that allows a use to edit a value.
        /// </summary>
        public static object EditValue(Session session, object value)
        {
            TypeInfo typeInfo = TypeInfo.Construct(value);

            if (typeInfo != null)
            {
                return EditValue(session, value, (uint)typeInfo.BuiltInType, typeInfo.ValueRank);
            }

            return null;
        }
Example #27
0
 /// <summary>
 /// Initializes the object with the default values
 /// </summary>
 /// <param name="server">The server associated with the browser</param>
 /// <param name="session">The session associated with the browser</param>
 public AreaBrowser(ComAeProxy server, Session session)
 {
     m_server = server;
     m_session = session;
     // ensure browse stack has been initialized.
     if (m_browseStack.Count == 0)
     {
         INode parent = m_session.NodeCache.Find(Objects.Server);
         m_browseStack.Push(parent);
     }
 }
Example #28
0
        /// <summary>
        /// Sets the nodes in the control.
        /// </summary>
        public bool Update(Session session, NodeId methodId, bool inputArgs)
        {
            if (session == null)  throw new ArgumentNullException("session");
            if (methodId == null) throw new ArgumentNullException("methodId");
            
            Clear();
            
            m_session = session;

            // find the method.
            MethodNode method = session.NodeCache.Find(methodId) as MethodNode;

            if (method == null)
            {
                return false;
            }

            // select the property to find.
            QualifiedName browseName = null;
                    
            if (inputArgs)
            {
                browseName = Opc.Ua.BrowseNames.InputArguments;
            }
            else
            {
                browseName = Opc.Ua.BrowseNames.OutputArguments;
            }

            // fetch the argument list.
            VariableNode argumentsNode = session.NodeCache.Find(methodId, ReferenceTypeIds.HasProperty, false, true, browseName) as VariableNode;

            if (argumentsNode == null)
            {
                return false;
            }

            // read the value from the server.
            DataValue value = m_session.ReadValue(argumentsNode.NodeId);

            ExtensionObject[] argumentsList = value.Value as ExtensionObject[];

            if (argumentsList != null)
            {
                for (int ii = 0; ii < argumentsList.Length; ii++)
                {
                    AddItem(argumentsList[ii].Body as Argument);
                }
            }

            AdjustColumns();

            return ItemsLV.Items.Count > 0;
        }        
Example #29
0
        /// <summary>
        /// Displays the dialog.
        /// </summary>
        public void Show(Session session, NodeId nodeId)
        {
            m_session = session;
            m_nodeId = nodeId;

            #region Task #B3 - Subscribe Data
            CreateSubscription();
            #endregion

            Show();
        }
        //private ILocalNode m_selectedType;
        #endregion
        
        #region Public Interface
        /// <summary>
        /// Displays the dialog.
        /// </summary>
        public void Show(
            Session session,
            NodeId  typeId)
        {
            if (session == null) throw new ArgumentNullException("session");

            m_session = session;                    
            
            //TypeNavigatorCTRL.Initialize(m_session, typeId);
            //TypeHierarchyCTRL.Initialize(m_session, typeId);
        }