public void LoadAsync() { var providers = ProvidersFactory.CreateProviders(ProfileManager.DataProviders); var accounts = AccountsFactory.GetAccounts(providers, IsInProfile); LoadAccounts(accounts); }
private void LoadTransactions(IAccount account, DateTime firstDayOfMonth, DateTime lastDayOfMonth) { IObservable <IEnumerable <ITransaction> > observableTransactions = AccountsFactory.GetTransations(account, firstDayOfMonth, lastDayOfMonth); observableTransactions?.ObserveOn(new DispatcherSynchronizationContext()).Subscribe((transactions) => { if (transactions == null) { return; } var list = transactions as List <ITransaction> ?? transactions.ToList(); list = list.OrderBy(t => t.EventDate).ToList(); DefaultActivityFilter(list); foreach (var transaction in list) { var transactionViewModel = new TransactionViewModel(transaction); OnNewTransactionLoaded(transactionViewModel); } OnNewAccountLoaded(account); }, (error) => { }); }
private void HandleNewAccount() { var credentials = BuildCredentialDetails(); if (!credentials.Any(nameValue => string.IsNullOrEmpty(nameValue.Value))) { IsBusy = true; NewAccounts.Clear(); var observableProvider = ProvidersFactory.CreateProvider(new ProviderDescriptor(SelectedCompany.Name, credentials, null)); var accounts = AccountsFactory.GetAccounts(observableProvider, (a) => true); accounts.ObserveOn(new DispatcherSynchronizationContext()).Subscribe((account) => { var newAccount = new AccountViewModel(account); _accountMap.Add(account, newAccount); NewAccounts.Add(newAccount); }, (error) => { Error = error.Message; IsBusy = false; }, () => { IsBusy = false; }); } }
public void Confirm() { string eBayToken = null; { EbayContext context = new EbayContext(null); FetchToken command = new FetchToken(context); command.SessionId = this.SessionId; command.Execute(); eBayToken = command.EbayToken; } // Get the User's Details string userId = null; string siteCode = null; { EbayContext context = new EbayContext(eBayToken); GetUserCommand command = new GetUserCommand(context); command.Execute(); userId = command.UserId; siteCode = command.SiteCode; } Account account = new Account() { EbayToken = eBayToken, UserId = userId, SiteCode = siteCode }; // Get the Account's related Site Details { PopulateSitesJob job = new PopulateSitesJob(); Site site = job.PopulateSite(this.Context.Sites, account); account.Site = site; } // Set the Accounts Alert Preferences // TODO: Need to try catch this. { UpdatePreferencesJob job = new UpdatePreferencesJob(); job.Execute(account, this.Context.AlertPreferences); } // Save the account { this.Context.Accounts.Add(account); AccountsFactory factory = new AccountsFactory(); factory.Save(this.Context.Accounts); ObservableCollection <Account> newAccounts = factory.Load(); } this.Result = "Account Added"; }
public void Run(Account account) { try { if (Repository.GetAccountDetails(account)) { var log = AccountsFactory .Get(account.UID) .GetCallLogFor(account.Telephone, account.Username, account.Password); if (IsLogInvalid(log)) { account.Retries++; if (account.Retries < 3) { Messages.Enqueue(new Message { Payload = account }); } } else { Repository.UpdateCallLog(account, log); } } } catch (Exception e) { var source = "Simple Queue Service"; if (!EventLog.SourceExists(source)) { EventLog.CreateEventSource(source, "Application"); } EventLog.WriteEntry(source, e.Message + "\r\n" + e.StackTrace, EventLogEntryType.Error, 200); } }
/// <summary>This is the main entrypoint of the application.</summary> protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // Set the Current Culture. FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag))); // Setup the Logger ILogger logger = LogManager.GetLogger(); logger.Log(LogLevel.Info, "Loading the Application."); // Load up the Context & Engine Engine engine = null; Context context = null; { // Load the Accounts ObservableCollection <Account> accounts; try { AccountsFactory accountFactory = new AccountsFactory(); accounts = accountFactory.Load(); } catch (Exception ex) { logger.Log(LogLevel.Error, "Failed to load the Accounts.", ex); accounts = new ObservableCollection <Account>(); } // Load the Sites ObservableCollection <Site> sites = null; try { SitesFactory siteFactory = new SitesFactory(); sites = siteFactory.Load(); } catch (Exception ex) { logger.Log(LogLevel.Error, "Failed to load the Sites.", ex); sites = new ObservableCollection <Site>(); } // Load the AlertPreferences ObservableCollection <AlertPreference> alertPreferences = null; AlertPreferencesFactory alertPreferencesFactory = new AlertPreferencesFactory(); try { alertPreferences = alertPreferencesFactory.Load(); } catch (Exception ex) { logger.Log(LogLevel.Error, "Failed to load the AlertPreferences.", ex); alertPreferences = alertPreferencesFactory.CreateNew(); } // Load the Scheduler Schedule scheduler = null; try { ScheduleFactory schedulerFactory = new ScheduleFactory(); scheduler = schedulerFactory.Load(); } catch (Exception ex) { logger.Log(LogLevel.Error, "Failed to load the Scheduler.", ex); scheduler = new Schedule(); } // Check to see that we have a site for each account loaded foreach (Account account in accounts) { Site site = sites.FirstOrDefault(s => s.SiteCode == account.SiteCode); if (site == null) { PopulateSitesJob job = new PopulateSitesJob(); site = job.PopulateSite(sites, account); } account.Site = site; } // Load the Context context = new Context(accounts, sites, alertPreferences, scheduler); // Load the Engine engine = new Engine(context); DependencyFactory.RegisterInstance(context); DependencyFactory.RegisterInstance(engine); } // Create Initial Account (if no acount exists) if (context.Accounts.Count == 0) { logger.Log(LogLevel.Info, "No accounts exist. Creating initial account."); StartupWizardView view = new StartupWizardView(); StartupWizardViewModel viewModel = (StartupWizardViewModel)view.DataContext; Application.Current.MainWindow = view; Application.Current.MainWindow.ShowDialog(); } // If the user hit cancel and no accounts are saved, end the application if (context.Accounts.Count == 0) { Shutdown(); } // Load up the Alert balloon try { logger.Log(LogLevel.Info, "Loading up the Alert balloons..."); PopupView view = new PopupView(); TaskbarIcon notifyIcon = (TaskbarIcon)FindResource("NotifyIcon"); notifyIcon.ShowCustomBalloon(view, PopupAnimation.None, null); } catch (Exception ex) { logger.Log(LogLevel.Error, "Failed loading the alert balloons.", ex); } // Login. logger.Log(LogLevel.Info, "Performing Login..."); engine.Login(); }