Пример #1
0
 /// <summary>
 /// Create service model from api model
 /// </summary>
 public static PublishedItemListRequestModel ToServiceModel(
     this PublishedItemListRequestApiModel model)
 {
     if (model == null)
     {
         return(null);
     }
     return(new PublishedItemListRequestModel {
         ContinuationToken = model.ContinuationToken
     });
 }
        public async Task <PublishedItemListResponseApiModel> GetFirstListOfPublishedNodesAsync(
            string endpointId, [FromBody][Required] PublishedItemListRequestApiModel request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var result = await _publisher.NodePublishListAsync(
                endpointId, request.ToServiceModel());

            return(result.ToApiModel());
        }
Пример #3
0
        /// <summary>
        /// List published nodes
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <PublishedItemListResponseApiModel> PublishListAsync(
            PublishedItemListRequestApiModel request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var result = await _publisher.NodePublishListAsync(
                _twin.Endpoint, request.ToServiceModel());

            return(new PublishedItemListResponseApiModel(result));
        }
        /// <inheritdoc/>
        public async Task <PublishedItemListResponseApiModel> NodePublishListAsync(
            string endpointId, PublishedItemListRequestApiModel content, CancellationToken ct)
        {
            if (string.IsNullOrEmpty(endpointId))
            {
                throw new ArgumentNullException(nameof(endpointId));
            }
            var request = _httpClient.NewRequest($"{_serviceUri}/v2/publish/{endpointId}",
                                                 _resourceId);

            request.SetContent(content);
            var response = await _httpClient.PostAsync(request, ct).ConfigureAwait(false);

            response.Validate();
            return(response.GetContent <PublishedItemListResponseApiModel>());
        }
 /// <summary>
 /// Get currently published nodes
 /// </summary>
 /// <remarks>
 /// Returns currently published node ids for an endpoint. The endpoint must be
 /// activated and connected and the module client and server must trust each
 /// other.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='endpointId'>
 /// The identifier of the activated endpoint.
 /// </param>
 /// <param name='body'>
 /// The list request
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <PublishedItemListResponseApiModel> GetFirstListOfPublishedNodesAsync(this IAzureOpcPublisherClient operations, string endpointId, PublishedItemListRequestApiModel body, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.GetFirstListOfPublishedNodesWithHttpMessagesAsync(endpointId, body, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Get currently published nodes
 /// </summary>
 /// <remarks>
 /// Returns currently published node ids for an endpoint. The endpoint must be
 /// activated and connected and the module client and server must trust each
 /// other.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='endpointId'>
 /// The identifier of the activated endpoint.
 /// </param>
 /// <param name='body'>
 /// The list request
 /// </param>
 public static PublishedItemListResponseApiModel GetFirstListOfPublishedNodes(this IAzureOpcPublisherClient operations, string endpointId, PublishedItemListRequestApiModel body)
 {
     return(operations.GetFirstListOfPublishedNodesAsync(endpointId, body).GetAwaiter().GetResult());
 }
        public async Task <ActionResult> GetChildren(string jstreeNode)
        {
            // This delimiter is used to allow the storing of the OPC UA parent node ID together with the OPC UA child node ID in jstree data structures and provide it as parameter to
            // Ajax calls.
            string[] delimiter       = { "__$__" };
            string[] jstreeNodeSplit = jstreeNode.Split(delimiter, 3, StringSplitOptions.None);
            string   node;

            if (jstreeNodeSplit.Length == 1)
            {
                node = jstreeNodeSplit[0];
            }
            else
            {
                node = jstreeNodeSplit[1];
            }

            List <object> jsonTree    = new List <object>();
            string        endpointId  = Session["EndpointId"].ToString();
            string        endpointUrl = Session["EndpointUrl"].ToString();
            string        ProductUri  = Session["ProductUri"].ToString();

            // read the currently published nodes
            PublishedItemListResponseApiModel publishedNodes = new PublishedItemListResponseApiModel();

            try
            {
                PublishedItemListRequestApiModel publishModel = new PublishedItemListRequestApiModel();
                publishedNodes = await TwinService.GetPublishedNodesAsync(endpointId, publishModel);
            }
            catch (Exception e)
            {
                // do nothing, since we still want to show the tree
                Trace.TraceWarning("Can not read published nodes for endpoint '{0}'.", endpointUrl);
                string errorMessage = string.Format(Strings.BrowserOpcException, e.Message,
                                                    e.InnerException?.Message ?? "--", e?.StackTrace ?? "--");
                Trace.TraceWarning(errorMessage);
            }

            BrowseResponseApiModel browseData = new BrowseResponseApiModel();

            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                try
                {
                    BrowseRequestApiModel model = new BrowseRequestApiModel();
                    model.NodeId          = node;
                    model.TargetNodesOnly = false;

                    browseData = TwinService.NodeBrowse(endpointId, model);
                }
                catch (Exception e)
                {
                    // skip this node
                    Trace.TraceError("Can not browse node '{0}'", node);
                    string errorMessage = string.Format(Strings.BrowserOpcException, e.Message,
                                                        e.InnerException?.Message ?? "--", e?.StackTrace ?? "--");
                    Trace.TraceError(errorMessage);
                }

                Trace.TraceInformation("Browsing node '{0}' data took {0} ms", node.ToString(), stopwatch.ElapsedMilliseconds);

                if (browseData.References != null)
                {
                    var idList = new List <string>();
                    foreach (var nodeReference in browseData.References)
                    {
                        bool idFound = false;
                        foreach (var id in idList)
                        {
                            if (id == nodeReference.Target.NodeId.ToString())
                            {
                                idFound = true;
                            }
                        }
                        if (idFound == true)
                        {
                            continue;
                        }

                        Trace.TraceInformation("Browse '{0}' count: {1}", nodeReference.Target.NodeId, jsonTree.Count);

                        NodeApiModel currentNode = nodeReference.Target;

                        currentNode = nodeReference.Target;

                        byte currentNodeAccessLevel   = 0;
                        byte currentNodeEventNotifier = 0;
                        bool currentNodeExecutable    = false;

                        switch (currentNode.NodeClass)
                        {
                        case NodeClass.Variable:
                            currentNodeAccessLevel = (byte)currentNode.UserAccessLevel;
                            if (!PermsChecker.HasPermission(Permission.ControlOpcServer))
                            {
                                currentNodeAccessLevel = (byte)((uint)currentNodeAccessLevel & ~0x2);
                            }
                            break;

                        case NodeClass.Object:
                            currentNodeEventNotifier = (byte)currentNode.EventNotifier;
                            break;

                        case NodeClass.View:
                            currentNodeEventNotifier = (byte)currentNode.EventNotifier;
                            break;

                        case NodeClass.Method:
                            if (PermsChecker.HasPermission(Permission.ControlOpcServer))
                            {
                                currentNodeExecutable = (bool)currentNode.UserExecutable;
                            }
                            break;

                        default:
                            break;
                        }

                        var isPublished = false;
                        var isRelevant  = false;
                        if (publishedNodes.Items != null)
                        {
                            foreach (var item in publishedNodes.Items)
                            {
                                if (item.NodeId == nodeReference.Target.NodeId.ToString())
                                {
                                    isPublished = true;
                                    ContosoOpcUaNode contosoOpcUaNode = Startup.Topology.GetOpcUaNode(ProductUri, item.NodeId);
                                    if (contosoOpcUaNode?.Relevance != null)
                                    {
                                        isRelevant = true;
                                    }
                                }
                            }
                        }

                        jsonTree.Add(new
                        {
                            id            = ("__" + node + delimiter[0] + nodeReference.Target.NodeId.ToString()),
                            text          = nodeReference.Target.DisplayName.ToString(),
                            nodeClass     = nodeReference.Target.NodeClass.ToString(),
                            accessLevel   = currentNodeAccessLevel.ToString(),
                            eventNotifier = currentNodeEventNotifier.ToString(),
                            executable    = currentNodeExecutable.ToString(),
                            children      = nodeReference.Target.HasChildren,
                            publishedNode = isPublished,
                            relevantNode  = isRelevant
                        });
                        idList.Add(nodeReference.Target.NodeId.ToString());
                    }
                }

                stopwatch.Stop();
                Trace.TraceInformation("Browing all childeren info of node '{0}' took {0} ms", node, stopwatch.ElapsedMilliseconds);

                return(Json(jsonTree, JsonRequestBehavior.AllowGet));
            }
            catch (Exception exception)
            {
                return(Content(CreateOpcExceptionActionString(exception)));
            }
        }
 /// <inheritdoc/>
 public Task <PublishedItemListResponseApiModel> NodePublishListAsync(
     string endpointId, PublishedItemListRequestApiModel content, CancellationToken ct)
 {
     return(Task.FromException <PublishedItemListResponseApiModel>(new NotImplementedException()));
 }
        public async Task <PublishedItemListResponseApiModel> GetPublishedNodesAsync(string endpoint, PublishedItemListRequestApiModel content)
        {
            var applications = await _twinServiceHandler.NodePublishListAsync(endpoint, content).ConfigureAwait(false);

            return(applications);
        }
        public PublishedItemListResponseApiModel GetPublishedNodes(string endpoint, PublishedItemListRequestApiModel content)
        {
            Task <PublishedItemListResponseApiModel> t = Task.Run(() => _twinServiceHandler.NodePublishListAsync(endpoint, content));

            return(t.Result);
        }