Esempio n. 1
0
        public virtual DicomDataSet GetDicomDataSet(DataRow instanceData, out string referencedFileLocation)
        {
            lock (_lockObject)
            {
                referencedFileLocation = string.Empty;
                DicomDataSet ds = RegisteredDataRows.InstanceInfo.LoadDicomDataSet(instanceData, Flags);
                if (CacheLocal)
                {
                    bool      exists = false;
                    Exception ex     = DefaultCrud.ExistsDicom(instanceData, out exists);
                    if (!exists)
                    {
                        StorageModuleConfigurationManager StorageConfigManager = new StorageModuleConfigurationManager(true);
                        StorageConfigManager.Load(ServiceDirectory);
                        StorageAddInsConfiguration storageSettings = StorageConfigManager.GetStorageAddInsSettings();

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

                        string storageLocation   = CStoreCommand.GetStorageLocation(storeConfig, ds);
                        string sopInstanceUid    = RegisteredDataRows.InstanceInfo.GetElementValue(instanceData, DicomTag.SOPInstanceUID);
                        string dicomInstancePath = Path.Combine(storageLocation, sopInstanceUid + "." + storeConfig.DicomFileExtension);

                        ICrud crud = DefaultInstanceInfo.GetRetrieveCrud(instanceData);
                        if (crud != null)
                        {
                            ex = crud.RetrieveFile(instanceData, dicomInstancePath);
                            if (ex == null)
                            {
                                ExternalStoreAgent.SetReferencedFile(sopInstanceUid, dicomInstancePath);
                                referencedFileLocation = dicomInstancePath;
                            }
                        }
                    }
                }
                return(ds);
            }
        }
Esempio n. 2
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();
                    }
                }
            }
        }