protected override void OnExecute(CommandProcessor theProcessor)
        {
            try
            {
                if (Directory.Exists(_dir))
                {
                    if (DeleteOnlyIfEmpty && !DirectoryUtility.IsEmpty(_dir))
                    {
                        return;
                    }

                    if (Log)
                        Platform.Log(LogLevel.Info, "Deleting {0}", _dir);

                    Directory.Move(_dir, _dir +".deleted");
                    _sourceDirRenamed = true;
                }
                
            }
            catch (Exception ex)
            {
                if (_failIfError)
                    throw;
            	// ignore it
            	Platform.Log(LogLevel.Warn, ex, "Unexpected exception occurred when deleting {0}. It is ignored.", _dir);
            }
        }
		protected override void OnExecute(CommandProcessor theProcessor)
		{
            if (String.IsNullOrEmpty(_directory) && GetDirectoryDelegate!=null)
            {
                _directory = GetDirectoryDelegate();
            }

			if (Directory.Exists(_directory))
			{
				_created = false;
				return;
			}

			try
			{
			    Directory.CreateDirectory(_directory);
			}
            catch(UnauthorizedAccessException)
            {
                //alert the system admin
                //ServerPlatform.Alert(AlertCategory.System, AlertLevel.Critical, "Filesystem", 
                //                        AlertTypeCodes.NoPermission, null, TimeSpan.Zero,
                //                     "Unauthorized access to {0} from {1}", _directory, ServerPlatform.HostId);
                throw;
            }

			_created = true;
		}
Exemplo n.º 3
0
        protected override void OnExecute(CommandProcessor theProcessor)
        {
            Platform.CheckTrue(File.Exists(_sourceFile), String.Format("Source file '{0}' doesn't exist", _sourceFile));

            if (File.Exists(_destinationFile))
            {
                if (_failIfExists)
                    throw new ApplicationException(String.Format("Destination file already exists: {0}", _destinationFile));
            }

            if (RequiresRollback)
                Backup();

            if (File.Exists(_destinationFile))
                FileUtils.Copy(_sourceFile, _destinationFile, !_failIfExists);
            else
                FileUtils.Copy(_sourceFile, _destinationFile, false);

            try
            {
                if ((File.GetAttributes(_destinationFile) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    File.SetAttributes(_destinationFile, FileAttributes.Normal);
            }
            catch (Exception)
            { }
        }
		protected override void OnExecute(CommandProcessor theProcessor)
		{
		    if (!File.Exists(_path))
			{
				Platform.Log(LogLevel.Error, "Unexpected error finding file to add to XML {0}", _path);
				throw new ApplicationException("Unexpected error finding file to add to XML {0}" + _path);
			}

			var finfo = new FileInfo(_path);
			long fileSize = finfo.Length;

			var dicomFile = new DicomFile(_path);
			dicomFile.Load(DicomReadOptions.StorePixelDataReferences | DicomReadOptions.Default);

		    _sopInstanceUid = dicomFile.DataSet[DicomTags.SopInstanceUid];
		    _seriesInstanceUid = dicomFile.DataSet[DicomTags.SeriesInstanceUid];

			// Setup the insert parameters
			if (false == _stream.AddFile(dicomFile, fileSize))
			{
				Platform.Log(LogLevel.Error, "Unexpected error adding SOP to XML Study Descriptor for file {0}",
				             _path);
				throw new ApplicationException("Unexpected error adding SOP to XML Study Descriptor for SOP: " +
				                               dicomFile.MediaStorageSopInstanceUid);
			}
		}
Exemplo n.º 5
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 theProcessor)
 {
     // backup
     if (_studyXml.Contains(_seriesUid))
     {
         Platform.Log(LogLevel.Info, "Removing series {0} from StudyXML for study {1}", _seriesUid, _studyInstanceUid);
         _oldSeriesXml = _studyXml[_seriesUid];
         if (!_studyXml.RemoveSeries(_seriesUid))
             throw new ApplicationException(String.Format("Could not remove series {0} from study {1}", _seriesUid, _studyInstanceUid));
     }
 }
Exemplo n.º 7
0
		protected override void OnExecute(CommandProcessor theProcessor)
        {
            if (!Directory.Exists(_src))
                throw new DirectoryNotFoundException(string.Format("Source directory {0} does not exist", _src));
            
            if (RequiresRollback)
            {
                Backup();
            }

            MoveSpeed.Start();
            ulong bytesCopied = DirectoryUtility.Copy(_src, _dest, _callback);
            MoveSpeed.SetData(bytesCopied);
            MoveSpeed.End();
        }
Exemplo n.º 8
0
		protected override void OnExecute(CommandProcessor theProcessor)
		{
            if (RequiresRollback)
            {
                Backup();
            }

			if (File.Exists(_originalFile))
			{
			    File.Delete(_originalFile);
			}
            else
			{
			    Platform.Log(LogLevel.Warn, "Attempted to delete file which doesn't exist: {0}", _originalFile);
			}
		}
Exemplo n.º 9
0
		protected override void OnExecute(CommandProcessor theProcessor)
		{
			// Check if its already in the right syntax.
			if (_file.TransferSyntax.Equals(_syntax))
				return;

			_timeSpan.Start();

			// Check for decompression first
			if (_file.TransferSyntax.Encapsulated)
				_file.ChangeTransferSyntax(TransferSyntax.ExplicitVrLittleEndian);

			_file.ChangeTransferSyntax(_syntax, _codec, _parms);

			_timeSpan.End();
		}
Exemplo n.º 10
0
        /// <summary>
        /// Execute the <see cref="CommandBase"/>.
        /// </summary>
        /// <param name="theProcessor">The <see cref="CommandProcessor"/> executing the command.</param>
        public void Execute(CommandProcessor theProcessor)
        {
            try
            {
                Statistics.Start();
                EventsHelper.Fire(_executingEventHandlers, this, new EventArgs());
                OnExecute(theProcessor);
            }
            finally
            {
                Statistics.End();
            }

        }
Exemplo n.º 11
0
 protected abstract void OnExecute(CommandProcessor theProcessor);
Exemplo n.º 12
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);
        }