Example #1
0
        private static void EndPointDetails(GetServiceCompletion.PayloadData endpointDetails)
        {
            Logger.WriteLine($"Got endpoint details {endpointDetails}");
            Logger.WriteLine($"Services:\n{string.Join("\n", from ep in endpointDetails.Services select ep.ToString())}");

            CardReaderUri = FindServiceUri(endpointDetails, XFSConstants.ServiceClass.CardReader);
        }
Example #2
0
        private static Uri FindServiceUri(GetServiceCompletion.PayloadData endpointDetails, XFSConstants.ServiceClass ServiceClass)
        {
            var service =
                (from ep in endpointDetails.Services
                 where ep.ServiceUri.Contains(ServiceClass.ToString())
                 select ep
                ).FirstOrDefault()
                ?.ServiceUri;

            if (string.IsNullOrEmpty(service))
            {
                throw new Exception($"Failed to find a device {ServiceClass} endpoint");
            }

            return(new Uri(service));
        }
Example #3
0
        public async Task Handle(IConnection Connection, object command, CancellationToken cancel)
        {
            Connection.IsNotNull($"Invalid parameter received in the {nameof(Handle)} method. {nameof(Connection)}");
            command.IsNotNull($"Invalid parameter received in the {nameof(Handle)} method. {nameof(command)}");
            Contracts.IsNotNull(cancel, $"Invalid parameter received in the {nameof(Handle)} method. {nameof(cancel)}");

            XFS4IoT.Common.Commands.GetServiceCommand getServiceCommand = command as XFS4IoT.Common.Commands.GetServiceCommand;
            getServiceCommand.IsNotNull($"Unexpected command received in the {nameof(Handle)} method. {nameof(command)}");

            // For now just return good result and fixed services available
            GetServiceCompletion.PayloadData payLoad = new GetServiceCompletion.PayloadData(GetServiceCompletion.PayloadData.CompletionCodeEnum.Success,
                                                                                            "ok",
                                                                                            "KAL",
                                                                                            from service in ServicePublisher.Services
                                                                                            select new GetServiceCompletion.PayloadData.ServiceUriDetails(service.WSUri.AbsoluteUri));

            await Connection.SendMessageAsync(new GetServiceCompletion(getServiceCommand.Headers.RequestId, payLoad));
        }
Example #4
0
        public async Task HandleError(IConnection Connection, object command, Exception commandErrorException)
        {
            Connection.IsNotNull($"Invalid parameter received in the {nameof(Handle)} method. {nameof(Connection)}");
            command.IsNotNull($"Invalid parameter received in the {nameof(Handle)} method. {nameof(command)}");
            commandErrorException.IsNotNull($"Invalid parameter received in the {nameof(Handle)} method. {nameof(commandErrorException)}");

            GetServiceCommand getServiceCommand = command as GetServiceCommand;

            getServiceCommand.IsNotNull($"Unexpected command received in the {nameof(Handle)} method. {nameof(command)}");

            GetServiceCompletion.PayloadData.CompletionCodeEnum errorCode = GetServiceCompletion.PayloadData.CompletionCodeEnum.InternalError;
            if (commandErrorException.GetType() == typeof(InvalidDataException))
            {
                errorCode = GetServiceCompletion.PayloadData.CompletionCodeEnum.InvalidData;
            }

            GetServiceCompletion.PayloadData payLoad = new GetServiceCompletion.PayloadData(errorCode, commandErrorException.Message);

            await Connection.SendMessageAsync(new GetServiceCompletion(getServiceCommand.Headers.RequestId, payLoad));
        }