static public Filesystem Load(IPersistenceContext read, ServerEntityKey key)
        {
            var        broker    = read.GetBroker <IFilesystemEntityBroker>();
            Filesystem theObject = broker.Load(key);

            return(theObject);
        }
 static public Filesystem Insert(Filesystem entity)
 {
     using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         Filesystem newEntity = Insert(update, entity);
         update.Commit();
         return(newEntity);
     }
 }
        public bool AddFileSystem(Filesystem filesystem)
        {
            Platform.Log(LogLevel.Info, "Adding new filesystem : description = {0}, path={1}", filesystem.Description,
                         filesystem.FilesystemPath);

            bool ok = _adapter.AddFileSystem(filesystem);

            Platform.Log(LogLevel.Info, "New filesystem added : description = {0}, path={1}", filesystem.Description,
                         filesystem.FilesystemPath);

            return ok;
        }
        public bool UpdateFileSystem(Filesystem filesystem)
        {
            Platform.Log(LogLevel.Info, "Updating filesystem : description = {0}, path={1}", filesystem.Description,
                         filesystem.FilesystemPath);

            bool ok = _adapter.Update(filesystem);

            if (ok)
                Platform.Log(LogLevel.Info, "Filesystem updated: description = {0}, path={1}", filesystem.Description,
                             filesystem.FilesystemPath);
            else
                Platform.Log(LogLevel.Info, "Unable to update Filesystem: description = {0}, path={1}",
                             filesystem.Description, filesystem.FilesystemPath);

            return ok;
        }
        static public Filesystem Insert(IUpdateContext update, Filesystem entity)
        {
            var broker        = update.GetBroker <IFilesystemEntityBroker>();
            var updateColumns = new FilesystemUpdateColumns();

            updateColumns.FilesystemPath     = entity.FilesystemPath;
            updateColumns.Enabled            = entity.Enabled;
            updateColumns.ReadOnly           = entity.ReadOnly;
            updateColumns.WriteOnly          = entity.WriteOnly;
            updateColumns.FilesystemTierEnum = entity.FilesystemTierEnum;
            updateColumns.LowWatermark       = entity.LowWatermark;
            updateColumns.HighWatermark      = entity.HighWatermark;
            updateColumns.Description        = entity.Description;
            Filesystem newEntity = broker.Insert(updateColumns);

            return(newEntity);
        }
		/// <summary>
		/// Traverse the filesystem directories for studies to rebuild the XML for.
		/// </summary>
		/// <param name="filesystem"></param>
		private void TraverseFilesystemStudies(Filesystem filesystem)
		{
			List<StudyStorageLocation> lockFailures = new List<StudyStorageLocation>();
			ServerPartition partition;

			DirectoryInfo filesystemDir = new DirectoryInfo(filesystem.FilesystemPath);

			foreach (DirectoryInfo partitionDir in filesystemDir.GetDirectories())
			{
				if (GetServerPartition(partitionDir.Name, out partition) == false)
					continue;

				foreach (DirectoryInfo dateDir in partitionDir.GetDirectories())
				{
					if (dateDir.FullName.EndsWith("Deleted")
						|| dateDir.FullName.EndsWith(ServerPlatform.ReconcileStorageFolder))
						continue;

                    foreach (DirectoryInfo studyDir in dateDir.GetDirectories())
                    {
                        // Check for Cancel message
                        if (CancelPending) return;

                        String studyInstanceUid = studyDir.Name;

                        StudyStorageLocation location;
                        try
                        {
                            FilesystemMonitor.Instance.GetWritableStudyStorageLocation(partition.Key, studyInstanceUid,
                                                                                       StudyRestore.False,
                                                                                       StudyCache.False, out location);
                        }
                        catch (StudyNotFoundException)
                        {
                            List<FileInfo> fileList = LoadSopFiles(studyDir, true);
                            if (fileList.Count == 0)
                            {
                                Platform.Log(LogLevel.Warn, "Found empty study folder: {0}\\{1}", dateDir.Name,
                                             studyDir.Name);
                                continue;
                            }

                            DicomFile file = LoadFileFromList(fileList);
                            if (file == null)
                            {
                                Platform.Log(LogLevel.Warn, "Found directory with no readable files: {0}\\{1}",
                                             dateDir.Name, studyDir.Name);
                                continue;
                            }

                            // Do a second check, using the study instance uid from a file in the directory.
                            // had an issue with trailing periods on uids causing us to not find the 
                            // study storage, and insert a new record into the database.
                            studyInstanceUid = file.DataSet[DicomTags.StudyInstanceUid].ToString();
                            if (!studyInstanceUid.Equals(studyDir.Name))
                                try
                                {
                                    FilesystemMonitor.Instance.GetWritableStudyStorageLocation(partition.Key,
                                                                                               studyInstanceUid,
                                                                                               StudyRestore.False,
                                                                                               StudyCache.False,
                                                                                               out location);
                                }
                                catch (Exception e)
                                {
                                    Platform.Log(LogLevel.Warn,
                                                 "Study {0} on filesystem partition {1} not found {2}: {3}",
                                                 studyInstanceUid,
                                                 partition.Description, studyDir.ToString(), e.Message);
                                    continue;
                                }
                            else
                            {
                                Platform.Log(LogLevel.Warn, "Study {0} on filesystem partition {1} not found {2}",
                                             studyInstanceUid,
                                             partition.Description, studyDir.ToString());
                                continue;
                            }
                        }
                        catch (Exception e)
                        {
                            Platform.Log(LogLevel.Warn, "Study {0} on filesystem partition {1} not found {2}: {3}",
                                         studyInstanceUid,
                                         partition.Description, studyDir.ToString(), e.Message);
                            continue;
                        }

                        // Location has been loaded, make sure its on the same filesystem
                        if (!location.FilesystemKey.Equals(filesystem.Key))
                        {
                            Platform.Log(LogLevel.Warn,
                                         "Study {0} on filesystem in directory: {1} is stored in different directory in the database: {2}",
                                         studyInstanceUid,
                                         studyDir.ToString(), location.GetStudyPath());
                            try
                            {
                                // Here due to defect #9673, attempting to cleanup errors from this ticket.                                    
                                if (Directory.Exists(location.GetStudyPath()))
                                {
                                    if (File.Exists(location.GetStudyXmlPath()))
                                    {
                                        Platform.Log(LogLevel.Warn,
                                                     "Deleting study {0}'s local directory.  The database location has valid study: {1}",
                                                     studyInstanceUid, studyDir.FullName);
                                        Directory.Delete(studyDir.FullName,true);
                                        continue;
                                    }

                                    Platform.Log(LogLevel.Warn,
                                                 "Deleting study {0} directory stored in database, it does not have a study xml file: {1}",
                                                 studyInstanceUid, location.GetStudyPath());
                                    // Delete the Database's location, and we'll just adjust the database to point to the current directory
                                    Directory.Delete(location.GetStudyPath(),true);
                                }

                                using (
                                    var readContext =
                                        PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(
                                            UpdateContextSyncMode.Flush))
                                {
                                    var update = new FilesystemStudyStorageUpdateColumns
                                                     {
                                                         FilesystemKey = filesystem.Key
                                                     };

                                    var broker = readContext.GetBroker<IFilesystemStudyStorageEntityBroker>();
                                    broker.Update(location.FilesystemStudyStorageKey, update);
                                    readContext.Commit();
                                }

                                Platform.Log(LogLevel.Warn,
                                             "Updated Study {0} FilesystemStudyStorage to point to the current filesystem.",
                                             studyInstanceUid);
                                FilesystemMonitor.Instance.GetWritableStudyStorageLocation(partition.Key,
                                                                                           studyInstanceUid,
                                                                                           StudyRestore.False,
                                                                                           StudyCache.False,
                                                                                           out location);

                            }
                            catch (Exception x)
                            {
                                Platform.Log(LogLevel.Error, x,
                                             "Unexpected error attempting to update storage location for study: {0}",
                                             studyInstanceUid);

                            }
                        }

                        try
                        {
                            if (!location.AcquireWriteLock())
                            {
                                Platform.Log(LogLevel.Warn, "Unable to lock study: {0}, delaying rebuild",
                                             location.StudyInstanceUid);
                                lockFailures.Add(location);
                                continue;
                            }

                            var rebuilder = new StudyXmlRebuilder(location);
                            rebuilder.RebuildXml();

                            location.ReleaseWriteLock();
                        }
                        catch (Exception e)
                        {
                            Platform.Log(LogLevel.Error, e,
                                         "Unexpected exception when rebuilding study xml for study: {0}",
                                         location.StudyInstanceUid);
                            lockFailures.Add(location);
                        }
                    }


				    // Cleanup the parent date directory, if its empty
					DirectoryUtility.DeleteIfEmpty(dateDir.FullName);
				}
			}

			// Re-do all studies that failed locks one time
			foreach (StudyStorageLocation location in lockFailures)
			{
				try
				{
					if (!location.AcquireWriteLock())
					{
						Platform.Log(LogLevel.Warn, "Unable to lock study: {0}, skipping rebuild", location.StudyInstanceUid);
						continue;
					}

					StudyXmlRebuilder rebuilder = new StudyXmlRebuilder(location);
					rebuilder.RebuildXml();

					location.ReleaseWriteLock();
				}
				catch (Exception e)
				{
					Platform.Log(LogLevel.Error, e, "Unexpected exception on retry when rebuilding study xml for study: {0}",
										 location.StudyInstanceUid);
				}
			}
		}
 public void OnEditFileSystem(FileSystemsConfigurationController controller, Filesystem fs)
 {
     AddEditFileSystemDialog1.EditMode = true;
     AddEditFileSystemDialog1.FileSystem = fs;
     AddEditFileSystemDialog1.Show(true);
 }
	    /// <summary>
        /// Reprocess a file systems
        /// </summary>
        /// <param name="filesystem"></param>
        private void ReprocessFilesystem(Filesystem filesystem)
        {
            var filesystemDir = new DirectoryInfo(filesystem.FilesystemPath);

            foreach (DirectoryInfo partitionDir in filesystemDir.GetDirectories())
            {
                ServerPartition partition;
                if (GetServerPartition(partitionDir.Name, out partition) == false)
                {
					if (!partitionDir.Name.EndsWith("_Incoming") && !partitionDir.Name.Equals("temp")
					 && !partitionDir.Name.Equals("ApplicationLog") && !partitionDir.Name.Equals("AlertLog"))
	                    Platform.Log(LogLevel.Error, "Unknown partition folder '{0}' in filesystem: {1}", partitionDir.Name,
                                 filesystem.Description);
                    continue;
                }

                // Since we found a partition, we should find a rules engine too.
                ServerRulesEngine engine = _engines[partition];
            	ServerRulesEngine postArchivalEngine = _postArchivalEngines[partition];
                ServerRulesEngine dataAccessEngine = _dataAccessEngine[partition];

				foreach (DirectoryInfo dateDir in partitionDir.GetDirectories())
				{
					if (dateDir.FullName.EndsWith("Deleted")
						|| dateDir.FullName.EndsWith(ServerPlatform.ReconcileStorageFolder))
						continue;

					foreach (DirectoryInfo studyDir in dateDir.GetDirectories())
					{
						String studyInstanceUid = studyDir.Name;
						try
						{
							StudyStorageLocation location = LoadReadableStorageLocation(partition.GetKey(), studyInstanceUid);
							if (location == null)
							{
								foreach (DirectoryInfo seriesDir in studyDir.GetDirectories())
								{
									FileInfo[] sopInstanceFiles = seriesDir.GetFiles("*.dcm");

									DicomFile file = null;
									foreach (FileInfo sopFile in sopInstanceFiles)
									{
										if (!sopFile.FullName.EndsWith(ServerPlatform.DicomFileExtension))
											continue;

										try
										{
											file = new DicomFile(sopFile.FullName);
                                            file.Load(DicomTags.StudyId, DicomReadOptions.DoNotStorePixelDataInDataSet | DicomReadOptions.Default);
											break;
										}
										catch (Exception e)
										{
											Platform.Log(LogLevel.Warn, e, "Unexpected failure loading file: {0}.  Continuing to next file.",
											             sopFile.FullName);
											file = null;
										}
									}
									if (file != null)
									{
										studyInstanceUid = file.DataSet[DicomTags.StudyInstanceUid].ToString();
										break;
									}
								}

								location = LoadReadableStorageLocation(partition.GetKey(), studyInstanceUid);
								if (location == null)
									continue;
							}

                            ProcessStudy(partition, location, engine, postArchivalEngine, dataAccessEngine);
							_stats.NumStudies++;

							if (CancelPending) return;
						}
						catch (Exception e)
						{
							Platform.Log(LogLevel.Error, e,
							             "Unexpected error while processing study: {0} on partition {1}.", studyInstanceUid,
							             partition.Description);
						}
					}

					// Cleanup the directory, if its empty.
					DirectoryUtility.DeleteIfEmpty(dateDir.FullName);
				}
            }
        }
		private void ReinventoryFilesystem(Filesystem filesystem)
        {
            ServerPartition partition;

            DirectoryInfo filesystemDir = new DirectoryInfo(filesystem.FilesystemPath);

            foreach(DirectoryInfo partitionDir in filesystemDir.GetDirectories())
            {
                if (GetServerPartition(partitionDir.Name, out partition) == false)
                    continue;

                foreach(DirectoryInfo dateDir in partitionDir.GetDirectories())
                {
                    if (dateDir.FullName.EndsWith("Deleted", StringComparison.InvariantCultureIgnoreCase)
						|| dateDir.FullName.EndsWith(ServerPlatform.ReconcileStorageFolder, StringComparison.InvariantCultureIgnoreCase))
						continue;
                	List<FileInfo> fileList;

					foreach (DirectoryInfo studyDir in dateDir.GetDirectories())
					{
                        if (studyDir.FullName.EndsWith("Deleted", StringComparison.InvariantCultureIgnoreCase))
                            continue;
					    
						// Check for Cancel message
						if (CancelPending) return;

						String studyInstanceUid = studyDir.Name;

						StudyStorageLocation location;
						if (GetStudyStorageLocation(partition.Key, studyInstanceUid, out location))
						{
                            #region Study record exists in db

                            int integrityQueueCount;
                            int workQueueCount;
                            Study theStudy = GetStudyAndQueues(location, out integrityQueueCount, out workQueueCount);
                            if (theStudy != null)
                                continue;

                            if (integrityQueueCount != 0 && workQueueCount != 0)
                                continue;

                            fileList = LoadSopFiles(studyDir, false);

                            if (fileList.Count == 0)
                            {
                                Platform.Log(LogLevel.Warn, "Found empty study folder with StorageLocation, deleteing StorageLocation: {0}\\{1}",
                                             dateDir.Name, studyDir.Name);
                                studyDir.Delete(true);

                                RemoveStudyStorage(location);
                                continue;
                            }

                            // WriteLock the new study storage for study processing
                            if (!location.QueueStudyStateEnum.Equals(QueueStudyStateEnum.ProcessingScheduled))
                            {
                            	string failureReason;
								if (!ServerHelper.LockStudy(location.Key,QueueStudyStateEnum.ProcessingScheduled, out failureReason))
                                    Platform.Log(LogLevel.Error, "Unable to lock study {0} for Study Processing", location.StudyInstanceUid);
                            } 
                            #endregion
						}
						else
						{
                            #region Directory not in DB, 

                            fileList = LoadSopFiles(studyDir, true);

                            if (fileList.Count == 0)
                            {
                                Platform.Log(LogLevel.Warn, "Found empty study folder: {0}\\{1}", dateDir.Name, studyDir.Name);
                                continue;
                            }

							DicomFile file = LoadFileFromList(fileList);

                            if (file == null)
                            {
                                Platform.Log(LogLevel.Warn, "Found directory with no readable files: {0}\\{1}", dateDir.Name, studyDir.Name);
                                continue;
                            }

                            // Do a second check, using the study instance uid from a file in the directory.
                            // had an issue with trailing periods on uids causing us to not find the 
                            // study storage, and insert a new record into the database.
                            studyInstanceUid = file.DataSet[DicomTags.StudyInstanceUid].ToString();
                            if (GetStudyStorageLocation(partition.Key, studyInstanceUid, out location))
                            {
                                continue;
                            }

                            StudyStorage storage;
                            if (GetStudyStorage(partition, studyInstanceUid, out storage))
                            {
                                Platform.Log(LogLevel.Warn, "Study {0} on filesystem partition {1} is offline {2}", studyInstanceUid,
                                             partition.Description, studyDir.ToString());
                                continue;
                            }

                            Platform.Log(LogLevel.Info, "Reinventory inserting study storage location for {0} on partition {1}", studyInstanceUid,
                                         partition.Description);

                            // Insert StudyStorage
                            using (IUpdateContext update = _store.OpenUpdateContext(UpdateContextSyncMode.Flush))
                            {
                                IInsertStudyStorage studyInsert = update.GetBroker<IInsertStudyStorage>();
                                InsertStudyStorageParameters insertParms = new InsertStudyStorageParameters
                                                                           	{
                                                                           		ServerPartitionKey = partition.GetKey(),
                                                                           		StudyInstanceUid = studyInstanceUid,
                                                                           		Folder = dateDir.Name,
                                                                           		FilesystemKey = filesystem.GetKey(),
                                                                           		QueueStudyStateEnum =
                                                                           			QueueStudyStateEnum.Idle
                                                                           	};
                            	if (file.TransferSyntax.LosslessCompressed)
                                {
                                    insertParms.TransferSyntaxUid = file.TransferSyntax.UidString;
                                    insertParms.StudyStatusEnum = StudyStatusEnum.OnlineLossless;
                                }
                                else if (file.TransferSyntax.LossyCompressed)
                                {
                                    insertParms.TransferSyntaxUid = file.TransferSyntax.UidString;
                                    insertParms.StudyStatusEnum = StudyStatusEnum.OnlineLossy;
                                }
                                else
                                {
                                    insertParms.TransferSyntaxUid = file.TransferSyntax.UidString;
                                    insertParms.StudyStatusEnum = StudyStatusEnum.Online;
                                }

                                location = studyInsert.FindOne(insertParms);

                                // WriteLock the new study storage for study processing
                                ILockStudy lockStudy = update.GetBroker<ILockStudy>();
                                LockStudyParameters lockParms = new LockStudyParameters
                                                                	{
                                                                		StudyStorageKey = location.Key,
                                                                		QueueStudyStateEnum =
                                                                			QueueStudyStateEnum.ProcessingScheduled
                                                                	};
                            	if (!lockStudy.Execute(lockParms) || !lockParms.Successful)
                                    Platform.Log(LogLevel.Error, "Unable to lock study {0} for Study Processing", location.StudyInstanceUid);

                                update.Commit();
                            }		 
                            #endregion					
						}

					    string studyXml = location.GetStudyXmlPath();
						if (File.Exists(studyXml))
							FileUtils.Delete(studyXml);

                        string studyGZipXml = location.GetCompressedStudyXmlPath();
                        if (File.Exists(studyGZipXml))
                            FileUtils.Delete(studyGZipXml);


						foreach (FileInfo sopFile in fileList)
						{
							String sopInstanceUid = sopFile.Name.Replace(sopFile.Extension, string.Empty);

							using (ServerExecutionContext context = new ServerExecutionContext())
							{
								// Just use a read context here, in hopes of improving 
								// performance.  Every other place in the code should use
								// Update contexts when doing transactions.
								IInsertWorkQueue workQueueInsert =
									context.ReadContext.GetBroker<IInsertWorkQueue>();

								InsertWorkQueueParameters queueInsertParms =
									new InsertWorkQueueParameters
										{
											WorkQueueTypeEnum = WorkQueueTypeEnum.StudyProcess,
											StudyStorageKey = location.GetKey(),
											ServerPartitionKey = partition.GetKey(),
											SeriesInstanceUid = sopFile.Directory.Name,
											SopInstanceUid = sopInstanceUid,
											ScheduledTime = Platform.Time
										};

								if (workQueueInsert.FindOne(queueInsertParms) == null)
									Platform.Log(LogLevel.Error,
									             "Failure attempting to insert SOP Instance into WorkQueue during Reinventory.");
							}
						}
					}

                	// Cleanup the date directory, if its empty.
                	DirectoryUtility.DeleteIfEmpty(dateDir.FullName);
                }
            }
        }
Exemple #10
0
 static public Filesystem Insert(IUpdateContext update, Filesystem entity)
 {
     var broker = update.GetBroker<IFilesystemEntityBroker>();
     var updateColumns = new FilesystemUpdateColumns();
     updateColumns.FilesystemPath = entity.FilesystemPath;
     updateColumns.Enabled = entity.Enabled;
     updateColumns.ReadOnly = entity.ReadOnly;
     updateColumns.WriteOnly = entity.WriteOnly;
     updateColumns.FilesystemTierEnum = entity.FilesystemTierEnum;
     updateColumns.LowWatermark = entity.LowWatermark;
     updateColumns.HighWatermark = entity.HighWatermark;
     updateColumns.Description = entity.Description;
     Filesystem newEntity = broker.Insert(updateColumns);
     return newEntity;
 }
Exemple #11
0
 static public Filesystem Insert(Filesystem entity)
 {
     using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         Filesystem newEntity = Insert(update, entity);
         update.Commit();
         return newEntity;
     }
 }
        private float GetFilesystemUsedPercentage(Filesystem fs)
        {
            if (!IsServiceAvailable())
                return float.NaN;

            try
            {
                FilesystemInfo fsInfo = null;
                Platform.GetService(delegate(IFilesystemService service)
                {
                    fsInfo = service.GetFilesystemInfo(fs.FilesystemPath);
                });

                _serviceIsOffline = false;
                _lastServiceAvailableTime = Platform.Time;
                return 100.0f - ((float)fsInfo.FreeSizeInKB) / fsInfo.SizeInKB * 100.0F;
            }
            catch (Exception)
            {
                _serviceIsOffline = true;
                _lastServiceAvailableTime = Platform.Time;
            }

            return float.NaN;
        }
 internal ServerFilesystemInfo(Filesystem filesystem)
 {
     _filesystem = filesystem;
     _online = true;
     LoadFreeSpace();
 }
 public ServerFilesystemInfo(ServerFilesystemInfo copy)
 {
     _filesystem = copy.Filesystem;
     _online = copy.Online;
     _freeBytes = copy.FreeBytes;
     _totalBytes = copy.TotalBytes;
 }
        private void SaveData()
        {
            
            if (FileSystem == null)
            {
                // create a filesystem 
                FileSystem = new Filesystem
                    {
                        LowWatermark = 80.00M, 
                        HighWatermark = 90.00M
                    };
            }

            FileSystem.Description = DescriptionTextBox.Text.Trim();
            FileSystem.FilesystemPath = PathTextBox.Text.Trim();
            FileSystem.ReadOnly = ReadCheckBox.Checked && WriteCheckBox.Checked == false;
            FileSystem.WriteOnly = WriteCheckBox.Checked && ReadCheckBox.Checked == false;
            FileSystem.Enabled = ReadCheckBox.Checked || WriteCheckBox.Checked;

            Decimal lowWatermark;
            if (Decimal.TryParse(LowWatermarkTextBox.Text, NumberStyles.Number, null, out lowWatermark))
                FileSystem.LowWatermark = lowWatermark;

            Decimal highWatermark;
			if (Decimal.TryParse(HighWatermarkTextBox.Text, NumberStyles.Number, null, out highWatermark))
                FileSystem.HighWatermark = highWatermark;

            FileSystem.FilesystemTierEnum = FilesystemTiers[TiersDropDownList.SelectedIndex];
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
            }
            else
            {
                // reload the filesystem information user is working on
                if (ViewState[ "EditMode"] != null)
                    _editMode = (bool)ViewState[ "EditMode"];

                FileSystem = ViewState[ "_FileSystem"] as Filesystem;
            }
        }