private void InsertStudy(SopGenerator generator, DateTime currentDay) { try { DicomFile file = generator.NewStudy(currentDay); if (_partition == null) { var scu = new StorageScu("TESTTOOL", _aeTitle, _host, _port); scu.AddStorageInstance(new StorageInstance(file)); int series = _rand.Next(1, generator.MaxSeries); for (int i = 1; i < series; i++) { file = generator.NewSeries(); scu.AddStorageInstance(new StorageInstance(file)); } scu.Send(); } else { InsertInstance(file); int series = _rand.Next(1, generator.MaxSeries); for (int i = 1; i < series; i++) { file = generator.NewSeries(); InsertInstance(file); } } } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Unexecpted exception inserting instance into the database."); } }
/// <summary> /// Send the images of a loaded DICOMDIR to a remote AE. /// </summary> /// <param name="rootPath"></param> /// <param name="aeTitle"></param> /// <param name="host"></param> /// <param name="port"></param> public void Send(string rootPath, string aeTitle, string host, int port) { if (_dir == null) { return; } var scu = new StorageScu("DICOMDIR", aeTitle, host, port); foreach (DirectoryRecordSequenceItem patientRecord in _dir.RootDirectoryRecordCollection) { foreach (DirectoryRecordSequenceItem studyRecord in patientRecord.LowerLevelDirectoryRecordCollection) { foreach (DirectoryRecordSequenceItem seriesRecord in studyRecord.LowerLevelDirectoryRecordCollection) { foreach (DirectoryRecordSequenceItem instanceRecord in seriesRecord.LowerLevelDirectoryRecordCollection) { string path = rootPath; foreach (string subpath in instanceRecord[DicomTags.ReferencedFileId].Values as string[]) { path = Path.Combine(path, subpath); } scu.AddStorageInstance(new StorageInstance(path)); } } } } // Do the send scu.Send(); }
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); }
private void ResendImages() { if (_prevSentFiles != null && _prevSentFiles.Count > 0) { using (StorageScu scu = new StorageScu(LocalAE.Text, ServerAE.Text, ServerHost.Text, int.Parse(ServerPort.Text))) { foreach (DicomFile file in _prevSentFiles) { SetDicomFields(file); scu.AddStorageInstance(new StorageInstance(file)); } scu.ImageStoreCompleted += new EventHandler <StorageInstance>(scu_ImageStoreCompleted); scu.Send(); scu.Join(); } } }
public void ScuAbortTest() { int port = 2112; /* 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() }; 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); }
private StorageScu SetupScu() { StorageScu scu = new StorageScu("TestAe", "AssocTestServer", "localhost", 2112); 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)); } return(scu); }
private StorageScu SetupScu(string moveOriginatorAe = "TestAE", ushort moveOriginatorId = 0) { StorageScu scu = moveOriginatorId == 0 ? new StorageScu("TestAe", "AssocTestServer", "localhost", 2112) : new StorageScu("TestAe", "AssocTestServer", "localhost", 2112, 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)); } return(scu); }
/// <summary> /// Builds the study tree and publishes all the created studies to the specified application entity. /// </summary> /// <remarks> /// <para>The <see cref="BuildTree"/> method is called automatically, and hence does not need to be explicitly called before invoking this method.</para> /// </remarks> /// <param name="localAE">The local AETITLE that is sending the studies.</param> /// <param name="remoteAE">The AETITLE of the device that is receiving the studies.</param> /// <param name="remoteHost">The hostname of the device that is receiving the studies.</param> /// <param name="remotePort">The port number on which the device receiving the studies is listening.</param> /// <returns>A list of the SOP instance UIDs that were created.</returns> public IList <string> Publish(string localAE, string remoteAE, string remoteHost, int remotePort) { List <SopInstanceNode> sops; try { sops = DoBuildTree(); } catch (Exception ex) { throw new StudyBuilderException("Unexpected StudyBuilder error", ex); } List <string> uids = new List <string>(sops.Count); try { StorageScu scu = new StorageScu(localAE, remoteAE, remoteHost, remotePort); // queue each instance into scu foreach (SopInstanceNode sop in sops) { StorageInstance sInst = new StorageInstance(sop.DicomFile); scu.AddStorageInstance(sInst); uids.Add(sop.InstanceUid); } // begin asynch send operation scu.Send(); } catch (Exception ex) { throw new StudyBuilderException("Storage SCU error", ex); } return(uids.AsReadOnly()); }
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); }