private static void AddPresentationContexts(ServerAssociationParameters assoc) { byte pcid = assoc.AddPresentationContext(SopClass.ModalityWorklistInformationModelFind); assoc.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian); assoc.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian); }
public override bool ReceiveMessageAsFileStream(Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationId, DicomMessage message) { var sopClassUid = message.AffectedSopClassUid; if (sopClassUid.Equals(SopClass.BreastTomosynthesisImageStorageUid) || sopClassUid.Equals(SopClass.EnhancedCtImageStorageUid) || sopClassUid.Equals(SopClass.EnhancedMrColorImageStorageUid) || sopClassUid.Equals(SopClass.EnhancedMrImageStorageUid) || sopClassUid.Equals(SopClass.EnhancedPetImageStorageUid) || sopClassUid.Equals(SopClass.EnhancedUsVolumeStorageUid) || sopClassUid.Equals(SopClass.EnhancedXaImageStorageUid) || sopClassUid.Equals(SopClass.EnhancedXrfImageStorageUid) || sopClassUid.Equals(SopClass.UltrasoundMultiFrameImageStorageUid) || sopClassUid.Equals(SopClass.MultiFrameGrayscaleByteSecondaryCaptureImageStorageUid) || sopClassUid.Equals(SopClass.MultiFrameGrayscaleWordSecondaryCaptureImageStorageUid) || sopClassUid.Equals(SopClass.MultiFrameSingleBitSecondaryCaptureImageStorageUid) || sopClassUid.Equals(SopClass.MultiFrameTrueColorSecondaryCaptureImageStorageUid)) { server.DimseDatasetStopTag = DicomTagDictionary.GetDicomTag(DicomTags.ReconstructionIndex); // Random tag at the end of group 20 server.StreamMessage = true; return true; } return false; }
public void OnReceiveRequestMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, ClearCanvas.Dicom.DicomMessage message) { foreach (byte pcid in association.GetPresentationContextIDs()) { DicomPresContext context = association.GetPresentationContext(pcid); if (context.Result == DicomPresContextResult.Accept) { if (context.AbstractSyntax == SopClass.StudyRootQueryRetrieveInformationModelFind) { DicomMessage response = new DicomMessage(); response.DataSet[DicomTags.StudyInstanceUid].SetStringValue("1.2.3"); response.DataSet[DicomTags.PatientId].SetStringValue("1"); response.DataSet[DicomTags.PatientsName].SetStringValue("test"); response.DataSet[DicomTags.StudyId].SetStringValue("1"); response.DataSet[DicomTags.StudyDescription].SetStringValue("dummy"); server.SendCFindResponse(presentationID, message.MessageId, response, DicomStatuses.Pending); DicomMessage finalResponse = new DicomMessage(); server.SendCFindResponse(presentationID, message.MessageId, finalResponse, DicomStatuses.Success); } else if (context.AbstractSyntax == SopClass.VerificationSopClass) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); } } } }
public override IDicomFilestreamHandler OnStartFilestream(Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationId, DicomMessage message) { if (_importContext == null) { LoadImportContext(association); } return new StorageFilestreamHandler(Context, _importContext); }
private void SetSocketOptions(ServerAssociationParameters parameters) { _socket.ReceiveBufferSize = parameters.ReceiveBufferSize; _socket.SendBufferSize = parameters.SendBufferSize; _socket.ReceiveTimeout = parameters.ReadTimeout; _socket.SendTimeout = parameters.WriteTimeout; _socket.LingerState = new LingerOption(false, 0); // Nagle option _socket.NoDelay = parameters.DisableNagle; }
public void OnReceiveAssociateRequest(DicomServer server, ServerAssociationParameters association) { if (_delayAssociationAccept.Checked) Thread.Sleep(TimeSpan.FromSeconds(35)); if (_rejectAssociation.Checked) server.SendAssociateReject(DicomRejectResult.Permanent, DicomRejectSource.ServiceUser, DicomRejectReason.CallingAENotRecognized); else server.SendAssociateAccept(association); }
internal Listener(ServerAssociationParameters parameters, StartAssociation acceptor) { ListenerInfo info = new ListenerInfo(); info.Parameters = parameters; info.StartDelegate = acceptor; _applications.Add(parameters.CalledAE, info); _ipEndPoint = parameters.LocalEndPoint; }
private static void AddPresentationContexts(ServerAssociationParameters assoc) { byte pcid = assoc.AddPresentationContext(SopClass.VerificationSopClass); assoc.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian); assoc.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian); pcid = assoc.AddPresentationContext(SopClass.ModalityPerformedProcedureStepSopClass); assoc.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian); assoc.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian); }
public StorageFilestreamHandler(DicomScpContext context, Device remoteDevice, ServerAssociationParameters assoc) { _context = context; _remoteDevice = remoteDevice; _importContext = new SopInstanceImporterContext( String.Format("{0}_{1}", assoc.CallingAE, assoc.TimeStamp.ToString("yyyyMMddhhmmss")), assoc.CallingAE, assoc.CalledAE); if (_remoteDevice != null && _remoteDevice.DeviceTypeEnum.Equals(DeviceTypeEnum.PrimaryPacs)) { _importContext.DuplicateProcessing = DuplicateProcessingEnum.OverwriteSopAndUpdateDatabase; } }
/// <summary> /// Method called when receiving an association request. /// </summary> /// <param name="association"></param> protected override void OnReceiveAssociateRequest(ServerAssociationParameters association) { ListenerInfo info; if (!_appList.TryGetValue(association.CalledAE, out info)) { Platform.Log(LogLevel.Error, "Rejecting association from {0}: Invalid Called AE Title ({1}).", association.CallingAE, association.CalledAE); SendAssociateReject(DicomRejectResult.Permanent, DicomRejectSource.ServiceProviderACSE, DicomRejectReason.CalledAENotRecognized); return; } // Populate the AssociationParameters properly association.ReadTimeout = info.Parameters.ReadTimeout; association.ReceiveBufferSize = info.Parameters.ReceiveBufferSize; association.WriteTimeout = info.Parameters.WriteTimeout; association.SendBufferSize = info.Parameters.SendBufferSize; association.RemoteEndPoint = _socket.RemoteEndPoint as IPEndPoint; association.LocalEndPoint = _socket.LocalEndPoint as IPEndPoint; // Setup Socketoptions based on the user's settings SetSocketOptions(association); // Select the presentation contexts bool anyValidContexts = NegotiateAssociation(association, info.Parameters); if (!anyValidContexts) { Platform.Log(LogLevel.Error, "Rejecting association from {0}: No valid presentation contexts.", association.CallingAE); SendAssociateReject(DicomRejectResult.Permanent, DicomRejectSource.ServiceProviderACSE, DicomRejectReason.NoReasonGiven); return; } _appList = null; try { _handler = info.StartDelegate(this, association); _handler.OnReceiveAssociateRequest(this, association); } catch (Exception e) { OnUserException(e, "Unexpected exception on OnReceiveAssociateRequest or StartDelegate"); } }
private static void SetImageTransferSyntaxes(byte pcid, ServerAssociationParameters assoc) { if (JpegLossless) assoc.AddTransferSyntax(pcid,TransferSyntax.JpegLosslessNonHierarchicalFirstOrderPredictionProcess14SelectionValue1); if (Rle) assoc.AddTransferSyntax(pcid, TransferSyntax.RleLossless); if (J2KLossy) assoc.AddTransferSyntax(pcid, TransferSyntax.Jpeg2000ImageCompression); if (J2KLossless) assoc.AddTransferSyntax(pcid, TransferSyntax.Jpeg2000ImageCompressionLosslessOnly); if (JpegLossy) { assoc.AddTransferSyntax(pcid, TransferSyntax.JpegBaselineProcess1); assoc.AddTransferSyntax(pcid, TransferSyntax.JpegExtendedProcess24); } assoc.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian); assoc.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian); }
public static bool Listen(ServerAssociationParameters parameters, StartAssociation acceptor) { lock (_syncLock) { Listener theListener; if (_listeners.TryGetValue(parameters.LocalEndPoint, out theListener)) { ListenerInfo info = new ListenerInfo(); info.StartDelegate = acceptor; info.Parameters = parameters; if (theListener._applications.ContainsKey(parameters.CalledAE)) { Platform.Log(LogLevel.Error, "Already listening with AE {0} on {1}", parameters.CalledAE, parameters.LocalEndPoint.ToString()); return false; } theListener._applications.Add(parameters.CalledAE, info); Platform.Log(LogLevel.Info, "Starting to listen with AE {0} on existing port {1}", parameters.CalledAE, parameters.LocalEndPoint.ToString()); } else { theListener = new Listener(parameters, acceptor); if (!theListener.StartListening()) { Platform.Log(LogLevel.Error, "Unexpected error starting to listen on {0}", parameters.LocalEndPoint.ToString()); return false; } _listeners[parameters.LocalEndPoint] = theListener; theListener.StartThread(); Platform.Log(LogLevel.Info, "Starting to listen with AE {0} on port {1}", parameters.CalledAE, parameters.LocalEndPoint.ToString()); } return true; } }
public static void StartListening(string aeTitle, int port) { if (_started) return; _staticAssocParameters = new ServerAssociationParameters(aeTitle, new IPEndPoint(IPAddress.Any, port)); Platform.Log(LogLevel.Info, "MPPS Server Started"); AddPresentationContexts(_staticAssocParameters); DicomServer.StartListening(_staticAssocParameters, delegate(DicomServer server, ServerAssociationParameters assoc) { return new MPPSScp(assoc); }); _started = true; }
public static bool Listen(ServerAssociationParameters parameters, StartAssociation acceptor) { lock (_syncLock) { Listener theListener; if (_listeners.TryGetValue(parameters.LocalEndPoint, out theListener)) { ListenerInfo info = new ListenerInfo(); info.StartDelegate = acceptor; info.Parameters = parameters; if (theListener._applications.ContainsKey(parameters.CalledAE)) { Platform.Log(LogLevel.Error, "Already listening with AE {0} on {1}", parameters.CalledAE, parameters.LocalEndPoint.ToString()); return(false); } theListener._applications.Add(parameters.CalledAE, info); Platform.Log(LogLevel.Info, "Starting to listen with AE {0} on existing port {1}", parameters.CalledAE, parameters.LocalEndPoint.ToString()); } else { theListener = new Listener(parameters, acceptor); if (!theListener.StartListening()) { Platform.Log(LogLevel.Error, "Unexpected error starting to listen on {0}", parameters.LocalEndPoint.ToString()); return(false); } _listeners[parameters.LocalEndPoint] = theListener; theListener.StartThread(); Platform.Log(LogLevel.Info, "Starting to listen with AE {0} on port {1}", parameters.CalledAE, parameters.LocalEndPoint.ToString()); } return(true); } }
public void ScuAbortTest() { int port = 2112; /* Setup the Server */ ServerAssociationParameters serverParameters = new ServerAssociationParameters("AssocTestServer", new IPEndPoint(IPAddress.Any, port)); byte pcid = serverParameters.AddPresentationContext(SopClass.MrImageStorage); serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian); serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrBigEndian); serverParameters.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian); _serverType = TestTypes.Receive; DicomServer.StartListening(serverParameters, ServerHandlerCreator); StorageScu scu = SetupScu(); IList<DicomAttributeCollection> list = SetupMRSeries(4, 2, DicomUid.GenerateUid().UID); foreach (DicomAttributeCollection collection in list) { DicomFile file = new DicomFile("test",new DicomAttributeCollection(),collection ); file.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian; file.MediaStorageSopClassUid = SopClass.MrImageStorage.Uid; file.MediaStorageSopInstanceUid = collection[DicomTags.SopInstanceUid].ToString(); scu.AddStorageInstance(new StorageInstance(file)); } scu.ImageStoreCompleted += delegate(object o, StorageInstance instance) { // Test abort scu.Abort(); }; scu.Send(); scu.Join(); Assert.AreEqual(scu.Status, ScuOperationStatus.NetworkError); // StopListening DicomServer.StopListening(serverParameters); }
public static bool StopListening(ServerAssociationParameters parameters) { lock (_syncLock) { Listener theListener; if (_listeners.TryGetValue(parameters.LocalEndPoint, out theListener)) { if (theListener._applications.ContainsKey(parameters.CalledAE)) { theListener._applications.Remove(parameters.CalledAE); if (theListener._applications.Count == 0) { // Cleanup the listener _listeners.Remove(parameters.LocalEndPoint); theListener.StopThread(); theListener.Dispose(); } Platform.Log(LogLevel.Info, "Stopping listening with AE {0} on {1}", parameters.CalledAE, parameters.LocalEndPoint.ToString()); } else { Platform.Log(LogLevel.Error, "Unable to stop listening on AE {0}, assembly was not listening with this AE.", parameters.CalledAE); return(false); } } else { Platform.Log(LogLevel.Error, "Unable to stop listening, assembly was not listening on end point {0}.", parameters.LocalEndPoint.ToString()); return(false); } return(true); } }
/// <summary> /// Do the actual verification if an association is acceptable. /// </summary> /// <remarks> /// This method primarily checks the remote AE title to see if it is a valid device that can /// connect to the partition. /// </remarks> /// <param name="context">Generic parameter passed in, is a DicomScpParameters instance.</param> /// <param name="assocParms">The association parameters.</param> /// <param name="result">Output parameter with the DicomRejectResult for rejecting the association.</param> /// <param name="reason">Output parameter with the DicomRejectReason for rejecting the association.</param> /// <returns>true if the association should be accepted, false if it should be rejected.</returns> public static bool Verify(DicomScpContext context, ServerAssociationParameters assocParms, out DicomRejectResult result, out DicomRejectReason reason) { bool isNew; Device device = DeviceManager.LookupDevice(context.Partition, assocParms, out isNew); if (device==null) { if (context.Partition.AcceptAnyDevice) { reason = DicomRejectReason.NoReasonGiven; result = DicomRejectResult.Permanent; return true; } reason = DicomRejectReason.CallingAENotRecognized; result = DicomRejectResult.Permanent; return false; } if (device.Enabled==false) { Platform.Log(LogLevel.Error, "Rejecting association from {0} to {1}. Device is disabled.", assocParms.CallingAE, assocParms.CalledAE); reason = DicomRejectReason.CallingAENotRecognized; result = DicomRejectResult.Permanent; return false; } reason = DicomRejectReason.NoReasonGiven; result = DicomRejectResult.Permanent; return true; }
public static void StartListening(string aeTitle, int port, int bufferedQueryResponses,int maxQueryResponses) { _bufferedQueryResponses = bufferedQueryResponses; _maxQueryResponses = maxQueryResponses; if (_started) return; _staticAssocParameters = new ServerAssociationParameters(aeTitle, new IPEndPoint(IPAddress.Any, port)); Platform.Log(LogLevel.Info, "MWL Server Started"); AddPresentationContexts(_staticAssocParameters); DicomServer.StartListening(_staticAssocParameters, delegate(DicomServer server, ServerAssociationParameters assoc) { return new MWLScp(assoc); }); _started = true; }
/// <summary> /// Starts the service. /// </summary> /// <returns>True/False depending if service started successfully.</returns> public bool Start() { try { if (isRunning) return true; _staticAssocParameters = new ServerAssociationParameters(_aet, new IPEndPoint(IPAddress.Any, _port)); AddPresentationContexts(_staticAssocParameters); if (DicomServer.StartListening(_staticAssocParameters, delegate (DicomServer server, ServerAssociationParameters assoc) { return new DicomSCP(assoc) { Aet = _aet, Port = _port }; })) { isRunning = true; } } catch (Exception ex) { throw ex; } return isRunning; }
public static void InstancesTransferredAuditLogger(DicomScpContext context, ServerAssociationParameters assocParams, List<StorageInstance> instances) { Dictionary<string, AuditPatientParticipantObject> list = new Dictionary<string, AuditPatientParticipantObject>(); foreach (StorageInstance instance in instances) { string key = instance.PatientId + instance.PatientsName; if (!list.ContainsKey(key)) { AuditPatientParticipantObject patient = new AuditPatientParticipantObject(instance.PatientsName, instance.PatientId); list.Add(key, patient); } } foreach (AuditPatientParticipantObject patient in list.Values) { // Audit Log DicomInstancesTransferredAuditHelper helper = new DicomInstancesTransferredAuditHelper(ServerPlatform.AuditSource, EventIdentificationContentsEventOutcomeIndicator.Success, EventIdentificationContentsEventActionCode.E, assocParams); foreach (StorageInstance instance in instances) { if (patient.PatientId.Equals(instance.PatientId) && patient.PatientsName.Equals(instance.PatientsName)) { helper.AddStorageInstance(instance); } } ServerAuditHelper.LogAuditMessage(helper); } }
protected void LoadImportContext(ServerAssociationParameters association) { _importContext = new DicomReceiveImportContext(association.CallingAE, GetRemoteHostName(association), StudyStore.GetConfiguration(), EventSource.CurrentProcess); // Publish new WorkItems as they're added to the context lock (_importContext.StudyWorkItemsSyncLock) { _importContext.StudyWorkItems.ItemAdded += (sender, args) => { _importContext.PublishWorkItemActivity(WorkItemDataHelper.FromWorkItem(args.Item)); var auditedInstances = new AuditedInstances(); var request = args.Item.Request as DicomReceiveRequest; if (request != null) auditedInstances.AddInstance(request.Patient.PatientId, request.Patient.PatientsName, request.Study.StudyInstanceUid); AuditHelper.LogReceivedInstances( association.CallingAE, GetRemoteHostName(association), auditedInstances, EventSource.CurrentProcess, EventResult.Success, EventReceiptAction.ActionUnknown); }; _importContext.StudyWorkItems.ItemChanged += (sender, args) => _importContext.PublishWorkItemActivity(WorkItemDataHelper.FromWorkItem(args.Item)); } }
public override bool OnReceiveRequest(Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { string studyInstanceUid; string seriesInstanceUid; DicomUid sopInstanceUid; bool ok = message.DataSet[DicomTags.SopInstanceUid].TryGetUid(0, out sopInstanceUid); if (ok) ok = message.DataSet[DicomTags.SeriesInstanceUid].TryGetString(0, out seriesInstanceUid); if (ok) ok = message.DataSet[DicomTags.StudyInstanceUid].TryGetString(0, out studyInstanceUid); if (!ok) { Platform.Log(LogLevel.Error, "Unable to retrieve UIDs from request message, sending failure status."); server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.ProcessingFailure); return true; } if (_importContext == null) { LoadImportContext(association); } var importer = new ImportFilesUtility(_importContext); var result = importer.Import(message, BadFileBehaviourEnum.Ignore, FileImportBehaviourEnum.Save); if (result.Successful) { if (!String.IsNullOrEmpty(result.AccessionNumber)) Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (A#:{3} StudyUid:{4})", result.SopInstanceUid, association.CallingAE, association.CalledAE, result.AccessionNumber, result.StudyInstanceUid); else Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (StudyUid:{3})", result.SopInstanceUid, association.CallingAE, association.CalledAE, result.StudyInstanceUid); server.SendCStoreResponse(presentationID, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus); } else { if (result.DicomStatus == DicomStatuses.ProcessingFailure) Platform.Log(LogLevel.Error, "Failure importing sop: {0}", result.ErrorMessage); //OnReceiveError(message, result.ErrorMessage, association.CallingAE); server.SendCStoreResponse(presentationID, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus, result.ErrorMessage); } return true; }
public IDicomServerHandler ServerHandlerCreator(DicomServer server, ServerAssociationParameters assoc) { return new ServerHandler(this, _serverType); }
/// <summary> /// Start listening for incoming associations. /// </summary> /// <remarks> /// <para> /// Note that StartListening can be called multiple times with different association parameters. /// </para> /// </remarks> /// <param name="parameters">The parameters to use when listening for associations.</param> /// <param name="acceptor">A delegate to be called to return a class instance that implements /// the <see cref="IDicomServerHandler"/> interface to handle an incoming association.</param> /// <returns><i>true</i> on success, <i>false</i> on failure</returns> public static bool StartListening(ServerAssociationParameters parameters, StartAssociation acceptor) { return(Listener.Listen(parameters, acceptor)); }
internal Listener(ServerAssociationParameters parameters, StartAssociation acceptor) { ListenerInfo info = new ListenerInfo(); info.Parameters = parameters; info.StartDelegate = acceptor; _applications.Add(parameters.CalledAE, info); _ipEndPoint = parameters.LocalEndPoint; }
public static bool StopListening(ServerAssociationParameters parameters) { lock (_syncLock) { Listener theListener; if (_listeners.TryGetValue(parameters.LocalEndPoint, out theListener)) { if (theListener._applications.ContainsKey(parameters.CalledAE)) { theListener._applications.Remove(parameters.CalledAE); if (theListener._applications.Count == 0) { // Cleanup the listener _listeners.Remove(parameters.LocalEndPoint); theListener.StopThread(); theListener.Dispose(); } Platform.Log(LogLevel.Info, "Stopping listening with AE {0} on {1}", parameters.CalledAE, parameters.LocalEndPoint.ToString()); } else { Platform.Log(LogLevel.Error, "Unable to stop listening on AE {0}, assembly was not listening with this AE.", parameters.CalledAE); return false; } } else { Platform.Log(LogLevel.Error, "Unable to stop listening, assembly was not listening on end point {0}.", parameters.LocalEndPoint.ToString()); return false; } return true; } }
public void StorageScuMoveOriginatorTest() { int port = 2112; _serverHandlerList.Clear(); /* Setup the Server */ var serverParameters = new ServerAssociationParameters("AssocTestServer", new IPEndPoint(IPAddress.Any, port)); byte pcid = serverParameters.AddPresentationContext(SopClass.MrImageStorage); serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian); serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrBigEndian); serverParameters.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian); _serverType = TestTypes.Receive; DicomServer.StartListening(serverParameters, ServerHandlerCreator); string moveOriginatorAe = "ORIGINATOR"; ushort moveOriginatorId = 999; StorageScu scu = SetupScu(moveOriginatorAe, moveOriginatorId); IList<DicomAttributeCollection> list = SetupMRSeries(4, 2, DicomUid.GenerateUid().UID); foreach (DicomAttributeCollection collection in list) { var file = new DicomFile("test", new DicomAttributeCollection(), collection) { TransferSyntax = TransferSyntax.ExplicitVrLittleEndian, MediaStorageSopClassUid = SopClass.MrImageStorage.Uid, MediaStorageSopInstanceUid = collection[DicomTags.SopInstanceUid].ToString() }; scu.AddStorageInstance(new StorageInstance(file)); } scu.Send(); scu.Join(); Assert.AreEqual(scu.Status, ScuOperationStatus.NotRunning); var handler = CollectionUtils.FirstElement(_serverHandlerList); var serverHandler = handler as ServerHandler; Assert.NotNull(serverHandler); foreach (var message in serverHandler.MessagesReceived) { Assert.AreEqual(message.MoveOriginatorApplicationEntityTitle, moveOriginatorAe); Assert.AreEqual(message.MoveOriginatorMessageId, moveOriginatorId); } // StopListening DicomServer.StopListening(serverParameters); }
public void OnReceiveReleaseRequest(DicomServer server, ServerAssociationParameters association) { }
public void OnReceiveResponseMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { server.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.NotSpecified); Assert.Fail("Unexpected OnReceiveResponseMessage"); }
public bool CompleteStream(DicomServer server, ServerAssociationParameters assoc, byte presentationId, DicomMessage message) { DicomProcessingResult result; try { if (_fileStream != null) { _fileStream.Flush(true); _fileStream.Close(); _fileStream.Dispose(); _fileStream = null; } var importer = new SopInstanceImporter(_importContext); result = importer.ImportFile(message, _sourceFilename); if (result.Successful) { if (!String.IsNullOrEmpty(result.AccessionNumber)) Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (A#:{3} StudyUid:{4})", result.SopInstanceUid, assoc.CallingAE, assoc.CalledAE, result.AccessionNumber, result.StudyInstanceUid); else Platform.Log(LogLevel.Info, "Received SOP Instance {0} from {1} to {2} (StudyUid:{3})", result.SopInstanceUid, assoc.CallingAE, assoc.CalledAE, result.StudyInstanceUid); } } catch (Exception e) { result = new DicomProcessingResult { DicomStatus = DicomStatuses.ProcessingFailure, ErrorMessage = e.Message }; } if (!result.Successful) { Platform.Log(LogLevel.Warn, "Failure importing sop: {0}", result.ErrorMessage); } CleanupDirectory(); server.SendCStoreResponse(presentationId, message.MessageId, message.AffectedSopInstanceUid, result.DicomStatus); return true; }
public IDicomServerHandler ServerHandlerCreator(DicomServer server, ServerAssociationParameters assoc) { var handler = new ServerHandler(this, _serverType); _serverHandlerList.Add(handler); return handler; }
public void StorageScuFromDisk() { int port = 2112; _serverHandlerList.Clear(); /* Setup the Server */ var serverParameters = new ServerAssociationParameters("AssocTestServer", new IPEndPoint(IPAddress.Any, port)); byte pcid = serverParameters.AddPresentationContext(SopClass.MrImageStorage); serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian); serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrBigEndian); serverParameters.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian); _serverType = TestTypes.Receive; DicomServer.StartListening(serverParameters, ServerHandlerCreator); StorageScu scu = SetupScu(); IList<DicomAttributeCollection> list = SetupMRSeries(4, 2, DicomUid.GenerateUid().UID); foreach (DicomAttributeCollection collection in list) { var file = new DicomFile("test", new DicomAttributeCollection(), collection) { TransferSyntax = TransferSyntax.ExplicitVrLittleEndian, MediaStorageSopClassUid = SopClass.MrImageStorage.Uid, MediaStorageSopInstanceUid = collection[DicomTags.SopInstanceUid].ToString() }; string instancePath = file.MediaStorageSopInstanceUid + ".dcm"; file.Save(instancePath); var instance = new StorageInstance(instancePath) { SopClass = file.SopClass, TransferSyntax = file.TransferSyntax, SopInstanceUid = file.MediaStorageSopClassUid, PatientId = file.DataSet[DicomTags.PatientId].GetString(0, string.Empty), PatientsName = file.DataSet[DicomTags.PatientsName].GetString(0, string.Empty), StudyInstanceUid = file.DataSet[DicomTags.StudyInstanceUid].GetString(0, string.Empty) }; scu.AddStorageInstance(instance); } scu.Send(); scu.Join(); Assert.AreEqual(scu.Status, ScuOperationStatus.NotRunning); var handler = CollectionUtils.FirstElement(_serverHandlerList); var serverHandler = handler as ServerHandler; Assert.NotNull(serverHandler); foreach (var message in serverHandler.MessagesReceived) { foreach (var file in list) { if (message.AffectedSopInstanceUid.Equals(file[DicomTags.SopInstanceUid].ToString())) { Assert.IsTrue(message.DataSet.Equals(file)); } } } // StopListening DicomServer.StopListening(serverParameters); }
private static bool NegotiateAssociation(AssociationParameters cp, ServerAssociationParameters sp) { foreach (DicomPresContext clientContext in cp.GetPresentationContexts()) { TransferSyntax selectedSyntax = null; foreach (DicomPresContext serverContext in sp.GetPresentationContexts()) { if (clientContext.AbstractSyntax.Uid.Equals(serverContext.AbstractSyntax.Uid)) { foreach (TransferSyntax ts in serverContext.GetTransfers()) { if (clientContext.HasTransfer(ts)) { selectedSyntax = ts; break; } } } if (selectedSyntax != null) { break; } } if (selectedSyntax != null) { clientContext.ClearTransfers(); clientContext.AddTransfer(selectedSyntax); clientContext.SetResult(DicomPresContextResult.Accept); } else { // No contexts accepted, set if abstract or transfer syntax reject if (0 == sp.FindAbstractSyntax(clientContext.AbstractSyntax)) { clientContext.SetResult(DicomPresContextResult.RejectAbstractSyntaxNotSupported); } else { clientContext.SetResult(DicomPresContextResult.RejectTransferSyntaxesNotSupported); } } } bool anyValidContexts = false; foreach (DicomPresContext clientContext in cp.GetPresentationContexts()) { if (clientContext.Result == DicomPresContextResult.Accept) { anyValidContexts = true; break; } } if (anyValidContexts == false) { return(false); } return(true); }
/// <summary> /// Stop listening for incoming associations. /// </summary> /// <remarks> /// <para> /// Note that <see cref="StartListening"/> can be called multiple times with different association /// parameters. /// </para> /// </remarks> /// <param name="parameters">The parameters to stop listening on.</param> public static void StopListening(ServerAssociationParameters parameters) { Listener.StopListening(parameters); }
public void OnReceiveAbort(DicomServer server, ServerAssociationParameters association, DicomAbortSource source, DicomAbortReason reason) { throw new Exception("The method or operation is not implemented."); }
protected virtual void OnReceiveAssociateRequest(ServerAssociationParameters association) { throw new Exception("The method or operation is not implemented."); }
public override bool OnReceiveRequest(ClearCanvas.Dicom.Network.DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { //// Check for a Cancel message, and cancel the SCU. if (message.CommandField == DicomCommandField.CCancelRequest) { OnReceiveCancelRequest(message); return true; } // TODO (CR Jun 2012): Log when there's more than 1. var remoteAE = ServerDirectory.GetRemoteServersByAETitle(message.MoveDestination).FirstOrDefault(); if (remoteAE == null) { server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.QueryRetrieveMoveDestinationUnknown); return true; } String level = message.DataSet[DicomTags.QueryRetrieveLevel].GetString(0, string.Empty); try { if (level.Equals("STUDY")) { OnReceiveMoveStudiesRequest(server, presentationID, message, remoteAE); } else if (level.Equals("SERIES")) { OnReceiveMoveSeriesRequest(server, presentationID, message, remoteAE); } else if (level.Equals("IMAGE")) { OnReceiveMoveImageRequest(server, presentationID, message, remoteAE); } else { Platform.Log(LogLevel.Error, "Unexpected Study Root Move Query/Retrieve level: {0}", level); server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.QueryRetrieveIdentifierDoesNotMatchSOPClass); return true; } } catch(Exception e) { Platform.Log(LogLevel.Error, e, "Unexpected exception when processing C-MOVE-RQ"); try { server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.QueryRetrieveUnableToProcess, e.Message); } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Unable to send final C-MOVE-RSP message on association from {0} to {1}", association.CallingAE, association.CalledAE); } } return true; }
public void ServerTest() { int port = 2112; /* Setup the Server */ ServerAssociationParameters serverParameters = new ServerAssociationParameters("AssocTestServer",new IPEndPoint(IPAddress.Any,port)); byte pcid = serverParameters.AddPresentationContext(SopClass.MrImageStorage); serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian); serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrBigEndian); serverParameters.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian); _serverType = TestTypes.SendMR; DicomServer.StartListening(serverParameters, ServerHandlerCreator); /* Setup the client */ ClientAssociationParameters clientParameters = new ClientAssociationParameters("AssocTestClient","AssocTestServer", new System.Net.IPEndPoint(IPAddress.Loopback,port)); pcid = clientParameters.AddPresentationContext(SopClass.MrImageStorage); clientParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian); clientParameters.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian); pcid = clientParameters.AddPresentationContext(SopClass.CtImageStorage); clientParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian); clientParameters.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian); /* Open the association */ ClientHandler handler = new ClientHandler(this,TestTypes.SendMR); DicomClient client = DicomClient.Connect(clientParameters, handler); handler._threadStop.WaitOne(); client.Dispose(); DicomServer.StopListening(serverParameters); }