private async Task PostProcessSession(IServerSession session, TaskResult result) { try { await session.ReleaseAsync(); } catch (Exception error) { Log.Warn($"Failed to release session '{session.SessionId}'!", error); } finally { session.Complete(result); } try { session.OnPostBuildEvent(); } catch (Exception error) { Log.Error("Session post-build event failed!", error); } }
private async Task PostProcessSession(IServerSession session, TaskResult result) { session.Output.WriteLine("Destroying working directory...", ConsoleColor.DarkCyan); try { await session.ReleaseAsync(); } catch (Exception error) { Log.Warn($"Failed to release session '{session.SessionId}'!", error); } finally { session.Complete(result); } try { session.OnPostBuildEvent(); } catch (Exception error) { Log.Error("Session post-build event failed!", error); } }
private async Task OnProcess(IServerSession session) { Log.Debug($"Processing Script Session '{session.SessionId}'."); var abort = false; var errorList = new List <Exception>(); try { session.OnPreBuildEvent(); } catch (Exception error) { Log.Error("Pre-Build Event Failed!", error); } try { session.Output .AppendLine("Preparing working directory...", ConsoleColor.DarkCyan); await session.PrepareWorkDirectoryAsync(); } catch (Exception error) { var _e = error; if (error is AggregateException _ae) { _e = _ae.Flatten(); } session.Output .Append("Failed to prepare working directory! ", ConsoleColor.DarkRed) .AppendLine(_e.UnfoldMessages(), ConsoleColor.DarkYellow); abort = true; errorList.Add(_e); } TaskResult result = null; if (!abort) { try { session.Output .AppendLine("Running script...", ConsoleColor.DarkCyan); await session.RunAsync(); result = TaskResult.Ok(); } catch (Exception error) { result = TaskResult.Error(error); errorList.Add(error); //abort = true; session.Output .Append("Script Failed! ", ConsoleColor.DarkRed) .AppendLine(error.UnfoldMessages(), ConsoleColor.DarkYellow); } } session.Output .AppendLine("Destroying working directory...", ConsoleColor.DarkCyan); try { await session.ReleaseAsync(); } catch (Exception error) { session.Output .AppendLine(error.UnfoldMessages(), ConsoleColor.DarkYellow); errorList.Add(error); } finally { session.Complete(result); } try { session.OnPostBuildEvent(); } catch (Exception error) { Log.Error("Post-Build Event Failed!", error); } if (errorList.Count > 1) { session.Exception = new AggregateException(errorList); } else if (errorList.Count == 1) { session.Exception = errorList[0]; } if (session.Exception != null) { Log.Warn($"Completed Script Session '{session.SessionId}' with errors.", session.Exception); } else { Log.Debug($"Completed Script Session '{session.SessionId}' successfully."); } }