Example #1
0
        /// <summary>
        /// GetParameterAsync
        /// </summary>
        /// <param name="endpointId"></param>
        /// <param name="nodeId"></param>
        /// <returns>Status</returns>
        public async Task <string> GetParameterAsync(string endpointId, string nodeId)
        {
            Parameter = new MethodMetadataResponseApiModel();
            var model = new MethodMetadataRequestApiModel()
            {
                MethodId = nodeId
            };

            try {
                Parameter = await _twinService.NodeMethodGetMetadataAsync(endpointId, model);

                if (Parameter.ErrorInfo == null)
                {
                    return(null);
                }
                else
                {
                    if (Parameter.ErrorInfo.Diagnostics != null)
                    {
                        return(Parameter.ErrorInfo.Diagnostics.ToString());
                    }
                    else
                    {
                        return(Parameter.ErrorInfo.ToString());
                    }
                }
            }
            catch (Exception e) {
                Trace.TraceError("Can not get method parameter from node '{0}'", nodeId);
                var errorMessage = string.Concat(e.Message, e.InnerException?.Message ?? "--", e?.StackTrace ?? "--");
                Trace.TraceError(errorMessage);
                return(errorMessage);
            }
        }
Example #2
0
        /// <summary>
        /// Get meta data
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <MethodMetadataResponseApiModel> MethodMetadataAsync(
            MethodMetadataRequestApiModel request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var result = await _nodes.NodeMethodGetMetadataAsync(
                _twin.Endpoint, request.ToServiceModel());

            return(new MethodMetadataResponseApiModel(result));
        }
Example #3
0
        public async Task <MethodMetadataResponseApiModel> GetCallMetadataAsync(
            string endpointId, [FromBody][Required] MethodMetadataRequestApiModel request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var metadataresult = await _nodes.NodeMethodGetMetadataAsync(
                endpointId, request.ToServiceModel());

            return(metadataresult.ToApiModel());
        }
 /// <summary>
 /// Convert back to service model
 /// </summary>
 /// <returns></returns>
 public static MethodMetadataRequestModel ToServiceModel(
     this MethodMetadataRequestApiModel model)
 {
     if (model == null)
     {
         return(null);
     }
     return(new MethodMetadataRequestModel {
         MethodId = model.MethodId,
         MethodBrowsePath = model.MethodBrowsePath,
         Header = model.Header.ToServiceModel()
     });
 }
Example #5
0
        /// <summary>
        /// GetParameterAsync
        /// </summary>
        /// <param name="endpointId"></param>
        /// <param name="nodeId"></param>
        /// <returns>Status</returns>
        public async Task <string> GetParameterAsync(string endpointId, string nodeId, CredentialModel credential = null)
        {
            Parameter = new MethodMetadataResponseApiModel();
            var model = new MethodMetadataRequestApiModel()
            {
                MethodId = nodeId
            };

            model.Header = Elevate(new RequestHeaderApiModel(), credential);

            try {
                Parameter = await _twinService.NodeMethodGetMetadataAsync(endpointId, model);

                if (Parameter.ErrorInfo == null)
                {
                    return(null);
                }
                else
                {
                    if (Parameter.ErrorInfo.Diagnostics != null)
                    {
                        return(Parameter.ErrorInfo.Diagnostics.ToString());
                    }
                    else
                    {
                        return(Parameter.ErrorInfo.ToString());
                    }
                }
            }
            catch (Exception e) {
                _logger.Error($"Can not get method parameter from node '{nodeId}'");
                var errorMessage = string.Concat(e.Message, e.InnerException?.Message ?? "--", e?.StackTrace ?? "--");
                _logger.Error(errorMessage);
                string error = JToken.Parse(e.Message).ToString(Formatting.Indented);
                if (error.Contains(StatusCodes.Status401Unauthorized.ToString()))
                {
                    errorMessage = "Unauthorized access: Bad User Access Denied.";
                }
                else
                {
                    errorMessage = error;
                }
                return(errorMessage);
            }
        }
        /// <inheritdoc/>
        public async Task <MethodMetadataResponseApiModel> NodeMethodGetMetadataAsync(
            string endpointId, MethodMetadataRequestApiModel content, CancellationToken ct)
        {
            if (string.IsNullOrEmpty(endpointId))
            {
                throw new ArgumentNullException(nameof(endpointId));
            }
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            var request = _httpClient.NewRequest($"{_serviceUri}/v2/call/{endpointId}/metadata",
                                                 _resourceId);

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

            response.Validate();
            return(response.GetContent <MethodMetadataResponseApiModel>());
        }
        /// <inheritdoc/>
        public async Task <MethodMetadataResponseApiModel> NodeMethodGetMetadataAsync(
            EndpointApiModel endpoint, MethodMetadataRequestApiModel request, CancellationToken ct)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }
            if (string.IsNullOrEmpty(endpoint.Url))
            {
                throw new ArgumentNullException(nameof(endpoint.Url));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var response = await _methodClient.CallMethodAsync(_deviceId, _moduleId,
                                                               "MethodMetadata_V2", _serializer.SerializeToString(new {
                endpoint,
                request
            }), null, ct);

            return(_serializer.Deserialize <MethodMetadataResponseApiModel>(response));
        }
        public async Task <ActionResult> MethodCallGetParameter(string jstreeNode)
        {
            string[]      delimiter       = { "__$__" };
            string[]      jstreeNodeSplit = jstreeNode.Split(delimiter, 3, StringSplitOptions.None);
            string        node;
            List <object> jsonParameter  = new List <object>();
            int           parameterCount = 0;
            string        endpointId     = Session["EndpointId"].ToString();

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

            try
            {
                MethodMetadataRequestApiModel model = new MethodMetadataRequestApiModel();
                model.MethodId = node;
                var data = await TwinService.NodeMethodGetMetadataAsync(endpointId, model);

                if (data.InputArguments == null)
                {
                    parameterCount = 0;
                    jsonParameter.Add(new { data.ObjectId });
                }
                else
                {
                    if (data.InputArguments.Count > 0)
                    {
                        foreach (var item in data.InputArguments)
                        {
                            jsonParameter.Add(new
                            {
                                objectId        = data.ObjectId,
                                name            = item.Name,
                                value           = item.DefaultValue,
                                valuerank       = item.ValueRank,
                                arraydimentions = item.ArrayDimensions,
                                description     = item.Description,
                                datatype        = item.Type.DataType,
                                typename        = item.Type.DisplayName
                            });
                        }
                    }
                    else
                    {
                        jsonParameter.Add(new { data.ObjectId });
                    }

                    parameterCount = data.InputArguments.Count;
                }

                return(Json(new { count = parameterCount, parameter = jsonParameter }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception exception)
            {
                return(Content(CreateOpcExceptionActionString(exception)));
            }
        }
 /// <summary>
 /// Get method meta data
 /// </summary>
 /// <remarks>
 /// Return method meta data to support a user interface displaying forms to
 /// input and output arguments. 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 method metadata request
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <MethodMetadataResponseApiModel> GetCallMetadataAsync(this IAzureOpcTwinClient operations, string endpointId, MethodMetadataRequestApiModel body, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.GetCallMetadataWithHttpMessagesAsync(endpointId, body, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Get method meta data
 /// </summary>
 /// <remarks>
 /// Return method meta data to support a user interface displaying forms to
 /// input and output arguments. 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 method metadata request
 /// </param>
 public static MethodMetadataResponseApiModel GetCallMetadata(this IAzureOpcTwinClient operations, string endpointId, MethodMetadataRequestApiModel body)
 {
     return(operations.GetCallMetadataAsync(endpointId, body).GetAwaiter().GetResult());
 }
Example #11
0
 /// <inheritdoc/>
 public Task <MethodMetadataResponseApiModel> NodeMethodGetMetadataAsync(
     string endpointId, MethodMetadataRequestApiModel content, CancellationToken ct)
 {
     return(Task.FromException <MethodMetadataResponseApiModel>(new NotImplementedException()));
 }
Example #12
0
 /// <summary>
 /// Get meta data for method call on endpoint
 /// </summary>
 /// <param name="api"></param>
 /// <param name="endpointUrl"></param>
 /// <param name="request"></param>
 /// <param name="ct"></param>
 /// <returns></returns>
 public static Task <MethodMetadataResponseApiModel> NodeMethodGetMetadataAsync(
     this ITwinModuleApi api, string endpointUrl, MethodMetadataRequestApiModel request,
     CancellationToken ct = default)
 {
     return(api.NodeMethodGetMetadataAsync(NewEndpoint(endpointUrl), request, ct));
 }
        public MethodMetadataResponseApiModel NodeMethodGetMetadata(string endpoint, MethodMetadataRequestApiModel content)
        {
            Task <MethodMetadataResponseApiModel> t = Task.Run(() => _twinServiceHandler.NodeMethodGetMetadataAsync(endpoint, content));

            return(t.Result);
        }
        public async Task <MethodMetadataResponseApiModel> NodeMethodGetMetadataAsync(string endpoint, MethodMetadataRequestApiModel content)
        {
            var applications = await _twinServiceHandler.NodeMethodGetMetadataAsync(endpoint, content).ConfigureAwait(false);

            return(applications);
        }