public void InternalRunThread(DicomScp scp, IForwardDataAccessAgent forwardAgent) { lock (forwardLock) { if (_serviceShuttingDown) { return; } ForwardInstance[] instances; try { instances = forwardAgent.GetForwardList(); } catch (Exception ex) { Logger.Global.SystemMessage(LogType.Error, ex.ToString(), _ServerAE); // throw; instances = new ForwardInstance[0]; } string message = string.Format("[Forwarder] {0} {1} found to forward", instances.Length, instances.Length == 1 ? "dataset" : "datasets"); Logger.Global.SystemMessage(LogType.Debug, message, _ServerAE); if (instances.Length > 0 && _Options.Verify) { message = string.Format("[Forwarder] {0} {1} will be verified after forwarding", instances.Length, instances.Length == 1 ? "instance" : "instances"); Logger.Global.SystemMessage(LogType.Warning, message, _ServerAE); } foreach (ForwardInstance instance in instances) { #if LEADTOOLS_V18_OR_LATER if (_cancelForward) { _cancelForward = false; Logger.Global.SystemMessage(LogType.Information, string.Format("Cancelling Forward Process"), _ServerAE); break; } if (_serviceShuttingDown) { break; } #endif // #if LEADTOOLS_V18_OR_LATER try { if (!File.Exists(instance.ReferencedFile)) { message = string.Format("[Forwarder] Referenced file doesn't exist. Instance ({0}) will be removed from forwarding queue. [{1}]", instance.SOPInstanceUID, instance.ReferencedFile); Logger.Global.SystemMessage(LogType.Warning, message, _ServerAE); forwardAgent.SetInstanceForwarded(instance.SOPInstanceUID, DateTime.Now, null); continue; } // SendInstance can fail because DicomEngine may be locked DicomCommandStatusType status = DicomCommandStatusType.Success; try { status = SendInstance(scp, instance); } catch (Exception) { // Console.WriteLine(ex.Message); throw; } if (status == DicomCommandStatusType.Success || status == DicomCommandStatusType.DuplicateInstance) { DateTime?expires = null; DateTime forwardDate = DateTime.Now; if (_Options.ImageHold != null && _Options.ImageHold != 0) { switch (_Options.HoldInterval) { case HoldInterval.Days: expires = forwardDate.AddDays(_Options.ImageHold.Value); break; case HoldInterval.Months: expires = forwardDate.AddMonths(_Options.ImageHold.Value); break; default: expires = forwardDate.AddYears(_Options.ImageHold.Value); break; } } if (!_Options.Verify || VerifyInstance(scp, instance.SOPInstanceUID) == DicomCommandStatusType.Success) { if (_Options.Verify) { message = string.Format("[Forwarder] SOP instance successfully verified: {0}", instance.SOPInstanceUID); Logger.Global.SystemMessage(LogType.Debug, message, _ServerAE); } forwardAgent.SetInstanceForwarded(instance.SOPInstanceUID, forwardDate, expires); } else { message = string.Format("[Forwarder] Failed to verify SOP instance: {0}. Instance not marked as forwarded.", instance.SOPInstanceUID); Logger.Global.SystemMessage(LogType.Error, message, _ServerAE); } } } catch (Exception e) { Logger.Global.SystemMessage(LogType.Error, "[Forwarder] " + e.Message, _ServerAE); } } } }
private void OnSendCStoreResponse(object sender, CStoreResponseSentEventArgs response) { try { bool process = false; lock ( _instancesListLock ) { process = (__MovedInstances.Contains(response.Instance) && !__ForwardedInstances.Contains(response.Instance)); } if (process && response.Status == DicomCommandStatusType.Success) { if (ServiceLocator.IsRegistered <ForwardOptions> ( ) && DataAccessServices.IsDataAccessServiceRegistered <IForwardDataAccessAgent> ( )) { ForwardOptions forwardOptions = ServiceLocator.Retrieve <ForwardOptions> ( ); IForwardDataAccessAgent dataAccess = DataAccessServices.GetDataAccessService <IForwardDataAccessAgent> ( ); if (null != forwardOptions && null != dataAccess) { DateTime?expires = null; DateTime forwardDate = DateTime.Now; if (dataAccess.IsForwarded(response.Instance)) { return; } if (forwardOptions.ImageHold != null && forwardOptions.ImageHold != 0) { switch (forwardOptions.HoldInterval) { case HoldInterval.Days: { expires = forwardDate.AddDays(forwardOptions.ImageHold.Value); } break; case HoldInterval.Months: { expires = forwardDate.AddMonths(forwardOptions.ImageHold.Value); } break; default: { expires = forwardDate.AddYears(forwardOptions.ImageHold.Value); } break; } } dataAccess.SetInstanceForwarded(response.Instance, forwardDate, expires); } } } } catch (Exception ex) { GatewaySession.Log(__Client, DicomCommandType.CMove, LogType.Error, MessageDirection.Output, null, "[Gateway] Failed to set instance forwarding.\n" + ex.Message); } }