/// <summary> /// Writes the text to the specified file /// </summary> /// <param name="text">The text to write</param> /// <param name="path">The path of the file to write to</param> /// <param name="append">If true, writes the text to the end of the file, otherwise overrides any existing file</param> /// <returns></returns> public async Task WriteTextToFileAsync(string text, string path, bool append = false) { // Normalize path path = NormalizePath(path); // Resolve to absolute path path = ResolvePath(path); // Lock the task await AsyncAwaiter.AwaitAsync(nameof(FileManager) + path, async() => { // Run the synchronous file access as a new task await IoC.Task.Run(() => { try { // Write the log message to file using (var fileStream = (TextWriter) new StreamWriter(File.Open(path, append ? FileMode.Append : FileMode.Create))) fileStream.Write(text); } catch (UnauthorizedAccessException) { // Log IoC.Logger.Log($"O programa não tem autorização suficiente para salvar o arquivo {path}", LogLevel.Error); } }); }); }
/// <summary> /// Draws on the screen /// </summary> public void Draw() { // Run the task async in the pool var task = AsyncAwaiter.AwaitAsync(RendererName, async() => { // Clears screen GL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // TODO: Remove in final version GL.ClearColor(Color.Gray.R / 255.0f, Color.Gray.G / 255.0f, Color.Gray.B / 255.0f, 0); // Set ortographic projection GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Viewport(0, 0, (int)ActualWidth, (int)ActualHeight); GL.Ortho(0d, 1d, 0d, 1d, -1d, 1d); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); // Re-binds the texture Tex.Bind(GL); // Draw image render rectangle that covers whole screen GL.Begin(BeginMode.Quads); GL.TexCoord(0, 1); GL.Vertex(0, 0); GL.TexCoord(0, 0); GL.Vertex(0, 1); GL.TexCoord(1, 0); GL.Vertex(1, 1); GL.TexCoord(1, 1); GL.Vertex(1, 0); GL.End(); }); }
/// <summary> /// Reads all the text from a specified file /// </summary> /// <param name="path">The path to the file</param> /// <returns></returns> public async Task <string> ReadTextFromFileAsync(string path) { // Normalize path path = NormalizePath(path); // Resolve to absolute path path = ResolvePath(path); // Lock the task return(await AsyncAwaiter.AwaitResultAsync(nameof(FileManager) + path, async() => { // Run the synchronous file access as a new task return await IoC.Task.Run(async() => { // Reads the file using (var fileStream = (TextReader) new StreamReader(File.Open(path, FileMode.Open))) return await fileStream.ReadToEndAsync(); }); })); }