public ClientDashboard(CIVAccount account) { InitializeComponent(); DataContext = account; // Construction de l'interface foreach(DisplayInfoTypes element in ProgramSettings.Instance.Display) spMainContainer.Children.Insert(spMainContainer.Children.Count, DisplayInfoFactory.Create(element, account)); IsWorking = false; Messages = new ObservableCollection<ScreenMessage>(); ApiClient = new XmlClient(ProgramSettings.Instance.UserLanguage, account.Account.Token, account.Account.Username); ApiClient.OnReadDailyWiredUsage += ReadDailyWiredUsage; ApiClient.OnError += ApiClientError; ApiClient.OnDownloadData += OnDownloadData; ApiClient.OnDownloadDataEnd += OnDownloadDataEnd; ApiClient.OnDownloadHistory += OnDownloadHistory; ApiClient.OnDownloadHistoryEnd += OnDownloadHistoryEnd; // Déclenche le rafraichissement du UI Account = account; if (Account.Account.LastUpdate == DateTime.MinValue) { // Mettre un délai aléatoire LaunchUpdate(false); } else ShowLastUpdate(); if (ProgramSettings.Instance.EmailSMTP.Active && Account.SendMail && !String.IsNullOrEmpty(Account.MailSubject) && !String.IsNullOrEmpty(Account.MailTemplate)) btnSendMail.Visibility = System.Windows.Visibility.Visible; else btnSendMail.Visibility = System.Windows.Visibility.Collapsed; if (DataBaseFactory.Instance.IsAvailable) { List<DailyUsageBO> usages = DailyUsageDAO.Instance.UsageByPeriod(account.Account.Username, DateTime.Now.Date, DateTime.Now.Date); if (usages.Count > 0) { Account.Account.CurrentDayUpload = usages[0].Upload; Account.Account.CurrentDayDownload = usages[0].Download; } } }
private void btnGetUsername_Click(object sender, RoutedEventArgs e) { ApiWaiting = new PleaseWait(); ApiWaiting.Title = strings.AccountManager_TokenValidation; ApiWaiting.Owner = this; ApiWaiting.Show(); string token = txtToken.Text; ThreadStart start = delegate() { XmlClient client = new XmlClient(_settings.UserLanguage, token); try { string message; List<string> result = client.GetUsernameByToken(out message); /*for (int i = 1; i < 100; i++) { result = client.GetUsernameByToken(out message); if (!String.IsNullOrEmpty(message)) { Dispatcher.Invoke(DispatcherPriority.Background, new Action<string>(TokenError), message); break; } }*/ if (result.Count > 0) Dispatcher.Invoke(DispatcherPriority.Background, new Action<List<string>>(InitializeUsernameList), result); else Dispatcher.Invoke(DispatcherPriority.Background, new Action<string>(TokenError), message); } catch { Dispatcher.Invoke(DispatcherPriority.Background, new Action<List<string>>(InitializeUsernameList), null); } }; new System.Threading.Thread(start).Start(); }