コード例 #1
0
ファイル: AutoCopyQueue.cs プロジェクト: sakpung/webstudy
        private void SendCopy(AutoCopyItem item)
        {
            AeInfoExtended[] aes   = _aeManagementAgent.GetRelatedAeTitles(item.SourceAE, Module.AUTOCOPY_RELATION);
            StoreScu         store = new StoreScu();

            Module.InitializeDicomSecurity(false);
            StoreScu storeSecure = null;

            DicomOpenSslVersion dicomOpenSslVersion = DicomNet.GetOpenSslVersion();

            if (dicomOpenSslVersion.IsAvailable)
            {
                storeSecure = new StoreScu(Module._Server.TemporaryDirectory, DicomNetSecurityMode.Tls, Module._openSslOptions);
                Module.SetCiphers(storeSecure);
            }

            DicomScp scp = null;

            string[] sopInstances = item.Datasets.ToArray();

            if (aes == null || aes.Length == 0)
            {
                return;
            }

            string clientAe = Module.Options.UseCustomAE ? Module.Options.AutoCopyAE : item.ClientAE;

            AddEventHandlers(store, clientAe);
            AddEventHandlers(storeSecure, clientAe);

            foreach (AeInfoExtended ae in aes)
            {
#if LEADTOOLS_V20_OR_LATER
                // Update dbo.AeInfo.LastAccessDate to Date.Now
                ae.LastAccessDate = DateTime.Now;
                _aeManagementAgent.Update(ae.AETitle, ae);
#endif

                bool useTls = ae.ClientPortUsage == ClientPortUsageType.Secure || ((ae.ClientPortUsage == ClientPortUsageType.SameAsServer) && (Module._Server.Secure));
                useTls = (useTls && dicomOpenSslVersion.IsAvailable);

                foreach (string sopInstance in sopInstances)
                {
                    MatchingParameterCollection mpc = new MatchingParameterCollection();
                    MatchingParameterList       mpl = new MatchingParameterList();

                    ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(sopInstance);
                    mpl.Add(instanceEntity);
                    mpc.Add(mpl);

                    DataSet instanceData = _StorageAgent.QueryCompositeInstances(mpc);
                    // if (instanceData.Instance.Rows.Count == 1)
                    if (instanceData.Tables[DataTableHelper.InstanceTableName].Rows.Count == 1)
                    {
                        // string file = instanceData.Instance[0].ReferencedFile;
                        DataRow instanceRow = instanceData.Tables[DataTableHelper.InstanceTableName].Rows[0];
                        string  file        = RegisteredDataRows.InstanceInfo.ReferencedFile(instanceRow);

                        scp = new DicomScp(IPAddress.Parse(ae.Address), ae.AETitle, ae.Port);
                        try
                        {
                            if (useTls)
                            {
                                storeSecure.Store(scp, file);
                            }
                            else
                            {
                                store.Store(scp, file);
                            }
                        }
                        catch (ClientAssociationException ce)
                        {
                            string message = string.Format("[Auto Copy] Failed to establish association with server: {0}.", ce.Reason);

                            LogEvent(LogType.Error, MessageDirection.None, message, DicomCommandType.Undefined, null, store, null);
                        }
                        catch (DicomException de)
                        {
                            string message = string.Format("[Auto Copy] Error: {0}.", de.Message);

                            LogEvent(LogType.Error, MessageDirection.Input, message, DicomCommandType.Undefined, null, store, null);
                        }
                        catch (Exception e)
                        {
                            string message = "[Auto Copy] " + 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);
                        }
                    }
                }
            }

            RemoveEventHandlers(store);
            RemoveEventHandlers(storeSecure);

            foreach (string sopInstance in sopInstances)
            {
                item.Datasets.Remove(sopInstance);
            }
        }
コード例 #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);
        }