public void Run() { // Running in a background thread, perform the web query which may take awhile. LogbookSettings settings = new LogbookSettings(); settings.Load(logbook); if (settings.UserId.Length > 0 && settings.PublicKey.Length > 0) { IList <WithingsWebServiceProxy.MeasurementInfo> measurements = null; try { measurements = WithingsWebServiceProxy.GetMeasurementsSinceLastUpdate(culture, settings.UserId, settings.PublicKey, settings.LastUpdate); } catch (Exception ex) { measurements = null; AddLogEntry(settings, "Could not read user measurements. " + ex.Message); } // Jump back to the UI thread to process the web response since it may cause data change events and UI updates. // TODO: Ugly way to get back on the UI thread via the ActiveView. Possibly a better solution in 3.0? IView activeView = Plugin.Instance.Application.ActiveView; while (activeView == null) { Thread.Sleep(2000); activeView = Plugin.Instance.Application.ActiveView; } activeView.CreatePageControl().BeginInvoke(new ProcessResponseCallback(ProcessResponse), new object[] { logbook, settings, measurements }); } }
private void ProcessReceivedMeasurements() { MeasurementImporter.ImportMeasurements(logbook, settings, measurements); settings.LastLogEntryDate = DateTime.Today; settings.LastLogEntry = CommonResources.Text.ActionOk; settings.LastUpdate = WithingsWebServiceProxy.GetNowEpoch(); settings.Save(logbook); }
private void ProcessResponse(ILogbook logbook, LogbookSettings settings, IList <WithingsWebServiceProxy.MeasurementInfo> measurements) { // Running in the UI thread. if (measurements != null) { MeasurementImporter.ImportMeasurements(logbook, settings, measurements); settings.LastUpdate = WithingsWebServiceProxy.GetNowEpoch(); AddLogEntry(settings, ""); } settings.Save(logbook); ExtendSettingsPages.RefreshSettings(); }
private bool GetUsers() { try { Cursor = Cursors.WaitCursor; string culture = Thread.CurrentThread.CurrentUICulture.ToString(); IList <WithingsWebServiceProxy.UserInfo> users = WithingsWebServiceProxy.GetUserList(culture, accountInfoPage.AccountName, accountInfoPage.Password); selectUserPage.Users = users; } catch (Exception ex) { MessageDialog.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } finally { Cursor = Cursors.Default; } return(true); }
private void HistoryImport() { // Running in a background thread errorText = ""; historyImportedOk = false; try { measurements = WithingsWebServiceProxy.GetAllMeasurements(culture, settings.UserId, settings.PublicKey); historyImportedOk = true; } catch (Exception ex) { errorText = ex.Message; } if (!IsDisposed && IsHandleCreated) { BeginInvoke(new HistoryImportCompleteCallback(HistoryImportComplete)); } }