private IEnumerable<IRenderingJob> CreateRenderingJobs(FileSystemInfo inputPath, IBatchRenderingOptions inputOutputInfo, RenderingMode? mode) { IEnumerable<IRenderingJob> output; if(inputPath != null && (inputPath is FileInfo)) { output = new [] { CreateRenderingJob((FileInfo) inputPath, mode, inputPath.GetParentDirectory()) }; } else if(inputPath != null && (inputPath is DirectoryInfo)) { var dir = (DirectoryInfo) inputPath; output = (from file in dir.GetFiles(inputOutputInfo.InputSearchPattern, SearchOption.AllDirectories) where !inputOutputInfo.IgnoredPaths.Any(x => file.IsChildOf(x)) select CreateRenderingJob(file, mode, dir)); } else { output = new IRenderingJob[0]; } return output; }
/// <summary> /// Validate the given options. /// </summary> /// <param name="options">The options to validate.</param> public void Validate(IBatchRenderingOptions options) { if(options == null) { throw new ArgumentNullException(nameof(options)); } if(options.InputStream == null && !options.InputPaths.Any()) { string message = Resources.ExceptionMessages.BatchOptionsMustHaveInputStreamOrPaths; throw new InvalidBatchRenderingOptionsException(message, BatchRenderingFatalErrorType.NoInputsSpecified); } else if(options.InputStream != null && options.InputPaths.Any()) { string message = Resources.ExceptionMessages.BatchOptionsMustNotHaveBothInputStreamAndPaths; throw new InvalidBatchRenderingOptionsException(message, BatchRenderingFatalErrorType.InputCannotBeBothStreamAndPaths); } if(options.OutputStream == null && options.OutputPath == null) { string message = Resources.ExceptionMessages.BatchOptionsMustHaveOutputStreamOrPath; throw new InvalidBatchRenderingOptionsException(message, BatchRenderingFatalErrorType.NoOutputsSpecified); } else if(options.OutputStream != null && options.OutputPath != null) { string message = Resources.ExceptionMessages.BatchOptionsMustNotHaveBothOutputStreamAndPath; throw new InvalidBatchRenderingOptionsException(message, BatchRenderingFatalErrorType.OutputCannotBeBothStreamAndPaths); } }
/// <summary> /// Gets the rendering jobs from the batch rendering options. /// </summary> /// <returns>The rendering jobs.</returns> /// <param name="inputOutputInfo">Input output info.</param> /// <param name="mode">Mode.</param> public IEnumerable<IRenderingJob> GetRenderingJobs(IBatchRenderingOptions inputOutputInfo, RenderingMode? mode) { IEnumerable<IRenderingJob> output; if(inputOutputInfo.InputStream != null) { output = ReadFromStream(inputOutputInfo.InputStream, mode); } else { output = ReadFromInputPaths(inputOutputInfo, mode); } return output; }
/// <summary> /// Parse and render the documents found using the given batch rendering options. /// </summary> /// <param name="settings">Rendering settings.</param> /// <param name="batchOptions">Batch rendering options, indicating the source and destination files.</param> public virtual IBatchRenderingResponse Render(IBatchRenderingOptions batchOptions, IRenderingSettings settings) { ValidateBatchOptions(batchOptions); var jobs = GetRenderingJobs(batchOptions, batchOptions.RenderingMode); List<IBatchRenderingDocumentResponse> documents = new List<IBatchRenderingDocumentResponse>(); foreach(var job in jobs) { var contextConfigurator = GetContextConfigurator(job); var docResponse = Render(job, settings, batchOptions, contextConfigurator); documents.Add(docResponse); } return new BatchRenderingResponse(documents); }
public Stream GetOutputStream(IBatchRenderingOptions batchOptions) { if(batchOptions == null) { throw new ArgumentNullException(nameof(batchOptions)); } Stream output; if(batchOptions.OutputStream != null) { output = batchOptions.OutputStream; } else { var outputFile = GetOutputFile(batchOptions); output = GetOutputStream(outputFile); } return output; }
public string GetOutputInfo(IBatchRenderingOptions batchOptions) { if(batchOptions == null) { throw new ArgumentNullException(nameof(batchOptions)); } string output; if(batchOptions.OutputStream != null) { output = "STDOUT"; } else { var outputFile = GetOutputFile(batchOptions); output = outputFile.FullName; } return output; }
/// <summary> /// Parse and render the documents found using the given batch rendering options. /// </summary> /// <param name="options">Rendering options.</param> /// <param name="batchOptions">Batch rendering options, indicating the source and destination files.</param> /// <returns> /// An object instance indicating the outcome of the rendering. /// </returns> public virtual IBatchRenderingResponse Render(IBatchRenderingOptions batchOptions, IRenderingOptions options = null) { return this.Render(batchOptions, _settingsFactory.CreateSettings(options)); }
/// <summary> /// Validates the batch rendering options. /// </summary> /// <param name="options">Options.</param> protected virtual void ValidateBatchOptions(IBatchRenderingOptions options) { _optionsValidator.Validate(options); }
/// <summary> /// Renders a single rendering job and returns a response. /// </summary> /// <param name="job">The job to render.</param> /// <param name="options">Rendering options.</param> /// <param name="batchOptions">Batch rendering options.</param> /// <param name="contextConfigurator">Context configurator.</param> protected virtual IBatchRenderingDocumentResponse Render(IRenderingJob job, IRenderingSettings options, IBatchRenderingOptions batchOptions, Action<IModelValueContainer> contextConfigurator) { var doc = GetDocument(job); var outputInfo = GetOutputInfo(job, batchOptions); using(var outputStream = GetOutputStream(job, batchOptions)) { return Render(doc, outputStream, options, contextConfigurator, outputInfo); } }
/// <summary> /// Gets the rendering jobs from the rendering job factory. /// </summary> /// <returns>The rendering jobs.</returns> /// <param name="options">Batch rendering options.</param> /// <param name="mode">An optional rendering mode override.</param> protected virtual IEnumerable<IRenderingJob> GetRenderingJobs(IBatchRenderingOptions options, RenderingMode? mode) { return _jobFactory.GetRenderingJobs(options, mode); }
/// <summary> /// Gets the output stream for a given rendering job. /// </summary> /// <returns>The output stream.</returns> /// <param name="job">Job.</param> /// <param name="batchOptions">Batch options.</param> protected virtual Stream GetOutputStream(IRenderingJob job, IBatchRenderingOptions batchOptions) { return job.GetOutputStream(batchOptions); }
/// <summary> /// Gets the output info for a given rendering job. /// </summary> /// <returns>The output info.</returns> /// <param name="job">Job.</param> /// <param name="batchOptions">Batch options.</param> protected virtual string GetOutputInfo(IRenderingJob job, IBatchRenderingOptions batchOptions) { return job.GetOutputInfo(batchOptions); }
private void ExerciseSut() { _result = _sut.GetBatchOptions(_options); }
private FileInfo GetOutputFile(IBatchRenderingOptions batchOptions) { FileInfo output; if(batchOptions.OutputPath is FileInfo) { output = (FileInfo) batchOptions.OutputPath; } else if(batchOptions.OutputPath is DirectoryInfo) { output = GetOutputFile((DirectoryInfo) batchOptions.OutputPath, batchOptions.OutputExtensionOverride); } else { throw new BatchRenderingException(Resources.ExceptionMessages.InvalidBatchRenderingOutputPath); } return output; }
private IEnumerable<IRenderingJob> ReadFromInputPaths(IBatchRenderingOptions inputOutputInfo, RenderingMode? mode) { return inputOutputInfo.InputPaths.SelectMany(x => CreateRenderingJobs(x, inputOutputInfo, mode)); }