/// <summary> /// Gets the list of instances to be sent from the study xml /// </summary> /// <returns></returns> protected override IEnumerable<StorageInstance> GetStorageInstanceList() { Platform.CheckForNullReference(StorageLocation, "StorageLocation"); var list = new List<StorageInstance>(); string studyPath = StorageLocation.GetStudyPath(); StudyXml studyXml = LoadStudyXml(StorageLocation); foreach (SeriesXml seriesXml in studyXml) { foreach (InstanceXml instanceXml in seriesXml) { string seriesPath = Path.Combine(studyPath, seriesXml.SeriesInstanceUid); string instancePath = Path.Combine(seriesPath, instanceXml.SopInstanceUid + ServerPlatform.DicomFileExtension); var instance = new StorageInstance(instancePath) { SopClass = instanceXml.SopClass, TransferSyntax = instanceXml.TransferSyntax, SopInstanceUid = instanceXml.SopInstanceUid, StudyInstanceUid = studyXml.StudyInstanceUid, SeriesInstanceUid = seriesXml.SeriesInstanceUid, PatientId = studyXml.PatientId, PatientsName = studyXml.PatientsName }; list.Add(instance); } } return list; }
/// <summary> /// Convert Uids into SopInstance /// </summary> /// <returns></returns> protected virtual IEnumerable<StorageInstance> GetStorageInstanceList() { string studyPath = StorageLocation.GetStudyPath(); StudyXml studyXml = LoadStudyXml(StorageLocation); Dictionary<string, StorageInstance> list = new Dictionary<string, StorageInstance>(); foreach(WorkQueueUid uid in WorkQueueUidList) { if (list.ContainsKey(uid.SopInstanceUid)) { Platform.Log(LogLevel.Warn, "AutoRoute WorkQueueUid {0} is a duplicate.", uid.Key); continue; // duplicate;} } SeriesXml seriesXml = studyXml[uid.SeriesInstanceUid]; InstanceXml instanceXml = seriesXml[uid.SopInstanceUid]; string seriesPath = Path.Combine(studyPath, uid.SeriesInstanceUid); string instancePath = Path.Combine(seriesPath, uid.SopInstanceUid + ServerPlatform.DicomFileExtension); StorageInstance instance = new StorageInstance(instancePath) { SopClass = instanceXml.SopClass, TransferSyntax = instanceXml.TransferSyntax, SopInstanceUid = instanceXml.SopInstanceUid, StudyInstanceUid = studyXml.StudyInstanceUid, PatientId = studyXml.PatientId, PatientsName = studyXml.PatientsName }; list.Add(uid.SopInstanceUid, instance); } return list.Values; }
/// <summary> /// Is called when an image store is completed. /// </summary> /// <remarks>If there are any callers hooked up to the <see cref="ImageStoreCompleted"/> event, it will /// forward the <paramref name="storageInstance"/> to the callers.</remarks> /// <param name="storageInstance">The storage instance.</param> protected virtual void OnImageStoreCompleted(StorageInstance storageInstance) { EventHandler <StorageInstance> tempHandler = ImageStoreCompleted; if (tempHandler != null) { tempHandler(this, storageInstance); } }
/// <summary> /// Gets the list of instances to be sent from the study xml /// </summary> /// <returns></returns> protected override IEnumerable<StorageInstance> GetStorageInstanceList() { IList<WorkQueueUid> seriesList = WorkQueueUidList; Platform.CheckForNullReference(StorageLocation, "StorageLocation"); List<StorageInstance> list = new List<StorageInstance>(); // We alread moved the series if (WorkQueueItem.Data != null && seriesList.Count == 0) return list; string studyPath = StorageLocation.GetStudyPath(); StudyXml studyXml = LoadStudyXml(StorageLocation); foreach (SeriesXml seriesXml in studyXml) { // FOR SERIES LEVEL Move, // Check if the series is in the WorkQueueUid list. If it is not in the list then don't include it. if (seriesList.Count > 0) { bool found = false; foreach (WorkQueueUid uid in seriesList) { if (!string.IsNullOrEmpty(uid.SeriesInstanceUid)) if (uid.SeriesInstanceUid.Equals(seriesXml.SeriesInstanceUid)) { found = true; break; } } if (!found) continue; // don't send this series } foreach (InstanceXml instanceXml in seriesXml) { string seriesPath = Path.Combine(studyPath, seriesXml.SeriesInstanceUid); string instancePath = Path.Combine(seriesPath, instanceXml.SopInstanceUid + ServerPlatform.DicomFileExtension); StorageInstance instance = new StorageInstance(instancePath) { SopClass = instanceXml.SopClass, TransferSyntax = instanceXml.TransferSyntax, SopInstanceUid = instanceXml.SopInstanceUid, StudyInstanceUid = studyXml.StudyInstanceUid, SeriesInstanceUid = seriesXml.SeriesInstanceUid, PatientId = studyXml.PatientId, PatientsName = studyXml.PatientsName }; list.Add(instance); } } return list; }
/// <summary> /// Fail the remaining SOP Instances for sending. /// </summary> private void FailRemaining(DicomStatus status) { while (_fileListIndex < _storageInstanceList.Count) { StorageInstance fileToSend = _storageInstanceList[_fileListIndex]; OnImageStoreStarted(fileToSend); fileToSend.SendStatus = status; _failureSubOperations++; _remainingSubOperations--; fileToSend.ExtendedFailureDescription = "The association was aborted."; OnImageStoreCompleted(fileToSend); _fileListIndex++; } }
private void LogError(StorageInstance instance, DicomMessage msg, DicomStatus dicomStatus) { if (dicomStatus == DicomStatuses.SOPClassNotSupported) { var log = new StringBuilder(); log.AppendLine(string.Format("Unable to transfer SOP {0} in study {1}. Remote device does not accept {2} in {3} transfer syntax", instance.SopInstanceUid, instance.StudyInstanceUid, msg.SopClass, msg.TransferSyntax)); if (instance.TransferSyntax.Encapsulated) { var codecExists = DicomCodecRegistry.GetCodec(instance.TransferSyntax) != null; log.AppendLine(codecExists ? string.Format("Note: codec is available for {0} but remote device does not support it?", instance.TransferSyntax) : string.Format("Note: codec is NOT available for {0}", instance.TransferSyntax)); } Platform.Log(LogLevel.Error, log.ToString()); } }
private void SendFilePresentationContext(DicomClient client, byte pcid, StorageInstance fileToSend) { fileToSend.SentMessageId = client.NextMessageID(); fileToSend.ParseMetaInfo(); using (var fs = fileToSend.StreamOpener.Open()) { // Seek to the Dataset fs.Seek(fileToSend.MetaInfoFileLength, SeekOrigin.Begin); if (_moveOriginatorAe == null) { client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, null, 0, fileToSend.SopInstanceUid, fileToSend.SopClass.Uid, fs); } else { client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, _moveOriginatorAe, _moveOriginatorMessageId, fileToSend.SopInstanceUid, fileToSend.SopClass.Uid, fs); } } }
private void SendOnPresentationContext(DicomClient client, ClientAssociationParameters association, byte pcid, StorageInstance fileToSend, DicomMessage msg) { var presContext = association.GetPresentationContext(pcid); if (msg.TransferSyntax.Encapsulated && presContext.AcceptedTransferSyntax.Encapsulated && !msg.TransferSyntax.Equals(presContext.AcceptedTransferSyntax)) { // Compressed in different syntaxes, decompress here first, ChangeTransferSyntax does not convert syntaxes properly in this case. msg.ChangeTransferSyntax(TransferSyntax.ExplicitVrLittleEndian); } fileToSend.SentMessageId = client.NextMessageID(); if (_moveOriginatorAe == null) client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, msg); else client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, _moveOriginatorAe, _moveOriginatorMessageId, msg); }
private byte SelectPresentationContext(ClientAssociationParameters association, StorageInstance fileToSend, DicomFile dicomFile, out DicomMessage msg) { byte pcid = 0; if (PresentationContextSelectionDelegate != null) { // Note, this may do a conversion of the file according to codecs, need to catch a codec exception if it occurs pcid = PresentationContextSelectionDelegate(association, dicomFile, out msg); } else { msg = new DicomMessage(dicomFile); if (fileToSend.TransferSyntax.Encapsulated) { pcid = association.FindAbstractSyntaxWithTransferSyntax(msg.SopClass, msg.TransferSyntax); if (DicomCodecRegistry.GetCodec(fileToSend.TransferSyntax) != null) { // We can compress/decompress the file. Check if remote device accepts it if (pcid == 0) pcid = SelectUncompressedPresentationContext(association, msg); } } else { if (pcid == 0) pcid = SelectUncompressedPresentationContext(association, msg); } } return pcid; }
/// <summary> /// Initializes a new instance of <see cref="ImageStoreEventArgs"/>. /// </summary> /// <param name="storageInstance"></param> public ImageStoreEventArgs(StorageInstance storageInstance) { StorageInstance = storageInstance; }
/// <summary> /// Adds the specified storage instanceto <see cref="StorageInstanceList"/>. /// </summary> /// <param name="storageInstance">The storage instance.</param> public void AddStorageInstance(StorageInstance storageInstance) { StorageInstanceList.Add(storageInstance); }
/// <summary> /// Add details of images within a study. SOP Class information is automatically updated. /// </summary> /// <param name="instance">Descriptive object being audited</param> public void AddStorageInstance(StorageInstance instance) { InternalAddStorageInstance(instance); }
private void SendFilePresentationContext(DicomClient client, byte pcid, StorageInstance fileToSend) { fileToSend.SentMessageId = client.NextMessageID(); fileToSend.ParseMetaInfo(); using (var fs = fileToSend.StreamOpener.Open()) { // Seek to the Dataset fs.Seek(fileToSend.MetaInfoFileLength, SeekOrigin.Begin); if (_moveOriginatorAe == null) client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, null, 0, fileToSend.SopInstanceUid, fileToSend.SopClass.Uid, fs); else client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, _moveOriginatorAe, _moveOriginatorMessageId, fileToSend.SopInstanceUid, fileToSend.SopClass.Uid, fs); } }
private List<WorkQueueUid> FindWorkQueueUids(StorageInstance instance) { if (_uidMaps == null) { if (WorkQueueUidList != null) { _uidMaps = new Dictionary<string, List<WorkQueueUid>>(); foreach (WorkQueueUid uid in WorkQueueUidList) { if (!String.IsNullOrEmpty(uid.SopInstanceUid)) { if (!_uidMaps.ContainsKey(uid.SopInstanceUid)) _uidMaps.Add(uid.SopInstanceUid, new List<WorkQueueUid>()); _uidMaps[uid.SopInstanceUid].Add(uid); } else { _uidMaps = null; if (uid.SeriesInstanceUid.Equals(instance.SeriesInstanceUid)) { return new List<WorkQueueUid>(1) { uid }; } } } } } if (_uidMaps!=null) { List<WorkQueueUid> foundUids; if (_uidMaps.TryGetValue(instance.SopInstanceUid, out foundUids)) { return foundUids; } } return null; }
/// <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(); }
void _storageScu_ImageStoreCompleted(object sender, StorageInstance e) { canbeContinued = true; }
/// <summary> /// Load all of the instances in a given <see cref="SeriesXml"/> file into the component for sending. /// </summary> /// <param name="seriesXml"></param> /// <param name="seriesPath"></param> /// <param name="patientsName"></param> /// <param name="patientId"></param> /// <param name="studyXml"></param> public void LoadSeriesFromSeriesXml(StudyXml studyXml, string seriesPath, SeriesXml seriesXml, string patientsName, string patientId) { foreach (InstanceXml instanceXml in seriesXml) { string instancePath = Path.Combine(seriesPath, instanceXml.SopInstanceUid + ServerPlatform.DicomFileExtension); var instance = new StorageInstance(instancePath); AddStorageInstance(instance); instance.SopClass = instanceXml.SopClass; instance.TransferSyntax = instanceXml.TransferSyntax; instance.SopInstanceUid = instanceXml.SopInstanceUid; instance.PatientId = patientId; instance.PatientsName = patientsName; instance.StudyInstanceUid = studyXml.StudyInstanceUid; } }
private void SendFilePresentationContext(DicomClient client, byte pcid, StorageInstance fileToSend) { fileToSend.SentMessageId = client.NextMessageID(); if (fileToSend.MetaInfoFileLength == 0) { DicomFile theFile = new DicomFile(fileToSend.Filename); theFile.Load(DicomTags.RelatedGeneralSopClassUid, DicomReadOptions.Default); fileToSend.MetaInfoFileLength = theFile.MetaInfoFileLength; } using (var fs = FileStreamOpener.OpenForRead(fileToSend.Filename, FileMode.Open)) { // Seek to the Dataset fs.Seek(fileToSend.MetaInfoFileLength, SeekOrigin.Begin); if (_moveOriginatorAe == null) client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, null, 0, fileToSend.SopInstanceUid, fileToSend.SopClass.Uid, fs); else client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, _moveOriginatorAe, _moveOriginatorMessageId, fileToSend.SopInstanceUid, fileToSend.SopClass.Uid, fs); } }
/// <summary> /// Is called when an image store is started. /// </summary> /// <param name="storageInstance">The storage instance.</param> protected virtual void OnImageStoreStarted(StorageInstance storageInstance) { EventsHelper.Fire(ImageStoreStarted, this, new ImageStoreEventArgs(storageInstance)); }
/// <summary> /// Adds the specified storage instanceto <see cref="StorageInstanceList"/>. /// </summary> /// <param name="storageInstance">The storage instance.</param> public void AddStorageInstance(StorageInstance storageInstance) { StorageInstanceList.Add(storageInstance); _totalSubOperations = _storageInstanceList.Count; }
private void LogError(StorageInstance instance, DicomMessage msg, DicomStatus dicomStatus) { if (dicomStatus == DicomStatuses.SOPClassNotSupported) { var log = new StringBuilder(); log.AppendLine(string.Format("Unable to transfer SOP {0} in study {1}. Remote device does not accept {2} in {3} transfer syntax", instance.SopInstanceUid, instance.StudyInstanceUid, msg.SopClass, msg.TransferSyntax)); if (instance.TransferSyntax.Encapsulated) { var codecExists = DicomCodecRegistry.GetCodec(instance.TransferSyntax) != null; log.AppendLine(codecExists ? string.Format("Note: codec is available for {0} but remote device does not support it?", instance.TransferSyntax) : string.Format("Note: codec is NOT available for {0}", instance.TransferSyntax)); } Platform.Log(LogLevel.Error, log.ToString()); } }
/// <summary> /// Initializes a new instance of <see cref="ImageStoreEventArgs"/>. /// </summary> /// <param name="storageInstance"></param> public ImageStoreEventArgs(StorageInstance storageInstance) { StorageInstance = storageInstance; }
protected virtual void OnInstanceSent(StorageInstance instance) { List<WorkQueueUid> foundUids = FindWorkQueueUids(instance); if (instance.SendStatus.Equals(DicomStatuses.SOPClassNotSupported)) { WorkQueueItem.FailureDescription = String.Format("SOP Class not supported by remote device: {0}", instance.SopClass.Name); Platform.Log(LogLevel.Warn, "Unable to transfer SOP Instance, SOP Class is not supported by remote device: {0}", instance.SopClass.Name); } if (instance.SendStatus.Status == DicomState.Failure) { WorkQueueItem.FailureDescription = instance.SendStatus.Description; foreach(WorkQueueUid uid in foundUids) { uid.FailureCount++; UpdateWorkQueueUid(uid); } } else if (foundUids!=null) { foreach (WorkQueueUid uid in foundUids) { DeleteWorkQueueUid(uid); WorkQueueUidList.Remove(uid); } } }
private byte SelectPresentationContext(ClientAssociationParameters association, StorageInstance fileToSend, DicomFile dicomFile, out DicomMessage msg) { byte pcid = 0; if (PresentationContextSelectionDelegate != null) { // Note, this may do a conversion of the file according to codecs, need to catch a codec exception if it occurs pcid = PresentationContextSelectionDelegate(association, dicomFile, out msg); } else { msg = new DicomMessage(dicomFile); if (fileToSend.TransferSyntax.Encapsulated) { pcid = association.FindAbstractSyntaxWithTransferSyntax(msg.SopClass, msg.TransferSyntax); if (DicomCodecRegistry.GetCodec(fileToSend.TransferSyntax) != null) { // We can compress/decompress the file. Check if remote device accepts it if (pcid == 0) { pcid = SelectUncompressedPresentationContext(association, msg); } } } else { if (pcid == 0) { pcid = SelectUncompressedPresentationContext(association, msg); } } } return(pcid); }
/// <summary> /// Adds the specified storage instanceto <see cref="StorageInstanceList"/>. /// </summary> /// <param name="storageInstance">The storage instance.</param> public void AddStorageInstance(StorageInstance storageInstance) { StorageInstanceList.Add(storageInstance); }
/// <summary> /// Generic routine to send the next C-STORE-RQ message in the <see cref="StorageInstanceList"/>. /// </summary> /// <param name="client">DICOM Client class</param> /// <param name="association">Association Parameters</param> private bool SendCStore(DicomClient client, ClientAssociationParameters association) { StorageInstance fileToSend = _storageInstanceList[_fileListIndex]; OnImageStoreStarted(fileToSend); DicomFile dicomFile; try { // Check to see if image does not exist or is corrupted if (fileToSend.SendStatus == DicomStatuses.ProcessingFailure) { _failureSubOperations++; _remainingSubOperations--; OnImageStoreCompleted(fileToSend); return(false); } dicomFile = fileToSend.LoadFile(); } catch (DicomException e) { Platform.Log(LogLevel.Error, e, "Unexpected exception when loading DICOM file {0}", fileToSend.Filename); fileToSend.ExtendedFailureDescription = e.GetType().Name + " " + e.Message; _failureSubOperations++; _remainingSubOperations--; OnImageStoreCompleted(fileToSend); return(false); } try { DicomMessage msg; byte pcid = SelectPresentationContext(association, fileToSend, dicomFile, out msg); if (pcid == 0) { fileToSend.SendStatus = DicomStatuses.SOPClassNotSupported; fileToSend.ExtendedFailureDescription = string.Format(SR.ErrorSendSopClassNotSupported, msg.SopClass); LogError(fileToSend, msg, DicomStatuses.SOPClassNotSupported); _failureSubOperations++; _remainingSubOperations--; OnImageStoreCompleted(fileToSend); return(false); } try { SendOnPresentationContext(client, association, pcid, fileToSend, msg); } catch (DicomCodecUnsupportedSopException e) { if (!msg.TransferSyntax.Encapsulated) { pcid = SelectUncompressedPresentationContext(association, msg); if (pcid != 0) { SendOnPresentationContext(client, association, pcid, fileToSend, msg); Platform.Log(LogLevel.Warn, "Could not send SOP as compressed, sent as uncompressed: {0}, file: {1}", e.Message, fileToSend.SopInstanceUid); return(true); } } throw; } } catch (DicomNetworkException) { throw; //This is a DicomException-derived class that we want to throw. } catch (DicomCodecException e) { Platform.Log(LogLevel.Error, e, "Unexpected exception when compressing or decompressing file before send {0}", fileToSend.Filename); fileToSend.SendStatus = DicomStatuses.ProcessingFailure; fileToSend.ExtendedFailureDescription = string.Format("Error decompressing or compressing file before send: {0}", e.Message); _failureSubOperations++; _remainingSubOperations--; OnImageStoreCompleted(fileToSend); return(false); } catch (DicomException e) { Platform.Log(LogLevel.Error, e, "Unexpected exception while sending file {0}", fileToSend.Filename); fileToSend.SendStatus = DicomStatuses.ProcessingFailure; fileToSend.ExtendedFailureDescription = string.Format("Unexpected exception while sending file: {0}", e.Message); _failureSubOperations++; _remainingSubOperations--; OnImageStoreCompleted(fileToSend); return(false); } return(true); }
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); }
/// <summary> /// Is called when an image store is started. /// </summary> /// <param name="storageInstance">The storage instance.</param> protected virtual void OnImageStoreStarted(StorageInstance storageInstance) { EventsHelper.Fire(ImageStoreStarted, this, new ImageStoreEventArgs(storageInstance)); }
protected void InternalAddStorageInstance(StorageInstance instance) { if (_participantObjectList.ContainsKey(instance.StudyInstanceUid)) { AuditStudyParticipantObject study = _participantObjectList[instance.StudyInstanceUid] as AuditStudyParticipantObject; if (study!=null) { study.AddStorageInstance(instance); } } else { AuditStudyParticipantObject o = new AuditStudyParticipantObject(instance.StudyInstanceUid); o.AddStorageInstance(instance); _participantObjectList.Add(instance.StudyInstanceUid, o); } }
/// <summary> /// Is called when an image store is started. /// </summary> /// <param name="storageInstance">The storage instance.</param> protected virtual void OnImageStoreStarted(StorageInstance storageInstance) { EventHandler<StorageInstance> tempHandler = ImageStoreStarted; if (tempHandler != null) tempHandler(this, storageInstance); }
/// <summary> /// Generic routine to send the next C-STORE-RQ message in the <see cref="StorageInstanceList"/>. /// </summary> /// <param name="client">DICOM Client class</param> /// <param name="association">Association Parameters</param> private bool SendCStore(DicomClient client, ClientAssociationParameters association) { StorageInstance fileToSend = _storageInstanceList[_fileListIndex]; OnImageStoreStarted(fileToSend); DicomFile dicomFile; try { // Check to see if image does not exist or is corrupted if (fileToSend.SendStatus == DicomStatuses.ProcessingFailure) { _failureSubOperations++; _remainingSubOperations--; OnImageStoreCompleted(fileToSend); return(false); } dicomFile = fileToSend.LoadFile(); } catch (DicomException e) { Platform.Log(LogLevel.Error, e, "Unexpected exception when loading DICOM file {0}", fileToSend.Filename); fileToSend.ExtendedFailureDescription = e.GetType().Name + " " + e.Message; _failureSubOperations++; _remainingSubOperations--; OnImageStoreCompleted(fileToSend); return(false); } DicomMessage msg = new DicomMessage(dicomFile); byte pcid = 0; if (fileToSend.TransferSyntax.Encapsulated) { pcid = association.FindAbstractSyntaxWithTransferSyntax(fileToSend.SopClass, fileToSend.TransferSyntax); if (DicomCodecRegistry.GetCodec(fileToSend.TransferSyntax) != null) { if (pcid == 0) { pcid = association.FindAbstractSyntaxWithTransferSyntax(fileToSend.SopClass, TransferSyntax.ExplicitVrLittleEndian); } if (pcid == 0) { pcid = association.FindAbstractSyntaxWithTransferSyntax(fileToSend.SopClass, TransferSyntax.ImplicitVrLittleEndian); } } } else { if (pcid == 0) { pcid = association.FindAbstractSyntaxWithTransferSyntax(fileToSend.SopClass, TransferSyntax.ExplicitVrLittleEndian); } if (pcid == 0) { pcid = association.FindAbstractSyntaxWithTransferSyntax(fileToSend.SopClass, TransferSyntax.ImplicitVrLittleEndian); } } if (pcid == 0) { fileToSend.SendStatus = DicomStatuses.SOPClassNotSupported; fileToSend.ExtendedFailureDescription = "No valid presentation contexts for file."; OnImageStoreCompleted(fileToSend); _failureSubOperations++; _remainingSubOperations--; return(false); } try { if (_moveOriginatorAe == null) { client.SendCStoreRequest(pcid, client.NextMessageID(), DicomPriority.Medium, msg); } else { client.SendCStoreRequest(pcid, client.NextMessageID(), DicomPriority.Medium, _moveOriginatorAe, _moveOriginatorMessageId, msg); } } catch (DicomNetworkException) { throw; //This is a DicomException-derived class that we want to throw. } catch (DicomCodecException e) { Platform.Log(LogLevel.Error, e, "Unexpected exception when compressing or decompressing file before send {0}", fileToSend.Filename); fileToSend.SendStatus = DicomStatuses.ProcessingFailure; fileToSend.ExtendedFailureDescription = "Error decompressing or compressing file before send."; OnImageStoreCompleted(fileToSend); _failureSubOperations++; _remainingSubOperations--; return(false); } catch (DicomException e) { Platform.Log(LogLevel.Error, e, "Unexpected exception while sending file {0}", fileToSend.Filename); fileToSend.SendStatus = DicomStatuses.ProcessingFailure; fileToSend.ExtendedFailureDescription = "Unexpected exception while sending file."; OnImageStoreCompleted(fileToSend); _failureSubOperations++; _remainingSubOperations--; return(false); } return(true); }
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); }
private void SendOnPresentationContext(DicomClient client, ClientAssociationParameters association, byte pcid, StorageInstance fileToSend, DicomMessage msg) { var presContext = association.GetPresentationContext(pcid); if (msg.TransferSyntax.Encapsulated && presContext.AcceptedTransferSyntax.Encapsulated && !msg.TransferSyntax.Equals(presContext.AcceptedTransferSyntax)) { // Compressed in different syntaxes, decompress here first, ChangeTransferSyntax does not convert syntaxes properly in this case. msg.ChangeTransferSyntax(TransferSyntax.ExplicitVrLittleEndian); } fileToSend.SentMessageId = client.NextMessageID(); if (_moveOriginatorAe == null) { client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, msg); } else { client.SendCStoreRequest(pcid, fileToSend.SentMessageId, DicomPriority.Medium, _moveOriginatorAe, _moveOriginatorMessageId, msg); } }
/// <summary> /// Load all of the instances in a given <see cref="SeriesXml"/> file into the component for sending. /// </summary> /// <param name="seriesXml"></param> /// <param name="location"></param> /// <param name="patientsName"></param> /// <param name="patientId"></param> /// <param name="studyXml"></param> private void LoadSeriesFromSeriesXml(StudyXml studyXml, StudyLocation location, SeriesXml seriesXml, string patientsName, string patientId) { foreach (InstanceXml instanceXml in seriesXml) { var instance = new StorageInstance(location.GetSopInstancePath(seriesXml.SeriesInstanceUid, instanceXml.SopInstanceUid)); AddStorageInstance(instance); instance.SopClass = instanceXml.SopClass; instance.TransferSyntax = instanceXml.TransferSyntax; instance.SopInstanceUid = instanceXml.SopInstanceUid; instance.PatientId = patientId; instance.PatientsName = patientsName; instance.StudyInstanceUid = studyXml.StudyInstanceUid; } }
public void AddStorageInstance(StorageInstance instance) { AuditSopClass sopClass; if (SopClassDictionary.TryGetValue(instance.SopClass.Uid,out sopClass)) { sopClass.NumberOfInstances++; } else { sopClass = new AuditSopClass(instance.SopClass.Uid, 1); SopClassDictionary.Add(sopClass.UID, sopClass); } }
/// <summary> /// Adds the specified storage instanceto <see cref="StorageInstanceList"/>. /// </summary> /// <param name="storageInstance">The storage instance.</param> public void AddStorageInstance(StorageInstance storageInstance) { StorageInstanceList.Add(storageInstance); _totalSubOperations = _storageInstanceList.Count; }