// Copyright Epic Games, Inc. All Rights Reserved. using Microsoft.Extensions.Logging; namespace HordeAgent.Services { /// /// Outcome from a session /// enum SessionOutcome { /// /// Continue the session with a backoff /// BackOff, /// /// Session completed normally, terminate the application. /// Terminate, /// /// Runs the given callback then attempts to reconnect /// RunCallback, } /// /// Reason for outcome of a session /// enum SessionReason { /// /// Session completed its operations normally /// Completed, /// /// Session encountered an unrecoverable error /// Failed, /// /// Session was explicitly cancelled by user or system /// Cancelled, } /// /// Result from executing a session /// class SessionResult : IEquatable { /// /// The outcome code /// public SessionOutcome Outcome { get; } /// /// Reason for the outcome /// public SessionReason Reason { get; } /// /// Callback for running upgrades /// public Func? CallbackAsync { get; } /// /// Constructor /// public SessionResult(SessionOutcome outcome, SessionReason reason) { Outcome = outcome; Reason = reason; } /// /// Constructor /// public SessionResult(Func callbackAsync) { Outcome = SessionOutcome.RunCallback; CallbackAsync = callbackAsync; } public bool Equals(SessionResult? other) { return Outcome == other?.Outcome && Reason == other.Reason; } public override bool Equals(object? obj) { return obj is SessionResult other && Equals(other); } public override int GetHashCode() { return HashCode.Combine((int)Outcome, (int)Reason); } public override string ToString() { return $"Outcome={Outcome} Reason={Reason}"; } } }