private string GetFormattedErrorMessage(Exception exception, string baseMessage)
        {
            if (exception is Leadtools.Dicom.Scu.Common.ClientConnectionException)
            {
                baseMessage = string.Format("{0}\n{1}\nDICOM Code: {2}\n{3}",
                                            baseMessage,
                                            exception.Message,
                                            ((Leadtools.Dicom.Scu.Common.ClientConnectionException)exception).Code,
                                            DicomException.GetCodeMessage(((Leadtools.Dicom.Scu.Common.ClientConnectionException)exception).Code));
            }
            else if (exception is Leadtools.Dicom.Scu.Common.ClientAssociationException)
            {
                baseMessage = string.Format("{0}\n{1}\nDICOM Reason: {2}\n{3}",
                                            baseMessage,
                                            exception.Message,
                                            ((Leadtools.Dicom.Scu.Common.ClientAssociationException)exception).Reason,
                                            WorkstationUtils.GetAssociationReasonMessage(((Leadtools.Dicom.Scu.Common.ClientAssociationException)exception).Reason));
            }
            else if (exception is Leadtools.Dicom.Scu.Common.ClientCommunicationException)
            {
                baseMessage = baseMessage + "\n" + exception.Message + "\nDICOM Status: " + ((Leadtools.Dicom.Scu.Common.ClientCommunicationException)exception).Status;
            }
            else
            {
                baseMessage = baseMessage + "\n" + exception.Message;
            }

            return(baseMessage);
        }
Example #2
0
        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);
        }
Example #3
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);
        }