private void AddToWallet(Card card, bool showSuccessMessage = false)
        {
            if (card == null) return;

            var walletCard = new WalletTransactionItem(card.Id)
            {
                DisplayName = card.Name,
                IssuerName = card.CardProvider.ProviderName,
                Logo99x99 = GetTileFromProvider(card.CardProvider, 99),
                Logo159x159 = GetTileFromProvider(card.CardProvider, 159),
                Logo336x336 = GetTileFromProvider(card.CardProvider, 336),
                BarcodeImage = (BitmapSource) new Converters.BarcodeToImageConverter().Convert(card, typeof (BitmapSource), "false", null),
                NavigationUri = new Uri(string.Format("/Views/DisplayBarcodeView.xaml?id={0}", card.Id), UriKind.Relative),
                CustomerName = card.DisplayBarcode
            };

            var walletTask = new AddWalletItemTask
            {
                Item = walletCard
            };
            walletTask.Completed += (sender, result) =>
            {
                if (result.Error != null)
                {
                    App.ShowMessage("There was an error adding your card");
                    return;
                }

                CheckWalletForCard(card.Id);
                if (showSuccessMessage)
                    App.ShowMessage("Card was added to the wallet");
            };
            walletTask.Show();
        }
        private void WireMessages()
        {
            Messenger.Default.Register<NotificationMessage>(this, m =>
            {
                if (m.Notification.Equals("ResultFoundMsg"))
                {
                    var result = (Result)m.Sender;
                    if (!SupportedFormats.Contains(result.BarcodeFormat))
                    {
                        // Show error message about unsupported barcode
                        //MessageBox.Show("Sorry, this barcode is currently unsupported. If you wish to request this to be looked into, please email from the about page, state what store card it was.", "Unsupported barcode", MessageBoxButton.OK);
                        navigationService.GoBack();
                        return;
                    }

                    SelectedCard = new Card
                                       {
                                           Id = Guid.NewGuid().ToString(),
                                           OriginalBarcodeFormat = result.BarcodeFormat,
                                           CardProvider = ((CardProviders)Application.Current.Resources["CardProviders"])[1]
                                       };

                    if (result.BarcodeFormat == BarcodeFormat.CODE_128
                        && result.Text.StartsWith("9794")
                        && result.Text.Length >= 16)
                    {
                        // This means it is almost certainly a Tesco clubcard
                        // The leading digits need to be stripped for the display name and replaced with 634004
                        // Example original: 9794024051183961
                        SelectedCard.OriginalBarcode = result.Text;
                        SelectedCard.DisplayBarcode = result.Text.Replace("9794", "634004");
                        SelectedCardIndex = 0;
                        OnSelectedCardIndexChanged();
                    }
                    else if (result.BarcodeFormat == BarcodeFormat.CODABAR)
                    {
                        var needsStartingA = false;
                        var needsClosingA = false;
                        if (!result.Text.ToLower().StartsWith("a") &&
                            !result.Text.ToLower().StartsWith("b") &&
                            !result.Text.ToLower().StartsWith("c") &&
                            !result.Text.ToLower().StartsWith("d"))
                        {
                            needsStartingA = true;
                        }

                        if (!result.Text.ToLower().EndsWith("a") &&
                            !result.Text.ToLower().EndsWith("b") &&
                            !result.Text.ToLower().EndsWith("c") &&
                            !result.Text.ToLower().EndsWith("d"))
                        {
                            needsClosingA = true;
                        }

                        SelectedCard.OriginalBarcode = SelectedCard.DisplayBarcode = result.Text;
                        if (needsStartingA) SelectedCard.OriginalBarcode = "A" + SelectedCard.OriginalBarcode;

                        if (needsClosingA) SelectedCard.OriginalBarcode = SelectedCard.OriginalBarcode + "T";

                        SelectedCardIndex = 1;
                    }
                    else
                    {
                        SelectedCard.OriginalBarcode = SelectedCard.DisplayBarcode = result.Text;
                        SelectedCardIndex = 1;
                    }

                    // Navigate to the card editing page
                    IsInEditMode = false;
                    navigationService.Navigate<CardDetailsView>();
                }
                if (m.Notification.Equals("RestoreCards"))
                {
                    Cards = (ObservableCollection<Card>) m.Sender;
                    App.ShowMessage("Cards restored");
                }
            });

            Messenger.Default.Register<NotificationMessageAction<ObservableCollection<Card>>>(this, m =>
                                                                                                        {
                                                                                                            if (m.Notification.Equals("ShowMeTheCards"))
                                                                                                            {
                                                                                                                m.Execute(Cards);
                                                                                                            }
                                                                                                        });
        }
        private void PinToStart(Card card)
        {
            var tileUrl = string.Format("/Views/DisplayBarcodeView.xaml?id={0}", card.Id);

            #if WP8
            var shellData = new FlipTileData
            {
                Title = "",
                BackgroundImage = new Uri(card.CardProvider.TileUrl, UriKind.Relative),
                WideBackgroundImage = new Uri(card.CardProvider.WideTileUrl, UriKind.Relative)
            };
            ShellTile.Create(new Uri(tileUrl, UriKind.Relative), shellData, true);
            #else
            var shellData = new StandardTileData
                                {
                                    Title = "",
                                    BackgroundImage = new Uri(card.CardProvider.TileUrl, UriKind.Relative)
                                };
            ShellTile.Create(new Uri(tileUrl, UriKind.Relative), shellData);
            #endif
            CanPinToStart = false;
        }