Beispiel #1
0
        /// <summary>
        /// Validates if the publisher is there and supports the method calls we need.
        /// </summary>
        /// <returns></returns>
        private static async Task <bool> ValidatePublisherVersionAsync(CancellationToken ct)
        {
            // fetch the information
            GetInfoMethodResponseModel info = await _publisher.GetInfoAsync(ct).ConfigureAwait(false);

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

            Logger.Information($"OPC Publisher V{info.VersionMajor}.{info.VersionMinor}.{info.VersionPatch} was detected.");
            Logger.Debug($"semantic version: {info.SemanticVersion}");
            Logger.Debug($"informational version: {info.InformationalVersion}");
            return(true);
        }
        /// <summary>
        /// Call the GetInfo method.
        /// </summary>
        public async Task <GetInfoMethodResponseModel> GetInfoAsync(CancellationToken ct)
        {
            GetInfoMethodResponseModel response = null;

            try
            {
                CloudToDeviceMethodResult methodResult = new CloudToDeviceMethodResult();
                if (string.IsNullOrEmpty(_publisherModuleName))
                {
                    methodResult = await _iotHubClient.InvokeDeviceMethodAsync(_publisherDeviceName, _getInfoMethod, ct).ConfigureAwait(false);
                }
                else
                {
                    methodResult = await _iotHubClient.InvokeDeviceMethodAsync(_publisherDeviceName, _publisherModuleName, _getInfoMethod, ct).ConfigureAwait(false);
                }

                if (!ct.IsCancellationRequested)
                {
                    if (methodResult.Status == (int)HttpStatusCode.OK)
                    {
                        response = JsonConvert.DeserializeObject <GetInfoMethodResponseModel>(methodResult.GetPayloadAsJson());
                    }
                    else
                    {
                        LogMethodResult(methodResult, _getConfiguredNodesOnEndpointMethod.MethodName);
                    }
                }
            }
            catch (Exception e)
            {
                if (!ct.IsCancellationRequested)
                {
                    Logger.Debug(e, $"Exception");
                }
            }

            if (response == null && !ct.IsCancellationRequested)
            {
                Logger.Information("");
                Logger.Information($"OPC Publisher is not responding. Either the used version is too old or it is not running.");
                Logger.Information("");
            }

            return(response);
        }