public void TestSave() { FormulaRenderArguments formulaRenderArguments = FormulaRenderArguments.FromString( "2.1,3.6;1.91,6.87;-0.62,2.26;-4.66,2.25\r\n0,0,0,0;-0.59,-1.43,0.47,0.2;0.21,-0.98,0.88,0.28\r\nSum Atan Pow x2 Cbrt Sin x1 Atan Pow Sin Sum x2 x0 x3"); WorkflowRenderResult formulaRenderResult = new WorkflowRenderResult(formulaRenderArguments, null, new FormulaBitmapMock(new Size()), TimeSpan.Zero); WallpaperFileManager wallpaperFileManager = new WallpaperFileManager(Path.GetTempPath()); Tuple<string, string> filesPath = wallpaperFileManager.Save(formulaRenderResult, false); Assert.IsTrue(File.Exists(filesPath.Item1)); Assert.IsNull(filesPath.Item2); filesPath = wallpaperFileManager.Save(formulaRenderResult, true); Assert.IsTrue(File.Exists(filesPath.Item1)); Assert.IsTrue(File.Exists(filesPath.Item2)); }
public Tuple<string, string> Save(WorkflowRenderResult workflowRenderResult, bool withFormulaRenderArguments) { if (!Directory.Exists(Path)) Directory.CreateDirectory(Path); string imagePath = GetNextFilePath(); using (FileStream stream = new FileStream(imagePath, FileMode.CreateNew)) { workflowRenderResult.Bitmap.WriteAsPng(stream); stream.Flush(); } AddFileToGallery(imagePath); string dataPath = null; if (withFormulaRenderArguments) { dataPath = imagePath.Replace(".png", ".txt"); File.WriteAllText(dataPath, workflowRenderResult.FormulaRenderArguments.ToString()); } return new Tuple<string, string>(imagePath, dataPath); }
public WorkflowRenderResult RenderFormula(bool generateNew, int threadsCount = 1) { if (FormulaRenderArguments == null && !generateNew) throw new InvalidOperationException("FormulaRenderArguments is null."); using (ProgressReporter.CreateScope()) { IsImageRendering = true; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); double formulaGenerationrProgressSpan = 0; if (generateNew) { formulaGenerationrProgressSpan = 0.01; using (ProgressReporter.CreateScope(formulaGenerationrProgressSpan)) FormulaRenderArguments = GenerateFormulaRenderArguments(); } using (ProgressReporter.CreateScope(1 - formulaGenerationrProgressSpan)) { FormulaRender.Render(FormulaRenderArguments.FormulaTree, FormulaRenderArguments.Ranges, ImageSize, FormulaRenderArguments.ColorTransformation, _reevaluateValues, threadsCount, _formulaRenderResult); _reevaluateValues = false; } stopwatch.Stop(); IsImageRendering = false; return LastWorkflowRenderResult = new WorkflowRenderResult(FormulaRenderArguments, _formulaRenderResult, _bitmap, stopwatch.Elapsed); } }
public Task<Tuple<string, string>> SaveAsync(WorkflowRenderResult workflowRenderResult, bool withFormulaRenderArguments) { return Task.Run(() => Save(workflowRenderResult, withFormulaRenderArguments)); }