Пример #1
0
        public async Task <StreamUploadResponse> UpdateWtmSettings(StreamUploadRequest request)
        {
            var memoryStream = new MemoryStream();

            try
            {
                await request.Stream.CopyToAsync(memoryStream);

                var wtmSettings = NetHelper.DeserializeFromStream <WtmSettingsObject>(memoryStream);
                if (request.ProxyPassword.Length != 0)
                {
                    wtmSettings.ProxyPassword          = request.ProxyPassword.ToSecureString();
                    wtmSettings.ProxyPasswordEncrypted = request.ProxyPassword.Encrypt();
                    Array.Clear(request.ProxyPassword, 0, request.ProxyPassword.Length);
                }
                ViewModel.Instance.WtmSettings = wtmSettings.Clone();
                ViewModel.Instance.SaveWtmSettings();
                var date = WtmSettingsObject.GetWtmSettingsLastUpdateTime();
                return(new StreamUploadResponse {
                    ResponseFlag = true, Date = date
                });
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
            finally
            {
                memoryStream.Dispose();
            }
        }
Пример #2
0
        private void MassUpdateWtmSettingsCommand(object obj)
        {
            var massUpdateWindow = new MassUpdate();
            var vm = new MassUpdateVM(Workers.GetComputers(Computer.OperationStatus.OperationInProgress));

            vm.Header       = $"Update Settings";
            vm.WindowTitle  = $"Mass Update";
            vm.ColumnHeader = "Settings Date";
            vm.SubHeader    = $"{Environment.MachineName}: {WtmSettingsObject.GetWtmSettingsLastUpdateTime()}";
            massUpdateWindow.DataContext = vm;
            var dialogResult = massUpdateWindow.ShowDialog();
        }
Пример #3
0
        public WtmSettingsObject Clone()
        {
            WtmSettingsObject _new = new WtmSettingsObject(true);

            _new.DisplayCurrencyList     = this.DisplayCurrencyList;
            _new.DisplayCurrency         = this.DisplayCurrency;
            _new.UseYahooRates           = this.UseYahooRates;
            _new.Average24               = this.Average24;
            _new.AutoSwitch              = this.AutoSwitch;
            _new.RestartMiner            = this.RestartMiner;
            _new.RestartComputer         = this.RestartComputer;
            _new.KillList                = new ObservableCollection <string>(this.KillList);
            _new.PriceMargin             = this.PriceMargin;
            _new.DelayNextSwitchTime     = this.DelayNextSwitchTime;
            _new.BackupHistoricalPrices  = this.BackupHistoricalPrices;
            _new.SaveAllCoins            = this.SaveAllCoins;
            _new.HistoricalAveragePeriod = this.HistoricalAveragePeriod;

            _new.StartWithWindows = this.StartWithWindows;
            _new.SwitchTimeFrom   = this.SwitchTimeFrom.Clone();
            _new.SwitchTimeTo     = this.SwitchTimeTo.Clone();

            _new.SwitchPeriod      = this.SwitchPeriod;
            _new.SwitchPeriodCount = this.SwitchPeriodCount;

            _new.UseHistoricalAverage = this.UseHistoricalAverage;
            _new.HistoryTimeFrom      = this.HistoryTimeFrom.Clone();
            _new.HistoryTimeTo        = this.HistoryTimeTo.Clone();

            _new.WtmRequestInterval     = this.WtmRequestInterval;
            _new.DynamicRequestTrigger  = this.DynamicRequestTrigger;
            _new.DynamicRequestInterval = this.DynamicRequestInterval;

            _new.UseProxy               = this.UseProxy;
            _new.Proxy                  = this.Proxy;
            _new.AnonymousProxy         = this.AnonymousProxy;
            _new._proxyUserName         = this.ProxyUserName;
            _new.ProxyPassword          = this.ProxyPassword;
            _new.ProxyPasswordEncrypted = this.ProxyPasswordEncrypted;
            _new.ApplicationMode        = this.ApplicationMode;
            _new.ServerName             = this.ServerName;
            _new.TcpPort                = this.TcpPort;

            _new.UpdateWorkersFromServer   = this.UpdateWorkersFromServer;
            _new.QueryWtmOnLocalServerFail = this.QueryWtmOnLocalServerFail;
            _new.DontSwitchServer          = this.DontSwitchServer;

            return(_new);
        }
Пример #4
0
        public static WtmSettingsObject ReadWtmSettings(bool showError = true)
        {
            WtmSettingsObject settings          = null;
            WtmSettingsObject convertedSettings = null;
            string            settingsContent   = string.Empty;

            if (File.Exists(Constants.WtmSettingsFile))
            {
                try { settingsContent = File.ReadAllText(Constants.WtmSettingsFile); }
                catch { return(null); }
                convertedSettings = JsonConverter.ConvertFromJson <WtmSettingsObject>(settingsContent, showError);
                if (convertedSettings != null)
                {
                    settings = convertedSettings.Clone();
                }
            }
            return(settings);
        }
Пример #5
0
        public async Task ScanLan()
        {
            ScanIsInProgress = true;

            UpdateCancelSource = new CancellationTokenSource();
            var token = UpdateCancelSource.Token;
            var tasks = new List <Task>();

            var appVersion      = new Version(Helpers.ApplicationVersion());
            var workersDate     = Workers.GetWorkersLastUpdateTime();
            var wtmSettingsDate = WtmSettingsObject.GetWtmSettingsLastUpdateTime();

            foreach (var pc in Computers)
            {
                Task task = null;
                switch (ColumnHeader)
                {
                case "Version":
                    task = Task.Run(async() => await QueryRemoteVersion(pc, token, appVersion));
                    break;

                case "Workers Date":
                    task = Task.Run(async() => await QueryRemoteWorkersDate(pc, token, workersDate));
                    break;

                case "Settings Date":
                    task = Task.Run(async() => await QueryRemoteWtmSettingsDate(pc, token, wtmSettingsDate));
                    break;
                }
                tasks.Add(task);
            }

            await Task.WhenAll(tasks);

            ScanIsInProgress = false;
        }
Пример #6
0
        public Task <DateTime> GetWtmSettingsDateAsync()
        {
            DateTime updateTime = WtmSettingsObject.GetWtmSettingsLastUpdateTime();

            return(Task.FromResult(updateTime));
        }
Пример #7
0
        private async void UpdateCommand(object obj)
        {
            UpdateIsInProgress = true;

            var workersDate     = Workers.GetWorkersLastUpdateTime();
            var wtmSettingsDate = WtmSettingsObject.GetWtmSettingsLastUpdateTime();

            UpdateCancelSource = new CancellationTokenSource();
            var token = UpdateCancelSource.Token;

            var          taskList   = new List <Task>();
            var          failList   = new List <ProfitTable>();
            FlowDocument report     = new FlowDocument();
            int          errorCount = 0;

            string appVersion = Helpers.ApplicationVersion();

            var jobCount = Computers.Count;

            ReportTitle = $"Progress: 0 of {jobCount}.";
            for (int i = 0; i < jobCount; i++)
            {
                var pc = Computers[i];
                if (!pc.Switch)
                {
                    continue;
                }
                Task task = null;
                switch (ColumnHeader)
                {
                case "Version":
                    task = Task.Run(async() => { errorCount = await UpdateVersion(pc, token, errorCount, i, jobCount, appVersion); });
                    break;

                case "Workers Date":
                    task = Task.Run(async() => { errorCount = await UpdateWorkers(pc, token, errorCount, i, jobCount, workersDate); });
                    break;

                case "Settings Date":
                    task = Task.Run(async() => { errorCount = await UpdateWtmSettings(pc, token, errorCount, i, jobCount, wtmSettingsDate); });
                    break;
                }
                taskList.Add(task);
            }

            await Task.WhenAll(taskList);

            if (errorCount == 0)
            {
                ReportTitle = "Report:";
                var paragraph = new Paragraph();
                paragraph.Inlines.Add(new Run("Operation has finished successfully."));
                NewParagraph = paragraph;
            }
            else
            {
                ReportTitle = "Error report:";
            }

            UpdateIsInProgress = false;
            UpdateIsFinished   = true;
        }
Пример #8
0
        // ViewModel constructor
        public ViewModel()
        {
            TestProperty = "TEST";

            IsInitializingWtm = true;

            ProfitTables = new ProfitTables {
                Tables = new ObservableCollection <ProfitTable>()
            };
            ProfitTables.Tables.CollectionChanged += ProfitTables_CollectionChanged;

            HistoricalCharts = new ObservableCollection <HistoricalChart>();

            // Read workers from file or create default
            Workers = Workers.ReadWorkers(false);
            if (Workers == null)
            {
                Workers        = new Workers(true).Clone();
                DefaultWorkers = true;
            }

            WorkersPropertyEventsAdd();

            // Read Wtm settings from file or create default settings
            WtmSettings = WtmSettingsObject.ReadWtmSettings(false);
            if (WtmSettings == null)
            {
                WtmSettings        = new WtmSettingsObject();
                DefaultWtmSettings = true;
            }

            WhatToMine.RequestInterval           = WtmSettings.WtmRequestInterval;
            WtmSettings.ServerSettingsAreUpdated = true;
            UpdateWtmHttpClient();

            WtmSwitchTimeFromStored          = WtmSettings.SwitchTimeFrom.Clone();
            WtmSwitchTimeToStored            = WtmSettings.SwitchTimeTo.Clone();
            WtmHistoricalAveragePeriodStored = WtmSettings.HistoricalAveragePeriod;
            WtmHistoryTimeFromStored         = WtmSettings.HistoryTimeFrom.Clone();
            WtmHistoryTimeToStored           = WtmSettings.HistoryTimeTo.Clone();

            HookUpWmtSettingsPropertyChangeEvents();

            SwitchTimeIsUpdated  = true;
            HistoryTimeIsUpdated = true;

            History = new History();

            ProfitTablesEnabled = true;

            Initialize            = new RelayCommandLight(InitializeCommand);
            AddWorker             = new RelayCommandLight(AddWorkerCommand);
            DeleteWorker          = new RelayCommandLight(DeleteWorkerCommand);
            NewWorker             = new RelayCommandLight(NewWorkerCommand);
            ExportWorkers         = new RelayCommandLight(ExportWorkersCommand);
            ImportWorkers         = new RelayCommandLight(ImportWorkersCommand);
            MultiplyHashrate      = new RelayCommandLight(MultiplyHashrateCommand);
            MoveWorker            = new RelayCommandLight(MoveWorkerCommand);
            CopyWorker            = new RelayCommandLight(CopyWorkerCommand);
            MoveWorkerDown        = new RelayCommandLight(MoveWorkerDownCommand);
            MoveWorkerUp          = new RelayCommandLight(MoveWorkerUpCommand);
            AddCoinTable          = new RelayCommandLight(AddCoinTableCommand);
            DeleteCoinTable       = new RelayCommandLight(DeleteCoinTableCommand);
            MoveCoinTable         = new RelayCommandLight(MoveCoinTableCommand);
            CopyCoinTable         = new RelayCommandLight(CopyCoinTableCommand);
            AddCoin               = new RelayCommandLight(AddCoinCommand);
            DeleteCoin            = new RelayCommandLight(DeleteCoinCommand);
            Save                  = new RelayCommandLight(SaveCommand);
            Undo                  = new RelayCommandLight(UndoCommand);
            Redo                  = new RelayCommandLight(RedoCommand);
            CalculateProfit       = new RelayCommandLight(CalculateProfitCommand, CalculateProfit_CanExecute);
            Export                = new RelayCommandLight(ExportCommand, Export_CanExecute);
            SwitchManually        = new RelayCommandLight(SwitchManuallyCommand, SwitchManually_CanExecute);
            ApplyAutoSwitch       = new RelayCommandLight(ApplyAutoSwitchCommand);
            ApplyHistoryBackup    = new RelayCommandLight(ApplyHistoryBackupCommand);
            EditKillList          = new RelayCommandLight(EditKillListCommand);
            GenerateRandomPort    = new RelayCommandLight(GenerateRandomPortCommand);
            ApplyServerSettings   = new RelayCommandLight(ApplyServerSettingsCommand);
            TestConnection        = new RelayCommandLight(TestConnectionCommand, TestConnection_CanExecute);
            LoadHistoricalCharts  = new RelayCommandLight(LoadHistoricalChartsCommand, CalculateProfit_CanExecute);
            LineSeriesSelectAll   = new RelayCommandLight(LineSeriesSelectAllCommand);
            LineSeriesSelectNone  = new RelayCommandLight(LineSeriesSelectNoneCommand);
            ScanLan               = new RelayCommandLight(ScanLanCommand);
            ScanLanStop           = new RelayCommandLight(ScanLanStopCommand);
            ClearProfitTables     = new RelayCommandLight(ClearProfitTablesCommand);
            MassUpdateApplication = new RelayCommandLight(MassUpdateApplicationCommand);
            MassUpdateWorkers     = new RelayCommandLight(MassUpdateWorkersCommand);
            MassUpdateWtmSettings = new RelayCommandLight(MassUpdateWtmSettingsCommand);
            AddCoinsByAlgorithm   = new RelayCommandLight(AddCoinsByAlgorithmCommand);
            UpdateCoins           = new RelayCommandLight(UpdateCoinsCommand);
            AddComputers          = new RelayCommandLight(AddComputersCommand);
            CancelWaiting         = new RelayCommandLight(CancelWaitingCommand);
            EditPath              = new RelayCommandLight(EditPathCommand);
            OpenInExplorer        = new RelayCommandLight(OpenInExplorerCommand);
            SortBy                = new RelayCommandLight(SortByCommand);

            WorkersExpandAll   = new RelayCommandLight(WorkersExpandAllCommand);
            WorkersCollapseAll = new RelayCommandLight(WorkersCollapseAllCommand);
            WorkerSelectAll    = new RelayCommandLight(WorkerSelectAllCommand);
            WorkerSelectNone   = new RelayCommandLight(WorkerSelectNoneCommand);
            WorkerQueryAll     = new RelayCommandLight(WorkerQueryAllCommand);
            WorkerQueryNone    = new RelayCommandLight(WorkerQueryNoneCommand);

            About = new RelayCommandLight(AboutCommand);
            Exit  = new RelayCommandLight(ExitCommand);
            Test  = new RelayCommandLight(TestCommand);

            Instance = this;
        } // end ViewModel constructor
Пример #9
0
        public static (decimal profit24, decimal revenue) CalculateProfit(
            CoinTable coinTable,
            Dictionary <string, WtmData> wtmDataDict,
            WtmData btc,
            WtmSettingsObject settings,
            decimal powerCost
            )
        {
            decimal revenueAllCoins = 0;

            revenueAllCoins = 0;

            decimal coinRate = 0; decimal btcRate = 0;

            foreach (Coin coin in coinTable.Coins)
            {
                WtmData currentCoin = null;
                wtmDataDict.TryGetValue(coin.Name, out currentCoin);
                if (currentCoin == null)
                {
                    continue;
                }
                if (settings.UseHistoricalAverage && currentCoin.HasAverage)
                {
                    coinRate = currentCoin.AveragePrice;
                    btcRate  = btc != null ? btc.AveragePrice : 0;
                }
                else
                {
                    string keyName;
                    if (settings.Average24)
                    {
                        keyName = "exchange_rate24";
                    }
                    else
                    {
                        keyName = "exchange_rate";
                    }
                    string coinValue;
                    currentCoin.Json.TryGetValue(keyName, out coinValue);
                    if (coinValue != null)
                    {
                        coinRate = Helpers.StringToDecimal(coinValue);
                    }
                    string btcValue = null;
                    btc?.Json.TryGetValue(keyName, out btcValue);
                    if (btcValue != null)
                    {
                        btcRate = Helpers.StringToDecimal(btcValue);
                    }
                }

                decimal ratio            = (decimal)coin.Hashrate / (decimal)currentCoin.DefaultHashrate;
                decimal revenueOneCoin   = 0;
                decimal estimatedRewards = Helpers.StringToDecimal(currentCoin.Json["estimated_rewards"]);
                revenueOneCoin   = ratio * estimatedRewards * coinRate * btcRate;
                revenueAllCoins += revenueOneCoin;
                //totalHashrate += Convert.ToString(coin.Hashrate, CultureInfo.InvariantCulture) + "+";
                //name += coin.Name + "+";
                //algorithm += currentCoin.Json["algorithm"] + "+";
            }
            decimal profit24 = 0;

            //name = name.TrimEnd('+');
            profit24 = revenueAllCoins - (revenueAllCoins * (decimal)coinTable.Fees / 100) - (((decimal)coinTable.Power / 1000) * 24 * powerCost);
            return(profit24, revenueAllCoins);
        }
Пример #10
0
        public static List <ProfitTable> CreateProfitTables(Dictionary <string, WtmData> wtmDataDict, List <Worker> workerList, decimal powerCost, WtmSettingsObject settings, bool switchableOnly = false)
        {
            var btc          = wtmDataDict["Bitcoin"];
            var profitList   = new List <ProfitTableRow>();
            var profitTables = new List <ProfitTable>();

            int j = 1; var workerCount = workerList.Count;

            foreach (var worker in workerList)
            {
                foreach (var entry in worker.CoinList)
                {
                    if (switchableOnly && !entry.Switch)
                    {
                        continue;
                    }
                    var     profitResult    = CalculateProfit(entry, wtmDataDict, btc, settings, powerCost);
                    decimal profit24        = profitResult.profit24;
                    decimal revenueAllCoins = profitResult.revenue;
                    bool    multicell       = (entry.Coins.Count > 1);
                    var     newRow          = new ProfitTableRow
                    {
                        Name        = entry.FullName,
                        Symbol      = entry.FullSymbol,
                        Algorithm   = entry.FullAlgorithm,
                        Hashrate    = entry.FullHashrate,
                        Multicell   = multicell,
                        Switchable  = entry.Switch,
                        Revenue     = revenueAllCoins,
                        ProfitDay   = profit24,
                        ProfitWeek  = profit24 * 7,
                        ProfitMonth = profit24 * 30,
                        ProfitYear  = profit24 * 365,
                        Path        = entry.Path ?? string.Empty,
                        Arguments   = entry.Arguments ?? string.Empty,
                        Notes       = entry.Notes,
                    };
                    profitList.Add(newRow);

                    newRow = null;
                }
                var newProfitTable = new ProfitTable
                {
                    Name      = worker.Name,
                    Index     = j,
                    ThisPC    = Helpers.ListContainsThisPC(worker.Computers),
                    Computers = new ObservableCollection <Computer>(worker?.Computers.Select(computer => new Computer {
                        Name = computer
                    })),
                    Description = worker.Description,
                    ProfitList  = profitList.OrderByDescending(p => p.ProfitDay).ToList()
                };

                var firstCoin = newProfitTable.ProfitList.FirstOrDefault();
                if (firstCoin != null)
                {
                    firstCoin.ManualSwitch = true;
                }

                //Show the topmost coin as the new coin in Computers list
                newProfitTable.HookPropertyChanched();
                newProfitTable.Row_PropertyChanged(newProfitTable.ProfitList.FirstOrDefault(), new PropertyChangedEventArgs("ManualSwitch"));

                profitTables.Add(newProfitTable);
                profitList.Clear();
                j++;
            }
            return(profitTables);
        }