예제 #1
0
        public void Start <T>() where T : ICommand
        {
            var commandType = typeof(T);

            if (!_timers.ContainsKey(commandType))
            {
                throw new Exception(String.Format("Schedule for {0} is not configured.", commandType.Name));
            }

            _uiThreadInvoker.Invoke(() =>
            {
                _timers[commandType].Start();
            });
        }
        public void Handle(ApplicationLoadedCommand command)
        {
            if (!_applicationState.IsDataLoaded)
            {
                _applicationState.IsDataLoading = true;
                _storageManager.LoadData();
            }

            _uiThreadInvoker.Invoke(() => _dialogService.Alert("By running this application you agree to not use it while driving and we are not responsible for what happens to you while running this application."));
        }
        public void Handle(SaveShortCodeCommand command)
        {
            var addPageViewModel = _container.GetInstance <IAddPageViewModel>();

            // let's validate
            var result = _shortCodeValidator.Validate(addPageViewModel.ActiveShortCode);

            if (!result.IsValid)
            {
                _uiThreadInvoker.Invoke(() =>
                {
                    addPageViewModel.Errors.Clear();
                    foreach (var error in result.Errors)
                    {
                        addPageViewModel.Errors.Add(error);
                    }
                });
                return;
            }

            // figure out editing or saving
            var existingShortCode = _applicationState.ShortCodes.SingleOrDefault(c => c.ShortCodeId == addPageViewModel.ActiveShortCode.ShortCodeId);

            if (existingShortCode == null)
            {
                var nextShortCode = _applicationState.NextShortCodeId++;
                addPageViewModel.ActiveShortCode.ShortCodeId = nextShortCode;
                addPageViewModel.ActiveShortCode.LastUsed    = DateTime.Now;
                _applicationState.ShortCodes.Add(addPageViewModel.ActiveShortCode);
            }
            else
            {
                existingShortCode.Name = addPageViewModel.ActiveShortCode.Name;
                existingShortCode.Code = addPageViewModel.ActiveShortCode.Code;
            }

            // save to storage
            _storageManager.SaveData();

            _uiThreadInvoker.Invoke(() => _navigationService.Navigate("/Views/MainPage.xaml"));
        }
        public void Handle(DeleteShortCodeCommand command)
        {
            if (command.ShortCode == null)
            {
                return;
            }

            _uiThreadInvoker.Invoke(() =>
            {
                if (!_dialogService.Confirm(String.Format("Are you sure you want to delete {0}?", command.ShortCode.Code)))
                {
                    return;
                }

                var existingCode = _applicationState.ShortCodes.SingleOrDefault(s => s.ShortCodeId == command.ShortCode.ShortCodeId);
                _applicationState.ShortCodes.Remove(existingCode);
                _storageManager.SaveData();
            });
        }
        public void Handle(DataLoadedMessage command)
        {
            // handle the lifting behind
            var shortCodes = _applicationState.ShortCodes.Select(c => new ShortCode
            {
                ShortCodeId = c.ShortCodeId,
                Name        = c.Name,
                Code        = c.Code,
                LastUsed    = c.LastUsed,
                TimesUsed   = c.TimesUsed
            });

            var allShortCodes      = shortCodes.OrderBy(c => c.Name);
            var recentShortCodes   = shortCodes.OrderByDescending(c => c.LastUsed).Take(5);
            var mostUsedShortCodes = shortCodes.Where(c => c.TimesUsed > 0).OrderByDescending(c => c.TimesUsed).Take(5);

            _uiThreadInvoker.Invoke(() =>
            {
                var viewModel = _container.GetInstance <IMainViewModel>();

                viewModel.AllShortCodes.Clear();
                foreach (var shortCode in allShortCodes)
                {
                    viewModel.AllShortCodes.Add(shortCode);
                }

                viewModel.RecentShortCodes.Clear();
                // needs to be decending as the add process flips it
                foreach (var shortCode in recentShortCodes)
                {
                    viewModel.RecentShortCodes.Add(shortCode);
                }

                viewModel.MostUsedShortCodes.Clear();
                // needs to be decending as the add process flips it
                foreach (var shortCode in mostUsedShortCodes)
                {
                    viewModel.MostUsedShortCodes.Add(shortCode);
                }
            });
        }
예제 #6
0
        public void Handle(EditShortCodeCommand command)
        {
            if (command.ShortCode == null)
            {
                return;
            }

            _uiThreadInvoker.Invoke(() =>
            {
                var addPageViewModel = _container.GetInstance <IAddPageViewModel>();

                addPageViewModel.ActiveShortCode = new ShortCode
                {
                    ShortCodeId = command.ShortCode.ShortCodeId,
                    Name        = command.ShortCode.Name,
                    Code        = command.ShortCode.Code
                };
                addPageViewModel.Errors.Clear();
                addPageViewModel.PageTitle = "edit code";

                _navigationService.Navigate("/Views/AddPage.xaml");
            });
        }
예제 #7
0
        public void Handle(AddNewShortCodeCommand command)
        {
            _uiThreadInvoker.Invoke(() =>
            {
                if (_trialService.IsTrial() && _applicationState.ShortCodes.Count > 0)
                {
                    var result = _dialogService.Confirm("The trial version is limited to storing 1 short code only.  Click Okay to buy the full version.");
                    if (result)
                    {
                        _trialService.SendUserToMarketplace();
                    }
                    return;
                }

                var addPageViewModel = _container.GetInstance <IAddPageViewModel>();

                addPageViewModel.ActiveShortCode = new ShortCode();
                addPageViewModel.Errors.Clear();
                addPageViewModel.PageTitle = "add code";

                _navigationService.Navigate("/Views/AddPage.xaml");
            });
        }