Esempio n. 1
0
 public virtual bool ShowDialog(ref ICatalogEntity entity, bool isNew, bool readOnly)
 {
     _isNew    = isNew;
     _entity   = entity;
     _readOnly = readOnly;
     return(ShowDialog() == DialogResult.OK);
 }
Esempio n. 2
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());
        }
Esempio n. 3
0
        public override void WriteEntity(XmlWriter xmlWriter, ICatalogEntity entity)
        {
            if (!(entity is Book book))
            {
                throw new ArgumentException($"provided {nameof(entity)} is null or not of type {nameof(Book)}");
            }

            var element = new XElement("book");

            AddAttribute(element, "name", book.Name);
            AddAttribute(element, "publicationCity", book.PublicationCity);
            AddAttribute(element, "publisherName", book.PublisherName);
            AddAttribute(element, "publishYear", book.PublishYear.ToString());
            AddAttribute(element, "pagesCount", book.PagesCount.ToString());
            AddAttribute(element, "isbn", book.IsbnNumber);
            AddElement(element, "note", book.Note);
            AddElement(element, "authors",
                       book.Authors?.Select(a => new XElement("author",
                                                              new XAttribute("name", a.Name),
                                                              new XAttribute("surname", a.Surname)
                                                              ))
                       );

            element.WriteTo(xmlWriter);
        }
Esempio n. 4
0
        public override void Click(enumContextKeys key)
        {
            switch (key)
            {
            case enumContextKeys.AddFeatureClass:
                using (frmFetClassDlg frm = new frmFetClassDlg())
                {
                    ICatalogEntity entity = new SpatialFeatureClass();
                    frm.SetSpatialDataset(_tag as SpatialFeatureDataset);
                    (entity as CatalogEntityBase)._connString = (_tag as CatalogEntityBase)._connString;
                    if (frm.ShowDialog(ref entity, true, false))
                    {
                        if ((entity as SpatialFeatureClass).SpatialRef == null)
                        {
                            (entity as SpatialFeatureClass).SpatialRef = (_tag as SpatialFeatureDataset).SpatialRef;
                        }
                        entity.Store();
                        AddChild(new CatalogFeatureClass(entity.Name, entity, entity.Description));
                    }
                }
                Refresh();
                break;

            case enumContextKeys.Property:
                using (frmFeatureDatasetsEditor frm = new frmFeatureDatasetsEditor())
                {
                    ICatalogEntity entity = _tag as ICatalogEntity;
                    if (frm.ShowDialog(ref entity, false, false))
                    {
                        entity.Store();
                        Refresh();
                    }
                }
                break;

            case enumContextKeys.Delete:
                if (MsgBox.ShowQuestionYesNo("确定要删除要素集\"" + _name + "\"吗?\n\n删除以后不能恢复。") == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
                SpatialFeatureDataset ds = _tag as SpatialFeatureDataset;
                using (ICatalogEntityClass c = new CatalogEntityClassFeatureDataset(ds._connString))
                {
                    c.Delete(ds);
                    ICatalogItem pIt = _parent;
                    _parent.Remove(this);
                    pIt.Refresh();
                }
                break;

            case enumContextKeys.ImportData:
                ImportData();
                break;

            default:
                base.Click(key);
                break;
            }
        }
        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);
        }
Esempio n. 6
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;
      }
Esempio n. 7
0
 public bool IsExist(ICatalogEntity entity)
 {
     using (IDbCommand cmd = _dbConnection.CreateCommand())
     {
         string sql = "select count(*) from " + GetTableName() + " where id='" + entity.Id + "'";
         cmd.CommandText = sql;
         object v   = cmd.ExecuteScalar();
         int    ret = int.Parse(v.ToString());
         return(ret > 0);
     }
 }
Esempio n. 8
0
        private void btnDataset_Click(object sender, EventArgs e)
        {
            ICatalogEntity c = txtDataset.Tag as ICatalogEntity;

            if (c == null)
            {
                return;
            }
            using (frmFeatureDatasetsEditor frm = new frmFeatureDatasetsEditor())
            {
                frm.ShowDialog(ref c, false, true);
            }
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        public void Insert(ICatalogEntity entity)
        {
            FieldAttAndValue[] fvs = GetFieldAttAndValues(entity);
            StringBuilder      sb  = new StringBuilder();

            sb.Append("insert into " + GetTableName() + "(");
            //fields
            for (int i = 0; i < fvs.Length; i++)
            {
                if (i == fvs.Length - 1)
                {
                    sb.Append(fvs[i].FieldAtt.FieldName + ") ");
                }
                else
                {
                    sb.Append(fvs[i].FieldAtt.FieldName + ",");
                }
            }
            //values
            sb.Append("values(");
            for (int i = 0; i < fvs.Length; i++)
            {
                if (i == fvs.Length - 1)
                {
                    sb.Append(FieldValueToSqlExp(fvs[i].FieldAtt.FieldType, fvs[i].Value) + ")");
                }
                else
                {
                    sb.Append(FieldValueToSqlExp(fvs[i].FieldAtt.FieldType, fvs[i].Value) + ",");
                }
            }
            //submit
            using (IDbCommand cmd = _dbConnection.CreateCommand())
            {
                try
                {
                    TransactionManager.BeginTransaction(_dbConnection, cmd);
                    cmd.CommandText = sb.ToString();
                    int ret = cmd.ExecuteNonQuery();
                    TransactionManager.Commit();
                }
                catch
                {
                    TransactionManager.Rollback();
                    throw;
                }
            }
        }
Esempio n. 11
0
        public void Update(ICatalogEntity entity)
        {
            FieldAttAndValue[] fvs = GetFieldAttAndValues(entity);
            StringBuilder      sb  = new StringBuilder();

            sb.Append("update " + GetTableName() + " set ");
            //fields
            for (int i = 0; i < fvs.Length; i++)
            {
                if (fvs[i].FieldAtt.FieldName.ToUpper() == "ID")
                {
                    continue;
                }
                if (i == fvs.Length - 1)
                {
                    sb.Append(fvs[i].FieldAtt.FieldName + " = " + FieldValueToSqlExp(fvs[i].FieldAtt.FieldType, fvs[i].Value));
                }
                else
                {
                    sb.Append(fvs[i].FieldAtt.FieldName + " = " + FieldValueToSqlExp(fvs[i].FieldAtt.FieldType, fvs[i].Value) + ",");
                }
            }
            string sql = sb.ToString();

            if (sql.EndsWith(","))
            {
                sql = sql.Substring(0, sql.Length - 1);
            }
            sql = sql + " where id='" + entity.Id + "'";
            using (IDbCommand cmd = _dbConnection.CreateCommand())
            {
                try
                {
                    TransactionManager.BeginTransaction(_dbConnection, cmd);
                    cmd.CommandText = sql;
                    cmd.ExecuteNonQuery();
                    TransactionManager.Commit();
                }
                catch
                {
                    TransactionManager.Rollback();
                    throw;
                }
            }
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
 public virtual void Delete(ICatalogEntity entity)
 {
     using (IDbCommand cmd = _dbConnection.CreateCommand())
     {
         string sql = "delete from " + GetTableName() + " where id='" + entity.Id + "'";
         TransactionManager.BeginTransaction(_dbConnection, cmd);
         try
         {
             cmd.CommandText = sql;
             int ret = cmd.ExecuteNonQuery();
             TransactionManager.Commit();
         }
         catch
         {
             TransactionManager.Rollback();
             throw;
         }
     }
 }
Esempio n. 14
0
        public override void WriteEntity(XmlWriter xmlWriter, ICatalogEntity entity)
        {
            if (!(entity is NewsPaper newsPaper))
            {
                throw new ArgumentException($"provided {nameof(entity)} is null or not of type {nameof(NewsPaper)}");
            }

            var element = new XElement("newspaper");

            AddAttribute(element, "name", newsPaper.Name, true);
            AddAttribute(element, "publicationCity", newsPaper.PublicationCity);
            AddAttribute(element, "publisherName", newsPaper.PublisherName);
            AddAttribute(element, "publishYear", newsPaper.PublishYear.ToString());
            AddAttribute(element, "pagesCount", newsPaper.PagesCount.ToString());
            AddAttribute(element, "date", newsPaper.Date.ToString(CultureInfo.InvariantCulture.DateTimeFormat.ShortDatePattern, CultureInfo.InvariantCulture));
            AddAttribute(element, "issn", newsPaper.IssnNumber, true);
            AddAttribute(element, "number", newsPaper.Number.ToString());
            AddElement(element, "note", newsPaper.Note);
            element.WriteTo(xmlWriter);
        }
Esempio n. 15
0
        private FieldAttAndValue[] GetFieldAttAndValues(ICatalogEntity entity)
        {
            BindingFlags flags = BindingFlags.GetProperty;
            Type         t     = entity.GetType();

            PropertyInfo[]          pInfos = t.GetProperties();
            List <FieldAttAndValue> values = new List <FieldAttAndValue>();

            foreach (PropertyInfo pInfo in pInfos)
            {
                object[] atts = pInfo.GetCustomAttributes(typeof(AttToFieldMapAttribute), true);
                if (atts == null || atts.Length == 0)
                {
                    continue;
                }
                AttToFieldMapAttribute fieldAtt = atts[0] as AttToFieldMapAttribute;
                object fieldValue = t.InvokeMember(pInfo.Name, flags, null, entity, null);
                values.Add(new FieldAttAndValue(fieldAtt, fieldValue));
            }
            return(values.ToArray());
        }
Esempio n. 16
0
        public override void WriteEntity(XmlWriter xmlWriter, ICatalogEntity entity)
        {
            if (!(entity is Patent patent))
            {
                throw new ArgumentException($"provided {nameof(entity)} is null or not of type {nameof(Patent)}");
            }

            var element = new XElement("patent");

            AddAttribute(element, "name", patent.Name);
            AddAttribute(element, "country", patent.Country);
            AddAttribute(element, "registrationNumber", patent.RegistrationNumber);
            AddAttribute(element, "filingDate", GetInvariantShortDateString(patent.FilingDate.Date));
            AddAttribute(element, "publishDate", GetInvariantShortDateString(patent.PublishDate.Date));
            AddAttribute(element, "pagesCount", patent.PagesCount.ToString());
            AddElement(element, "note", patent.Note);
            AddElement(element, "creators", patent.Creators.Select(
                           c => new XElement("creator",
                                             new XAttribute("name", c.Name),
                                             new XAttribute("surname", c.Surname))));
            element.WriteTo(xmlWriter);
        }
Esempio n. 17
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);
            }
        }
Esempio n. 18
0
        public override void Click(enumContextKeys key)
        {
            switch (key)
            {
            case enumContextKeys.Delete:
                if (MsgBox.ShowQuestionYesNo("确定要删除要素类\"" + _name + "\"吗?\n\n删除以后不能恢复。") == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
                SpatialFeatureClass ds = _tag as SpatialFeatureClass;
                using (ICatalogEntityClass c = new CatalogEntityClassFeatureClass(ds._connString))
                {
                    c.Delete(ds);
                    ICatalogItem pIt = _parent;
                    _parent.Remove(this);
                    pIt.Refresh();
                    break;
                }

            case enumContextKeys.Property:
                using (frmFetClassDlg frm = new frmFetClassDlg())
                {
                    ICatalogEntity entity = _tag as ICatalogEntity;
                    if (frm.ShowDialog(ref entity, false, false))
                    {
                        entity.Store();
                        Refresh();
                    }
                }
                break;

            default:
                base.Click(key);
                break;
            }
        }
Esempio n. 19
0
        public void Test_MixedEntities_Write()
        {
            var actualResult = new StringBuilder();
            var sw           = new StringWriter(actualResult);
            var book         = CreateBook();
            var newspaper    = CreateNewspaper();
            var patent       = CreatePatent();
            var entities     = new ICatalogEntity[]
            {
                book,
                newspaper,
                patent
            };
            var expectedResult = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
                                 "<catalog>" +
                                 GetBookXml() +
                                 GetNewspaperXml() +
                                 GetPatentXml() +
                                 "</catalog>";

            _catalog.WriteTo(sw, entities);

            Assert.AreEqual(expectedResult, actualResult.ToString());
        }
Esempio n. 20
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);
            }
        }
Esempio n. 21
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();
                    }
                }
            }
        }
Esempio n. 22
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;
         }
      }
Esempio n. 23
0
 public ICatalogEntity[] Query(ICatalogEntity templateEntity)
 {
     return(Query(templateEntity, null));
 }
        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;
                }
            }
        }
Esempio n. 25
0
        public ICatalogEntity[] Query(ICatalogEntity templateEntity, string where)
        {
            if (templateEntity == null)
            {
                return(null);
            }
            FieldAttAndValue[] fvs = GetFieldAttAndValues(templateEntity);
            StringBuilder      sb  = new StringBuilder();

            sb.Append("select ");
            //fields
            for (int i = 0; i < fvs.Length; i++)
            {
                string fname = fvs[i].FieldAtt.FieldName;
                if (fvs[i].FieldAtt.FieldType.Equals(typeof(Envelope)))
                {
                    fname = _adapter.SQLToWktForShapeField(fname);
                }
                if (i == fvs.Length - 1)
                {
                    sb.Append(fname + " from " + GetTableName() + " t");
                }
                else
                {
                    sb.Append(fname + ",");
                }
            }
            if (where != null)
            {
                sb.Append(" where " + where);
            }
            string sql = sb.ToString();

            if (sql.EndsWith(","))
            {
                sql = sql.Substring(0, sql.Length - 1);
            }
            //query
            using (IDbCommand cmd = _dbConnection.CreateCommand())
            {
                cmd.CommandText = sql;
                using (IDataReader dr = cmd.ExecuteReader())
                {
                    if (dr == null)
                    {
                        return(null);
                    }
                    List <ICatalogEntity> retobjs = new List <ICatalogEntity>();
                    while (dr.Read())
                    {
                        ICatalogEntity c = NewCatalogEntity();
                        //
                        (c as CatalogEntityBase)._connString = _connString;
                        //fill value
                        Type t = c.GetType();
                        for (int i = 0; i < fvs.Length; i++)
                        {
                            t.InvokeMember(fvs[i].FieldAtt.FieldName, BindingFlags.SetProperty, null, c, new object[] { DataReaderToFieldValue(fvs[i].FieldAtt.FieldType, dr, i) });
                        }
                        //
                        (c as CatalogEntityBase)._connString = _connString;
                        //
                        retobjs.Add(c);
                    }
                    return(retobjs.Count > 0 ? retobjs.ToArray() : null);
                }
            }
        }
Esempio n. 26
0
 public override void Delete(ICatalogEntity entity)
 {
     using (IDbCommand cmd = _dbConnection.CreateCommand())
     {
         string sql = null;
         TransactionManager.BeginTransaction(_dbConnection, cmd);
         try
         {
             int ret = 0;
             //delete tables
             sql             = "select datatable,annotable from " + BudGISMetadata.cstFeatureClassTableName + " where datasetid='" + entity.Id + "'";
             cmd.CommandText = sql;
             List <string> dropTables = new List <string>();
             using (IDataReader dr = cmd.ExecuteReader())
             {
                 while (dr.Read())
                 {
                     string tname    = dr.GetString(0);
                     string anntname = dr.GetString(1);
                     if (tname != null)
                     {
                         dropTables.Add(tname);
                     }
                     if (anntname != null)
                     {
                         dropTables.Add(anntname);
                     }
                 }
             }
             if (dropTables.Count > 0)
             {
                 //check table is exist
                 for (int i = dropTables.Count - 1; i >= 0; i--)
                 {
                     sql             = _adapter.GetTableIsExistSql(dropTables[i], _adapter.GetDataSource(_connString));
                     cmd.CommandText = sql;
                     object v = cmd.ExecuteScalar();
                     ret = int.Parse(v.ToString());
                     if (ret < 1)// remove not existed table
                     {
                         dropTables.RemoveAt(i);
                     }
                 }
                 //drop tables
                 foreach (string table in dropTables)
                 {
                     sql             = "drop table " + table;
                     cmd.CommandText = sql;
                     ret             = cmd.ExecuteNonQuery();
                 }
             }
             //delete featureclass
             sql             = "delete from " + BudGISMetadata.cstFeatureClassTableName + " where datasetid='" + entity.Id + "'";
             cmd.CommandText = sql;
             ret             = cmd.ExecuteNonQuery();
             //delete dataset
             sql             = "delete from " + GetTableName() + " where id='" + entity.Id + "'";
             cmd.CommandText = sql;
             ret             = cmd.ExecuteNonQuery();
             TransactionManager.Commit();
         }
         catch
         {
             TransactionManager.Rollback();
             throw;
         }
     }
 }
Esempio n. 27
0
 public override void Delete(ICatalogEntity entity)
 {
     using (IDbCommand cmd = _dbConnection.CreateCommand())
     {
         TransactionManager.BeginTransaction(_dbConnection, cmd);
         string sql = null;
         try
         {
             int ret = 0;
             //delete table
             SpatialFeatureClass fetc = entity as SpatialFeatureClass;
             if (fetc.DataTable != null)
             {
                 //delete fetclass table
                 sql             = _adapter.GetTableIsExistSql(fetc.DataTable, _adapter.GetDataSource(_connString));
                 cmd.CommandText = sql;
                 object v = cmd.ExecuteScalar();
                 ret = int.Parse(v.ToString());
                 if (ret > 0)
                 {
                     sql             = "drop table " + fetc.DataTable;
                     cmd.CommandText = sql;
                     ret             = cmd.ExecuteNonQuery();
                     //delete spatialindex metadata
                     sql = _adapter.DeleteSpatiaoIndexMetadata(fetc.DataTable);
                     if (sql != null)
                     {
                         cmd.CommandText = sql;
                         cmd.ExecuteNonQuery();
                     }
                 }
                 //delete ann table
                 sql             = _adapter.GetTableIsExistSql(fetc.AnnoTable, _adapter.GetDataSource(_connString));
                 cmd.CommandText = sql;
                 v   = cmd.ExecuteScalar();
                 ret = int.Parse(v.ToString());
                 if (ret > 0)
                 {
                     sql             = "drop table " + fetc.AnnoTable;
                     cmd.CommandText = sql;
                     ret             = cmd.ExecuteNonQuery();
                     //delete spatialindex metadata
                     sql = _adapter.DeleteSpatiaoIndexMetadata(fetc.AnnoTable);
                     if (sql != null)
                     {
                         cmd.CommandText = sql;
                         cmd.ExecuteNonQuery();
                     }
                 }
             }
             //delete fetclass
             sql             = "delete from " + GetTableName() + " where id='" + entity.Id + "'";
             cmd.CommandText = sql;
             ret             = cmd.ExecuteNonQuery();
             TransactionManager.Commit();
         }
         catch
         {
             TransactionManager.Rollback();
             throw;
         }
     }
 }
        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;
            }
        }
Esempio n. 29
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;
                }
            }
        }
Esempio n. 30
0
 public abstract void WriteEntity(XmlWriter xmlWriter, ICatalogEntity entity);