public DicomCommandStatusType OnNAction(DicomClient Client, byte PresentationId, int MessageID, string AffectedClass, string Instance, int Action, DicomDataSet Request, DicomDataSet Response) { ClientSession clientSession = null; INActionClientSessionProxy sessionProxy = null; DicomCommand patientUpdateCommand = null; CompositeInstanceDataSet.InstanceRow[] instanceRows = null; if (_TemporaryDirectory == null) { _TemporaryDirectory = Client.Server.TemporaryDirectory; } if (Instance != PatientUpdaterConstants.UID.PatientUpdateInstance) { return(DicomCommandStatusType.InvalidObjectInstance); } if (clientSession != null) { clientSession.NActionResponse -= clientSession_NActionResponse; clientSession = null; } clientSession = new ClientSession(Client); clientSession.NActionResponse += new EventHandler <NActionResponseEventArgs>(clientSession_NActionResponse); sessionProxy = new NActionClientSessionProxy(clientSession, PresentationId, MessageID, AffectedClass, Instance, Action, Response); patientUpdateCommand = DicomCommandFactory.GetInstance().CreateNActionCommand(sessionProxy, Request); _ClientSession = clientSession; _SessionProxy = sessionProxy; // // If we are deleting we need to get the instance rows // List <string> studyInstanceUids; instanceRows = GetInstanceRows(Action, Request, out studyInstanceUids); ConfigureCommand(patientUpdateCommand as PatientUpdaterCommand); _ClientSession.ProcessNActionRequest(PresentationId, MessageID, AffectedClass, Instance, Action, patientUpdateCommand).WaitOne(); if (_Status == DicomCommandStatusType.Success) { // // We need to delete the dicom files according to the user options // if (Action == PatientUpdaterConstants.Action.DeletePatient || Action == PatientUpdaterConstants.Action.DeleteSeries) { if (instanceRows != null) { DicomFileDeleter deleter = new DicomFileDeleter(); try { StorageAddInsConfiguration storageSettings = Module.StorageConfigManager.GetStorageAddInsSettings(); deleter.DicomFileDeleted += new EventHandler <Leadtools.Medical.Winforms.EventBrokerArgs.DicomFileDeletedEventArgs>(deleter_DicomFileDeleted); deleter.DicomFileDeleteFailed += new EventHandler <Leadtools.Medical.Winforms.EventBrokerArgs.DicomFileDeletedEventArgs>(deleter_DicomFileDeleteFailed); if (storageSettings != null) { deleter.DeleteFilesOnDatabaseDelete = storageSettings.StoreAddIn.DeleteFiles; deleter.BackupFilesOnDatabaseDelete = storageSettings.StoreAddIn.BackupFilesOnDelete; deleter.BackupFilesOnDeleteFolder = storageSettings.StoreAddIn.DeleteBackupLocation; } deleter.Delete(null, instanceRows); } catch (Exception e) { Logger.Global.Error(Module.Source, "[Patient Updater] " + e.Message); } finally { deleter.DicomFileDeleted -= deleter_DicomFileDeleted; deleter.DicomFileDeleteFailed -= deleter_DicomFileDeleteFailed; } } } // // If auto update is enabled we need to forward this message to associated ae title // if (Module.Options != null && Module.Options.EnableAutoUpdate && Module.UpdateQueue != null) { AutoUpdateItem item = new AutoUpdateItem(Client.AETitle) { Action = Action, ClientAE = Client.Server.AETitle }; if (Action == PatientUpdaterConstants.Action.MergePatient && (instanceRows != null)) { MergePatient mergePatientData = Request.Get <MergePatient>(null); foreach (string studyInstanceUid in studyInstanceUids) { mergePatientData.ReferencedStudySequence.Add(new StudyInstanceReference(studyInstanceUid)); } mergePatientData.PatientToMerge.Clear(); Request.Set(mergePatientData); } else if (studyInstanceUids.Count > 0) { DeletePatient deletePatientData = Request.Get <DeletePatient>(null); foreach (string studyInstanceUid in studyInstanceUids) { deletePatientData.ReferencedStudySequence.Add(new StudyInstanceReference(studyInstanceUid)); } Request.Set(deletePatientData); } // Request.InsertElementAndSetValue(DicomTag.ReferencedStudySequence) item.Dicom = Request; if (ShouldAutoUpdate(item.Action)) { Module.UpdateQueue.AddItem(item); } } } return(_Status); }
public void RunThread(IForwardDataAccessAgent forwardAgent, IStorageDataAccessAgent storageAgent) { lock (cleanLock) { ForwardInstance[] instances = forwardAgent.GetCleanList(); StorageAddInsConfiguration storageSettings = Module.StorageConfigManager.GetStorageAddInsSettings(); string message = string.Format("[Forwarder] {0} {1} found to clean", instances.Length, instances.Length == 1 ? "dataset" : "datasets"); DicomFileDeleter deleter = new DicomFileDeleter(); MatchingParameterCollection mpc = new MatchingParameterCollection(); deleter.DicomFileDeleted += new EventHandler<Leadtools.Medical.Winforms.EventBrokerArgs.DicomFileDeletedEventArgs>(deleter_DicomFileDeleted); deleter.DicomFileDeleteFailed += new EventHandler<Leadtools.Medical.Winforms.EventBrokerArgs.DicomFileDeletedEventArgs>(deleter_DicomFileDeleteFailed); if (storageSettings != null) { deleter.DeleteFilesOnDatabaseDelete = storageSettings.StoreAddIn.DeleteFiles; deleter.BackupFilesOnDatabaseDelete = storageSettings.StoreAddIn.BackupFilesOnDelete; deleter.BackupFilesOnDeleteFolder = storageSettings.StoreAddIn.DeleteBackupLocation; } Logger.Global.SystemMessage(LogType.Debug, message, _ServerAE); foreach (ForwardInstance instance in instances) { #if LEADTOOLS_V18_OR_LATER if (_cancelClean) { _cancelClean = false; Logger.Global.SystemMessage(LogType.Information, string.Format("Cancelling Clean Process"), _ServerAE); break; } #endif // #if LEADTOOLS_V18_OR_LATER MatchingParameterList mpl = new MatchingParameterList(); ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(instance.SOPInstanceUID); mpl.Add(instanceEntity); mpc.Add(mpl); try { DataSet ds = storageAgent.QueryCompositeInstances(mpc); // // Find the instance to delete // storageAgent.DeleteInstance(GetMatchingParameters(instance.SOPInstanceUID)); if (ds != null) { deleter.Delete(null, ds.Tables[DataTableHelper.InstanceTableName].Select()); } } catch (Exception e) { message = string.Format("[Forwarder] Error ({0}) deleting instance: {1}", e.Message, instance.SOPInstanceUID); Logger.Global.SystemMessage(LogType.Error, message, _ServerAE); } finally { mpc.Clear(); } } deleter.DicomFileDeleted -= deleter_DicomFileDeleted; deleter.DicomFileDeleteFailed -= deleter_DicomFileDeleteFailed; } }
public void Run(IExternalStoreDataAccessAgent externalStoreAgent, IStorageDataAccessAgent storageAgent, int expirationDays) { DicomUtilities.DebugString(DebugStringOptions.ShowCounter, "CleanProcess.Run"); lock (cleanLock) { ExternalStoreInstance[] instances = externalStoreAgent.GetClearList(expirationDays); // StorageAddInsConfiguration storageSettings = Module.StorageConfigManager.GetStorageAddInsSettings(); if (instances.Length > 0) { string message = string.Format("{0} {1} found to clear", instances.Length, "local dataset(s)"); Logger.Global.SystemMessage(LogType.Information, message, _serviceName); DicomFileDeleter deleter = new DicomFileDeleter(); MatchingParameterCollection mpc = new MatchingParameterCollection(); deleter.DicomFileDeleted += new EventHandler <Leadtools.Medical.Winforms.EventBrokerArgs.DicomFileDeletedEventArgs>(deleter_DicomFileDeleted); deleter.DicomFileDeleteFailed += new EventHandler <Leadtools.Medical.Winforms.EventBrokerArgs.DicomFileDeletedEventArgs>(deleter_DicomFileDeleteFailed); if (_storageSettings != null) { deleter.DeleteFilesOnDatabaseDelete = _storageSettings.StoreAddIn.DeleteFiles; deleter.BackupFilesOnDatabaseDelete = _storageSettings.StoreAddIn.BackupFilesOnDelete; deleter.BackupFilesOnDeleteFolder = _storageSettings.StoreAddIn.DeleteBackupLocation; deleter.DeleteAnnotationsOnImageDelete = false; deleter.DeleteReferencedImagesOnImageDelete = false; } foreach (ExternalStoreInstance instance in instances) { MatchingParameterList mpl = new MatchingParameterList(); ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(instance.SOPInstanceUID); mpl.Add(instanceEntity); mpc.Add(mpl); try { DataSet ds = storageAgent.QueryCompositeInstances(mpc); // // Find the instance to delete //// deleter.Delete(null, ds.Tables[DataTableHelper.InstanceTableName].Select()); externalStoreAgent.SetReferencedFile(instance.SOPInstanceUID, string.Empty); } catch (Exception e) { message = string.Format("Error ({0}) deleting instance: {1}", e.Message, instance.SOPInstanceUID); Logger.Global.SystemMessage(LogType.Error, message, _serviceName); } finally { mpc.Clear(); } } deleter.DicomFileDeleted -= deleter_DicomFileDeleted; deleter.DicomFileDeleteFailed -= deleter_DicomFileDeleteFailed; } } }