public GetViewerInfoResult GetViewerInfo(GetViewerInfoRequest request) { if (request == null) { string message = "The get viewer info request cannot be null."; Platform.Log(LogLevel.Debug, message); throw new FaultException(message); } if (request.Viewer == null || request.Viewer.Identifier.Equals(Guid.Empty)) { string message = "A valid viewer id must be specified."; Platform.Log(LogLevel.Debug, message); throw new FaultException(message); } IImageViewer viewer = ViewerAutomationTool.GetViewer(request.Viewer.Identifier); if (viewer == null) { string message = String.Format("The specified viewer ({0}) was not found, " + "likely because it has already been closed by the user.", request.Viewer.Identifier); Platform.Log(LogLevel.Debug, message); throw new FaultException <ViewerNotFoundFault>(new ViewerNotFoundFault(message), _viewerNotFoundReason); } GetViewerInfoResult result = new GetViewerInfoResult(); result.AdditionalStudyInstanceUids = GetAdditionalStudyInstanceUids(viewer); return(result); }
public OpenStudiesResult OpenStudies(OpenStudiesRequest request) { if (request == null) { string message = "The open studies request cannot be null."; Platform.Log(LogLevel.Debug, message); throw new FaultException(message); } if (request.StudiesToOpen == null || request.StudiesToOpen.Count == 0) { string message = "At least one study must be specified."; Platform.Log(LogLevel.Debug, message); throw new FaultException(message); } OpenStudiesResult result = new OpenStudiesResult(); bool activateIfOpen = request.ActivateIfAlreadyOpen ?? true; try { string primaryStudyInstanceUid = request.StudiesToOpen[0].StudyInstanceUid; IImageViewer viewer = null; if (activateIfOpen) { Workspace workspace = GetViewerWorkspace(primaryStudyInstanceUid); if (workspace != null) { viewer = ImageViewerComponent.GetAsImageViewer(workspace); workspace.Activate(); } } if (viewer == null) { viewer = LaunchViewer(request, primaryStudyInstanceUid); } Guid?viewerId = ViewerAutomationTool.GetViewerId(viewer); if (viewerId == null) { throw new FaultException("Failed to retrieve the id of the specified viewer."); } result.Viewer = new Viewer(viewerId.Value, GetPrimaryStudyIdentifier(viewer)); return(result); } catch (FaultException) { throw; } catch (Exception e) { string message = "An unexpected error has occurred while attempting to open the study(s)."; Platform.Log(LogLevel.Error, e, message); throw new FaultException(message); } }
public void CloseViewer(CloseViewerRequest request) { if (request == null) { string message = "The close viewer request cannot be null."; Platform.Log(LogLevel.Debug, message); throw new FaultException(message); } if (request.Viewer == null || request.Viewer.Identifier.Equals(Guid.Empty)) { string message = "A valid viewer id must be specified."; Platform.Log(LogLevel.Debug, message); throw new FaultException(message); } IImageViewer viewer = ViewerAutomationTool.GetViewer(request.Viewer.Identifier); if (viewer == null) { string message = String.Format("The specified viewer ({0}) was not found, " + "likely because it has already been closed by the user.", request.Viewer.Identifier); Platform.Log(LogLevel.Debug, message); throw new FaultException <ViewerNotFoundFault>(new ViewerNotFoundFault(message), _viewerNotFoundReason); } IWorkspace workspace = GetViewerWorkspace(viewer); if (workspace == null) { string message = String.Format("The specified viewer ({0}) was found, " + "but it does not appear to be hosted in one of the active workspaces.", request.Viewer.Identifier); Platform.Log(LogLevel.Error, message); throw new FaultException <ViewerNotFoundFault>(new ViewerNotFoundFault(message), _viewerNotFoundReason); } try { workspace.Close(UserInteraction.NotAllowed); } catch (Exception e) { string message = String.Format("An unexpected error has occurred while attempting " + "to close the specified viewer ({0}).", request.Viewer.Identifier); Platform.Log(LogLevel.Error, e, message); throw new FaultException(message); } }
internal static IImageViewer GetViewer(Guid viewerId) { lock (_syncLock) { ViewerAutomationTool foundTool = CollectionUtils.SelectFirst(_tools, delegate(ViewerAutomationTool tool) { return(tool._viewerId == viewerId); }); if (foundTool != null) { return(foundTool._viewer); } return(null); } }
public GetViewersResult GetViewers(GetViewersRequest request) { List <Viewer> viewers = new List <Viewer>(); //The tool stores the viewer ids in order of activation, most recent first foreach (Guid viewerId in ViewerAutomationTool.GetViewerIds()) { IImageViewer viewer = ViewerAutomationTool.GetViewer(viewerId); if (viewer != null && GetViewerWorkspace(viewer) != null) { viewers.Add(new Viewer(viewerId, GetPrimaryStudyIdentifier(viewer))); } } if (viewers.Count == 0) { throw new FaultException <NoViewersFault>(new NoViewersFault(), "No active viewers were found."); } return(new GetViewersResult { Viewers = viewers }); }
/// TODO (CR Dec 2011): Build this functionality right into ImageViewerComponent? public static IImageViewer GetViewer(Viewer viewer) { return(ViewerAutomationTool.GetViewer(viewer.Identifier)); }
public OpenFilesResult OpenFiles(OpenFilesRequest request) { if (request == null) { const string message = "The open files request cannot be null."; Platform.Log(LogLevel.Debug, message); throw new FaultException(message); } if (request.Files == null || request.Files.Count == 0) { const string message = "At least one file or directory must be specified."; Platform.Log(LogLevel.Debug, message); throw new FaultException(message); } var helper = new OpenFilesHelper(); try { foreach (var file in request.Files) { FileProcessor.Process(file, null, helper.AddFile, true); } } catch (Exception e) { Platform.Log(LogLevel.Error, e); const string message = "There was a problem with the files/directories specified."; throw new FaultException <OpenFilesFault>(new OpenFilesFault { FailureDescription = message }, message); } if (request.WaitForFilesToOpen.HasValue && !request.WaitForFilesToOpen.Value) { SynchronizationContext.Current.Post(ignore => helper.OpenFiles(), null); return(new OpenFilesResult()); } try { helper.HandleErrors = false; var viewer = helper.OpenFiles(); var viewerId = ViewerAutomationTool.GetViewerId(viewer); return(new OpenFilesResult { Viewer = new Viewer(viewerId.Value, GetPrimaryStudyIdentifier(viewer)) }); } catch (Exception e) { if (!request.ReportFaultToUser.HasValue || request.ReportFaultToUser.Value) { SynchronizationContext.Current.Post( ignore => ExceptionHandler.Report(e, ImageViewer.StudyManagement.SR.MessageFailedToOpenImages, Application.ActiveDesktopWindow), null); } const string message = "There was a problem opening the files/directories specified in the viewer."; throw new FaultException <OpenFilesFault>(new OpenFilesFault { FailureDescription = message }, message); } }