Ejemplo n.º 1
0
        private static bool ContainsOnlyBackupFiles(DirectoryInfo dir, ScanResultEntry scanResult)
        {
            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                string ext = file.Name.ToUpper();
                if (!ext.Contains("BAK") && !ext.Contains("TMP") && !ext.Contains("TEMP"))
                {
                    scanResult.BackupFilesOnly = false;
                    return(false);
                }
            }

            DirectoryInfo[] subDirs = dir.GetDirectories();
            foreach (DirectoryInfo subDir in subDirs)
            {
                if (!ContainsOnlyBackupFiles(subDir, scanResult))
                {
                    scanResult.BackupFilesOnly = false;
                    return(false);
                }
            }

            scanResult.BackupFilesOnly = true;
            return(true);
        }
Ejemplo n.º 2
0
        private static bool CheckIfFolderIsEmpty(DirectoryInfo dir, ScanResultEntry scanResult)
        {
            DirectoryInfo[] subDirs = dir.GetDirectories();
            FileInfo[]      files   = dir.GetFiles();
            if (subDirs.Length == 0 && files.Length == 0)
            {
                scanResult.IsEmpty = true;
                return(true);
            }

            if (files.Length > 0)
            {
                scanResult.IsEmpty = false;
                return(false);
            }

            foreach (DirectoryInfo subDir in subDirs)
            {
                if (!CheckIfFolderIsEmpty(subDir, scanResult))
                {
                    scanResult.IsEmpty = false;
                    return(false);
                }
            }

            scanResult.IsEmpty = true;
            return(true);
        }
Ejemplo n.º 3
0
 private bool CheckIfStudyWasDeletedAfterward(FileSystemInfo dir, ScanResultEntry scanResult)
 {
     scanResult.StudyWasOnceDeleted = (null != CollectionUtils.SelectFirst(_deletedStudies,
                                                                           record => record.StudyInstanceUid == scanResult.StudyInstanceUid &&
                                                                           record.Timestamp.ToUniversalTime() > dir.LastWriteTimeUtc
                                                                           ));
     return(scanResult.StudyWasOnceDeleted);
 }
Ejemplo n.º 4
0
 private static StudyStorage FindStudyStorage(ScanResultEntry result)
 {
     using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
     {
         IStudyStorageEntityBroker  broker   = ctx.GetBroker <IStudyStorageEntityBroker>();
         StudyStorageSelectCriteria criteria = new StudyStorageSelectCriteria();
         criteria.StudyInstanceUid.EqualTo(result.StudyInstanceUid);
         criteria.ServerPartitionKey.EqualTo(result.ServerPartitionKey);
         return(broker.FindOne(criteria));
     }
 }
Ejemplo n.º 5
0
        private static bool CheckIfStudyNoLongerExists(ScanResultEntry scanResult)
        {
            StudyStorage storage = FindStudyStorage(scanResult);

            scanResult.StudyNoLongerExists = storage == null;
            if (storage != null)
            {
                scanResult.StudyInsertTime = storage.InsertTime;
                scanResult.Storage         = storage;
            }

            return(scanResult.StudyNoLongerExists);
        }
Ejemplo n.º 6
0
        private static bool CheckIfStudyIsInWorkQueue(ScanResultEntry scanResult)
        {
            using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IWorkQueueEntityBroker  broker   = ctx.GetBroker <IWorkQueueEntityBroker>();
                WorkQueueSelectCriteria criteria = new WorkQueueSelectCriteria();
                criteria.StudyStorageKey.EqualTo(scanResult.Storage.Key);
                var list = broker.Find(criteria);
                scanResult.IsInWorkQueue = list != null && list.Count > 0;
            }

            return(scanResult.IsInWorkQueue);
        }
Ejemplo n.º 7
0
        private bool CheckInSIQ(FileSystemInfo groupDir, ScanResultEntry scanResult)
        {
            Guid guid = Guid.Empty;

            try
            {
                guid = new Guid(groupDir.Name);
            }
            catch (Exception)
            { }

            scanResult.IsInSIQ = !guid.Equals(Guid.Empty) ? FindSIQByGuid(guid) : FindSIQByGroupID(groupDir.Name);

            return(scanResult.IsInSIQ);
        }
Ejemplo n.º 8
0
        private static bool CheckIfStudyWasInsertedAfter(FileSystemInfo dir, ScanResultEntry scanResult)
        {
            scanResult.StudyWasResent = dir.LastWriteTimeUtc < scanResult.StudyInsertTime.ToUniversalTime();

            return(scanResult.StudyWasResent);
        }
Ejemplo n.º 9
0
        private ScanResultEntry ProcessDir(DirectoryInfo groupDir, ServerEntityKey partitionKey)
        {
            var result = new ScanResultEntry
            {
                Path = groupDir.FullName,
                DirectoryLastWriteTime = groupDir.LastWriteTimeUtc
            };

            if (groupDir.LastWriteTimeUtc >= Platform.Time.ToUniversalTime() - TimeSpan.FromMinutes(30))
            {
                return(new ScanResultEntry {
                    Path = groupDir.FullName, Skipped = true
                });
            }

            if (CheckInSIQ(groupDir, result))
            {
                return(result);
            }


            if (CheckIfFolderIsEmpty(groupDir, result))
            {
                return(result);
            }

            // check if all files are backup files
            if (ContainsOnlyBackupFiles(groupDir, result))
            {
                return(result);
            }

            try
            {
                result.StudyInstanceUid   = FindStudyUid(groupDir);
                result.ServerPartitionKey = partitionKey;
            }
            catch (Exception ex)
            {
                Platform.Log(LogLevel.Error, ex);
                result.ScanFailed = true;
                result.FailReason = ex.Message;
                return(result);
            }

            if (CheckIfStudyNoLongerExists(result))
            {
                return(result);
            }

            Debug.Assert(result.Storage != null);
            if (CheckIfStudyIsInWorkQueue(result))
            {
                return(result);
            }

            if (CheckIfStudyWasDeletedAfterward(groupDir, result))
            {
                return(result);
            }

            if (CheckIfStudyWasInsertedAfter(groupDir, result))
            {
                return(result);
            }

            result.Undetermined = true;
            return(result);
        }