/// <summary> /// Invalidate every resource due to a critical event /// </summary> /// <param name="codeErrorMessage">Message for cancelled codes</param> /// <returns>Asynchronous task</returns> public static async Task InvalidateData(string codeErrorMessage) { // Close every open file. This closes the internal macro files as well await Print.Cancel(); // Resolve pending macros, unbuffered (system) codes and flush requests foreach (CodeChannel channel in CodeChannels) { MacroFile.AbortAllFiles(channel); using (await Channels[channel].LockAsync()) { Channels[channel].Invalidate(codeErrorMessage); } } _bytesReserved = _bufferSpace = 0; // Resolve pending heightmap requests using (await _heightmapLock.LockAsync()) { _getHeightmapRequest?.SetException(new OperationCanceledException(codeErrorMessage)); _heightmapRequested = false; _setHeightmapRequest?.SetException(new OperationCanceledException(codeErrorMessage)); _heightmapToSet = null; } }
private static async Task HandleAbortFileRequest() { DataTransfer.ReadAbortFile(out CodeChannel channel, out bool abortAll); Console.WriteLine($"[info] Received file abort request on channel {channel} for {(abortAll ? "all files" : "the last file")}"); if (abortAll) { if (channel == CodeChannel.File) { await Print.Cancel(); } MacroFile.AbortAllFiles(channel); _channels[channel].InvalidateBuffer(false); } else { MacroFile.AbortLastFile(channel); _channels[channel].InvalidateBuffer(true); if (_channels[channel].NestedMacros.TryPop(out MacroFile macroFile)) { Console.WriteLine($"[info] Aborted last macro file '{macroFile.FileName}'"); macroFile.Dispose(); } } }
private static async Task HandleAbortFileRequest() { DataTransfer.ReadAbortFile(out CodeChannel channel); Console.WriteLine($"[info] Received file abort request for channel {channel}"); if (channel == CodeChannel.File) { await Print.Cancel(); } MacroFile.AbortAllFiles(channel); Channels[channel].InvalidateBuffer(); }