/// <summary> /// Validates the dicom application entity settings. /// </summary> /// <param name="ownApplicationEntityTitle">The own application entity title.</param> /// <param name="peerApplicationEntityTitle">The peer application entity title.</param> /// <param name="peerApplicationEntityPort">The peer application entity port.</param> /// <param name="peerApplicationEntityIPAddress">The peer application entity IP address.</param> /// <exception cref="ArgumentNullException">peerApplicationEntity</exception> /// <exception cref="ArgumentException"> /// peerApplicationEntity /// or /// ownApplicationEntityTitle /// </exception> protected static void ValidateDicomApplicationEntitySettings( string ownApplicationEntityTitle, string peerApplicationEntityTitle, int peerApplicationEntityPort, string peerApplicationEntityIPAddress) { var peerApplicationEntityTitleValidationResult = ApplicationEntityValidationHelpers.ValidateTitle(peerApplicationEntityTitle); var peerApplicationEntityPortValidationResult = ApplicationEntityValidationHelpers.ValidatePort(peerApplicationEntityPort); var peerApplicationEntityIPAddressValidationResult = ApplicationEntityValidationHelpers.ValidateIPAddress(peerApplicationEntityIPAddress); var result = peerApplicationEntityTitleValidationResult && peerApplicationEntityPortValidationResult && peerApplicationEntityIPAddressValidationResult; Trace.TraceInformation( string.Format(CultureInfo.InvariantCulture, "[DicomDataSender] Validation result {0}.", result), new Dictionary <string, object>() { { "PeerApplicationEntityTitle", peerApplicationEntityTitle }, { "PeerApplicationEntityPort", peerApplicationEntityPort }, { "PeerApplicationEntityIPAddress", peerApplicationEntityIPAddress }, { "PeerApplicationEntityTitleValidationResult", peerApplicationEntityTitleValidationResult }, { "PeerApplicationEntityPortValidationResult", peerApplicationEntityPortValidationResult }, { "PeerApplicationEntityIpAddressValidationResult", peerApplicationEntityIPAddressValidationResult } }); if (!result) { throw new ArgumentException("The peer application entity is invalid.", nameof(peerApplicationEntityTitle)); } if (!ApplicationEntityValidationHelpers.ValidateTitle(ownApplicationEntityTitle)) { throw new ArgumentException("The application entity title is invalid.", nameof(ownApplicationEntityTitle)); } }
/// <inheritdoc /> /// <exception cref="DicomNetworkException">If the service is already listening.</exception> /// <exception cref="System.Net.Sockets.SocketException">If another service is already listening on this socket.</exception> public bool StartServer(int port, Func <IReadOnlyDictionary <DicomUID, DicomTransferSyntax[]> > getAcceptedTransferSyntaxes, TimeSpan timeout) { if (!ApplicationEntityValidationHelpers.ValidatePort(port)) { throw new ArgumentException("The port is not valid.", nameof(port)); } // Check if we are already listening if (IsListening) { throw new DicomNetworkException("We are already listening. Please call stop server before starting."); } // Looks like StartServer has been called before but failed to start listening. // Lets dispose of the current instance and try again. if (_dicomServer != null) { DisposeDicomServer(); } var fileStoreParameters = new DicomFileStoreParameters(DicomDataReceiverUpdate, getAcceptedTransferSyntaxes, _dicomSaver); // Preload dictionary to prevent timeouts DicomDictionary.EnsureDefaultDictionariesLoaded(); // Constructing the listener dicom server will attempt to start the service. _dicomServer = DicomServer.Create <ListenerDicomService>(ipAddress: "localhost", port: port, userState: fileStoreParameters); // Wait until listening or we have an exception. SpinWait.SpinUntil(() => _dicomServer.IsListening || _dicomServer.Exception != null, timeout); if (_dicomServer.Exception != null) { // Throw any exceptions throw _dicomServer.Exception; } return(_dicomServer?.IsListening ?? false); }
/// <summary> /// Validates the DICOM endpoint. /// </summary> /// <param name="uploadQueueItem">Upload queue item.</param> /// <param name="dicomEndPoint">The DICOM endpoint to validate.</param> private void ValidateDicomEndpoint(UploadQueueItem uploadQueueItem, DicomEndPoint dicomEndPoint) { var titleValidationResult = ApplicationEntityValidationHelpers.ValidateTitle(dicomEndPoint.Title); var portValidationResult = ApplicationEntityValidationHelpers.ValidatePort(dicomEndPoint.Port); var ipValidationResult = ApplicationEntityValidationHelpers.ValidateIPAddress(dicomEndPoint.Ip); var result = titleValidationResult && portValidationResult && ipValidationResult; // Validate the destination before uploading. if (!result) { var exception = new ArgumentException("The DICOM endpoint is not valid.", nameof(dicomEndPoint)); LogError(LogEntry.Create(AssociationStatus.UploadErrorDicomEndpointInvalid, uploadQueueItem: uploadQueueItem, destination: (ipAddress: dicomEndPoint.Ip, title: dicomEndPoint.Title, port: dicomEndPoint.Port)), exception); // We cannot process message throw exception; } }