Exemplo n.º 1
0
        //private async void CheckVersion()
        //{
        //    StartScreenViewModel startViewModel = this;
        //    startViewModel._sw.Start();
        //    startViewModel.CurrentMessage = "Проверка обновлений";
        //    NewVersionUpdater updater = new NewVersionUpdater();
        //    bool isNeedUpdate = false;
        //    try
        //    {
        //        isNeedUpdate = await updater.IsNeedUpdate();
        //    }
        //    catch (Exception ex)
        //    {
        //        await startViewModel.ShowErrorDialogAsync("Проверка обновлений, не удалась. Подождите 10-30 секунд и попробуйте еще раз " + Environment.NewLine + " " + ex.Message);
        //        if (await startViewModel.ShowYesOrNoDialogAsync("Запрос", "Можем попробовать продолжить без обновлений, но возможна не стабильная работа. Продолжить?") == MessageDialogResult.Negative)
        //        {
        //            Application.Current.Invoke(new Action(Application.Current.Shutdown));
        //            return;
        //        }
        //    }
        //    if (isNeedUpdate)
        //    {
        //        int num1 = 1;
        //        object obj;
        //        do
        //        {
        //            int num2 = 0;
        //            try
        //            {
        //                startViewModel.CurrentMessage = "Загружаем обновления";
        //                await updater.DownLoadUpdater();
        //                updater.LaunchUpdater();
        //            }
        //            catch (Exception ex)
        //            {
        //                obj = (object)ex;
        //                num2 = 1;
        //            }
        //            if (num2 == 1)
        //                ++num1;
        //            else
        //                goto label_19;
        //        }
        //        while (await startViewModel.ShowYesOrNoDialogAsync("Ошибка", string.Format("Updater не загрузился. Попробовать {0} раз?", (object)num1)) != MessageDialogResult.Negative);
        //        Process.Start("");
        //        Application.Current.Invoke(new Action(Application.Current.Shutdown));
        //        return;
        //    label_19:
        //        obj = (object)null;
        //        Application.Current.Invoke(new Action(Application.Current.Shutdown));
        //    }
        //    else
        //    {
        //        startViewModel.CurrentMessage = "Проверка обновлений завершена";
        //        await startViewModel.Sleep(startViewModel._loadLimit, startViewModel._sw.Elapsed);
        //        startViewModel.LoadCurrencies();
        //    }
        //}

        private async void LoadCurrencies()
        {
            StartScreenViewModel startViewModel = this;

            startViewModel._sw.Restart();
            startViewModel.CurrentMessage = "Загрузка курсов валют";
            CurrenciesDownloader downloader = new CurrenciesDownloader();

            try
            {
                Dictionary <ECurrency, Decimal> actualCursesFromCb = await downloader.GetActualCursesFromCb();

                startViewModel._settigs.UserSettings.Curses = actualCursesFromCb;
            }
            catch (Exception ex1)
            {
                await startViewModel.ShowErrorDialogAsync("Ошибка загрузки курса с Цб. Пробуем загрузить с зеркала", ex1);

                try
                {
                    Dictionary <ECurrency, Decimal> cursesFromMirror = await downloader.GetActualCursesFromMirror();

                    startViewModel._settigs.UserSettings.Curses = cursesFromMirror;
                }
                catch (Exception ex2)
                {
                    await startViewModel.ShowErrorDialogAsync("Ошибка загрузки курса с зеркала", ex2);

                    if (await startViewModel.ShowYesOrNoDialogAsync("Запрос", "Вы хотите продолжить без актуальных курсов валют?") == MessageDialogResult.Negative)
                    {
                        Application.Current.Invoke((Action)(() => Application.Current.Shutdown()));
                        return;
                    }
                    if (startViewModel._settigs.UserSettings.Curses == null)
                    {
                        startViewModel._settigs.UserSettings.Curses = downloader.GetDefaultCurses();
                    }
                }
            }
            try
            {
                CurrencyItemManager currencyItemManager = new CurrencyItemManager(startViewModel._settigs.UserSettings.CurrencyItems, downloader);
                currencyItemManager.UpdateCurses(startViewModel._settigs.UserSettings.Curses);
                startViewModel._settigs.UserSettings.CurrencyItems = currencyItemManager.GetCurrencyUserSettings();
            }
            catch (Exception ex)
            {
                await startViewModel.ShowErrorDialogAsync("Ошибка обновление актуальных курсов", ex);
            }
            await startViewModel.Sleep(startViewModel._loadLimit, startViewModel._sw.Elapsed);

            startViewModel.LoadFrigateSettings();
        }
Exemplo n.º 2
0
        static CurrencyItem()
        {
            Dictionary <ECurrency, Decimal> defaultCurses = new CurrenciesDownloader().GetDefaultCurses();

            foreach (ECurrency key in Enum.GetValues(typeof(ECurrency)).Cast <ECurrency>().ToList <ECurrency>())
            {
                CurrencyItem._allCurrencyItems.Add(key, new CurrencyItem()
                {
                    Currency  = key,
                    IsCustom  = false,
                    RoundRule = ERoundRule.To01,
                    Value     = defaultCurses[key]
                });
            }
        }
Exemplo n.º 3
0
 public SettingsViewModel([CanBeNull] ServerClient client)
 {
     this._appEncoding                = ClientConfig.AppEncoding;
     this._client                     = client;
     this.RemoveBkFromListCommand     = new ReallyCommand <Bookmaker>(new Action <Bookmaker>(this.RemoveBkFromList));
     this.CopyLoginPasswordCommand    = new ReallyCommand <Bookmaker>(new Action <Bookmaker>(this.CopyLoginPassword));
     this.SaveCommand                 = new ReallyCommand(new Action(this.Save));
     this.ResetBrowserCommand         = new ReallyCommand(new Action(this.ResetBrowser));
     this.ClearCacheCommand           = new ReallyCommand(new Action(this.ClearCache));
     this.ShowDemoCommand             = new ReallyCommand(new Action <object>(this.ShowDemo));
     this.DeleteSettingsCommand       = new ReallyCommand(new Action(this.DeleteSettings));
     this.PlaySoundCommand            = new ReallyCommand(new Action(this.PlaySound));
     this.DeleteInitDataCommand       = new ReallyCommand(new Action(this.DeleteInitData));
     this.CopyCurrentUserAgentCommand = new ReallyCommand((Action)(async() =>
     {
         SettingsViewModel settingsViewModel = this;
         Clipboard.SetText(settingsViewModel.CurrentUserAgent);
         await settingsViewModel.ShowSuccessDialogAsync("UserAgent скопирован в буфер обмена");
     }));
     this.OpenUrlCommand = new ReallyCommand <string>((Action <string>)(url =>
     {
         if (string.IsNullOrWhiteSpace(url))
         {
             return;
         }
         Process.Start(url);
     }));
     this.CurrentSettings = this._settigs.Clone();
     if (this.CurrentSettings.UserSettings.UserHotKeys == null)
     {
         this.CurrentSettings.UserSettings.UserHotKeys = UserHotKeys.Default;
     }
     this.Bookmakers             = new ObservableCollection <Bookmaker>(this.CurrentSettings.UserSettings.BookmakersList);
     this.SelectedBookmaker      = this.Bookmakers.FirstOrDefault <Bookmaker>();
     this.CurrentUserAgent       = this.CurrentSettings.UserSettings.FakeProfile.UserAgent;
     this.AllCurrencies          = Enum.GetValues(typeof(ECurrency)).Cast <ECurrency>().ToList <ECurrency>();
     this.FakeProfiles           = this.LoadUserAgents();
     this.UserCurrenciesSettings = this.CurrentSettings.UserSettings.CurrencyItems;
     this.RoundRules             = Enum.GetValues(typeof(ERoundRule)).Cast <ERoundRule>().ToList <ERoundRule>();
     this.SearchSoundFiles();
     this.CurrentLanguageInfo    = EChromeLanguageHelper.GetFullInfo(this.CurrentSettings.UserSettings.ChromeLanguage);
     this.ENewListForksFilter    = this._settigs.UserSettings.NewListForksFilterType;
     this.IsHighlightingNewForks = this._settigs.UserSettings.IsHighlightingNewForks;
     this.IsAllowMultiProxy      = this._settigs.IsAllowMultiProxy;
     this.DisabledIndProxy       = new ReallyCommand <Bookmaker>((Action <Bookmaker>)(bookmaker => bookmaker.Proxy.IsCustomProxy = false));
     this._downloader            = new CurrenciesDownloader();
     this._currencyItemManager   = new CurrencyItemManager(this.CurrentSettings.UserSettings.CurrencyItems, this._downloader);
     this.UpdateCurseCommand     = new ReallyCommand <CurrencyItem>((Action <CurrencyItem>)(async curse =>
     {
         SettingsViewModel settingsViewModel = this;
         settingsViewModel.IsLoadCursesNow   = true;
         if (curse != null)
         {
             try
             {
                 CurrencyItem currencyItem = await settingsViewModel._currencyItemManager.UpdateCurse(curse);
             }
             catch (Exception ex)
             {
                 await settingsViewModel.ShowErrorDialogAsync("Ошибка", ex);
             }
         }
         settingsViewModel.IsLoadCursesNow = false;
     }));
     this.SetCustomUserAgentCommand = new ReallyCommand(new Action(this.SetCustomUserAgent));
 }
Exemplo n.º 4
0
 public CurrencyItemManager(List <CurrencyItem> currenciesUser, CurrenciesDownloader downloader)
 {
     this._currenciesUser = currenciesUser;
     this._downloader     = downloader;
 }