public void PerformSearch()
        {
            var initialSearchCommand = new AimDataServiceSearchCommand();

            initialSearchCommand.Coordinator = this;
            SearchResultsComponent.Table.Items.Clear();

            _uiThreadSynchronizationContext = SynchronizationContext.Current;

            _totalCommandsToExecute = 1;
            _commandsExecuted       = 0;

            _cancel       = false;
            _resultsAdded = false;

            SearchResultsComponent.Title = "Searching...";

            ApiKeyCredentials credentials = AimDataServiceLoginTool.Credentials;

            if (credentials == null)
            {
                AimDataServiceLoginTool.RequestLogin();
                credentials = AimDataServiceLoginTool.Credentials;
            }

            if (credentials != null)
            {
                _threadPool.Start();
                _threadPool.Enqueue(initialSearchCommand.Execute);
            }
        }
Exemple #2
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);
         }
     }
 }
Exemple #3
0
        protected void RetrieveAnnotationsFromAimService(object[] searchResults)
        {
            string errorMsg = null;

            if (!AimDataServiceLoginTool.CredentialsValid)
            {
                AimDataServiceLoginTool.RequestLogin();
            }
            var task = new BackgroundTask(
                delegate(IBackgroundTaskContext context)
            {
                try
                {
                    int cnt = 0;
                    BackgroundTaskProgress progress;
                    var xmlFiles = new List <string>();

                    foreach (AimeAnnotationContainer result in searchResults)
                    {
                        cnt++;

                        if (result.Annotations == null)
                        {
                            continue;
                        }

                        xmlFiles.Add(DownloadAnnotationFromWebService(result.AnnotationContainerUid));

                        progress = new BackgroundTaskProgress(cnt, searchResults.Length + 1,
                                                              "Discovering Annotation " + cnt);
                        context.ReportProgress(progress);
                    }

                    if (xmlFiles.Count > 0)
                    {
                        List <string> invalidFiles;
                        List <string> tempDcmFiles =
                            AimManager.ConvertAnnotationsFromXmlToDicomFiles(AimManager.DefaultAimVersion,
                                                                             xmlFiles, context, out invalidFiles);

                        if (tempDcmFiles.Count > 0)
                        {
                            progress = new BackgroundTaskProgress(searchResults.Length, searchResults.Length + 1,
                                                                  "Importing Annotations");
                            context.ReportProgress(progress);

                            ImportDicomFiles(tempDcmFiles);
                        }
                    }
                }
                catch (Exception ex)
                {
                    // TODO: Smarter handling of invalid credentials/expiring credentials
                    if (ex.Message.Contains("401"))
                    {
                        AimDataServiceLoginTool.Credentials = null;
                    }

                    errorMsg = ex.Message;
                    Platform.Log(LogLevel.Error, ex, "Failed to import annotation(s)");
                }

                context.Complete(null);
            }, true);

            ProgressDialog.Show(task, Context.DesktopWindow, true, ProgressBarStyle.Blocks);

            if (!string.IsNullOrEmpty(errorMsg))
            {
                Context.DesktopWindow.ShowMessageBox(errorMsg, MessageBoxActions.Ok);
            }
        }