Example #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);
            }
        }
Example #2
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);
            }
        }