public Drawing(Stream drawingContent, FileDetail fileDetail) { if (drawingContent == null) { throw new ArgumentNullException("drawingContent"); } if (fileDetail == null) { throw new ArgumentNullException("fileDetail"); } _drawingContent = drawingContent; _fileDetail = fileDetail; }
void IInitializeWithStream.Initialize(IStream pstream, uint grfMode) { try { if (_previewForm == null) { return; } _previewForm.Reset(); _fileDetail = _GetPreviewFileDetail(pstream); _previewFileStream = pstream.ToStream().ToMemoryStream(); Marshal.ReleaseComObject(pstream); } catch (Exception exc) { Trace.TraceError("PreviewHandlerController.Initialize: {0}", exc); } }
public void OnPreviewRequired(Stream stream, FileDetail fileDetail) { if (stream == null) { throw new ArgumentNullException("stream"); } if (fileDetail == null) { throw new ArgumentNullException("fileDetail"); } if (!stream.CanRead) { throw new ArgumentException("Stream must be readable", "stream"); } TokenSource.Cancel(); TokenSource = new CancellationTokenSource(); FileStream = stream; FileDetail = fileDetail; DisplayPreview = true; PreviewRequired?.Invoke(this, EventArgs.Empty); }
public async Task <GeneratePreviewResult> GeneratePreview(Stream drawingContent, FileDetail fileDetail, Size previewSize, CancellationToken token) { if (drawingContent == null) { throw new ArgumentNullException(nameof(drawingContent)); } if (fileDetail == null) { throw new ArgumentNullException(nameof(fileDetail)); } if (!drawingContent.CanRead) { throw new ArgumentException("Stream must be readable", nameof(drawingContent)); } var process = new Process { StartInfo = { FileName = Path.Combine(_settings.DotApplicationPath), RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true, Arguments = "-T" + _settings.RenderingFormat.ToString().ToLower() }, EnableRaisingEvents = true }; process.Start(); var baseOutputStream = process.StandardOutput.BaseStream; var baseErrorStream = process.StandardError.BaseStream; var drawingStreamSansBom = _streamHelper.ExcludeBomFromStream(drawingContent); await drawingStreamSansBom.CopyToAsync(process.StandardInput.BaseStream); process.StandardInput.BaseStream.Close(); var outputStream = new MemoryStream(); baseOutputStream.CopyTo(outputStream); var errorStream = new MemoryStream(); baseErrorStream.CopyTo(errorStream); process.WaitForExit(); if (errorStream.Length > 0) { errorStream.Seek(0, SeekOrigin.Begin); var message = new StreamReader(errorStream).ReadToEnd(); return(new GeneratePreviewResult(message)); } if (process.ExitCode != 0) { return(new GeneratePreviewResult("Failed to render drawing: " + process.ExitCode)); } outputStream.Seek(0, SeekOrigin.Begin); return(new GeneratePreviewResult(outputStream)); }