コード例 #1
0
        public async override Task DoWork()
        {
            if (Controller.DidTimeoutOccur || Controller.DeviceEvent != DeviceEvent.None)
            {
                // recover device to idle
                IDeviceCancellationBroker cancellationBroker = Controller.GetDeviceCancellationBroker();

                LinkRequest          linkRequest      = StateObject as LinkRequest;
                LinkDeviceIdentifier deviceIdentifier = linkRequest.GetDeviceIdentifier();

                ICardDevice cardDevice = FindTargetDevice(deviceIdentifier);
                if (cardDevice != null)
                {
                    var timeoutPolicy = await cancellationBroker.ExecuteWithTimeoutAsync <bool>(
                        _ => cardDevice.DeviceRecovery(),
                        DeviceConstants.DeviceRecoveryTimeout,
                        this.CancellationToken);

                    if (timeoutPolicy.Outcome == Polly.OutcomeType.Failure)
                    {
                        //_ = Controller.LoggingClient.LogErrorAsync("Unable to recover device.");
                        Console.WriteLine("Unable to recover device.");
                    }
                }
            }

            if (StateObject != null)
            {
                Controller.SaveState(StateObject);
            }

            _ = Complete(this);
        }
コード例 #2
0
        public ICardDevice FindTargetDevice(LinkDeviceIdentifier deviceIdentifier)
        {
            if (deviceIdentifier == null)
            {
                return(null);
            }

            return(FindMatchingDevice(deviceIdentifier));
        }
コード例 #3
0
        private protected ICardDevice FindMatchingDevice(LinkDeviceIdentifier deviceIdentifier)
        {
            ICardDevice cardDevice = null;

            foreach (var device in Controller.TargetDevices)
            {
                if (device.DeviceInformation != null)
                {
                    if (device.DeviceInformation.Manufacturer.Equals(deviceIdentifier.Manufacturer, StringComparison.CurrentCultureIgnoreCase) &&
                        device.DeviceInformation.Model.Equals(deviceIdentifier.Model, StringComparison.CurrentCultureIgnoreCase) &&
                        device.DeviceInformation.SerialNumber.Equals(deviceIdentifier.SerialNumber, StringComparison.CurrentCultureIgnoreCase))
                    {
                        cardDevice = device;
                        break;
                    }
                }
            }

            return(cardDevice);
        }
コード例 #4
0
        public override async Task DoWork()
        {
            if (StateObject is null)
            {
                //_ = Controller.LoggingClient.LogErrorAsync("Unable to find a state object while attempting to call abort command.");
                Console.WriteLine("Unable to find a state object while attempting to call abort command.");
                _ = Error(this);
            }
            else
            {
                LinkRequest               linkRequest        = StateObject as LinkRequest;
                LinkDeviceIdentifier      deviceIdentifier   = linkRequest.GetDeviceIdentifier();
                IDeviceCancellationBroker cancellationBroker = Controller.GetDeviceCancellationBroker();

                ICardDevice cardDevice = FindTargetDevice(deviceIdentifier);
                if (cardDevice != null)
                {
                    var timeoutPolicy = await cancellationBroker.ExecuteWithTimeoutAsync <LinkRequest>(
                        _ => cardDevice.AbortCommand(linkRequest),
                        DeviceConstants.CardCaptureTimeout,
                        this.CancellationToken);

                    if (timeoutPolicy.Outcome == Polly.OutcomeType.Failure)
                    {
                        //_ = Controller.LoggingClient.LogErrorAsync($"Unable to process Abort request from device - '{Controller.DeviceEvent}'.");
                        Console.WriteLine($"Unable to process Abort request from device - '{Controller.DeviceEvent}'.");
                        BuildSubworkflowErrorResponse(linkRequest, cardDevice.DeviceInformation, Controller.DeviceEvent);
                    }
                }
                else
                {
                    UpdateRequestDeviceNotFound(linkRequest, deviceIdentifier);
                }

                Controller.SaveState(linkRequest);

                _ = Complete(this);
            }
        }
コード例 #5
0
        private async Task ProcessListenerRequest(LinkRequest linkRequest)
        {
            try
            {
                //_ = Controller.LoggingClient.LogInfoAsync($"Received from {linkRequest}");
                Console.WriteLine($"Received from {linkRequest}");
                LinkRequest linkRequestResponse = null;
                bool        deviceConnected     = false;

                // Setup workflow
                WorkflowOptions workflowOptions = new WorkflowOptions();
                workflowOptions.StateObject = linkRequest;

                Controller.SaveState(workflowOptions);

                // Payment: targeted device
                if (linkRequest.Actions?[0]?.Action == LinkAction.Payment ||
                    linkRequest.Actions?[0]?.Action == LinkAction.DALAction)
                {
                    LinkDeviceIdentifier deviceIdentifier = linkRequest.GetDeviceIdentifier();
                    ICardDevice          cardDevice       = FindTargetDevice(deviceIdentifier);
                    if (cardDevice != null)
                    {
                        deviceConnected = cardDevice.IsConnected(linkRequest);
                        if (deviceConnected)
                        {
                            workflowOptions.StateObject = linkRequest;
                        }
                    }
                }
                else
                {
                    // Session: device discovery
                    foreach (var device in Controller.TargetDevices)
                    {
                        deviceConnected = device.IsConnected(linkRequest);
                        if (deviceConnected)
                        {
                            workflowOptions.StateObject = linkRequest;
                        }
                    }
                }

                if (deviceConnected)
                {
                    Controller.SaveState(workflowOptions);
                }
                else
                {
                    //linkRequestResponse = RequestHelper.LinkRequestResponseError(linkRequest, ErrorCodes.NoDevice, ErrorDescriptions.DeviceNotFound);

                    object response = JsonConvert.SerializeObject(linkRequestResponse);
                    //_ = Controller.LoggingClient.LogInfoAsync($"Sending to Listener");
                    Console.WriteLine($"Sending to Listener");
                    //await Controller.Connector.Publish(response, new TopicOption[] { TopicOption.Servicer }).ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                //_ = Controller.LoggingClient.LogErrorAsync($"{e.Message} {linkRequest}");
                Console.WriteLine($"{e.Message} {linkRequest}");
                //if (Controller.Connector != null)
                //{
                //    await Controller.Connector.Publish(RequestHelper.LinkRequestResponseError(null, ErrorCodes.DalError, e.Message), new TopicOption[] { TopicOption.Servicer }).ConfigureAwait(false);
                //}
            }
        }