示例#1
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)
        {

            // 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);
        }