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(); }
void scu_ImageStoreCompleted(object sender, StorageInstance e) { StorageScu scu = sender as StorageScu; Random rand = new Random(); //Thread.Sleep(rand.Next(300, 1000)); textBox1.BeginInvoke(new LogDelegate(Log), e.SopInstanceUid); }
public void SendDicomFile(string filepath) { using (var scu = new StorageScu(LocalNode.AeTitle, RemoteNode.AeTitle, RemoteNode.IpAddress, RemoteNode.Port)) { scu.ImageStoreCompleted += ScuOnImageStorageCompleted; scu.AddFile(filepath); scu.Send(); } }
private void SendComplete(IAsyncResult ar) { StorageScu storageScu = (StorageScu)ar.AsyncState; string strFile = string.Format("发送完成 成功:[{0}] 失败:[{1}]", storageScu.SuccessSubOperations, storageScu.FailureSubOperations); System.Windows.Forms.MessageBox.Show(strFile); System.Diagnostics.Debug.Write(storageScu.SuccessSubOperations); }
private void OnAnnotationSendComplete(IAsyncResult ar) { StorageScu storageScu = (StorageScu)ar.AsyncState; if (storageScu.TotalSubOperations - storageScu.SuccessSubOperations > 0) { Platform.Log(LogLevel.Error, "Not all annotations could be stored to server."); } storageScu.Dispose(); }
private void SendImages() { Random ran = new Random(); textBox1.Clear(); _seriesMap = new Dictionary <string, string>(); _prevSentFiles = new List <DicomFile>(); List <StorageScu> scuClients = new List <StorageScu>(); StorageScu scu = new StorageScu(LocalAE.Text, ServerAE.Text, ServerHost.Text, int.Parse(ServerPort.Text)); scu.ImageStoreCompleted += new EventHandler <ImageStoreEventArgs>(scu_ImageStoreCompleted); scuClients.Add(scu); int seriesCount = 0; do { String seriesDescription = _seriesDesc[ran.Next(_seriesDesc.Count)]; string[] seriesUids = new string[_seriesToFilesMap.Count]; _seriesToFilesMap.Keys.CopyTo(seriesUids, 0); String seriesToUse = seriesUids[ran.Next(_seriesToFilesMap.Count)]; List <string> files = _seriesToFilesMap[seriesToUse]; foreach (string path in files) { DicomFile file = new DicomFile(path); file.Load(); RandomizeFile(file, seriesDescription); _prevSentFiles.Add(file); foreach (StorageScu client in scuClients) { client.AddStorageInstance(new StorageInstance(file)); } if (ran.Next() % 50 == 0) { break; // don't use all images } } seriesCount++; } while (ran.Next() % 5 != 0); Log(String.Format("Sending {0} images using {1} client(s)", _prevSentFiles.Count, scuClients.Count)); scu.BeginSend(InstanceSent, scu); scu.Join(); scu.Dispose(); }
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(); } } }
private void ButtonStorageScuConnectClick(object sender, EventArgs e) { int port; if (!int.TryParse(_textBoxStorageScuRemotePort.Text, out port)) { Platform.Log(LogLevel.Error, "Unable to parse port number: {0}", _textBoxStorageScuRemotePort.Text); return; } _storageScu = new StorageScu(_textBoxStorageScuLocalAe.Text, _textBoxStorageScuRemoteAe.Text, _textBoxStorageScuRemoteHost.Text, port); _storageScu.AddStorageInstanceList(_storageList); _storageScu.BeginSend(InstanceSent, _storageScu); }
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); }
public override void Process() { string localAe = Request.DestinationServerAETitle; string remoteAe = Request.DestinationServerAETitle; string remoteHostname = Request.DestinationServerHostname; int remotePort = Request.DestinationServerPort; _scu = new StorageScu(localAe, remoteAe, remoteHostname, remotePort); Progress.TotalImagesToSend = _scu.TotalSubOperations; Progress.FailureSubOperations = 0; Progress.WarningSubOperations = 0; Progress.SuccessSubOperations = 0; Progress.IsCancelable = true; Proxy.UpdateProgress(); _scu.Send(); }
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); }
// Called when a SOP Instance is imported into the local datastore private void OnSopInstanceImported(object sender, ItemEventArgs <ImportedSopInstanceInformation> e) { if (_sopInstanceUidToAeTitle.ContainsKey(e.Item.SopInstanceUid)) { var destinationAeTitle = _sopInstanceUidToAeTitle[e.Item.SopInstanceUid]; var destinationServer = FindAETitle(new ServerTree().RootNode.ServerGroupNode, destinationAeTitle); if (destinationServer == null) { Platform.Log(LogLevel.Error, "Study " + e.Item.SopInstanceUid + " cannot be send to server. Failed to find server infromation for AE Title " + destinationAeTitle + "."); } else { var storageScu = new StorageScu(ServerTree.GetClientAETitle(), destinationServer.AETitle, destinationServer.Host, destinationServer.Port); storageScu.ImageStoreCompleted += OnStoreEachInstanceCompleted; storageScu.AddFile(e.Item.SopInstanceFileName); storageScu.BeginSend(OnAnnotationSendComplete, storageScu); } lock (_mapLock) _sopInstanceUidToAeTitle.Remove(e.Item.SopInstanceUid); } }
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()); }
/// <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 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 void ButtonStorageScuConnectClick(object sender, EventArgs e) { int port; if (!int.TryParse(_textBoxStorageScuRemotePort.Text,out port)) { Platform.Log(LogLevel.Error, "Unable to parse port number: {0}", _textBoxStorageScuRemotePort.Text); return; } _storageScu = new StorageScu(_textBoxStorageScuLocalAe.Text, _textBoxStorageScuRemoteAe.Text, _textBoxStorageScuRemoteHost.Text, port); _storageScu.AddStorageInstanceList(_storageList); _storageScu.BeginSend(InstanceSent, _storageScu); }
void storageScu_StoreCompleted(object sender, StorageInstance e) { StorageScu storageScu = (StorageScu)sender; System.Diagnostics.Debug.Write(e.SendStatus); }
private void button1_Click(object sender, EventArgs e) { _storageScu = new StorageScu(editAE.Text, editAE.Text, editIP.Text, Convert.ToInt16(editPort.Text)); _storageScu.ImageStoreCompleted += new EventHandler <StorageInstance>(storageScu_StoreCompleted); //_storageScu.AddStorageInstance(new StorageInstance("AnotherFile.dcm")); ClearCanvas.ImageViewer.ImageViewerComponent viewer = null; DesktopWindow desktopWindow = null; List <string> _filenames = new List <string>(); foreach (DesktopWindow window in Application.DesktopWindows) { foreach (Workspace space in window.Workspaces) { if (space.Title == "imageview") { desktopWindow = window; viewer = space.Component as ClearCanvas.ImageViewer.ImageViewerComponent; } } } if (viewer != null) { //foreach (string strfile in viewer.getCurrentFiles()) // _storageScu.AddFile(strfile); //先解压缩,然后再发送 //foreach (string strfile in viewer.getCurrentFiles()) // _storageScu.AddFile(strfile); RasterSupport.Unlock(RasterSupportType.Dicom, "y47S3rZv6U"); RasterSupport.Unlock(RasterSupportType.Document, "HbQR9NSXQ3"); RasterSupport.Unlock(RasterSupportType.DocumentWriters, "BhaNezSEBB"); RasterSupport.Unlock(RasterSupportType.DocumentWritersPdf, "3b39Q3YMdX"); RasterSupport.Unlock(RasterSupportType.ExtGray, "bpTmxSfx8R"); RasterSupport.Unlock(RasterSupportType.Forms, "GpC33ZK78k"); RasterSupport.Unlock(RasterSupportType.IcrPlus, "9vdKEtBhFy"); RasterSupport.Unlock(RasterSupportType.IcrProfessional, "3p2UAxjTy5"); RasterSupport.Unlock(RasterSupportType.J2k, "Hvu2PRAr3z"); RasterSupport.Unlock(RasterSupportType.Jbig2, "43WiSV4YNB"); RasterSupport.Unlock(RasterSupportType.Jpip, "YbGG7wWiVJ"); RasterSupport.Unlock(RasterSupportType.Pro, ""); RasterSupport.Unlock(RasterSupportType.LeadOmr, "J3vh828GC8"); RasterSupport.Unlock(RasterSupportType.MediaWriter, "TpjDw2kJD2"); RasterSupport.Unlock(RasterSupportType.Medical, "ZhyFRnk3sY"); RasterSupport.Unlock(RasterSupportType.Medical3d, "DvuzH3ePeu"); RasterSupport.Unlock(RasterSupportType.MedicalNet, "b4nBinY7tv"); RasterSupport.Unlock(RasterSupportType.MedicalServer, "QbXwuZxA3h"); RasterSupport.Unlock(RasterSupportType.Mobile, ""); RasterSupport.Unlock(RasterSupportType.Nitf, "G37rmw5dTr"); DicomEngine.Startup(); foreach (string strfile in viewer.getCurrentFiles()) { DicomDataSet ds = new DicomDataSet(); try { ds.Load(strfile, DicomDataSetLoadFlags.None); ds.ChangeTransferSyntax(DicomUidType.ImplicitVRLittleEndian, 2, ChangeTransferSyntaxFlags.None); ds.Save(strfile + "1", DicomDataSetSaveFlags.None); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); } _storageScu.AddFile(strfile + "1"); } } else { System.Windows.Forms.MessageBox.Show("没有合适的图像。。。"); } IAsyncResult asyncResult = _storageScu.BeginSend(new AsyncCallback(SendComplete), _storageScu); }