コード例 #1
0
ファイル: MoveClient.cs プロジェクト: sakpung/webstudy
        public static bool Move(DicomScp scp, MoveInfo info, string aetitle, string temporaryDirectory, ref string lastStatus)
        {
            bool success = false;
            RuleQueryRetrieve scu;

            scu = new RuleQueryRetrieve(temporaryDirectory);
            scu.BeforeConnect          += new BeforeConnectDelegate(scu_BeforeConnect);
            scu.AfterConnect           += new AfterConnectDelegate(scu_AfterConnect);
            scu.BeforeAssociateRequest += new BeforeAssociationRequestDelegate(scu_BeforeAssociateRequest);
            scu.AfterAssociateRequest  += new AfterAssociateRequestDelegate(scu_AfterAssociateRequest);
            scu.BeforeCMove            += new BeforeCMoveDelegate(scu_BeforeCMove);
            scu.AfterCMove             += new AfterCMoveDelegate(scu_AfterCMove);
            scu.BeforeReleaseRequest   += new EventHandler(scu_BeforeReleaseRequest);
            scu.AfterReleaseRequest    += new EventHandler(scu_AfterReleaseRequest);
            scu.AETitle = Module._Options.AETitle;

            try
            {
                switch (info.MoveType)
                {
                case MoveType.Patient:
                    scu.MovePatient(scp, aetitle, info.Id);
                    break;

                case MoveType.Study:
                    scu.Move(scp, aetitle, info.Id);
                    break;

                case MoveType.Series:
                    scu.Move(scp, aetitle, string.Empty, info.Id);
                    break;

                case MoveType.Instance:
                    scu.Move(scp, aetitle, string.Empty, string.Empty, info.Id);
                    break;
                }

                if (scu.Rejected)
                {
                    lastStatus = scu.RejectReason;
                }
                else
                {
                    if (scu.Status != DicomCommandStatusType.Success)
                    {
                        lastStatus = scu.Status.ToString();
                    }
                    else
                    {
                        success = true;
                    }
                }
            }
            catch (Exception e)
            {
                if (e is ClientAssociationException)
                {
                    ClientAssociationException ce = e as ClientAssociationException;
                    string message = string.Format("[Rules] Failed to establish association with server: {0}.", ce.Reason);

                    Utils.LogEvent(LogType.Error, MessageDirection.None, message, DicomCommandType.Undefined, null, scu, null);
                    lastStatus = message;
                }
                if (e is DicomException)
                {
                    DicomException de      = e as DicomException;
                    string         message = string.Format("[Rules] Error: {0}.", de.Message);

                    Utils.LogEvent(LogType.Error, MessageDirection.Input, message, DicomCommandType.Undefined, null, scu, null);
                    lastStatus = de.Message;
                }
                else
                {
                    string message = "[Rules] " + e.Message;

                    Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined,
                                      DateTime.Now, LogType.Error, MessageDirection.None, message, null, null);
                    lastStatus = e.Message;
                }
            }
            finally
            {
                scu.BeforeConnect          -= scu_BeforeConnect;
                scu.AfterConnect           -= scu_AfterConnect;
                scu.BeforeAssociateRequest -= scu_BeforeAssociateRequest;
                scu.AfterAssociateRequest  -= scu_AfterAssociateRequest;
                scu.BeforeCMove            -= new BeforeCMoveDelegate(scu_BeforeCMove);
                scu.AfterCMove             -= new AfterCMoveDelegate(scu_AfterCMove);
                scu.BeforeReleaseRequest   -= scu_BeforeReleaseRequest;
                scu.AfterReleaseRequest    -= scu_AfterReleaseRequest;
            }

            return(success);
        }
コード例 #2
0
        public static bool Store(string serverAE, DicomScp scp, DicomDataSet ds, ref string lastStatus)
        {
            StoreScu    store  = new StoreScu();
            DicomServer server = ServiceLocator.Retrieve <DicomServer>();

            bool success = false;

            store.AETitle                 = serverAE;
            store.BeforeConnect          += new BeforeConnectDelegate(store_BeforeConnect);
            store.AfterConnect           += new AfterConnectDelegate(store_AfterConnect);
            store.BeforeAssociateRequest += new BeforeAssociationRequestDelegate(store_BeforeAssociateRequest);
            store.AfterAssociateRequest  += new AfterAssociateRequestDelegate(store_AfterAssociateRequest);
            store.BeforeCStore           += new BeforeCStoreDelegate(store_BeforeCStore);
            store.AfterCStore            += new AfterCStoreDelegate(store_AfterCStore);
            store.BeforeReleaseRequest   += new EventHandler(store_BeforeReleaseRequest);
            store.AfterReleaseRequest    += new EventHandler(store_AfterReleaseRequest);

            try
            {
                scp.Timeout = server.ClientTimeout;
                store.Store(scp, ds);
                if (store.Rejected)
                {
                    lastStatus = store.RejectReason;
                }
                else
                {
                    if (store.Status != DicomCommandStatusType.Success)
                    {
                        lastStatus = store.Status.ToString();
                    }
                    else
                    {
                        success = true;
                    }
                }
            }
            catch (Exception e)
            {
                if (e is ClientAssociationException)
                {
                    ClientAssociationException ce = e as ClientAssociationException;
                    string message = string.Format("[Rules] Failed to establish association with server: {0}.", ce.Reason);

                    Utils.LogEvent(LogType.Error, MessageDirection.None, message, DicomCommandType.Undefined, null, store, null);
                    lastStatus = message;
                }
                if (e is DicomException)
                {
                    DicomException de      = e as DicomException;
                    string         message = string.Format("[Rules] Error: {0}.", de.Message);

                    Utils.LogEvent(LogType.Error, MessageDirection.Input, message, DicomCommandType.Undefined, null, store, null);
                    lastStatus = de.Code.ToString();
                }
                else
                {
                    string message = "[Rules] " + e.Message;

                    Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined,
                                      DateTime.Now, LogType.Error, MessageDirection.None, message, null, null);
                    lastStatus = e.Message;
                }
            }
            finally
            {
                store.BeforeConnect          -= new BeforeConnectDelegate(store_BeforeConnect);
                store.AfterConnect           -= new AfterConnectDelegate(store_AfterConnect);
                store.BeforeAssociateRequest -= new BeforeAssociationRequestDelegate(store_BeforeAssociateRequest);
                store.AfterAssociateRequest  -= new AfterAssociateRequestDelegate(store_AfterAssociateRequest);
                store.BeforeCStore           -= new BeforeCStoreDelegate(store_BeforeCStore);
                store.AfterCStore            -= new AfterCStoreDelegate(store_AfterCStore);
                store.BeforeReleaseRequest   -= new EventHandler(store_BeforeReleaseRequest);
                store.AfterReleaseRequest    -= new EventHandler(store_AfterReleaseRequest);
                ds = null;
            }
            return(success);
        }