/// <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));
            }
        }
Beispiel #2
0
        /// <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;
            }
        }