Sending dicom file to a remote AE using c# in visual studio 2010 -


my goal send dicom file remote ae using c# in visual studio 2010, plan implement clearcanvas library, have divided task 5 parts:

//    //1 initiate tcp\ip connection //    //2 negotiate association parameters agree can done //    //3 send dicom object //    //4 close association //    //5 close tcp/ip connection 

i know storagescu involved in sending part3), tried looking things on clearcanvas forum, codes not make sense yet, not know start exactly, can had experience in sending dicom file remote ae give clue how should research? on right track?

your appreciated!

i built on clear canvas able send extremely large files. other programs wrote failed on large size images made stripped down version send dicom files in size of multiple gb , worked. command line , program.cs in program. simplest answer question of how send dicom file using clear canvas.

there 1 thing note. need way communicate between thread launching request , clear canvas, in case c-store request program.cs , class associationhandler : idicomclienthandler.

here use boolean , while loop before allowing thread creating request proceed. in other programs have used multi-dimensional string array hold values each association, , can perform dicom operation, c-store, c-move, c-find, n-action, ect, in multi-threaded fashion clear canvas. there no better open source dicom toolkit.

all have run code create console application , work out references clear canvas libraries. please ask questions.

command line arguments listed in code output.

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 title bar , logging is: " + processid);                 log4net.globalcontext.properties["procid"] = processid;                       (int = 0; < 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 = 1; < 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 use is: " + addr.tostring());                         break;                     }                 if (addr == null)                 {                     platform.log(loglevel.error, "no valid ip addresses 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 default: " + g_assocparams.localmaximumpdulength.tostring());                     platform.log(loglevel.info, "localmaximumpdulength 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 connect remote ae.");                     platform.log(loglevel.info, "attempting connect remote ae.");                     g_dicomclient = dicomclient.connect(g_assocparams, (idicomclienthandler)handler);                       while (assoc_accept_reject == false)                     {                         console.writeline("waiting association accepted or rejected.");                         platform.log(loglevel.info, "waiting association 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. error is: " + es.tostring ());                      }                      while (c_store_response == false)                     {                          console.writeline("waiting c-store response.");                         platform.log(loglevel.info, "waiting 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 exit!");                     console.readline();                  }                 catch (exception e)                 {                     console.writeline("error reading file. error is:");                     console.writeline("");                     console.writeline(e.message);                     console.writeline("");                     console.writeline("stack trace:");                     console.writeline(e.tostring());                     console.writeline("press enter exit!");                     console.readline();                      platform.log(loglevel.error, "error reading file. error is:");                     platform.log(loglevel.error, e.tostring());                 }              }//if (args .length != 0 )             else             {                 console.writeline ("you must provide proper command line arguments.");                 console.writeline ("required arguments are:");                 console.writeline ("");                 console.writeline ("-f [full file path 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 exit!");                 console.readline();                  platform.log(loglevel.error, "you must provide proper command line arguments.");                 platform.log(loglevel.error, "required arguments are:");                 platform.log(loglevel.error, "");                 platform.log(loglevel.error, " -f [full file path 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 accepted!");                 platform.log(loglevel.info, "association accepted!");                 assoc_accept_reject = true;             }              public void onreceiveassociatereject(dicomclient client, clientassociationparameters association, dicomrejectresult result, dicomrejectsource source, dicomrejectreason reason)             {                 console.writeline("association rejected!");                 platform.log(loglevel.info, "association 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 error message...");                     platform.log(loglevel.error, e.tostring ());                 }                 catch (nullreferenceexception)                 {                     platform.log(loglevel.error, "the error message 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 

Comments