Ejemplo n.º 1
0
 public void BeginEdit()
 {
     try
     {
         _scope   = _modelItem.BeginEdit();
         _session = new UaSession {
             EndpointUrl = Session.EndpointUrl
         };
         if (_session != null)
         {
             try
             {
                 NamespaceItems.Clear();
                 var root = new ReferenceDescriptionViewModel(new ReferenceDescription {
                     DisplayName = "Objects", NodeId = new NodeId(Objects.ObjectsFolder, 0)
                 }, null, LoadChildren);
                 NamespaceItems.Add(root);
                 root.IsExpanded = true;
             }
             catch (Exception ex)
             {
                 Debug.WriteLine(ex.Message);
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 2
0
 public ModelItem AddMethod(ReferenceDescriptionViewModel vm)
 {
     if (_session != null && _session.Connected)
     {
         var name  = string.Concat(vm.Parent.DisplayName, vm.DisplayName, "Method").Replace(" ", "");
         var regex = new Regex(@"[^\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Nl}\p{Mn}\p{Mc}\p{Cf}\p{Pc}\p{Lm}]");
         name = regex.Replace(name, "_");
         if (!char.IsLetter(name, 0))
         {
             name = string.Concat("_", name);
         }
         var list2 = Methods.Select(mi => (string)mi.Properties["DisplayName"].ComputedValue).ToList();
         while (list2.Contains(name))
         {
             name = string.Concat(name, "_2");
         }
         var type = typeof(bool);
         var item = ModelFactory.CreateItem(_modelItem.Context, new UaItem {
             DisplayName = name, StartNodeId = ExpandedNodeId.ToNodeId(vm.Parent.NodeId, _session.NamespaceUris), Type = type, NodeClass = vm.NodeClass, RelativePath = vm.BrowseName
         });
         Methods.Add(item);
         return(item);
     }
     return(null);
 }
Ejemplo n.º 3
0
        public async Task <ModelItem> AddDataSource(ReferenceDescriptionViewModel vm)
        {
            if (_session != null && _session.Connected)
            {
                var nodeId = ExpandedNodeId.ToNodeId(vm.NodeId, _session.NamespaceUris);
                var type   = await _session.GetDataTypeFromNodeId(nodeId);

                var name  = string.Concat(vm.Parent.DisplayName, vm.DisplayName, "Source").Replace(" ", "");
                var regex = new Regex(@"[^\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Nl}\p{Mn}\p{Mc}\p{Cf}\p{Pc}\p{Lm}]");
                name = regex.Replace(name, "_");
                if (!char.IsLetter(name, 0))
                {
                    name = string.Concat("_", name);
                }
                var list2 = Properties.Select(mi => (string)mi.Properties["DisplayName"].ComputedValue).Concat(Commands.Select(mi => (string)mi.Properties["DisplayName"].ComputedValue)).Concat(DataSources.Select(mi => (string)mi.Properties["DisplayName"].ComputedValue)).ToList();
                while (list2.Contains(name))
                {
                    name = string.Concat(name, "_2");
                }
                var item = ModelFactory.CreateItem(_modelItem.Context, new UaItem {
                    DisplayName = name, StartNodeId = nodeId, Type = type, NodeClass = vm.NodeClass, CacheQueueSize = 240
                });
                DataSources.Add(item);
                return(item);
            }
            return(null);
        }
Ejemplo n.º 4
0
        private async Task LoadChildren(ReferenceDescriptionViewModel viewModel)
        {
            if (_session == null || _session.Disposed)
            {
                return;
            }
            try
            {
                if (!_session.Connected)
                {
                    await _session.ConnectAsync();
                }
                var browseRequest = new BrowseRequest {
                    NodesToBrowse = { new BrowseDescription {
                                          NodeId = ExpandedNodeId.ToNodeId(viewModel.NodeId, _session.NamespaceUris), ReferenceTypeId = ReferenceTypeIds.HierarchicalReferences, ResultMask = (uint)BrowseResultMask.All, NodeClassMask = (uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method, BrowseDirection = BrowseDirection.Forward
                                      } }
                };
                var browseResponse = await _session.BrowseAsync(browseRequest);

                foreach (var description in browseResponse.Results.SelectMany(result => result.References))
                {
                    viewModel.Children.Add(new ReferenceDescriptionViewModel(description, viewModel, LoadChildren));
                    await Task.Delay(50);
                }
                var continuationPoints = new ByteStringCollection(browseResponse.Results.Select(br => br.ContinuationPoint).Where(cp => null != cp));
                while (continuationPoints.Count > 0)
                {
                    var browseNextRequest = new BrowseNextRequest {
                        ContinuationPoints = continuationPoints, ReleaseContinuationPoints = false
                    };
                    var browseNextResponse = await _session.BrowseNextAsync(browseNextRequest);

                    foreach (var description in browseNextResponse.Results.SelectMany(result => result.References))
                    {
                        viewModel.Children.Add(new ReferenceDescriptionViewModel(description, viewModel, LoadChildren));
                        await Task.Delay(50);
                    }
                    continuationPoints = new ByteStringCollection(browseNextResponse.Results.Select(br => br.ContinuationPoint).Where(cp => null != cp));
                }
            }
            catch (OperationCanceledException)
            {
            }
        }