void store_BeforeCStore(object sender, BeforeCStoreEventArgs e) { StoreScu scu = sender as StoreScu; string message = string.Format(CSTORE_REQUEST_SEND, e.MessageId, e.PresentationID, e.AffectedClass, e.Instance); LogEvent(LogType.Information, MessageDirection.Output, message, DicomCommandType.CStore, null, scu, null); }
void store_AfterCStore(object sender, AfterCStoreEventArgs e) { StoreScu scu = sender as StoreScu; string message = string.Format(CSTORE_RESPONSE_RECEIVED, e.MessageId, e.PresentationID, e.AffectedClass, e.Instance, e.Status); LogEvent(LogType.Information, MessageDirection.Input, message, DicomCommandType.CStore, null, scu, null); }
void store_BeforeAssociateRequest(object sender, BeforeAssociateRequestEventArgs e) { StoreScu scu = sender as StoreScu; LogEvent(LogType.Information, MessageDirection.Output, string.Format(ASSOCIATE_REQUEST_SENT, e.Associate.ToString()), DicomCommandType.Undefined, null, scu, null); }
public static void LogEvent(LogType type, MessageDirection messageDirection, string description, DicomCommandType command, DicomDataSet dataset, StoreScu Client, SerializableDictionary <string, object> customInformation) { try { string ae = Client.AETitle; DicomNet net = Client as DicomNet; SerializableDictionary <string, object> logCustomInformation = DicomLogEntry.CustomInformationDicomMessage; if (customInformation != null) { logCustomInformation = new SerializableDictionary <string, object>(); foreach (KeyValuePair <string, object> kvp in customInformation) { logCustomInformation.Add(kvp.Key, kvp.Value); } logCustomInformation.Add(DicomLogEntry.DicomMessageKey, DicomLogEntry.DicomMessageValue); } Logger.Global.Log("Auto Copy", Client.CurrentScp.AETitle, Client.CurrentScp.PeerAddress.ToString(), Client.CurrentScp.Port, net.IsAssociated() ? net.Association.Calling : ae, net.HostAddress != null ? net.HostAddress.ToString() : string.Empty, net.IsConnected() ? net.HostPort : -1, command, DateTime.Now, type, messageDirection, description, dataset, logCustomInformation); } catch (Exception exception) { Logger.Global.Exception("Auto Copy", exception); } }
public bool Verify(string AETitle) { StoreScu scu = new StoreScu(); Scp.PeerAddress = System.Net.IPAddress.Parse(IPAddress); scu.AETitle = AETitle; return(scu.Verify(Scp)); }
public StoreClient(List <DicomScp> scps, DicomDataSet ds) { DicomServer server = ServiceLocator.Retrieve <DicomServer>(); _Scu = new StoreScu(server.TemporaryDirectory); _DataSet = ds; _Scps.AddRange(scps); }
void store_AfterConnect(object sender, AfterConnectEventArgs e) { StoreScu scu = sender as StoreScu; string message = CONNECT_RESPONSE_RECEIVED; if (e.Error != DicomExceptionCode.Success) { message = string.Format(CONNECT_RESPONSE_RECEIVED_FAILURE, e.Error); } LogEvent(LogType.Information, MessageDirection.Input, message, DicomCommandType.Undefined, null, scu, null); }
void store_AfterAssociateRequest(object sender, AfterAssociateRequestEventArgs e) { StoreScu scu = sender as StoreScu; if (!e.Rejected) { LogEvent(LogType.Information, MessageDirection.Input, ASSOCIATE_REQUEST_ACCEPTED, DicomCommandType.Undefined, null, scu, null); } else { LogEvent(LogType.Information, MessageDirection.Input, string.Format(ASSOCIATE_REQUEST_REJECTED, e.Reason), DicomCommandType.Undefined, null, scu, null); } }
private void RemoveEventHandlers(StoreScu store) { if (store != null) { store.BeforeConnect -= new BeforeConnectDelegate(store_BeforeConnect); store.AfterConnect -= new AfterConnectDelegate(store_AfterConnect); store.AfterSecureLinkReady -= store_AfterSecureLinkReady; 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); } }
private void AddEventHandlers(StoreScu store, string clientAe) { if (store != null) { store.AETitle = clientAe; store.BeforeConnect += new BeforeConnectDelegate(store_BeforeConnect); store.AfterConnect += new AfterConnectDelegate(store_AfterConnect); store.AfterSecureLinkReady += store_AfterSecureLinkReady; 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); } }
private void store_AfterSecureLinkReady(object sender, AfterSecureLinkReadyEventArgs e) { StoreScu connection = sender as StoreScu; if (e.Error == DicomExceptionCode.Success) { DicomTlsCipherSuiteType cipher = connection.GetTlsCipherSuite(); LogEvent(LogType.Information, MessageDirection.Input, String.Format(SECURE_LINK_READY_CIPHERSUITE, cipher.GetCipherFriendlyName()), DicomCommandType.Undefined, null, connection, null); } else { LogEvent(LogType.Information, MessageDirection.Input, String.Format(SECURE_LINK_FAILED, e.Error), DicomCommandType.Undefined, null, connection, null); } }
public string VerifyConnection(PACSConnection server, ClientConnection client) { AeInfo scpInfo = GetScp(server); using (StoreScu scu = new StoreScu()) { DicomScp scp = new DicomScp(IPAddress.Parse(scpInfo.Address), scpInfo.AETitle, scpInfo.Port); scu.AETitle = client.AETitle; try { if (scu.Verify(scp)) { return(string.Empty); } } catch (Exception exception) { return(exception.Message); } } return(string.Empty); }
void store_AfterReleaseRequest(object sender, EventArgs e) { StoreScu scu = sender as StoreScu; LogEvent(LogType.Information, MessageDirection.Input, RELEASE_RESPONSE_RECEIVED, DicomCommandType.Undefined, null, scu, null); }
void store_BeforeReleaseRequest(object sender, EventArgs e) { StoreScu scu = sender as StoreScu; LogEvent(LogType.Information, MessageDirection.Output, RELEASE_REQUEST_SENT, DicomCommandType.Undefined, null, scu, null); }
private DicomCommandStatusType SendInstance(DicomScp scp, ForwardInstance instance) { StoreScu store = null; if (_useTls && Module.IsDicomSecurityAvailable()) { store = new StoreScu(Module._Server.TemporaryDirectory, DicomNetSecurityMode.Tls, Module._openSslOptions) { AETitle = _Options.UseCustomAE ? _Options.CustomAE : _ServerAE }; Module.SetCiphers(store); } else { store = new StoreScu() { AETitle = _Options.UseCustomAE ? _Options.CustomAE : _ServerAE }; } store.Tag = DicomCommandStatusType.Failure; try { store.BeforeConnect += new BeforeConnectDelegate(BeforeConnect); store.AfterConnect += new AfterConnectDelegate(AfterConnect); store.AfterSecureLinkReady += AfterSecureLinkReady; store.BeforeAssociateRequest += new BeforeAssociationRequestDelegate(BeforeAssociateRequest); store.AfterAssociateRequest += new AfterAssociateRequestDelegate(AfterAssociateRequest); store.BeforeCStore += new BeforeCStoreDelegate(store_BeforeCStore); store.AfterCStore += new AfterCStoreDelegate(store_AfterCStore); store.BeforeReleaseRequest += new EventHandler(BeforeReleaseRequest); store.AfterReleaseRequest += new EventHandler(AfterReleaseRequest); store.Store(scp, instance.ReferencedFile); } catch (ClientAssociationException ce) { string message = string.Format("[Forwarder] 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("[Forwarder] Error: {0}.", de.Message); LogEvent(LogType.Error, MessageDirection.Input, message, DicomCommandType.Undefined, null, store, null); } catch (Exception e) { string message = "[Forwarder] " + 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); } finally { store.BeforeConnect -= new BeforeConnectDelegate(BeforeConnect); store.AfterConnect -= new AfterConnectDelegate(AfterConnect); store.AfterSecureLinkReady -= AfterSecureLinkReady; store.BeforeAssociateRequest -= new BeforeAssociationRequestDelegate(BeforeAssociateRequest); store.AfterAssociateRequest -= new AfterAssociateRequestDelegate(AfterAssociateRequest); store.BeforeCStore -= new BeforeCStoreDelegate(store_BeforeCStore); store.AfterCStore -= new AfterCStoreDelegate(store_AfterCStore); store.BeforeReleaseRequest -= new EventHandler(BeforeReleaseRequest); store.AfterReleaseRequest -= new EventHandler(AfterReleaseRequest); store.Dispose(); } return((DicomCommandStatusType)store.Tag); }
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); }
void store_BeforeConnect(object sender, BeforeConnectEventArgs e) { StoreScu scu = sender as StoreScu; LogEvent(LogType.Information, MessageDirection.Output, CONNECT_REQUEST_SENT, DicomCommandType.Undefined, null, scu, null); }
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); } }