-
打开 Visual Studio 2005.
-
选择 文件->新建->项目.
-
在 新建项目 对话框中, 在项目类型列表中选择 Visual C# 或 VB , 并在模板列表中选择 类库.
-
在项目名称字段中键入项目名称为SampleStorageCommit,然后单击 确定。 如果需要,键入项目的新位置或使用浏览按钮选择目录,然后单击确定。
-
在“解决方案资源管理器”窗口中,右键单击“引用”,然后从菜单中选择“添加引用”。 在“添加引用”对话框中,选择“浏览”选项卡,然后转至 LEADTOOLS 19 \ Bin \ DotNet \ Win32文件夹,选择以下DLLS:
- Leadtools.dllLeadtools.Dicom.dll
- Leadtools.Dicom.AddIn.dll
- Microsoft.Practices.Unity
添加下面的 .NET 系统DLL:
System.Core (.NET 3.5 dll)
-
单击确定按钮将上述DLL添加到应用程序。
-
在"解决方案管理器" 窗口右击 "SampleAddIn" 选择 添加->类 . 在"新建项" 对话框中, 在"名称" 字段中键入 StorageCommitAddIn.cs . 点击 "添加" 按钮.
-
打开 StorageCommitAddIn.cs文件添加以下使用语句:
C#
using Leadtools.Dicom;
using Leadtools.Dicom.AddIn;
using Leadtools.Dicom.AddIn.Interfaces;
using Leadtools.Dicom.AddIn.Attributes;
using Microsoft.Practices.Unity;
-
将IProcessNAction 添加到StorageCommitAddIn 类派生列表中。 你的类应该如下所示:
C#
public class StorageCommitAddIn : IProcessNAction
{
}
-
将DicomAddInAttribute添加到类声明中。 让服务知道该类处理Dicom消息。 添加属性后,该类应该如下所示:
C#
[DicomAddInAttribute("Storage Commit AddIn", "1.0.0.0", Description = "Implements Storage Commitment", Author = "")]
public class StorageCommitAddIn : IProcessNAction
{
}
-
右键单击IProcessNAction,然后从菜单中选择实现接口 - >实现接口。 你的类现在应该如下:
C#
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.");
}
}
-
要告诉服务器我们感兴趣的响应, 我们需要通过OnNAction方法指定PresentationContextAttributes。这将允许服务器构建一个在客户端连接时使用的association 。 为了支持存储提交,我们需要确保对OnNAction方法属性如下:
C#
[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.");
}
-
将以下支持属性添加到StorageCommitAddIn类中:
C#
private IDicomRequest _DicomRequest;
/// <summary>
/// Allows the user 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;
}
}
上述代码使用Microsoft Unity依赖注入来获取实现我们的插件所需功能的注册接口。 例如,IDicomRequest接口由Leadtools.Dicom.Server.exe实现。
-
添加IProcessNAction接口的代码。 示例代码在单独的线程上处理提交请求,并在稍后响应客户端。 有关存储提交的完整工作示例,请参阅作为LEADTOOLS PACS Framework的一部分安装的Storage Commit加载项。 您的代码应如下所示:
C#
[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)
{
// The LEADTOOLS PACS Framework provides a default implementation.
}
-
添加对IProcessBreak界面的支持。 这允许停止StorageCommit操作。 将以下代码添加到您的StorageCommitAddin类中:
C#
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();
}
-
构建类库并获取输出并将其放在先前创建的服务器的AddIn目录中。
-
如果服务器正在运行,停止然后重新启动服务器。
-
有关Storage Commit的更实际的实现,请参阅LEADTOOLS PACS Framework安装附带的存储提交示例。
关于葡萄城
赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。
了解详情,请访问葡萄城官网。