private QueryRetrieveScu GetScu(AeInfo server) { QueryRetrieveScu scu = null; bool useSecurePort = (server.Port == 0) && (server.SecurePort != 0); int port = useSecurePort ? server.SecurePort : server.Port; if (useSecurePort) { GatewaySession.InitializeDicomSecurity(false); scu = new QueryRetrieveScu(string.Empty, DicomNetSecurityMode.Tls, GatewaySession._openSslOptions); scu.UseSecureHost = true; GatewaySession.SetCiphers(scu); } if (scu == null) { scu = new QueryRetrieveScu(); } scu.AETitle = server.AETitle; scu.HostAddress = IPAddress.Parse(server.Address); scu.HostPort = port; return(scu); }
//[PresentationContext(DicomUidType.PatientRootQueryFind, new byte[] {1,0,1},DicomUidType.ImplicitVRLittleEndian)] //[PresentationContext(DicomUidType.PatientStudyQueryFind, DicomUidType.ImplicitVRLittleEndian)] //[PresentationContext(DicomUidType.StudyRootQueryFind, DicomUidType.ImplicitVRLittleEndian)] public DicomCommandStatusType OnFind ( DicomClient client, byte presentationId, int messageId, string affectedClass, DicomCommandPriorityType priority, DicomDataSet request ) { int countOfServersConnection; try { __Client = client; if (null == __ServersManager) { GatewaySession.Log(string.Empty, string.Empty, -1, DicomCommandType.CFind, LogType.Error, MessageDirection.None, null, "[Gateway] Gateway server not available"); return(DicomCommandStatusType.ProcessingFailure); } countOfServersConnection = 0; //make sure to break the loop on success or normal failure while (countOfServersConnection < __ServersManager.Servers.Count) { AeInfo currentRemoteServer; DicomScp remoteScp; QueryRetrieveScu cFindScu; countOfServersConnection++; currentRemoteServer = __ServersManager.GetRemoteServer(); remoteScp = GetScp(currentRemoteServer); cFindScu = GetScu(__ServersManager.Gateway.Server); try { RegisterEvents(cFindScu); if (cFindScu.SecurityMode == DicomNetSecurityMode.Tls) { GatewaySession.InitializeDicomSecurity(false); GatewaySession.SetCiphers(cFindScu); GatewaySession.SetSecurityCertificates(cFindScu); } __CFindScu = cFindScu; __CurrentStatus = DicomCommandStatusType.Success; GatewaySession.Log(client, DicomCommandType.CFind, LogType.Information, MessageDirection.Output, request, "[Gateway] Sending C-Find request to remote server \"" + currentRemoteServer.AETitle + "\""); cFindScu.Find(remoteScp, request); GatewaySession.Log(client, DicomCommandType.CFind, LogType.Information, MessageDirection.None, null, "[Gateway] C-Find request sent successfully \"" + currentRemoteServer.AETitle + "\""); break; } catch (ClientConnectionException exception) { GatewaySession.Log(client, DicomCommandType.CFind, LogType.Warning, MessageDirection.None, null, "[Gateway] Connecting to server failed \"" + currentRemoteServer.AETitle + "\"\n" + exception.Message); __ServersManager.SetRemoteServerConnectionFailure(); __CurrentStatus = DicomCommandStatusType.Failure; } catch (ClientCommunicationException exception) { __CurrentStatus = exception.Status; GatewaySession.Log(client, DicomCommandType.CFind, LogType.Error, MessageDirection.None, null, "[Gateway] Communicating with server failed \"" + currentRemoteServer.AETitle + "\"\n" + exception.Message); break; } catch (DicomException exception) { if (__CurrentStatus == DicomCommandStatusType.Success) { __CurrentStatus = DicomCommandStatusType.Failure; } GatewaySession.Log(client, DicomCommandType.CFind, LogType.Error, MessageDirection.None, null, "[Gateway] Forwarding to server failed \"" + currentRemoteServer.AETitle + "\"\n" + exception.Message); break; } catch (Exception exception) { if (__CurrentStatus == DicomCommandStatusType.Success) { __CurrentStatus = DicomCommandStatusType.ProcessingFailure; } GatewaySession.Log(client, DicomCommandType.CFind, LogType.Error, MessageDirection.None, null, "[Gateway] Forwarding to server failed \"" + currentRemoteServer.AETitle + "\"\n" + exception.Message); break; } finally { UnregisterEvents(cFindScu); cFindScu.Dispose(); __CFindScu = null; } } return(__CurrentStatus); } finally { request.Dispose(); } }