[Showing a C# code example]
Leadtools.dllLeadtools.Dicom.dll Leadtools.Dicom.AddIn.dll Microsoft.Practices.UnityAdd the following .NET System DLL:
System.Core (.NET 3.5 dll)
using Leadtools.Dicom; using Leadtools.Dicom.AddIn; using Leadtools.Dicom.AddIn.Interfaces; using Leadtools.Dicom.AddIn.Attributes; using Microsoft.Practices.Unity;
public class StorageCommitAddIn : IProcessNAction { }
[DicomAddInAttribute("Storage Commit AddIn", "1.0.0.0", Description = "Implements Storage Commitment", Author = "")] public class StorageCommitAddIn : IProcessNAction { }
public class StorageCommitAddIn : IProcessNAction { public DicomCommandStatusType OnNAction(DicomClient Client, byte PresentationId, int MessageID, string AffectedClass, string Instance, int Action, DicomDataSet Request, DicomDataSet Response) { throw new Exception("The method or operation is not implemented."); } #endregion #region IProcessBreak Members public void Break(BreakType type) { throw new Exception("The method or operation is not implemented."); } }
[PresentationContext(DicomUidType.StorageCommitmentPushModelClass, DicomUidType.ImplicitVRLittleEndian)] public DicomCommandStatusType OnNAction(DicomClient Client, byte PresentationId, int MessageID, string AffectedClass, string Instance, int Action, DicomDataSet Request, DicomDataSet Response) { throw new Exception("The method or operation is not implemented."); }
private IServiceLog _ServiceLog; /// <summary> /// Allows us to perform service logging. /// </summary> /// <value>The service log.</value> [Dependency] public IServiceLog ServiceLog { set { _ServiceLog = value; } } private IDicomRequest _DicomRequest; /// <summary> /// Allows use to send a dicom request from an addin. /// </summary> /// <value>The dicom request.</value> [Dependency] public IDicomRequest DicomRequest { set { _DicomRequest = value; } } private IAETitle _AeTitle; /// <summary> /// Let's get the AE title information. /// </summary> /// <value>The AE title.</value> [Dependency] public IAETitle AeTitle { set { _AeTitle = value; } }
The above code uses the Microsoft Unity Dependency injection to get registered interfaces that implement features required by our addin. For instance, the IDicomRequest interface is implemented by the Leadtools.Dicom.Server.exe.
[PresentationContext(DicomUidType.StorageCommitmentPushModelClass, DicomUidType.ImplicitVRLittleEndian)] public DicomCommandStatusType OnNAction(DicomClient Client, byte PresentationId, int MessageID, string AffectedClass, string Instance, int Action, DicomDataSet Request, DicomDataSet Response) { DicomDataSet ds = new DicomDataSet(Client.Server.TemporaryDirectory); // Copy the dataset. We will be using it in a thread so we need to copy // it so will be available in the thread. ds.Copy(Request, null, null); // Process the commit on a separate thread. This will allow us to immediately // return a notification to the client informing that we have received the // message. result = AsyncHelper.Execute(delegate() { DicomDataSet commitDS = new DicomDataSet(Client.Server.TemporaryDirectory); PresentationContext pc = new PresentationContext(); DicomRequest request = new DicomRequest(Client); // At this point we would process the storage commit and build a response // dataset. For a complete example of this refer to the sample storage commit // add-in that ships with the LEADTOOLS PACS Framework. // Prepare to send our response back to the requesting client pc.AbstractSyntax = DicomUidType.StorageCommitmentPushModelClass; pc.TransferSyntaxes.Add(DicomUidType.ImplicitVRLittleEndian); request.PresentationContexts.Add(pc); request.RequireMessagePump = true; request.ReceiveNReportResponse += new ReceiveNReportResponseDelegate(request_ReceiveNReportResponse); request.ConnectType = ConnectType.Conditional; _DicomRequest.SendNReportRequest(request, PresentationId, 1000, DicomUidType.StorageCommitmentPushModelClass, DicomUidType.StorageCommitmentPushModelInstance,1, commitDS); }); Response = null; return DicomCommandStatusType.Success; } void request_ReceiveNReportResponse(DicomRequest request, byte presentationID, int messageID, string affectedClass, string instance, DicomCommandStatusType status, int dicomEvent, DicomDataSet dataSet) { // _ServiceLog could be null if there is no implementation. The // LEADTOOLS PACS Framework provides a default implementation. if(_ServiceLog!=null) { _ServiceLog.Info("NReport Response Received: {0}", status); } }
private AsyncResult result = null; public void Break(BreakType type) { // Stop the commit process if we received a request // to stop processing if(result != null && !result.IsCompleted) result.Cancel(); }