Exemplo n.º 1
0
        protected override void OnLoaded()
        {
            base.OnLoaded();
            BtnCommand             = new RelayCommand <string>(OnCommand);
            MouseDubleClickCommand = new RelayCommand <UrlInfo>(OnMouseDubleClick);
            RegeistMessenger <UrlInfo>(OnRequestCreateUrl);

            ReceiveAddressBookMonitor.Default.MonitorCallBack += accounts =>
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    var selectedItem = this.SelectedItem;
                    UrlInfos.Clear();
                    accounts.ForEach(x => UrlInfos.Add(new UrlInfo()
                    {
                        Address = x.Address, Tag = x.Tag
                    }));
                    if (selectedItem != null)
                    {
                        this.SelectedItem = UrlInfos.FirstOrDefault(x => x.Address == selectedItem.Address);
                    }
                });
                ReceiveAddressBookMonitor.Default.Start(6000);
            };

            LoadUrls();
            UrlInfos.CollectionChanged += (s, e) => { RaisePropertyChanged("UrlInfos"); };
        }
Exemplo n.º 2
0
        protected override void OnLoaded()
        {
            base.OnLoaded();

            BtnCommand             = new RelayCommand <string>(OnCommand);
            MouseDubleClickCommand = new RelayCommand <UrlInfo>(OnMouseDubleClick);
            RegeistMessenger <UrlInfo>(OnRequestCreateUrl);
            RegeistMessenger <PayUrlPageType>(OnGetRequest);
            PayAddressBookMonitor.Default.MonitorCallBack += books =>
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    string account = null;
                    if (SelectedItem != null)
                    {
                        account = SelectedItem.Address;
                    }
                    UrlInfos.Clear();
                    books.ForEach(x =>
                    {
                        UrlInfos.Add(new UrlInfo(x));
                    });
                    if (account != null)
                    {
                        SelectedItem = UrlInfos.FirstOrDefault(x => x.Address == account);
                    }
                    StaticViewModel.GlobalViewModel.IsLoading = false;
                });
            };
            LoadUrls();
            UrlInfos.CollectionChanged += (s, e) => { RaisePropertyChanged("UrlInfos"); };
        }
Exemplo n.º 3
0
        void OnDelete()
        {
            var removeItem = SelectedItem;

            if (SelectedItem == null)
            {
                removeItem = UrlInfos.FirstOrDefault();
            }

            var result = AddressBookService.Default.GetAddressBookItemByAddress(removeItem.Address);

            if (result.IsFail)
            {
                ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Delete_Fail));
                return;
            }

            var deleteResult = AddressBookService.Default.DeleteAddressBookByIds(result.Value.Id);

            if (deleteResult.IsFail)
            {
                ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Delete_Fail));
                return;
            }

            UrlInfos.Remove(removeItem);
        }
Exemplo n.º 4
0
        void OnRequestCreateUrl(UrlInfo urlInfo)
        {
            if (urlInfo == null)
            {
                return;
            }
            var netstr = OmniCoinSetting.NodeTypeStr;

            if (!AddressTools.AddressVerfy(netstr, urlInfo.Address))
            {
                ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Error_Address));
                return;
            }
            switch (urlInfo.Mode)
            {
            case UrlMode.CreatePay:
                if (UrlInfos.Any(x => x.Address.Equals(urlInfo.Address)))
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Address_Existed));
                    return;
                }
                StaticViewModel.GlobalViewModel.IsLoading = true;
                var result = AddressBookService.Default.UpsertAddrBookItem(urlInfo.Address, urlInfo.Tag);
                if (!result.IsFail)
                {
                    LoadUrls();
                }
                else
                {
                    ShowMessage(result.GetErrorMsg());
                }
                break;

            case UrlMode.Edit:
                if (UrlInfos.Any(x => x.Address.Equals(urlInfo.Address) && x.Id != urlInfo.Id))
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Address_Existed));
                    return;
                }
                var updateResult = AddressBookService.Default.UpsertAddrBookItem(urlInfo.Address, urlInfo.Tag, urlInfo.Id);
                if (!updateResult.IsFail)
                {
                    var selectedUrlinfo = UrlInfos.FirstOrDefault(x => x.Id == urlInfo.Id);
                    if (selectedUrlinfo == null)
                    {
                        UrlInfos.Add(urlInfo);
                    }
                    else
                    {
                        selectedUrlinfo.Tag     = urlInfo.Tag;
                        selectedUrlinfo.Address = urlInfo.Address;
                        selectedUrlinfo.Mode    = urlInfo.Mode;
                        SelectedItem            = selectedUrlinfo;
                    }
                }
                else
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Edit_Fail));
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 5
0
        void OnRequestCreateUrl(UrlInfo urlInfo)
        {
            if (urlInfo == null)
            {
                return;
            }
            var netstr = "mainnet";

            switch (NodeSetting.CurrentNetworkType)
            {
            case Biz.NetworkType.MainnetPort:
                break;

            case Biz.NetworkType.TestNetPort:
                netstr = "testnet";
                break;

            default:
                break;
            }

            if (!AddressTools.AddressVerfy(netstr, urlInfo.Address))
            {
                ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Error_Address));
                return;
            }
            switch (urlInfo.Mode)
            {
            case UrlMode.CreatePay:
                if (UrlInfos.Any(x => x.Address.Equals(urlInfo.Address)))
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Address_Existed));
                    return;
                }
                var result = AddressBookService.Default.AddNewAddressBookItem(urlInfo.Address, urlInfo.Tag);
                if (!result.IsFail)
                {
                    //UrlInfos.Add(urlInfo);
                    LoadUrls();
                }
                else
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Add_Fail));
                }
                break;

            case UrlMode.Edit:
                if (UrlInfos.Any(x => x.Address.Equals(urlInfo.Address) && x.Id != urlInfo.Id))
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Address_Existed));
                    return;
                }
                var updateResult = AddressBookService.Default.AddNewAddressBookItem(urlInfo.Address, urlInfo.Tag);
                if (!updateResult.IsFail)
                {
                    var urlinfo = UrlInfos.FirstOrDefault(x => x.Id == urlInfo.Id);
                    if (urlinfo == null)
                    {
                        UrlInfos.Add(urlInfo);
                    }
                    else
                    {
                        urlinfo.Tag     = urlInfo.Tag;
                        urlinfo.Address = urlInfo.Address;
                    }
                }
                else
                {
                    ShowMessage(LanguageService.Default.GetLanguageValue(MessageKeys.Edit_Fail));
                }
                SelectedItem.Address = urlInfo.Address;
                SelectedItem.Tag     = urlInfo.Tag;
                SelectedItem.Mode    = urlInfo.Mode;
                break;

            default:
                break;
            }
        }