예제 #1
0
 private void CalculateProfitCommandQuit()
 {
     CalculateProfit.SetCanExecute(true);
     LoadHistoricalCharts.SetCanExecute(true);
     SwitchManually.SetCanExecute(true);
     UpdateNextJobStatus();
 }
예제 #2
0
        private async void Workers_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Query")
            {
                var somethingToDo = Workers.WorkerList.FirstOrDefault(item => item.Query == true);
                if (somethingToDo != null)
                {
                    CalculateProfit.SetCanExecute(true);
                    LoadHistoricalCharts.SetCanExecute(true);
                    SwitchManually.SetCanExecute(true);
                }
                else
                {
                    CalculateProfit.SetCanExecute(false);
                    LoadHistoricalCharts.SetCanExecute(false);
                    SwitchManually.SetCanExecute(false);
                }
            }

            if (e.PropertyName == "CoinType")
            {
                Helpers.MouseCursorWait();
                IsInitializingWtm   = true;
                ScanLanCancelSource = new CancellationTokenSource();
                var token = ScanLanCancelSource.Token;
                await LoadWtmCoins(token).ContinueWith(action => IsInitializingWtm = false);
            }
        }
예제 #3
0
        private async void CalculateProfitCommand(object parameter)
        {
            CalculateProfit.SetCanExecute(false);
            LoadHistoricalCharts.SetCanExecute(false);
            SwitchManually.SetCanExecute(false);

            ProfitTablesEnabled = true;

            var coinList = Workers.GetCoins(Workers.WorkerList, true);

            if (!coinList.Contains("Bitcoin"))
            {
                coinList.Add("Bitcoin");
            }

            //Update Yahoo rates if necessary
            if (WtmSettings.UseYahooRates &&
                WtmSettings.DisplayCurrency != "USD" &&
                WtmSettings.DisplayCurrency != "BTC" &&
                WtmSettingsObject.DisplayCurrencyListDate.Date != DateTime.Today)
            {
                await WtmSettings.GetYahooRates();

                if (WtmSettings.DisplayCurrencyList.Count == 2)
                {
                    BypassUndo(() => WtmSettings.UseYahooRates = false);
                    MessageBox.Show($"{Constants.AppName} could not download the list of currencies from Yahoo. Values will be displayed in USD.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }

            // Calculate mean hashrate
            var coinHashList = GetHashrates(coinList);

            // Get WTM coin data
            Dictionary <string, WtmData> wtmDataDict = null;

            (Dictionary <string, WtmData> data, WhatToMine.GetWtmCoinDataResult)wtmDataResult = (null, WhatToMine.GetWtmCoinDataResult.Fail);
            try
            {
                wtmDataResult = await WhatToMine.GetWtmCoinData(coinHashList, true);
            }
            catch (Exception ex)
            {
            }
            wtmDataDict = wtmDataResult.data;
            if (wtmDataDict == null)
            {
                CalculateProfitCommandQuit();
                return;
            }


            var    btc = wtmDataDict["Bitcoin"];
            string keyName;

            if (WtmSettings.Average24)
            {
                keyName = "exchange_rate24";
            }
            else
            {
                keyName = "exchange_rate";
            }

            string btcValue;

            btc.Json.TryGetValue(keyName, out btcValue);
            if (btcValue != null)
            {
                WtmSettings.DisplayCurrencyList["BTC"] = Helpers.StringToDecimal(btcValue);
            }
            else
            {
                MessageBox.Show("Failed to read BTC price from whattomine.com", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            // Form profit tables from wtmDataList
            ProfitTables.Tables.Clear();
            var workersChecked = Workers.WorkerList.Where(w => w.Query).ToList();
            var profitTables   = WhatToMine.CreateProfitTables(wtmDataDict, workersChecked, (decimal)Workers.PowerCost, WtmSettings);

            foreach (var table in profitTables)
            {
                ProfitTables.Tables.Add(table);
            }

            CalculateProfitCommandQuit();

            ScanLan.RaiseCanExecuteChanged();
            ScanLanCommand(null);
        }