Пример #1
0
        /// <summary>
        /// Call API and retrieve new GUID
        /// </summary>
        /// <param name="parameter"></param>
        public void GetNewAccountID(object parameter)
        {
            try
            {
                // Call API to get new GUID
                // Set GUID in account identity object
                AccountIdentityAPI accountIdentityAPI = new AccountIdentityAPI();
                AccountIdentity = accountIdentityAPI.GetAccountID();

                // Set global variable for Account ID
                Application.Current.Properties["AccountID"] = AccountIdentity.AccountGuid;

                // Write GUID to account identity config file
                AccountIdentityFile accountIdentityFile = new AccountIdentityFile();
                accountIdentityFile.WriteJsonToFile(AccountIdentity);

                // Notify UI to update
                OnPropertyChanged("AccountGuid");

                // Removed previous collection of account workers
                accountWorkersList = new ObservableCollection <AccountWorkers>();

                // Insert new worker for account
                InsertAccountWorkers();

                // Notify success
                ShowSuccess("New Account ID created");
            }
            catch (Exception e)
            {
                throw new ApplicationException(string.Format("Error retrieving new account id"), e);
            }
        }
Пример #2
0
        internal static MinerAccount Init()
        {
            // Attempt to read the GUID from the config file
            AccountIdentityFile accountIdentityFile = new AccountIdentityFile();
            var accountIdentity = accountIdentityFile.ReadJsonFromFile();

            var accountId = accountIdentity.AccountGuid;

            // Validate if a GUID was actually read
            if (accountId == Guid.Empty)
            {
                throw new Exception("Account Identity could not be found - you need to configure this node with an account id.");
            }


            AccountWalletAPI   accountWalletAPI   = new AccountWalletAPI();
            GPUSettingsAPI     gpuSettingsAPI     = new GPUSettingsAPI();
            WorkerSettingsFile workerSettingsFile = new WorkerSettingsFile();
            var workerSettings = workerSettingsFile.ReadJsonFromFile();

            return(new MinerAccount()
            {
                AccountId = accountId.ToString(),
                AccountWalletList = accountWalletAPI.GetAccountWalletList(accountId.ToString()),
                WorkerSettings = workerSettings,
                GPUSettingsList = gpuSettingsAPI.GetGPUSettings(accountId.ToString(), workerSettings.WorkerName)
            });
        }
Пример #3
0
        /// <summary>
        /// Update GUID when user enters new value in UI and set data in config file
        /// </summary>
        /// <param name="parameter"></param>
        public void UpdateAccountID(object parameter)
        {
            try
            {
                if (parameter == null)
                {
                    return;
                }

                // Set GUID in account identity object
                Guid parsedGuid;
                bool parseResult = Guid.TryParse(parameter.ToString(), out parsedGuid);
                if (parseResult == false)
                {
                    throw new ApplicationException(string.Format("Error {0} is not a valid account id", parsedGuid));
                }

                // Set global variable for Account ID
                AccountIdentity.AccountGuid = parsedGuid;
                Application.Current.Properties["AccountID"] = AccountIdentity.AccountGuid;

                // Write GUID to account identity config file
                AccountIdentityFile accountIdentityFile = new AccountIdentityFile();
                accountIdentityFile.WriteJsonToFile(AccountIdentity);

                // Notify UI to update
                OnPropertyChanged("AccountGuid");

                // Insert new worker for account
                InsertAccountWorkers();

                // Reload Wallet Addresses
                WalletViewModel.CommandInitAccountWallet.Execute(null);

                // Notify success
                ShowSuccess("Updated existing Account ID");
            }
            catch (Exception e)
            {
                throw new ApplicationException(string.Format("Error updating account id"), e);
            }
        }
Пример #4
0
        /// <summary>
        /// Load previous GUID from config file or get a new GUID from the API
        /// </summary>
        private void InitAccountID()
        {
            try
            {
                // Empty GUID used for validation
                Guid guidEmpty = new Guid();

                // Attempt to read the GUID from the config file
                AccountIdentityFile accountIdentityFile = new AccountIdentityFile();
                AccountIdentity = accountIdentityFile.ReadJsonFromFile();

                // Validate if a GUID was actually read
                if (AccountIdentity.AccountGuid == guidEmpty)
                {
                    try
                    {
                        // If no GUID found, then get a new GUID from the API
                        AccountIdentityAPI accountIdentityAPI = new AccountIdentityAPI();
                        AccountIdentity = accountIdentityAPI.GetAccountID();

                        // Notify UI to update
                        OnPropertyChanged("AccountGuid");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("There was an error retrieving a new account id from the web. Please create a new one manually by selecting 'new account' before mining.");
                    }
                    // Write GUID to account identity config file
                    accountIdentityFile.WriteJsonToFile(AccountIdentity);

                    // Insert new worker for account
                    InsertAccountWorkers();
                }

                // Set global variable for Account ID
                Application.Current.Properties["AccountID"] = AccountIdentity.AccountGuid;
            }
            catch (Exception e)
            {
                throw new ApplicationException(string.Format("Error initializing account id"), e);
            }
        }