Ejemplo n.º 1
0
 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);
         }
     }
 }