private List <AimeAnnotationContainer> Find() { var results = new List <AimeAnnotationContainer>(); AimeSearchCriteria searchCriteria = Coordinator.CriteriaComponent.SearchCriteria; ApiKeyCredentials credentials = AimDataServiceLoginTool.Credentials; if (!String.IsNullOrEmpty(credentials.ApiKey)) { results = AimeWebService.Find(credentials.ApiKey, searchCriteria); } return(results); }
public void Login(string username, string password) { try { Credentials = AimeWebService.Login(username, password); base.ExitCode = ApplicationComponentExitCode.Accepted; Host.Exit(); } catch (Exception ex) { Host.DesktopWindow.ShowMessageBox(ex.Message, "Login Error", MessageBoxActions.Ok); Platform.Log(LogLevel.Error, ex, "AIM Data Service 2 Login Error", null); } }
public void SendAnnotations(List <string> annotations) { if (annotations != null && annotations.Count > 0) { try { SynchronizationContext.Post((delegate { if (!AimDataServiceLoginTool.CredentialsValid) { AimDataServiceLoginTool.RequestLogin(); } if (AimDataServiceLoginTool.CredentialsValid) { var task = new BackgroundTask(delegate { foreach (string annotation in annotations) { if (annotation != null) { var result = AimeWebService.Submit( AimDataServiceLoginTool.Credentials.ApiKey, annotation); if (result.Contains("fail")) { throw new Exception(result); } } } }, false); task.Run(); } }), null); } catch (Exception ex) { // TODO: Smarter handling of invalid credentials/expiring credentials if (ex.Message.Contains("401")) { AimDataServiceLoginTool.Credentials = null; } // AimAnnotationComponents handles the exception from here. throw (ex); } } }
private string DownloadAnnotationFromWebService(string annotationContainerUid) { string filename = Path.GetTempFileName(); // Will cause GUI thread exception unless run on the original synchronization context // The RetrieveAnnotationsFromAimService should already be checking this, so leaving commented out //if (!AimDataServiceLoginTool.CredentialsValid) // AimDataServiceLoginTool.RequestLogin(); if (AimDataServiceLoginTool.CredentialsValid) { string xml = AimeWebService.Retrieve(AimDataServiceLoginTool.Credentials.ApiKey, new AimeSearchCriteria { AnnotationContainreUid = annotationContainerUid }); using (var streamWriter = new StreamWriter(filename)) { streamWriter.Write(xml); } } return(filename); }