Esempio n. 1
0
        public void send_a_message_to_generic_listeners()
        {
            var message = new Message1 {
                Name = "this one"
            };

            theHub.Send(message);

            listener1.AssertWasCalled(x => x.Receive(message));
            listener2.AssertWasCalled(x => x.Receive(message));
            listener3.AssertWasCalled(x => x.Receive(message));
        }
        public void send_a_message_to_generic_listeners()
        {
            var message = new Message1 {
                Name = "this one"
            };

            theHub.Send(message);

            listener1.Received().Receive(message);
            listener2.Received().Receive(message);
            listener3.Received().Receive(message);
        }
Esempio n. 3
0
 public void OnLocationChanged(Location location)
 {
     if (location != null)
     {
         MessagingHub.Send(QueueType.Location, LocationData.CreateFrom(location));
     }
 }
        public void Recycle()
        {
            _messaging.Send(new SystemRecycleStarted());

            Teardown();

            _messaging.Send(new QueueState());

            bootstrap(_mode).Task.ContinueWith(x =>
            {
                _messaging.Send(x.Result);

                LatestSystemRecycled = x.Result;

                return(x.Result);
            });
        }
Esempio n. 5
0
 public void OnProviderEnabled(string provider)
 {
     if (_providerName == provider)
     {
         var location = _locationManager.GetLastKnownLocation(provider);
         if (location != null)
         {
             MessagingHub.Send(QueueType.Location, LocationData.CreateFrom(location));
         }
     }
 }
Esempio n. 6
0
 public void FinishRace()
 {
     foreach (var c in CountersGroup.All)
     {
         c.Stop();
     }
     Race.FinishRace();
     if (LastLocaton != null)
     {
         MessagingHub.Send(QueueType.Race, new RaceEvent(LastLocaton, RaceEventTypes.Finish));
         MessagingHub.Send(new VibrateCommand("99"));
     }
 }
Esempio n. 7
0
        private void ProcessClickCommand(GlobalCommand cmd)
        {
            switch (cmd.Code)
            {
            case GlobalCommandCodes.StartFinish:
                if (Race.IsRunning)
                {
                    MessagingHub.Send(QueueType.AskConfirmation, GlobalCommand.AskConfirmation(cmd, "Do you really want to finish the race?"));
                }
                else
                {
                    StartRace();
                }
                break;

            case GlobalCommandCodes.ResetAll:
                if (Race.IsRunning)
                {
                    MessagingHub.Send(QueueType.AskConfirmation, GlobalCommand.AskConfirmation(cmd, "Do you really want to reset after start?"));
                }
                else
                {
                    ResetAll();
                }
                break;

            case GlobalCommandCodes.ResetTime:
                Race.ResetTimeOnCheckpoint();
                break;

            case GlobalCommandCodes.ClearAll:
                MessagingHub.Send(QueueType.AskConfirmation, GlobalCommand.AskConfirmation(cmd, "Delete all data?"));
                break;

            case GlobalCommandCodes.GPSReset:
                MessagingHub.Send(QueueType.Global, cmd);
                break;

            case GlobalCommandCodes.Turn:
                MakeATurn();
                break;

            case GlobalCommandCodes.Back:
                GoBack();
                break;

            case GlobalCommandCodes.DelSegment:
                Race.DeleteLastSegment();
                break;
            }
        }
Esempio n. 8
0
 public void StartRace()
 {
     foreach (var c in CountersGroup.All)
     {
         c.Reset();
         c.Start();
     }
     Race.StartRace();
     if (LastLocaton != null)
     {
         MessagingHub.Send(QueueType.Race, new RaceEvent(LastLocaton, RaceEventTypes.Start));
         MessagingHub.Send(new VibrateCommand("11"));
     }
     Speech?.Speak("Поехали");
 }
Esempio n. 9
0
        private async void ProcessCommand(GlobalCommand cmd)
        {
            if (cmd.Code == GlobalCommandCodes.AskConfirmation)
            {
                var answer = await DisplayAlert("Alert", cmd.Message, "Yes", "No");

                //var answer = await DisplayAlert("Alert", cmd.Message, "Yes", "No");
                if (answer)
                {
                    MessagingHub.Send(QueueType.Confirmed, GlobalCommand.ReplyConfirmation(cmd.CommandToConfirm));
                }
                else
                {
                    MessagingHub.Send(QueueType.Canceled, GlobalCommand.ReplyConfirmation(cmd.CommandToConfirm));
                }
            }
        }
Esempio n. 10
0
 public void GoBack()
 {
     foreach (var c in CountersGroup.Segment)
     {
         var h = c as ISupportHistory;
         if (h != null)
         {
             h.Pop();
         }
         else
         {
             c.Reset();
         }
     }
     Race.RemoveLastTurn();
     if (LastLocaton != null)
     {
         MessagingHub.Send(QueueType.Race, new RaceEvent(LastLocaton, RaceEventTypes.Back));
         MessagingHub.Send(new VibrateCommand("3"));
     }
 }
Esempio n. 11
0
 public void MakeATurn()
 {
     Race.AddTurn();
     foreach (var c in CountersGroup.Segment)
     {
         var h = c as ISupportHistory;
         if (h != null)
         {
             h.Push();
         }
         else
         {
             c.Reset();
         }
     }
     if (LastLocaton != null)
     {
         MessagingHub.Send(QueueType.Race, new RaceEvent(LastLocaton, RaceEventTypes.Turn));
         MessagingHub.Send(new VibrateCommand("1"));
     }
     //Speech?.Speak("Поворот");
 }
Esempio n. 12
0
        private void Worker(object state)
        {
            var rspeed = state as IRaceCounter <double?>;

            if (rspeed == null)
            {
                return;
            }
            if (!model.Race.IsRunning)
            {
                return;
            }
            samples = ++samples % 60;


            var targetSpeed = rspeed?.Value;

            targetSpeed = targetSpeed > 80 ? 80 : targetSpeed;
            var delta = Math.Round(Math.Abs(targetSpeed.GetValueOrDefault() - speed), 0);

            //speed += targetSpeed > (speed + delta/2) ? delta/2 : (targetSpeed < (speed - delta/2) ? -delta/2: 0);
            speed = 10;
            //if (speed.HasValue)
            //{
            //	speed = speed > 80 ? 80 : speed;
            //	speed += r.Next(16) - 8;
            //}
            //else
            //{
            //	speed = r.Next(10) + 15;
            //}
            //if (samples > 30) speed = 5;
            if (samples > 50)
            {
                speed = 0;
            }
            //speed = 8;

            var k = LocationData.DistanceBetween(
                new LocationData()
            {
                Longitude = 50.0001, Latitude = 30.0001
            },
                new LocationData()
            {
                Longitude = 50.0002, Latitude = 30.0002
            });

            var loc = new LocationData()
            {
                Latitude  = prevLoc.Latitude + 0.0001 / k * (speed / 3.6),
                Longitude = prevLoc.Longitude + 0.0001 / k * (speed / 3.6),
                Speed     = speed / 3.6,
                Time      = DateTime.Now.ToUniversalTime()
            };

            prevLoc = loc;
            MessagingHub.Send(QueueType.Location, loc);

            tick += 1000;
        }
Esempio n. 13
0
        private View BuildLeftPanel()
        {
            var cmd = new Command((param) => { MessagingHub.Send(QueueType.Click, (GlobalCommand)param); });

            var btnFunc = new Func <string, GlobalCommand, Button>((text, cmdCode) =>
            {
                var btn = new Button()
                {
                    Text             = text,
                    WidthRequest     = UIConfiguration.LargeButtonWidth,
                    HeightRequest    = -1,
                    BackgroundColor  = UIConfiguration.ButtonColor,
                    FontSize         = UIConfiguration.LargeButtonFontSize,
                    BindingContext   = model.Race,
                    Margin           = new Thickness(2, 0, 2, 0),
                    BorderRadius     = 0,
                    TextColor        = UIConfiguration.CounterColors[CounterColor.White],
                    CommandParameter = cmdCode,
                };
                btn.Command = cmd;
                return(btn);
            });


            var speechSwitcher = new Switch
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = model,
                Margin            = new Thickness(2, 0, 2, 0),
                BackgroundColor   = Color.Black,
                IsToggled         = model.Speech != null,
                WidthRequest      = UIConfiguration.LargeButtonWidth / 2,
            };

            speechSwitcher.Toggled += SpeechSwitcher_Toggled;

            var badlangSwitcher = new Switch
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = model,
                Margin            = new Thickness(2, 0, 2, 0),
                BackgroundColor   = Color.Black,
                IsToggled         = model.UseBadLanguage,
                WidthRequest      = UIConfiguration.LargeButtonWidth / 2,
            };

            badlangSwitcher.Toggled += BadlangSwitcher_Toggled;

            var startFinishButton = btnFunc(null, GlobalCommand.StartFinish);

            startFinishButton.SetBinding(Button.TextProperty,
                                         FuncBinding.Create <bool, string>("IsRunning", x => x ? "Finish" : "Start"));

            var resetButton     = btnFunc("Reset", GlobalCommand.ResetAll);
            var resetTimeButton = btnFunc("Reset time", GlobalCommand.ResetTime);

            var clearButton = btnFunc("Clear", GlobalCommand.ClearAll);

            clearButton.SetBinding(VisualElement.IsEnabledProperty, FuncBinding.Create <bool, bool>("IsRunning", x => !x));

            var gpsButton = btnFunc("GPS", GlobalCommand.GPSReset);

            var backButton = btnFunc("Back", GlobalCommand.Back).With(x =>
            {
                x.SetBinding(VisualElement.IsEnabledProperty, "CanGoBack");
            });

            var dummyButton = btnFunc("", GlobalCommand.None).With(x =>
            {
                x.IsEnabled       = false;
                x.BackgroundColor = Color.Black;
                x.WidthRequest    = UIConfiguration.LargeButtonWidth / 2;
            });

            var turnButton = btnFunc("Turn", GlobalCommand.Turn).With(x =>
            {
                x.WidthRequest = UIConfiguration.LargeButtonWidth * 2;
                x.SetBinding(VisualElement.IsEnabledProperty, "IsRunning");
                x.SetBinding(Button.TextProperty,
                             FuncBinding.Create <ObservableCollection <TurnInfo>, string>(
                                 "Turns", y => y.Count > 1 ? $"Turn ({y.Count - 1})" : "Turn"));
            });

            var deleteButton = btnFunc("Del", GlobalCommand.DelSegment).With(x =>
            {
                x.WidthRequest = UIConfiguration.LargeButtonWidth;
                x.SetBinding(VisualElement.IsEnabledProperty, "CanDelete");
            });



            var grid = new Grid()
            {
                RowDefinitions =
                {
                    new RowDefinition {
                        Height = new GridLength(UIConfiguration.LargeButtonHeight)
                    },
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                    //new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
                    new RowDefinition {
                        Height = new GridLength(UIConfiguration.LargeButtonHeight * 1.5)
                    }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    }
                },
                ColumnSpacing = 0,
                RowSpacing    = 2
            }.With(x =>
            {
                x.Children.Add(BuildButtonsPanel(startFinishButton, resetButton, resetTimeButton, clearButton, gpsButton, deleteButton), 0, 0);
                x.Children.Add(new CountersPanelBuilder(model).Build(), 0, 1);
                x.Children.Add(BuildButtonsPanel(badlangSwitcher, speechSwitcher, turnButton, backButton), 0, 2);
            });

            return(grid);
        }
Esempio n. 14
0
 public void OnProviderDisabled(string provider)
 {
     MessagingHub.Send(QueueType.Location, LocationData.Offline);
 }