// Remove worker from list private void RemoveAccountWorkers(object param) { try { if (param != null) { AccountWorkers accountWorkersRemove = (AccountWorkers)param; // Delete worker from account using API AccountWorkersAPI accountWorkersAPI = new AccountWorkersAPI(); accountWorkersAPI.DeleteAccountWorkers(accountWorkersRemove); // Remove worker from local list of workers AccountWorkersList.Remove(accountWorkersRemove); // Notify UI of change OnPropertyChanged("AccountWorkersList"); // Update worker list on main window _mainWindowViewModel.GetAccountWorkerList(); // Notify success ShowSuccess(string.Format("Worker {0} successfully removed", accountWorkersRemove.WorkerName)); } } catch (Exception e) { throw new ApplicationException(string.Format("Error removing worker from account"), e); } }
/// <summary> /// Load list of workers for account /// </summary> private void InitAccountWorkers() { try { if (Application.Current.Properties["AccountID"] != null) { // Load list of account workers AccountWorkersAPI accountWorkersAPI = new AccountWorkersAPI(); AccountWorkersList = accountWorkersAPI.GetAccountWorkers(Application.Current.Properties["AccountID"].ToString()); // Notify UI of change OnPropertyChanged("AccountWorkersList"); } } catch (Exception e) { throw new ApplicationException(string.Format("Error loading worker list"), e); } }
/// <summary> /// Insert a new worker for account /// </summary> private void InsertAccountWorkers() { try { if (Application.Current.Properties["AccountID"] != null && WorkerSettings.WorkerName != null) { // Reload Account Work List InitAccountWorkers(); // Create new worker object AccountWorkers accountWorker = new AccountWorkers(); accountWorker.AccountGuid = (Guid)Application.Current.Properties["AccountID"]; accountWorker.WorkerName = WorkerSettings.WorkerName; // Insert new worker for account into API AccountWorkersAPI accountWorkersAPI = new AccountWorkersAPI(); accountWorkersAPI.PostAccountWorkers(accountWorker); // Insert worker into local list if it doesnt already exist List <AccountWorkers> AccountWorkersListMatches = AccountWorkersList.Where(x => x.AccountGuid == accountWorker.AccountGuid && x.WorkerName == accountWorker.WorkerName).ToList(); if (AccountWorkersListMatches.Count == 0) { // Add new worker to local list AccountWorkersList.Add(accountWorker); } // Update worker list on main window _mainWindowViewModel.GetAccountWorkerList(); // Set Label on Main Window _mainWindowViewModel.LabelMainTitle = string.Format("BITPOOL MINER - {0}", WorkerSettings.WorkerName); // Notify UI of change OnPropertyChanged("AccountWorkersList"); } } catch (Exception e) { throw new ApplicationException(string.Format("Error inserting worker to account"), e); } }