Ejemplo n.º 1
0
        public void RunThread(IExternalStoreDataAccessAgent externalStoreAgent, IStorageDataAccessAgent storageAgent, DateRange range)
        {
            DicomUtilities.DebugString(DebugStringOptions.ShowCounter, "RestoreProcess.Run");

            lock (_restoreLock)
            {
                ExternalStoreInstance[] instances = externalStoreAgent.GetRestoreList(range);
                string message = string.Format("{0} {1} found to restore", instances.Length, "dataset(s)");
                MatchingParameterCollection mpc = new MatchingParameterCollection();

                Logger.Global.SystemMessage(LogType.Information, message, _serviceName);

                CStoreCommandConfiguration storeConfig = new CStoreCommandConfiguration();
                storeConfig.DicomFileExtension = _storageAddinsConfiguration.StoreAddIn.StoreFileExtension;
                FillStoreCommandDefaultSettings(storeConfig, _storageAddinsConfiguration);

                foreach (ExternalStoreInstance instance in instances)
                {
                    if (_cancelRestore)
                    {
                        _cancelRestore = false;
                        Logger.Global.SystemMessage(LogType.Information, "Cancelling Restore Process", _serviceName);
                        break;
                    }

                    MatchingParameterList mpl = new MatchingParameterList();

                    ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(instance.SOPInstanceUID);
                    mpl.Add(instanceEntity);
                    mpc.Add(mpl);
                    try
                    {
                        DataSet ds = storageAgent.QueryCompositeInstances(mpc);

                        DataRow[] rows = ds.Tables[DataTableHelper.InstanceTableName].Select();
                        foreach (DataRow row in rows)
                        {
                            // Get the ICrud that the file was originally stored with
                            ICrud crud = DataAccessServiceLocator.Retrieve <ICrud>(instance.ExternalStoreGuid);
                            if (crud != null)
                            {
                                DicomDataSet dicomDataSet = null;
                                Exception    ex           = crud.RetrieveDicom(row, DicomDataSetLoadFlags.None, out dicomDataSet);
                                if (ex == null)
                                {
                                    string storageLocation   = CStoreCommand.GetStorageLocation(storeConfig, dicomDataSet);
                                    string dicomInstancePath = Path.Combine(storageLocation,
                                                                            instance.SOPInstanceUID) + "." + storeConfig.DicomFileExtension;

                                    ex = crud.RetrieveFile(row, dicomInstancePath);
                                    if (ex != null)
                                    {
                                        throw ex;
                                    }

                                    externalStoreAgent.SetReferencedFile(instance.SOPInstanceUID, dicomInstancePath);
                                    Logger.Global.SystemMessage(LogType.Information, string.Format("File Restored: {0} ", dicomInstancePath), _serviceName);
                                }
                            }
                            else
                            {
                                Logger.Global.SystemMessage(LogType.Information, string.Format("Error:  File Not Restored -- Store Token: {0}.  The Addin that for ExternalStoreGuid '{1}' cannot be found.", instance.StoreToken, instance.ExternalStoreGuid), _serviceName);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        message = string.Format("Error ({0}) restoring instance: {1}", e.Message, instance.SOPInstanceUID);
                        Logger.Global.SystemMessage(LogType.Error, message, _serviceName);
                    }
                    finally
                    {
                        mpc.Clear();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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;
                }
            }
        }