コード例 #1
0
ファイル: Browser.cs プロジェクト: garolion/Industrial-IoT
        /// <summary>
        /// MethodCallAsync
        /// </summary>
        /// <param name="parameterValues"></param>
        /// <param name="nodeId"></param>
        /// <returns>Status</returns>
        public async Task <string> MethodCallAsync(MethodMetadataResponseApiModel parameters, string[] parameterValues,
                                                   string endpointId, string nodeId, CredentialModel credential = null)
        {
            var argumentsList = new List <MethodCallArgumentApiModel>();
            var model         = new MethodCallRequestApiModel()
            {
                MethodId = nodeId,
                ObjectId = parameters.ObjectId
            };

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

            try {
                var count = 0;
                foreach (var item in parameters.InputArguments)
                {
                    var argument = new MethodCallArgumentApiModel {
                        Value    = parameterValues[count] ?? string.Empty,
                        DataType = item.Type.DataType
                    };
                    argumentsList.Add(argument);
                    count++;
                }
                model.Arguments = argumentsList;

                MethodCallResponse = await _twinService.NodeMethodCallAsync(endpointId, model);

                if (MethodCallResponse.ErrorInfo == null)
                {
                    return(null);
                }
                else
                {
                    if (MethodCallResponse.ErrorInfo.Diagnostics != null)
                    {
                        return(MethodCallResponse.ErrorInfo.Diagnostics.ToString());
                    }
                    else
                    {
                        return(MethodCallResponse.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);
            }
        }
コード例 #2
0
        /// <summary>
        /// MethodCallAsync
        /// </summary>
        /// <param name="parameterValues"></param>
        /// <param name="nodeId"></param>
        /// <returns>Status</returns>
        public async Task <string> MethodCallAsync(MethodMetadataResponseApiModel parameters, string[] parameterValues,
                                                   string endpointId, string nodeId)
        {
            var argumentsList = new List <MethodCallArgumentApiModel>();
            var model         = new MethodCallRequestApiModel()
            {
                MethodId = nodeId,
                ObjectId = parameters.ObjectId
            };

            try {
                var count = 0;
                foreach (var item in parameters.InputArguments)
                {
                    var argument = new MethodCallArgumentApiModel {
                        Value    = parameterValues[count] ?? string.Empty,
                        DataType = item.Type.DataType
                    };
                    argumentsList.Add(argument);
                    count++;
                }
                model.Arguments = argumentsList;

                MethodCallResponse = await _twinService.NodeMethodCallAsync(endpointId, model);

                if (MethodCallResponse.ErrorInfo == null)
                {
                    return(null);
                }
                else
                {
                    if (MethodCallResponse.ErrorInfo.Diagnostics != null)
                    {
                        return(MethodCallResponse.ErrorInfo.Diagnostics.ToString());
                    }
                    else
                    {
                        return(MethodCallResponse.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);
            }
        }