public void DiscoverReaders(StripeDiscoveryConfiguration config, Action <IList <StripeTerminalReader> > readers, Action scanTimeoutCallback)
        {
            // this assures the discovery succeeds on Android. Old code, ignores this, leading to lack of success in finding other types of readers except for Chipper2x
            var deviceType = DeviceType.Chipper2x;

            switch (config.DeviceType)
            {
            case "Chipper2X":
                deviceType = DeviceType.Chipper2x;
                break;

            case "VerifoneP400":
                deviceType = DeviceType.VerifoneP400;
                break;

            case "WisePad3":
                deviceType = DeviceType.Wisepad3;
                break;
            }


            var configuration = new DiscoveryConfiguration(config.TimeOut, deviceType, isSimulated: config.IsSimulated);


            _onReadersDiscoveredAction = readers;
            _discoveryCancelable?.Cancel(new GenericCallback((ex) =>
            {
                // Do Nothing...
            }));
            _discoveryCancelable = StripeTerminal.Instance.DiscoverReaders(configuration, this, new GenericCallback((ex) =>
            {
                // Do Nothing...
                scanTimeoutCallback();
            }));
        }
Beispiel #2
0
 public void DiscoverReaders(StripeDiscoveryConfiguration config, Action <IList <StripeTerminalReader> > readers, Action scanTimeoutCallback)
 {
     _onReadersDiscoveredAction = readers;
     _discoveryCancelable?.Cancel(new GenericCallback((ex) =>
     {
         // Do Nothing...
     }));
     _discoveryCancelable = StripeTerminal.Instance.DiscoverReaders(new DiscoveryConfiguration(config.TimeOut, DeviceType.Chipper2x, isSimulated: config.IsSimulated), this, new GenericCallback((ex) =>
     {
         // Do Nothing...
         scanTimeoutCallback();
     }));
 }
Beispiel #3
0
        /// <summary>
        /// Sends a message to the collection of routees.
        /// </summary>
        /// <param name="message">The message that is being sent.</param>
        /// <param name="sender">The actor sending the message.</param>
        public override void Send(object message, IActorRef sender)
        {
            _routees.Shuffle();
            var routeeIndex = new AtomicCounter(0);

            var completion = new TaskCompletionSource <object>();
            var cancelable = new Cancelable(_scheduler);

            completion.Task
            .ContinueWith(task => cancelable.Cancel(false));

            if (_routees.Length == 0)
            {
                completion.TrySetResult(NoRoutee);
            }
            else
            {
                _scheduler.Advanced.ScheduleRepeatedly(TimeSpan.Zero, _interval, async() =>
                {
                    var currentIndex = routeeIndex.GetAndIncrement();
                    if (currentIndex >= _routees.Length)
                    {
                        return;
                    }

                    try
                    {
                        completion.TrySetResult(await(_routees[currentIndex].Ask(message, _within)).ConfigureAwait(false));
                    }
                    catch (TaskCanceledException)
                    {
                        completion.TrySetResult(
                            new Status.Failure(
                                new AskTimeoutException($"Ask timed out on {sender} after {_within}")));
                    }
                }, cancelable);
            }

            completion.Task.PipeTo(sender);
        }
            public TestReceiveActor()
            {
                Receive <ScheduleOnceMessage>(x =>
                {
                    Context.System.Scheduler.ScheduleTellOnce(x.ScheduleOffset, Sender, x, Self);
                });

                Receive <RescheduleMessage>(x =>
                {
                    Context.System.Scheduler.ScheduleTellRepeatedly(x.InitialOffset, x.ScheduleOffset, Sender, x, Self);
                });

                Receive <CancelableMessage>(x =>
                {
                    _cancelable = new Cancelable(Context.System.Scheduler);
                    Context.System.Scheduler.ScheduleTellRepeatedly(x.ScheduleOffset, x.ScheduleOffset, Sender, x, Self, _cancelable);
                });

                Receive <CancelMessage>(x =>
                {
                    _cancelable.Cancel();
                });
            }
Beispiel #5
0
        protected override void OnReceive(object message)
        {
            if (message is string)
            {
                var line     = message.ToString();
                var commands = line.Split(' ');
                switch (commands[0])
                {
                case "print":
                    _writer.Tell("Welcome!");
                    _writer.Tell("Available commands are: start, exit, cs #, pos #");
                    break;

                case "stat":
                    _vehicles.Ask <float>("stat").PipeTo(_writer);
                    break;

                case "exit":
                    _writer.Tell("Shutting down...");
                    Context.System.Terminate();
                    return;

                case "cs":
                    var count = int.Parse(commands[1]);
                    var batch = new List <Message <VehiclesActor.UpdateCurrentStatus> >();
                    for (int i = 0; i < count; i++)
                    {
                        batch.Add(new Message <VehiclesActor.UpdateCurrentStatus>(i,
                                                                                  new VehiclesActor.UpdateCurrentStatus(i, "vin-" + i, "Started"), _vehicles));
                    }
                    var batcher = Context.ActorOf(BatchActor <VehiclesActor.UpdateCurrentStatus> .Props(_writer));
                    Context.Watch(batcher);
                    batcher.Tell(new MessageBatch <VehiclesActor.UpdateCurrentStatus>(batch));
                    break;

                case "pos":
                    var count2 = int.Parse(commands[1]);
                    var batch2 = new List <Message <VehiclesActor.UpdatePosition> >();
                    for (int i = 0; i < count2; i++)
                    {
                        batch2.Add(new Message <VehiclesActor.UpdatePosition>(i, new VehiclesActor.UpdatePosition(i, "vin-" + i, new Position(50, 51)), _vehicles));
                        batch2.Add(new Message <VehiclesActor.UpdatePosition>(i + count2, new VehiclesActor.UpdatePosition(i + count2, "vin-" + i, new Position(50, 51)), _vehicles));
                        batch2.Add(new Message <VehiclesActor.UpdatePosition>(i + count2 + count2, new VehiclesActor.UpdatePosition(i + count2 + count2, "vin-" + i, new Position(50, 51)), _vehicles));
                    }
                    ;
                    var batcher2 = Context.ActorOf(BatchActor <VehiclesActor.UpdatePosition> .Props(_writer));
                    Context.Watch(batcher2);
                    batcher2.Tell(new MessageBatch <VehiclesActor.UpdatePosition>(batch2));
                    break;

                case "timer":
                    var cmd = commands[1];
                    switch (cmd)
                    {
                    case "start":
                        var interval  = int.Parse(commands[2]);
                        var batchSize = int.Parse(commands[3]);
                        _cancel = new Cancelable(Context.System.Scheduler, 30000);
                        _writer.Tell($"Starting timer for {batchSize} position updates every {interval}");
                        Context.System.Scheduler.ScheduleTellRepeatedly(interval, interval, Self,
                                                                        "pos " + batchSize, Self, _cancel);
                        break;

                    case "stop":
                        _writer.Tell($"Stopping timer");
                        _cancel.Cancel();
                        break;
                    }

                    break;

                default:
                    _writer.Tell("Unhandled message!");
                    break;
                }
            }
            else
            {
                switch (message)
                {
                case MessageDone msg when msg.Id < 0:
                    _writer.Tell("Stopping actor " + Sender);
                    Context.Stop(Sender);
                    break;

                case Terminated t:
                    _writer.Tell($"Actor {t.ActorRef} stopped");

                    break;
                }
                return;
            }

            Context.ActorSelection("akka://theSystem/user/reader").Tell("read");
        }