/// <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> /// Adds the specified storage instanceto <see cref="StorageInstanceList"/>. /// </summary> /// <param name="storageInstance">The storage instance.</param> public void AddStorageInstance(StorageInstance storageInstance) { StorageInstanceList.Add(storageInstance); }
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 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> /// 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); }