示例#1
0
		protected override void OnExecute(CommandProcessor theProcessor)
		{
			StudyXml currentXml = LoadStudyXml();

            _newXml = new StudyXml(_studyInstanceUid);
			foreach (SeriesXml series in currentXml)
			{
				string seriesPath = Path.Combine(_rootPath, series.SeriesInstanceUid);
                if (!Directory.Exists(seriesPath))
                {
                    Platform.Log(LogLevel.Info, "RebuildXML: series folder {0} is missing", seriesPath);
                    continue;
                }

			    foreach (InstanceXml instance in series)
			    {
			        string instancePath = Path.Combine(seriesPath, instance.SopInstanceUid + ServerPlatform.DicomFileExtension);
			        if (!File.Exists(instancePath))
			        {
                        Platform.Log(LogLevel.Info, "RebuildXML: file {0} is missing", instancePath);
			        }
			        else
			        {
                        if (!theProcessor.ExecuteSubCommand(this, new InsertInstanceXmlCommand(_newXml, instancePath)))
			                throw new ApplicationException(theProcessor.FailureReason);
			        }
			    }
			}

            if (!theProcessor.ExecuteSubCommand(this, new SaveXmlCommand(_newXml, _rootPath, _studyInstanceUid)))
				throw new ApplicationException(theProcessor.FailureReason);
		}
示例#2
0
 protected override void OnExecute(CommandProcessor theProcessor)
 {
     while (_subCommands.Count > 0)
     {
         if (!theProcessor.ExecuteSubCommand(this, _subCommands.Dequeue()))
             throw new ApplicationException(theProcessor.FailureReason);
     }
 }
示例#3
0
 protected override void OnExecute(CommandProcessor theProcessor)
 {
     while (_subCommands.Count > 0)
     {
         if (!theProcessor.ExecuteSubCommand(this, _subCommands.Dequeue()))
         {
             throw new ApplicationException(theProcessor.FailureReason);
         }
     }
 }
        protected override void OnExecute(CommandProcessor commandProcessor)
        {
            _instanceXml = _studyXml.FindInstanceXml(_seriesInstanceUid, _sopInstanceUid);

            _studyXml.RemoveInstance(_seriesInstanceUid, _sopInstanceUid);

            // flush it into disk
            // Write it back out.  We flush it out with every added image so that if a failure happens,
            // we can recover properly.
            if (!commandProcessor.ExecuteSubCommand(this, new SaveXmlCommand(_studyXml, _studyLocation)))
                throw new ApplicationException(commandProcessor.FailureReason);
        }
示例#5
0
        protected override void OnExecute(CommandProcessor theProcessor)
        {
            // Make sure the directory exists where we're storing the file.
            var p = Path.GetDirectoryName(_path);

            if (string.IsNullOrEmpty(p) || !Directory.Exists(p))
            {
                if (!theProcessor.ExecuteSubCommand(this, new CreateDirectoryCommand(Path.GetDirectoryName(_path))))
                {
                    throw new ApplicationException(theProcessor.FailureReason);
                }
            }

            if (RequiresRollback)
            {
                Backup();
            }

            string path = GetTempPath();

            using (FileStream stream = FileStreamOpener.OpenForSoleUpdate(path,
                                                                          _failOnExists
                                                                             ? FileMode.CreateNew
                                                                             : FileMode.Create))
            {
                _file.Save(stream, DicomWriteOptions.Default);
                stream.Flush();
                stream.Close();
            }

            if (_failOnExists && File.Exists(_path))
            {
                // Do this test after creating the temp folder in case another thread is receiving the file at the same
                // time.
                try
                {
                    // Delete the temp file we saved
                    FileUtils.Delete(path);
                }
                catch (Exception x)
                {
                    throw new ApplicationException(String.Format("DICOM File unexpectedly already exists: {0}", _path),
                                                   x);
                }
                throw new ApplicationException(String.Format("DICOM File unexpectedly already exists: {0}", _path));
            }

            FileUtils.Copy(path, _path, true);
            _fileCreated = true;
            FileUtils.Delete(path);
        }
		protected override void OnExecute(CommandProcessor theProcessor)
		{
			if (_path == null)
			{
				String seriesUid = _file.DataSet[DicomTags.SeriesInstanceUid].GetString(0, String.Empty);
				String sopUid = _file.DataSet[DicomTags.SopInstanceUid].GetString(0, String.Empty);
				_path = _storageLocation.GetSopInstancePath(seriesUid, sopUid);
			}

			// Make sure the directory exists where we're storing the file.
		    var p = Path.GetDirectoryName(_path);
			if (string.IsNullOrEmpty(p) || !Directory.Exists(p))
			{
				if (!theProcessor.ExecuteSubCommand(this, new CreateDirectoryCommand(Path.GetDirectoryName(_path))))
					throw new ApplicationException(theProcessor.FailureReason);
			}

            if (RequiresRollback)
                Backup();

	        string path = GetTempPath();

	    	using (FileStream stream = FileStreamOpener.OpenForSoleUpdate(path, FileMode.Create))
			{
				// Set _fileCreated here, because the file has been opened.
                _saveSpeed.Start();
				_file.Save(stream, DicomWriteOptions.Default);
				stream.Flush();
				stream.Close();
                _saveSpeed.End();

                var fi = new FileInfo(path);
                _saveSpeed.SetData(fi.Length);
                
			}

				if (File.Exists(_path))
				{
				    if (_failOnExists)
					{
						try
						{
							FileUtils.Delete(path);
						}
						catch (Exception x)
						{
	                    throw new ApplicationException(
	                        String.Format("DICOM File unexpectedly already exists: {0}", _path), x);
						}
						throw new ApplicationException(String.Format("DICOM File unexpectedly already exists: {0}", _path));
					}
				}

	        FileUtils.Copy(path, _path, true);
				_fileCreated = true;
	        FileUtils.Delete(path);
		}
        protected override void OnExecute(CommandProcessor theProcessor)
        {

            // Make sure the directory exists where we're storing the file.
            var p = Path.GetDirectoryName(_path);
            if (string.IsNullOrEmpty(p) || !Directory.Exists(p))
            {
                if (!theProcessor.ExecuteSubCommand(this, new CreateDirectoryCommand(Path.GetDirectoryName(_path))))
                    throw new ApplicationException(theProcessor.FailureReason);
            }

            if (RequiresRollback)
                Backup();

            string path = GetTempPath();

            using (FileStream stream = FileStreamOpener.OpenForSoleUpdate(path,
                                                                          _failOnExists
                                                                             ? FileMode.CreateNew
                                                                             : FileMode.Create))
            {
                _file.Save(stream, DicomWriteOptions.Default);
                stream.Flush();
                stream.Close();
            }

            if (_failOnExists && File.Exists(_path))
            {
                // Do this test after creating the temp folder in case another thread is receiving the file at the same 
                // time.
                try
                {
                    // Delete the temp file we saved
                    FileUtils.Delete(path);
                }
                catch (Exception x)
                {
                    throw new ApplicationException(String.Format("DICOM File unexpectedly already exists: {0}", _path),
                                                   x);
                }
                throw new ApplicationException(String.Format("DICOM File unexpectedly already exists: {0}", _path));
            }

            FileUtils.Copy(path, _path, true);
            _fileCreated = true;
            FileUtils.Delete(path);
        }
		protected override void OnExecute(CommandProcessor theProcessor)
		{
			// Make sure the directory exists where we're storing the file.
			var p = Path.GetDirectoryName(_path);
			if (string.IsNullOrEmpty(p) || !Directory.Exists(p))
			{
				if (!theProcessor.ExecuteSubCommand(this, new CreateDirectoryCommand(Path.GetDirectoryName(_path))))
					throw new ApplicationException(theProcessor.FailureReason);
			}

			string path = GetTempPath();

			var fileMode = _failOnExists ? FileMode.CreateNew : FileMode.Create;
			using (var stream = new FileStream(path, fileMode, FileAccess.Write, FileShare.None, 65536, FileOptions.SequentialScan))
			{
				_file.Save(stream, DicomWriteOptions.Default);
				stream.Flush();
				stream.Close();
			}

			if (_failOnExists && File.Exists(_path))
			{
				// Do check *after* creating the temp file in case another thread received file at the same time (and finished before us!)
				try
				{
					// Delete the temp file we saved
					FileUtils.Delete(path);
				}
				catch (Exception x)
				{
					throw new ApplicationException(String.Format("DICOM File unexpectedly already exists: {0}", _path), x);
				}
				throw new ApplicationException(String.Format("DICOM File unexpectedly already exists: {0}", _path));
			}

			_backupPath = RequiresRollback ? GetBackupPath() : null;

			FileUtils.TrySetFileReadOnly(path, false);
			FileUtils.TrySetFileReadOnly(_path, false);
			FileUtils.TrySetFileReadOnly(_backupPath, false);
			FileUtils.Replace(path, _path, _backupPath);

			_fileCreated = true;
		}