- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的目标是在 visual studio 2010 中使用 c# 将 dicom 文件发送到远程 AE,我计划实现 clearcanvas 库,我将任务分为 5 个部分:
// //1 initiate tcp\ip connection
// //2 negotiate the association parameters to agree what can be done
// //3 send the dicom object
// //4 close the association
// //5 close the TCP/IP connection
我知道 storagescu 将参与发送 part3), 我尝试在 clearcanvas 论坛上查找内容,代码还没有多大意义,所以我不知 Prop 体从哪里开始,任何有经验的人都可以将 dicom 文件发送到远程 ae 可以提供一些关于我应该如何进行研究的线索?我在正确的轨道上吗?
非常感谢您的帮助!
最佳答案
我专门在 Clear Canvas 上构建了它,以便能够发送非常大的文件。我编写的其他程序在大尺寸图像上失败,所以我制作了一个精简版本来发送大小为数 GB 的 DICOM 文件并且它有效。此程序中只有命令行和 program.cs。这是对如何使用 Clear Canvas 发送 DICOM 文件的问题的最简单回答。
有一点需要注意。您需要一种在发起请求的线程和 Clear Canvas 之间进行通信的方法,在本例中是来自 program.cs 的 C-Store 请求和 AssociationHandler 类:IDicomClientHandler。
在允许创建请求的线程继续进行之前,我在这里只使用了一个 bool 值和一个 while 循环。在其他程序中,我使用多维字符串数组来保存每个关联的值,并且我可以在多线程中执行任何 DICOM 操作、C-Store、C-Move、C-Find、N-Action 等透明 Canvas 时尚。没有比这更好的开源 DICOM 工具包了。
运行此代码所需要做的就是创建一个控制台应用程序并计算出对 Clear Canvas 库的引用。请提出任何问题。
命令行参数列在帮助输出的代码中。
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Data;
using ClearCanvas.Dicom;
using System.IO;
using System.Diagnostics;
using ClearCanvas.Dicom.Network;
using ClearCanvas.Common;
using System.Net;
using System.Threading;
namespace CC_SendFile
{
class Program
{
public static Boolean C_Store_Response = false;
public static Boolean Assoc_Accept_Reject = false;
public static Boolean NetworkError = false;
public static String FilePath = null;
public static String LocalAE = null;
public static String RemoteAE = null;
public static String RemoteIP = null;
public static String RemotePort = null;
public static uint MaxPDUSize = 0;
public static int MaxPDUTimeoutMilliSeconds = 30000;
static void Main(string[] args)
{
if (args.Length != 0)
{
String ProcessID = null;
System.Diagnostics.Process myProcess = System.Diagnostics.Process.GetCurrentProcess();
ProcessID = "[" + myProcess.Id.ToString() + "] ";
myProcess.Close();
myProcess.Dispose();
Platform.Log(LogLevel.Debug, "Process ID obtained for title bar and logging is: " + ProcessID);
log4net.GlobalContext.Properties["procid"] = ProcessID;
for (int i = 0; i < args.Length - 1; i++)
{
String ArgTemp = null;
ArgTemp = args[i];
if (ArgTemp == "-l")
{
LocalAE = args[i + 1];
i++;
}
if (ArgTemp == "-r")
{
RemoteAE = args[i + 1];
i++;
}
if (ArgTemp == "-h")
{
RemoteIP = args[i + 1];
i++;
}
if (ArgTemp == "-p")
{
RemotePort = args[i + 1];
i++;
}
if (ArgTemp == "-f")
{
FilePath = args[i + 1];
i++;
}
if (ArgTemp == "-u")
{
MaxPDUSize = uint.Parse(args[i + 1]);
i++;
}
if (ArgTemp == "-n")
{
MaxPDUTimeoutMilliSeconds = int.Parse(args[i + 1]);
}
}//for (int i = 1; i < args.Length - 1; i++)
ClientAssociationParameters g_assocParams = null;
DicomClient g_dicomClient = null;
IPAddress addr = null;
foreach (IPAddress dnsAddr in Dns.GetHostAddresses(RemoteIP))
if (dnsAddr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
addr = dnsAddr;
Platform.Log(LogLevel.Info , "IP address found to use is: " + addr.ToString());
break;
}
if (addr == null)
{
Platform.Log(LogLevel.Error, "No Valid IP addresses for host {0}", RemoteIP);
return;
}
g_assocParams = new ClientAssociationParameters(LocalAE, RemoteAE, new IPEndPoint(addr, int.Parse(RemotePort)));
if (MaxPDUSize != 0)
{
g_assocParams.LocalMaximumPduLength = MaxPDUSize;
Console.WriteLine("LocalMaximumPduLength has been set to: " + g_assocParams.LocalMaximumPduLength.ToString());
Platform.Log(LogLevel.Info, "LocalMaximumPduLength has been set to: " + g_assocParams.LocalMaximumPduLength.ToString());
}
else
{
Console.WriteLine("LocalMaximumPduLength is by default: " + g_assocParams.LocalMaximumPduLength.ToString());
Platform.Log(LogLevel.Info, "LocalMaximumPduLength is by default: " + g_assocParams.LocalMaximumPduLength.ToString());
}
try
{
Console.WriteLine("");
Console.WriteLine("Loading File: " + FilePath + ", please wait...");
Console.WriteLine("");
Platform.Log(LogLevel.Info, "Loading File: " + FilePath + ", please wait...");
DicomFile DF = new DicomFile(FilePath);
GC.AddMemoryPressure(1047881834);
try
{
//DF.Load(DicomReadOptions.KeepGroupLengths);
DF.Load(DicomReadOptions.Default);
}
catch (Exception eL)
{
}
Console.WriteLine("SOP Class: " + DF.SopClass.ToString());
Console.WriteLine("Transfer Syntax: " + DF.TransferSyntax.ToString ());
Platform.Log(LogLevel.Info, "SOP Class: " + DF.SopClass.ToString());
Platform.Log(LogLevel.Info, "Transfer Syntax: " + DF.TransferSyntax.ToString());
byte pcid = g_assocParams.AddPresentationContext(DF.SopClass);
g_assocParams.AddTransferSyntax(pcid, DF.TransferSyntax);
DicomMessage msg = new DicomMessage(DF);
DF = null;
GC.Collect();
GC.WaitForPendingFinalizers();
AssociationHandler handler = new AssociationHandler();
Console.WriteLine("Attempting to connect to remote AE.");
Platform.Log(LogLevel.Info, "Attempting to connect to remote AE.");
g_dicomClient = DicomClient.Connect(g_assocParams, (IDicomClientHandler)handler);
while (Assoc_Accept_Reject == false)
{
Console.WriteLine("Waiting for Association to be accepted or rejected.");
Platform.Log(LogLevel.Info, "Waiting for Association to be accepted or rejected.");
Thread.Sleep(1000);
}
try
{
if (MaxPDUTimeoutMilliSeconds != 0)
{
g_dicomClient.InternalSocket.SendTimeout = MaxPDUTimeoutMilliSeconds;
g_dicomClient.InternalSocket.ReceiveTimeout = MaxPDUTimeoutMilliSeconds;
Console.WriteLine("Internal Socket Send/Receive Timeout has been set to: " + g_dicomClient.InternalSocket.SendTimeout.ToString() + " ms.");
Platform.Log(LogLevel.Info, "Internal Socket Send/Receive Timeout has been set to: " + g_dicomClient.InternalSocket.SendTimeout.ToString() + " ms.");
g_dicomClient.InternalSocket.SendTimeout = MaxPDUTimeoutMilliSeconds;
}
Console.WriteLine("Sending C-Store Request.");
Platform.Log(LogLevel.Info, "Sending C-Store Request.");
g_dicomClient.SendCStoreRequest(pcid, g_dicomClient.NextMessageID(), DicomPriority.Medium, msg);
}
catch (Exception eS)
{
Console.WriteLine("Error sending C-Store Request.");
Console.WriteLine(eS.ToString());
Platform.Log(LogLevel.Error, "Error sending C-Store Request. The error is: " + eS.ToString ());
}
while (C_Store_Response == false)
{
Console.WriteLine("Waiting for C-Store response.");
Platform.Log(LogLevel.Info, "Waiting for C-Store response.");
Thread.Sleep(1000);
}
if (NetworkError == false)
{
Console.WriteLine("Sending release request.");
Platform.Log(LogLevel.Info, "Sending release request.");
g_dicomClient.SendReleaseRequest();
}
Thread.Sleep(1000);
Console.WriteLine("Operations have completed.");
Console.WriteLine("Press ENTER to exit!");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Error reading file. The error is:");
Console.WriteLine("");
Console.WriteLine(e.Message);
Console.WriteLine("");
Console.WriteLine("Stack Trace:");
Console.WriteLine(e.ToString());
Console.WriteLine("Press ENTER to exit!");
Console.ReadLine();
Platform.Log(LogLevel.Error, "Error reading file. The error is:");
Platform.Log(LogLevel.Error, e.ToString());
}
}//if (args .Length != 0 )
else
{
Console.WriteLine ("You must provide the proper command line arguments.");
Console.WriteLine ("Required arguments are:");
Console.WriteLine ("");
Console.WriteLine ("-f [full file path to DCM file] (No whitespaces please!)");
Console.WriteLine ("-l [Local AE Title]");
Console.WriteLine ("-r [Remote AE Title]");
Console.WriteLine ("-h [Remote HostName or IP address]");
Console.WriteLine ("-p [Remote Port]");
Console.WriteLine ("");
Console.WriteLine("Press ENTER to exit!");
Console.ReadLine();
Platform.Log(LogLevel.Error, "You must provide the proper command line arguments.");
Platform.Log(LogLevel.Error, "Required arguments are:");
Platform.Log(LogLevel.Error, "");
Platform.Log(LogLevel.Error, " -f [full file path to DCM file] (No whitespaces please!)");
Platform.Log(LogLevel.Error, " -l [Local AE Title]");
Platform.Log(LogLevel.Error, " -r [Remote AE Title]");
Platform.Log(LogLevel.Error, " -h [Remote HostName or IP address]");
Platform.Log(LogLevel.Error, " -p [Remote Port]");
Platform.Log(LogLevel.Error, "");
}
}//static void Main(string[] args)
class AssociationHandler : IDicomClientHandler
{
#region IDicomClientHandler Members
public void OnReceiveAssociateAccept(DicomClient client, ClientAssociationParameters association)
{
Console.WriteLine("Association was accepted!");
Platform.Log(LogLevel.Info, "Association was accepted!");
Assoc_Accept_Reject = true;
}
public void OnReceiveAssociateReject(DicomClient client, ClientAssociationParameters association, DicomRejectResult result, DicomRejectSource source, DicomRejectReason reason)
{
Console.WriteLine("Association was rejected!");
Platform.Log(LogLevel.Info, "Association was rejected!");
Assoc_Accept_Reject = true;
}
public void OnReceiveRequestMessage(DicomClient client, ClientAssociationParameters association, byte presentationID, DicomMessage message)
{
}
public void OnReceiveResponseMessage(DicomClient client, ClientAssociationParameters association, byte presentationID, DicomMessage message)
{
if (message.Status.Status == DicomState.Success)
{
Console.WriteLine("DICOM success message received!");
Platform.Log(LogLevel.Info, "DICOM success message received!");
C_Store_Response = true;
}
if (message.Status.Status != DicomState.Failure)
{
Console.WriteLine("DICOM faliure message received!");
Platform.Log(LogLevel.Info, "DICOM faliure message received!");
C_Store_Response = true;
}
}
public void OnReceiveReleaseResponse(DicomClient client, ClientAssociationParameters association)
{
Console.WriteLine("Received Release Response.");
Platform.Log(LogLevel.Info, "Received Release Response.");
}
public void OnReceiveAbort(DicomClient client, ClientAssociationParameters association, DicomAbortSource source, DicomAbortReason reason)
{
}
public void OnNetworkError(DicomClient client, ClientAssociationParameters association, Exception e)
{
Console.WriteLine("Network Error occured.");
Platform.Log(LogLevel.Info, "Network Error occured.");
try
{
Platform.Log(LogLevel.Info, "Attempting to get error message...");
Platform.Log(LogLevel.Error, e.ToString ());
}
catch (NullReferenceException)
{
Platform.Log(LogLevel.Error, "The error message was null.");
}
C_Store_Response = true;
NetworkError = true;
}
public void OnDimseTimeout(DicomClient client, ClientAssociationParameters association)
{
Platform.Log(LogLevel.Error, "DimseTimeout occured on client. Continuing...");
}
#endregion
}
}//class Program
}//namespace CC_SendFile
关于c# - 在 visual studio 2010 中使用 c# 将 dicom 文件发送到远程 AE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31418156/
我经常使用 SSMS 查询数据和构建数据集,我的 IT 部门负责数据库管理。 最近我发现了 Azure Data Studio,我喜欢: 智能感知 源代码控制(例如使用 Git) 来自社区的扩展 SQ
我想根据我使用的 visual studio 版本编译不同的东西,比如 #if VISUAL_STUDIO_VERSION > 2015 eventH?.Invoke(this, EventArgs.
我们的开发团队计划从 visual studio 2005 升级到 visual studio 2010 -- 跳过 visual studio 2008。 大部分项目是VB ASP.NET项目,使用
我的Visual Studio 2015无法构建2010平台工具集。它说: The build tools for Visual Studio 2010 (v100) cannot be found.
我目前正在使用 Visual Studio 2015 来编程 ASP.NET Core 应用程序。我对安装 Visual Studio 2017 有以下疑问: 什么被认为是最佳实践和/或最干净的方法?
尝试从扩展和更新获取 Visual Studio 扩展时,出现以下错误:- 向 visualstudiogallery.msdn.microsoft.com/Services/VStudio/Exte
这个问题在这里已经有了答案: Can Visual Studio Code and VS 2012 be installed on same computer? (1 个回答) 关闭去年。 在安装了
作为标准安装的一部分,Visual Studio Code 带有一个名为“Monokai Dimmed”的颜色主题。 有没有办法将它移植到 Visual Studio 2015?我检查了社区主题( h
我想开始编程 CUDA。 我已经安装了 Visual Studio 2010 Express。 我还安装了 nVidia nSight Visual Studio。 而且我具备所有常见的先决条件(Ne
Visual Studio Community Edition是否可以使用Visual Studio Online帐户上的存储库? 我一直为包含在Online帐户中的Visual Studio Onl
我有一个我一直在开发的应用程序,但在 android studio 上遇到了问题。当我点击“build->run”然后选择我的设备时,应用程序永远不会在我的手机上运行(并且自动出现的android-s
我正在使用Visual Studio2010。我面临的一个问题是,当我创建一个新的Web项目时,Visual Studio将创建该项目,并且不会在解决方案资源管理器中显示其解决方案。 另一件事是,我想
我通读了这里的许多帖子,却找不到一个有效的明确答案。因此,在花了一些时间使它生效之后,我认为应该发布它。 问题:发布配置文件将建立在服务器上,但不会发布。 解: 确保已安装Microsoft Wind
我正在尝试使用Visual Studio 2012构建针对.NET 3.5的C++ CLI应用程序。 通过安装Visual Studio 2008,并指定v90平台工具集,我已经在一台机器上进行了这项
我在 Microsoft Visual Studios 2013 中有一个项目,我想在 Microsoft Visual Studios 2010 中打开它。有什么简单的方法吗?还是我必须在2010年
我想知道,如果我发送一个解决方案文件夹(它是用 visual studio C# 编写的),您可以在 visual studio for mac 中打开解决方案吗? 在visual studio 20
有没有办法在 Visual Studio Code 和 Visual Studio 中设置相同的快捷方式(而不必每次都手动更改它们)? 例如,我在 Visual Studio Code 中经常使用 A
我刚开始了解 Visual Studio Code。我想知道,我可以将 Visual Studio 替换为所有 .NET 开发相关的工作吗? 我可以节省 Visual Studio 许可的成本吗? V
我安装了具有有效许可证(Visual Studio 订阅)的 Visual Studio 2019 企业版(VS 2019 16.1.4),它运行良好。 突然之间,当我尝试打开项目或项目中的任何文件时
我一直在使用 Compass 编译 Windows 环境中的 sass 文件,无论是在命令行上还是使用 Compass-app 来查看目录。 我刚刚开始使用 Visual Studio(专业版 201
我是一名优秀的程序员,十分优秀!