Example #1
0
        private CompositeInstanceDataSet GetReferencedCompositeInstancesAndFillInstanceProfiles
        (
            Dictionary <string, string> instanceSopProfileName
        )
        {
            MatchingParameterCollection matchingCollection;
            MatchingParameterList       matchingList;


            matchingCollection = new MatchingParameterCollection( );

            foreach (MediaCreationReferencedSop referencedSop in MediaObject.ReferencedSopSequence)
            {
                matchingList = new MatchingParameterList( );

                matchingCollection.Add(matchingList);

                ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(referencedSop.SopInstance.ReferencedSopInstanceUid);
                matchingList.Add(instanceEntity);

                instanceSopProfileName.Add(referencedSop.SopInstance.ReferencedSopInstanceUid,
                                           referencedSop.RequestedMediaApplicationProfile);
            }

            return(StorageService.QueryCompositeInstances(matchingCollection).ToCompositeInstanceDataSet());
        }
        MatchingParameterCollection GenerateMatchingParameterCollection(ViewGenerator.ViewDataRow metadataRow, out string rowKeyValue, out string rowKeyName, out string viewName)
        {
            DataRow originalRow = metadataRow.OriginalRow;
            MatchingParameterCollection matchingParamCollection = new MatchingParameterCollection();
            MatchingParameterList       matchingParamList       = new MatchingParameterList();

            matchingParamCollection.Add(matchingParamList);

            if (string.Compare(originalRow.Table.TableName, DataTableHelper.InstanceTableName) == 0)
            {
                string         sSopInstanceUid = RegisteredDataRows.InstanceInfo.GetElementValue(originalRow, DicomTag.SOPInstanceUID);
                ICatalogEntity imageInstance   = RegisteredEntities.GetInstanceEntity(sSopInstanceUid);

                rowKeyValue = sSopInstanceUid;
                rowKeyName  = "SOPInstanceUID";
                viewName    = "Images";

                matchingParamList.Add(imageInstance);
            }
            else if (string.Compare(originalRow.Table.TableName, DataTableHelper.SeriesTableName) == 0)
            {
                string         sSeriesInstanceUid = RegisteredDataRows.SeriesInfo.GetElementValue(originalRow, DicomTag.SeriesInstanceUID);
                ICatalogEntity seriesEntity       = RegisteredEntities.GetSeriesEntity(sSeriesInstanceUid);

                rowKeyValue = sSeriesInstanceUid;
                rowKeyName  = "SeriesInstanceUID";
                viewName    = "Series";

                matchingParamList.Add(seriesEntity);
            }
            else if (string.Compare(originalRow.Table.TableName, DataTableHelper.StudyTableName) == 0)
            {
                string         sStudyInstanceUid = RegisteredDataRows.StudyInfo.GetElementValue(originalRow, DicomTag.StudyInstanceUID);
                ICatalogEntity studyEntity       = RegisteredEntities.GetStudyEntity(sStudyInstanceUid);

                rowKeyValue = sStudyInstanceUid;
                rowKeyName  = "StudyInstanceUID";
                viewName    = "Studies";

                matchingParamList.Add(studyEntity);
            }
            else if (string.Compare(originalRow.Table.TableName, DataTableHelper.PatientTableName) == 0)
            {
                string         sPatientId    = RegisteredDataRows.PatientInfo.GetElementValue(originalRow, DicomTag.PatientID);
                ICatalogEntity patientEntity = RegisteredEntities.GetPatientEntity(sPatientId);

                rowKeyValue = sPatientId;
                rowKeyName  = "PatientId";
                viewName    = "Patients";

                matchingParamList.Add(patientEntity);
            }
            else
            {
                throw new ApplicationException("Row is not a valid DICOM format.");
            }

            return(matchingParamCollection);
        }
Example #3
0
        public static void RegisterInterfaces()
        {
#if TUTORIAL_CUSTOM_DATABASE
            // The 'RegisterInterfaces' method is implemented as part of the "Changing the LEAD HTML5 Medical Viewer to use a different database schema" tutorial.
            // For the tutorial, 'RegisterInterfaces' is used to register custom classes that you define to interact with a custom database.
            // For the shipping version, the 'RegisterInterfaces' does nothing
            //
            // Since the WCF services are stateless (below), this method is called before using any of the services.
            // The AddinsFactory class is used to generate the addins required by each of the services.
            // So the AddinsFactory constructor calls 'RegisterInterfaces' if it has not already been called.
            //
            // WCF Services:
            // * AuthenticationService
            // * ObjectRetrieveService
            // * PacsQueryService
            // * PACSRetrieveService
            // * StoreService
            //
            // The MyPatientInfo, MyStudyInfo, MySeriesInfo, and MyInstanceInfo classes are used for extracting DICOM data from a System.Data.DataRow.
            // The MyStorageSqlDbDataAccessAgent and MyStorageDataAccessConfigurationView classes are used for accessing your custom database
            // The MyPatient, MyStudy, MySeries, and MyInstance classes are used to generate the WHERE statement of the database query
            // For more details, see the "Changing the LEAD HTML5 Medical Viewer to use a different database schema" tutorial.

            if (!DataAccessServiceLocator.IsRegistered <IPatientInfo>())
            {
                DataAccessServiceLocator.Register <IPatientInfo>(new MyPatientInfo());
            }

            if (!DataAccessServiceLocator.IsRegistered <IStudyInfo>())
            {
                DataAccessServiceLocator.Register <IStudyInfo>(new MyStudyInfo());
            }

            if (!DataAccessServiceLocator.IsRegistered <ISeriesInfo>())
            {
                DataAccessServiceLocator.Register <ISeriesInfo>(new MySeriesInfo());
            }

            if (!DataAccessServiceLocator.IsRegistered <IInstanceInfo>())
            {
                DataAccessServiceLocator.Register <IInstanceInfo>(new MyInstanceInfo());
            }

            if (!DataAccessServices.IsDataAccessServiceRegistered <IStorageDataAccessAgent3>())
            {
                System.Configuration.Configuration configuration     = ServiceUtils.GetGlobalPacsConfig();
                IStorageDataAccessAgent3           storageDataAccess = DataAccessFactory.GetInstance(new MyStorageDataAccessConfigurationView(configuration, ServiceUtils.ProductNameStorageServer, null)).CreateDataAccessAgent <IStorageDataAccessAgent3>();
                DataAccessServices.RegisterDataAccessService <IStorageDataAccessAgent3>(storageDataAccess);
            }

            RegisteredEntities.AddItem(RegisteredEntities.PatientEntityName, typeof(MyPatient));
            RegisteredEntities.AddItem(RegisteredEntities.StudyEntityName, typeof(MyStudy));
            RegisteredEntities.AddItem(RegisteredEntities.SeriesEntityName, typeof(MySeries));
            RegisteredEntities.AddItem(RegisteredEntities.InstanceEntityName, typeof(MyInstance));
#endif
        }
Example #4
0
      private MatchingParameterCollection GetMatchingParameters(string sopInstanceUID)
      {
         MatchingParameterCollection matchingParamCollection = new MatchingParameterCollection();
         MatchingParameterList matchingParamList = new MatchingParameterList();
         // Instance instance = new Instance(sopInstanceUID);
         ICatalogEntity instance = RegisteredEntities.GetInstanceEntity(sopInstanceUID);

         matchingParamList.Add(instance);
         matchingParamCollection.Add(matchingParamList);
         return matchingParamCollection;
      }
Example #5
0
        internal static string FindReferencedFile(
#if LEADTOOLS_V19_OR_LATER
            IExternalStoreDataAccessAgent externalStoreAgent,
#endif // #if LEADTOOLS_V19_OR_LATER
            string sopInstanceUID)
        {
            MatchingParameterCollection          mpc = new MatchingParameterCollection();
            MatchingParameterList                mpl = new MatchingParameterList();
            DataSet /*CompositeInstanceDataSet*/ instanceData;
            IStorageDataAccessAgent              agent = null;
            string referencedFile = string.Empty;

            if (DataAccessServices.IsDataAccessServiceRegistered <IStorageDataAccessAgent>())
            {
                agent = DataAccessServices.GetDataAccessService <IStorageDataAccessAgent>();
            }

            if (agent != null)
            {
                ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(sopInstanceUID);
                mpl.Add(instanceEntity);
                mpc.Add(mpl);

                instanceData = agent.QueryCompositeInstances(mpc);
                if (instanceData.Tables[DataTableHelper.InstanceTableName].Rows.Count == 1)
                {
                    DataRow row = instanceData.Tables[DataTableHelper.InstanceTableName].Rows[0];
                    referencedFile = RegisteredDataRows.InstanceInfo.ReferencedFile(row);

#if (LEADTOOLS_V19_OR_LATER_MEDICAL_EXTERNAL_STORE) || (LEADTOOLS_V19_OR_LATER)
                    if (string.IsNullOrEmpty(referencedFile))
                    {
                        // If empty, it might be on the cloud
                        // Use DicomInstanceRetrieveExternalStoreCommand with cache set to true to copy it locally
                        if (externalStoreAgent == null)
                        {
                            if (DataAccessServices.IsDataAccessServiceRegistered <IExternalStoreDataAccessAgent>())
                            {
                                externalStoreAgent = DataAccessServices.GetDataAccessService <IExternalStoreDataAccessAgent>();
                            }
                        }

                        DicomInstanceRetrieveExternalStoreCommand c = new DicomInstanceRetrieveExternalStoreCommand(agent, externalStoreAgent, AddInsSession.ServiceDirectory, true);
                        DicomDataSet ds = c.GetDicomDataSet(row, out referencedFile);
                    }
#endif // (LEADTOOLS_V19_OR_LATER_MEDICAL_EXTERNAL_STORE) || (LEADTOOLS_V19_OR_LATER)
                }
            }
            return(referencedFile);
        }
Example #6
0
        private void RetrieveSceneEntitiesFromServer()
        {
            if (SceneEntitiesToSynchronize.Count > 0)
            {
                var entity = (SceneEntity)SceneEntitiesToSynchronize.Dequeue();

                int entityUniqueId = _incomingMessage.ReadVariableInt32();

                if (RegisteredEntities.ContainsKey(entityUniqueId))
                {
                    RegisteredEntities[entityUniqueId] = entity;
                }
                else
                {
                    entity.UniqueId = entityUniqueId;
                    RegisteredEntities.Add(entity.UniqueId, entity);
                }
            }
        }
        private static string GetPatientName(MediaCreationManagement mediaObject)
        {
            string patientName;
            IStorageDataAccessAgent     dataAccess;
            MatchingParameterCollection matchingCollection;
            MatchingParameterList       matchingList;
            CompositeInstanceDataSet    compositeInstance;


            patientName        = string.Empty;
            dataAccess         = DataAccessServices.GetDataAccessService <IStorageDataAccessAgent> ( );
            matchingCollection = new MatchingParameterCollection( );
            matchingList       = new MatchingParameterList( );
            // Instance matchingInstance   = new Instance ( mediaObject.ReferencedSopSequence [ 0 ].SopInstance.ReferencedSopInstanceUid ) ;
            ICatalogEntity matchingInstance = RegisteredEntities.GetInstanceEntity(mediaObject.ReferencedSopSequence [0].SopInstance.ReferencedSopInstanceUid);

            if (null == dataAccess)
            {
                dataAccess = DataAccessFactory.GetInstance(new StorageDataAccessConfigurationView( )).CreateDataAccessAgent <IStorageDataAccessAgent> ( );
            }

            matchingCollection.Add(matchingList);
            matchingList.Add(matchingInstance);

            compositeInstance = dataAccess.QueryCompositeInstances(matchingCollection).ToCompositeInstanceDataSet();

            if (!string.IsNullOrEmpty(compositeInstance.Patient [0].FamilyName))
            {
                patientName += compositeInstance.Patient [0].FamilyName;
            }

            if (!string.IsNullOrEmpty(compositeInstance.Patient [0].GivenName))
            {
                if (!string.IsNullOrEmpty(patientName))
                {
                    patientName += ", ";
                }

                patientName += compositeInstance.Patient [0].GivenName;
            }

            return(patientName);
        }
Example #8
0
        private static DicomDataSet GetFirstReferencedInstanceDataSet
        (
            IStorageDataAccessAgent dataAccess,
            MediaCreationManagement mediaObject)
        {
            MatchingParameterCollection matchingCollection;
            MatchingParameterList       matchingList;
            CompositeInstanceDataSet    compositeInstance;


            matchingCollection = new MatchingParameterCollection( );
            matchingList       = new MatchingParameterList( );
            // Instance instance           = new Instance ( mediaObject.ReferencedSopSequence [ 0 ].SopInstance.ReferencedSopInstanceUid ) ;
            ICatalogEntity instance = RegisteredEntities.GetInstanceEntity(mediaObject.ReferencedSopSequence [0].SopInstance.ReferencedSopInstanceUid);


            matchingCollection.Add(matchingList);
            matchingList.Add(instance);

            compositeInstance = dataAccess.QueryCompositeInstances(matchingCollection).ToCompositeInstanceDataSet();

            if (compositeInstance.Instance.Count > 0)
            {
                DicomDataSet ds;


                ds = new DicomDataSet( );

                ds.Load(compositeInstance.Instance [0].ReferencedFile, DicomDataSetLoadFlags.None);

                return(ds);
            }
            else
            {
                return(null);
            }
        }
Example #9
0
        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);
            }
        }
Example #10
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();
                    }
                }
            }
        }
Example #11
0
      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;
         }
      }
        protected override void OnDoWork(DoWorkEventArgs e)
        {
            int count = 0;
            int imagesToExportCount   = 0;
            InstanceCStoreCommand cmd = null;

            MatchingParameterCollection matchingParamCollection;
            MatchingParameterList       matchingParamList;

            if (this.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            ExportDicomWorkerArgs args = e.Argument as ExportDicomWorkerArgs;

            if (args == null)
            {
                throw new ArgumentException("Invalid ExportDicom argument");
            }

            if (args.CreateDicomDir)
            {
                DicomDirectory = new DicomDir(args.OutputFolder);
            }

            if (args.Anonymize)
            {
                Anonymizer.BeginBatch();
            }

            try
            {
                ViewGenerator.ViewDataRow[] exportRows = (args.Rows);

                imagesToExportCount = exportRows.Length;

                foreach (ViewGenerator.ViewDataRow exportRow in exportRows)
                {
                    try
                    {
                        string rowKeyValue;
                        string rowKeyName;
                        string viewName;

                        if (this.CancellationPending)
                        {
                            e.Cancel = true;

                            return;
                        }

                        DataRow originalRow = exportRow.OriginalRow;
                        matchingParamCollection = new MatchingParameterCollection( );
                        matchingParamList       = new MatchingParameterList( );

                        matchingParamCollection.Add(matchingParamList);

                        if (string.Compare(originalRow.Table.TableName, DataTableHelper.InstanceTableName) == 0)
                        {
                            string         sSopInstanceUid = RegisteredDataRows.InstanceInfo.GetElementValue(originalRow, DicomTag.SOPInstanceUID);
                            ICatalogEntity imageInstance   = RegisteredEntities.GetInstanceEntity(sSopInstanceUid);

                            rowKeyValue = sSopInstanceUid;
                            rowKeyName  = "SOPInstanceUID";
                            viewName    = "Images";

                            matchingParamList.Add(imageInstance);
                        }
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.SeriesTableName) == 0)
                        {
                            string         sSeriesInstanceUid = RegisteredDataRows.SeriesInfo.GetElementValue(originalRow, DicomTag.SeriesInstanceUID);
                            ICatalogEntity seriesEntity       = RegisteredEntities.GetSeriesEntity(sSeriesInstanceUid);

                            rowKeyValue = sSeriesInstanceUid;
                            rowKeyName  = "SeriesInstanceUID";
                            viewName    = "Series";

                            matchingParamList.Add(seriesEntity);
                        }
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.StudyTableName) == 0)
                        {
                            string         sStudyInstanceUid = RegisteredDataRows.StudyInfo.GetElementValue(originalRow, DicomTag.StudyInstanceUID);
                            ICatalogEntity studyEntity       = RegisteredEntities.GetStudyEntity(sStudyInstanceUid);

                            rowKeyValue = sStudyInstanceUid;
                            rowKeyName  = "StudyInstanceUID";
                            viewName    = "Studies";

                            matchingParamList.Add(studyEntity);
                        }
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.PatientTableName) == 0)
                        {
                            string         sPatientId    = RegisteredDataRows.PatientInfo.GetElementValue(originalRow, DicomTag.PatientID);
                            ICatalogEntity patientEntity = RegisteredEntities.GetPatientEntity(sPatientId);

                            rowKeyValue = sPatientId;
                            rowKeyName  = "PatientId";
                            viewName    = "Patients";

                            matchingParamList.Add(patientEntity);
                        }
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.HangingProtocolTableName) == 0)
                        {
                            string         sSopInstanceUid         = RegisteredDataRows.InstanceInfo.GetElementValue(originalRow, DicomTag.SOPInstanceUID);
                            ICatalogEntity hangingProtocolInstance = RegisteredEntities.GetHangingProtocolEntity(sSopInstanceUid);

                            rowKeyValue = sSopInstanceUid;
                            rowKeyName  = "SOPInstanceUID";
                            viewName    = "Hanging Protocol";

                            matchingParamList.Add(hangingProtocolInstance);
                        }
                        else
                        {
                            throw new ApplicationException("Deleted row is not a valid DICOM format.");
                        }

                        DataSet   exportDataSet = null;
                        DataRow[] rows          = null;

                        if (string.Compare(originalRow.Table.TableName, DataTableHelper.HangingProtocolTableName) == 0 && _dataAccessAgent3 != null)
                        {
                            exportDataSet = _dataAccessAgent3.QueryHangingProtocol(matchingParamCollection);
                            rows          = exportDataSet.Tables[DataTableHelper.HangingProtocolTableName].Select();
                        }
                        else
                        {
                            exportDataSet = _dataAccessAgent.QueryCompositeInstances(matchingParamCollection);
                            rows          = exportDataSet.Tables[DataTableHelper.InstanceTableName].Select();
                        }

                        foreach (DataRow row in rows)
                        {
                            DicomDataSet dicomDataSet = RegisteredDataRows.InstanceInfo.LoadDicomDataSet(row);

                            if (args.Anonymize)
                            {
                                Anonymizer.Anonymize(dicomDataSet);
                            }

                            AddDicomBackgroundWorker.StoreClientSessionProxy proxy = new AddDicomBackgroundWorker.StoreClientSessionProxy();
                            proxy.AffectedSOPInstance = dicomDataSet.GetValue <string>(DicomTag.SOPInstanceUID, string.Empty);
                            proxy.AbstractClass       = dicomDataSet.GetValue <string>(DicomTag.SOPClassUID, string.Empty);


                            try
                            {
                                cmd = new InstanceCStoreCommand(proxy, dicomDataSet, _dataAccessAgent);

                                OnStoreCommandCreated(this, new StoreCommandEventArgs(cmd));

                                cmd.Configuration.DataSetStorageLocation = args.OutputFolder;
#if (LEADTOOLS_V19_OR_LATER)
                                cmd.Configuration.HangingProtocolLocation = args.OutputFolder;
#endif

                                string fileLocation = CStoreCommand.GetStorageFullPath(cmd.Configuration, dicomDataSet);
                                if (args.Overwrite || !File.Exists(fileLocation))
                                {
                                    // Only exporting, so do not validate SopInstance and do not add to database
                                    cmd.DoValidateSopInstance      = false;
                                    cmd.DoUpdateDatabase           = false;
                                    cmd.DoUseExternalStoreSettings = false;
                                    cmd.DataSetStored += cmd_DataSetStored;

                                    cmd.Execute();
                                }
                                else
                                {
                                    // File already exists -- it is not overwritten
                                    DataSetStoredEventArgs storedArgs = new DataSetStoredEventArgs(dicomDataSet, string.Empty, string.Empty, fileLocation);
                                    cmd_DataSetStored(this, storedArgs);
                                }
                            }
                            finally
                            {
                                if (cmd != null)
                                {
                                    cmd.DataSetStored -= cmd_DataSetStored;
                                }
                            }
                        }

                        count++;

                        ExportDicomWorkerProgressState state = new ExportDicomWorkerProgressState( );

                        state.Error               = null;
                        state.CurrentCount        = count;
                        state.ExportRow           = exportRow;
                        state.ExportedImagesCount = 1;
                        state.TotalCount          = imagesToExportCount;
                        state.RowKeyValue         = rowKeyValue;
                        state.RowKeyName          = rowKeyName;
                        state.ViewName            = viewName;

                        ReportProgress((count * 100) / exportRows.Length, state);
                    }
                    catch (Exception exception)
                    {
                        ExportDicomWorkerProgressState state = new ExportDicomWorkerProgressState( );

                        count++;

                        state.Error               = exception;
                        state.CurrentCount        = count;
                        state.ExportRow           = exportRow;
                        state.TotalCount          = imagesToExportCount;
                        state.ExportedImagesCount = 0;

                        ReportProgress((count * 100) / exportRows.Length, state);
                    }
                }
            }
            finally
            {
                e.Result = imagesToExportCount;
                if (DicomDirectory != null)
                {
                    DicomDirectory.Save();
                    DicomDirectory = null;
                }

                if (Anonymizer != null)
                {
                    Anonymizer.EndBatch();
                    Anonymizer = null;
                }
            }
        }
Example #13
0
        /// <summary>
        /// Listens to all data received from the network interface
        /// </summary>
        public override void ListenIncoming()
        {
            if (CommandsToSynchronize.Count != 0)
            {
                int count = CommandsToSynchronize.Count;
                for (int i = 0; i < count; i++)
                {
                    Command command = CommandsToSynchronize.Dequeue();

                    if (command.Id == 0 && command.Id != command.LocalId)
                    {
                        CommandsToSynchronize.Enqueue(command);
                    }
                    else
                    {
                        Commands.Add(command.Id, command);
                    }
                }
            }

            if (SceneEntitiesToSynchronize.Count != 0)
            {
                int count = SceneEntitiesToSynchronize.Count;
                for (int i = 0; i < count; i++)
                {
                    ISceneEntity sceneEntity = SceneEntitiesToSynchronize.Dequeue();

                    if (!RegisteredEntities.ContainsKey(sceneEntity.UniqueId))
                    {
                        RegisteredEntities.Add(sceneEntity.UniqueId, sceneEntity);
                    }
                }
            }

            if (_executeCommands.Count != 0)
            {
                foreach (var executeCommand in _executeCommands)
                {
                    _processingCommands.Add(executeCommand.Key, executeCommand.Value);
                }
                _executeCommands.Clear();

                foreach (var processingCommand in _processingCommands)
                {
                    Command command   = processingCommand.Key;
                    ushort  execution = processingCommand.Value;

                    if (execution == Constants.ExecuteCommandOnServerDataExchanged || execution == Constants.ExecuteCommandOnServerNoDataExchanged)
                    {
                        if (command.Condition == null || (command.Condition.Invoke()))
                        {
                            command.NetworkValue = command.ServerExecution(command, command.NetworkValue);
                        }

                        if (command.ApplyServerResult != null)
                        {
                            ExecuteServerCommandOnClients(command);
                        }
                        else
                        {
                            command.WaitingForServerReply = false;
                        }
                    }
                    else if (execution == Constants.ExecuteServerCommandOnClientsDataExchanged || execution == Constants.ExecuteServerCommandOnClientsNoDataExchanged)
                    {
                        command.WaitingForServerReply = false;
                        command.ApplyServerResult(command, command.NetworkValue);
                    }
                }

                _processingCommands.Clear();
            }
        }
Example #14
0
        /// <summary>
        /// Listens to all data received from the network interface
        /// </summary>
        public override void ListenIncoming()
        {
            // we loop on all LocalPlayers to gather network data
            foreach (LiveIdentifiedPlayer identifiedPlayer in LocalPlayers)
            {
                var gamer = (LocalNetworkGamer)identifiedPlayer.LiveGamer;

                while (gamer.IsDataAvailable)
                {
                    NetworkGamer sender;

                    gamer.ReceiveData(_packetReader, out sender);

                    byte message = _packetReader.ReadByte();

                    // If the message is to execute commands on server, we execute them and ask all clients to execute them with the server computed value
                    if (message == Constants.ExecuteCommandOnServerDataExchanged)
                    {
                        if (!gamer.IsHost)
                        {
                            throw new CoreException("Gamer isn't host");
                        }

                        ushort commandId = _packetReader.ReadUInt16();

                        Command command = Commands[commandId];

                        if (command.NetworkValueType == typeof(bool))
                        {
                            command.NetworkValue = _packetReader.ReadBoolean();
                        }
                        else if (command.NetworkValueType == typeof(byte))
                        {
                            command.NetworkValue = _packetReader.ReadByte();
                        }
                        else if (command.NetworkValueType == typeof(byte[]))
                        {
                            int tempNumberOfBytes = _packetReader.ReadInt32();
                            command.NetworkValue = _packetReader.ReadBytes(tempNumberOfBytes);
                        }
                        else if (command.NetworkValueType == typeof(char))
                        {
                            command.NetworkValue = _packetReader.ReadChar();
                        }
                        else if (command.NetworkValueType == typeof(char[]))
                        {
                            int tempNumberOfChars = _packetReader.ReadInt32();
                            command.NetworkValue = _packetReader.ReadChars(tempNumberOfChars);
                        }
                        else if (command.NetworkValueType == typeof(Color))
                        {
                            command.NetworkValue = _packetReader.ReadColor();
                        }
                        else if (command.NetworkValueType == typeof(double))
                        {
                            command.NetworkValue = _packetReader.ReadDouble();
                        }
                        else if (command.NetworkValueType == typeof(float))
                        {
                            command.NetworkValue = _packetReader.ReadSingle();
                        }
                        else if (command.NetworkValueType == typeof(int))
                        {
                            command.NetworkValue = _packetReader.ReadInt32();
                        }
                        else if (command.NetworkValueType == typeof(long))
                        {
                            command.NetworkValue = _packetReader.ReadInt64();
                        }
                        else if (command.NetworkValueType == typeof(Matrix))
                        {
                            command.NetworkValue = _packetReader.ReadMatrix();
                        }
                        else if (command.NetworkValueType == typeof(Quaternion))
                        {
                            command.NetworkValue = _packetReader.ReadQuaternion();
                        }
                        else if (command.NetworkValueType == typeof(sbyte))
                        {
                            command.NetworkValue = _packetReader.ReadSByte();
                        }
                        else if (command.NetworkValueType == typeof(short))
                        {
                            command.NetworkValue = _packetReader.ReadInt16();
                        }
                        else if (command.NetworkValueType == typeof(string))
                        {
                            command.NetworkValue = _packetReader.ReadString();
                        }
                        else if (command.NetworkValueType == typeof(uint))
                        {
                            command.NetworkValue = _packetReader.ReadUInt32();
                        }
                        else if (command.NetworkValueType == typeof(ulong))
                        {
                            command.NetworkValue = _packetReader.ReadInt64();
                        }
                        else if (command.NetworkValueType == typeof(ushort))
                        {
                            command.NetworkValue = _packetReader.ReadUInt16();
                        }
                        else if (command.NetworkValueType == typeof(Vector2))
                        {
                            command.NetworkValue = _packetReader.ReadVector2();
                        }
                        else if (command.NetworkValueType == typeof(Vector3))
                        {
                            command.NetworkValue = _packetReader.ReadVector3();
                        }
                        else if (command.NetworkValueType == typeof(Vector4))
                        {
                            command.NetworkValue = _packetReader.ReadVector4();
                        }

                        if (command.NetworkValue == null)
                        {
                            throw new CoreException("No value transfered");
                        }

                        if (command.Condition == null || (command.Condition.Invoke()))
                        {
                            command.NetworkValue = command.ServerExecution(command, command.NetworkValue);
                        }

                        if (command.ApplyServerResult != null)
                        {
                            ExecuteServerCommandOnClients(command);
                        }
                        else
                        {
                            command.WaitingForServerReply = false;
                        }
                    }
                    // Some Commands may not return values and ask the server to compute it for all clients
                    else if (message == Constants.ExecuteCommandOnServerNoDataExchanged)
                    {
                        if (!gamer.IsHost)
                        {
                            throw new CoreException("Gamer isn't host");
                        }

                        ushort commandId = _packetReader.ReadUInt16();

                        Command command = Commands[commandId];

                        if (command.Condition == null || (command.Condition.Invoke()))
                        {
                            command.NetworkValue = command.ServerExecution(command, null);
                        }

                        if (command.ApplyServerResult != null)
                        {
                            ExecuteServerCommandOnClients(command);
                        }
                        else
                        {
                            command.WaitingForServerReply = false;
                        }
                    }
                    else if (message == Constants.SynchronizeCommandOnClient)
                    {
                        if (CommandsToSynchronize.Count > 0)
                        {
                            Command command = CommandsToSynchronize.Dequeue();

                            ushort commandId = _packetReader.ReadUInt16();

                            if (Commands.ContainsKey(commandId))
                            {
                                Commands[commandId] = command;
                            }
                            else
                            {
                                command.Id = commandId;
                                Commands.Add(command.Id, command);
                            }
                        }
                    }
                    else if (message == Constants.SynchronizeSceneEntitiesOnClient)
                    {
                        if (SceneEntitiesToSynchronize.Count > 0)
                        {
                            SceneEntity entity = (SceneEntity)SceneEntitiesToSynchronize.Dequeue();

                            var entityUniqueId = _packetReader.ReadInt32();

                            if (RegisteredEntities.ContainsKey(entityUniqueId))
                            {
                                RegisteredEntities[entityUniqueId] = entity;
                            }
                            else
                            {
                                entity.UniqueId = entityUniqueId;
                                RegisteredEntities.Add(entity.UniqueId, entity);
                            }
                        }
                    }
                    else if (message == Constants.SynchronizationDoneOnClient)
                    {
                        if (!gamer.IsHost)
                        {
                            throw new CoreException("Gamer isn't host");
                        }

                        var synchronizedPlayers = new List <IdentifiedPlayer>();

                        if (sender.IsLocal)
                        {
                            foreach (var player in PlayersToSynchronize)
                            {
                                if (player.IsLocal)
                                {
                                    synchronizedPlayers.Add(player);
                                }
                            }
                        }
                        else
                        {
                            var senderMachine = sender.Machine;

                            foreach (var player in PlayersToSynchronize)
                            {
                                if (!player.IsLocal)
                                {
                                    if (((NetworkGamer)((LiveIdentifiedPlayer)player).LiveGamer).Machine.Equals(senderMachine))
                                    {
                                        synchronizedPlayers.Add(player);
                                    }
                                }
                            }
                        }

                        if (synchronizedPlayers.Count > 0)
                        {
                            foreach (var synchronizedPlayer in synchronizedPlayers)
                            {
                                PlayersToSynchronize.Remove(synchronizedPlayer);
                            }

                            if (PlayersToSynchronize.Count == 0)
                            {
                                _sessionState = SessionState.Playing;
                                OnStarted();
                            }
                        }
                    }
                    else
                    {
                        ushort commandId = _packetReader.ReadUInt16();

                        Command command = Commands[commandId];

                        command.WaitingForServerReply = false;

                        object networkValue = null;

                        if (message == Constants.ExecuteServerCommandOnClientsDataExchanged)
                        {
                            if (command.NetworkValueType == typeof(bool))
                            {
                                networkValue = _packetReader.ReadBoolean();
                            }
                            else if (command.NetworkValueType == typeof(byte))
                            {
                                networkValue = _packetReader.ReadByte();
                            }
                            else if (command.NetworkValueType == typeof(byte[]))
                            {
                                int tempNumberOfBytes = _packetReader.ReadInt32();
                                networkValue = _packetReader.ReadBytes(tempNumberOfBytes);
                            }
                            else if (command.NetworkValueType == typeof(char))
                            {
                                networkValue = _packetReader.ReadChar();
                            }
                            else if (command.NetworkValueType == typeof(char[]))
                            {
                                int tempNumberOfChars = _packetReader.ReadInt32();
                                networkValue = _packetReader.ReadChars(tempNumberOfChars);
                            }
                            else if (command.NetworkValueType == typeof(Color))
                            {
                                networkValue = _packetReader.ReadColor();
                            }
                            else if (command.NetworkValueType == typeof(double))
                            {
                                networkValue = _packetReader.ReadDouble();
                            }
                            else if (command.NetworkValueType == typeof(float))
                            {
                                networkValue = _packetReader.ReadSingle();
                            }
                            else if (command.NetworkValueType == typeof(int))
                            {
                                networkValue = _packetReader.ReadInt32();
                            }
                            else if (command.NetworkValueType == typeof(long))
                            {
                                networkValue = _packetReader.ReadInt64();
                            }
                            else if (command.NetworkValueType == typeof(Matrix))
                            {
                                networkValue = _packetReader.ReadMatrix();
                            }
                            else if (command.NetworkValueType == typeof(Quaternion))
                            {
                                networkValue = _packetReader.ReadQuaternion();
                            }
                            else if (command.NetworkValueType == typeof(sbyte))
                            {
                                networkValue = _packetReader.ReadSByte();
                            }
                            else if (command.NetworkValueType == typeof(short))
                            {
                                networkValue = _packetReader.ReadInt16();
                            }
                            else if (command.NetworkValueType == typeof(string))
                            {
                                networkValue = _packetReader.ReadString();
                            }
                            else if (command.NetworkValueType == typeof(uint))
                            {
                                networkValue = _packetReader.ReadUInt32();
                            }
                            else if (command.NetworkValueType == typeof(ulong))
                            {
                                networkValue = _packetReader.ReadInt64();
                            }
                            else if (command.NetworkValueType == typeof(ushort))
                            {
                                networkValue = _packetReader.ReadUInt16();
                            }
                            else if (command.NetworkValueType == typeof(Vector2))
                            {
                                networkValue = _packetReader.ReadVector2();
                            }
                            else if (command.NetworkValueType == typeof(Vector3))
                            {
                                networkValue = _packetReader.ReadVector3();
                            }
                            else if (command.NetworkValueType == typeof(Vector4))
                            {
                                networkValue = _packetReader.ReadVector4();
                            }
                        }

                        command.ApplyServerResult(command, networkValue);
                    }
                }
            }
        }
        protected override void OnDoWork(DoWorkEventArgs e)
        {
            int count;
            int totalDeletedImagesCount;

            ViewGenerator.ViewDataRow [] deleteRows;


            count = 0;
            totalDeletedImagesCount = 0;

            try
            {
                MatchingParameterCollection matchingParamCollection;
                MatchingParameterList       matchingParamList;


                if (this.CancellationPending)
                {
                    e.Cancel = true;

                    return;
                }

                if (!(e.Argument is ViewGenerator.ViewDataRow []))
                {
                    throw new ArgumentException("Invalid RemoveDicom argument");
                }

                deleteRows = (e.Argument as ViewGenerator.ViewDataRow []);

                foreach (ViewGenerator.ViewDataRow deletedRow in deleteRows)
                {
                    try
                    {
                        DataRow originalRow;
                        int     deletedImagesCount;
                        string  rowKeyValue;
                        string  rowKeyName;
                        string  viewName;


                        if (this.CancellationPending)
                        {
                            e.Cancel = true;

                            return;
                        }

                        originalRow             = deletedRow.OriginalRow;
                        matchingParamCollection = new MatchingParameterCollection( );
                        matchingParamList       = new MatchingParameterList( );

                        matchingParamCollection.Add(matchingParamList);

                        // if ( originalRow is CompositeInstanceDataSet.InstanceRow )
                        if (string.Compare(originalRow.Table.TableName, DataTableHelper.InstanceTableName) == 0)
                        {
                            // imageInstance = new Instance( ( ( CompositeInstanceDataSet.InstanceRow ) originalRow ).SOPInstanceUID ) ;
                            string         sSopInstanceUid = RegisteredDataRows.InstanceInfo.GetElementValue(originalRow, DicomTag.SOPInstanceUID);
                            ICatalogEntity imageInstance   = RegisteredEntities.GetInstanceEntity(sSopInstanceUid);


                            rowKeyValue = sSopInstanceUid;
                            rowKeyName  = "SOPInstanceUID";
                            viewName    = "Images";

                            matchingParamList.Add(imageInstance);
                        }
                        // else if ( originalRow is CompositeInstanceDataSet.SeriesRow )
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.SeriesTableName) == 0)
                        {
                            // ICatalogEntity seriesEntity ;


                            // seriesEntity = new Series ( ( ( CompositeInstanceDataSet.SeriesRow ) originalRow ).SeriesInstanceUID ) ;
                            string         sSeriesInstanceUid = RegisteredDataRows.SeriesInfo.GetElementValue(originalRow, DicomTag.SeriesInstanceUID);
                            ICatalogEntity seriesEntity       = RegisteredEntities.GetSeriesEntity(sSeriesInstanceUid);
                            // seriesEntity = new Series ( ( ( CompositeInstanceDataSet.SeriesRow ) originalRow ).SeriesInstanceUID ) ;


                            rowKeyValue = sSeriesInstanceUid;
                            rowKeyName  = "SeriesInstanceUID";
                            viewName    = "Series";

                            matchingParamList.Add(seriesEntity);
                        }
                        // else if ( originalRow is CompositeInstanceDataSet.StudyRow )
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.StudyTableName) == 0)
                        {
                            // Study studyEntity = new Study ( ( ( CompositeInstanceDataSet.StudyRow ) originalRow ).StudyInstanceUID ) ;
                            string         sStudyInstanceUid = RegisteredDataRows.StudyInfo.GetElementValue(originalRow, DicomTag.StudyInstanceUID);
                            ICatalogEntity studyEntity       = RegisteredEntities.GetStudyEntity(sStudyInstanceUid);

                            rowKeyValue = sStudyInstanceUid;
                            rowKeyName  = "StudyInstanceUID";
                            viewName    = "Studies";

                            matchingParamList.Add(studyEntity);
                        }
                        // else if ( originalRow is CompositeInstanceDataSet.PatientRow )
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.PatientTableName) == 0)
                        {
                            // Patient patientEntity = new Patient ( ( ( CompositeInstanceDataSet.PatientRow ) originalRow ).PatientID ) ;
                            string         sPatientId    = RegisteredDataRows.PatientInfo.GetElementValue(originalRow, DicomTag.PatientID);
                            ICatalogEntity patientEntity = RegisteredEntities.GetPatientEntity(sPatientId);

                            rowKeyValue = sPatientId;
                            rowKeyName  = "PatientId";
                            viewName    = "Patients";

                            matchingParamList.Add(patientEntity);
                        }
#if (LEADTOOLS_V19_OR_LATER)
                        else if (string.Compare(originalRow.Table.TableName, DataTableHelper.HangingProtocolTableName) == 0)
                        {
                            string         sSopInstanceUid         = RegisteredDataRows.InstanceInfo.GetElementValue(originalRow, DicomTag.SOPInstanceUID);
                            ICatalogEntity hangingProtocolInstance = RegisteredEntities.GetHangingProtocolEntity(sSopInstanceUid);


                            rowKeyValue = sSopInstanceUid;
                            rowKeyName  = "SOPInstanceUID";
                            viewName    = "Hanging Protocol";

                            matchingParamList.Add(hangingProtocolInstance);
                        }
#endif
                        else
                        {
                            throw new ApplicationException("Deleted row is not a valid DICOM format.");
                        }

#if (LEADTOOLS_V19_OR_LATER)
                        if (string.Compare(originalRow.Table.TableName, DataTableHelper.HangingProtocolTableName) == 0 && _dataAccessAgent3 != null)
                        {
                            deletedImagesCount = _dataAccessAgent3.DeleteHangingProtocol(matchingParamCollection);
                        }
                        else
                        {
                            deletedImagesCount = _dataAccessAgent.DeleteInstance(matchingParamCollection);
                        }
#else
                        deletedImagesCount = _dataAccessAgent.DeleteInstance(matchingParamCollection);
#endif

                        count++;

                        RemoveDiconWorkerProgressState state;


                        state = new RemoveDiconWorkerProgressState( );

                        totalDeletedImagesCount += deletedImagesCount;

                        state.Error              = null;
                        state.CurrentCount       = count;
                        state.DeletedRow         = deletedRow;
                        state.RemovedImagesCount = deletedImagesCount;
                        state.TotalCount         = totalDeletedImagesCount;
                        state.RowKeyValue        = rowKeyValue;
                        state.RowKeyName         = rowKeyName;
                        state.ViewName           = viewName;

                        ReportProgress((count * 100) / deleteRows.Length, state);
                    }
                    catch (Exception exception)
                    {
                        RemoveDiconWorkerProgressState state;


                        state = new RemoveDiconWorkerProgressState( );

                        count++;

                        state.Error              = exception;
                        state.CurrentCount       = count;
                        state.DeletedRow         = deletedRow;
                        state.TotalCount         = totalDeletedImagesCount;
                        state.RemovedImagesCount = 0;

                        ReportProgress((count * 100) / deleteRows.Length, state);
                    }
                }
            }
            finally
            {
                e.Result = totalDeletedImagesCount;
            }
        }
Example #16
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;
                }
            }
        }