// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tools.DotNETCommon { /// /// Writes a status message to the log, which can be updated with a progress indicator as a slow task is being performed. /// public class LogStatusScope : IDisposable { /// /// The base status message /// string Message; /// /// Constructor /// /// The status message public LogStatusScope(string Message) { this.Message = Message; Log.PushStatus(Message); } /// /// Constructor /// /// The format specifier for the message /// Arguments for the status message public LogStatusScope(string Format, params object[] Args) : this(String.Format(Format, Args)) { } /// /// Updates the base status message passed into the constructor. /// /// The status message public void SetMessage(string Message) { this.Message = Message; Log.UpdateStatus(Message); } /// /// Updates the base status message passed into the constructor. /// /// The format specifier for the message /// Arguments for the status message public void SetMessage(string Format, params object[] Args) { SetMessage(String.Format(Format, Args)); } /// /// Appends a progress string to the status message. Overwrites any previous progress message. /// /// The progress message public void SetProgress(string Progress) { StringBuilder FullMessage = new StringBuilder(Message); FullMessage.Append(' '); FullMessage.Append(Progress); Log.UpdateStatus(FullMessage.ToString()); } /// /// Appends a progress string to the status message. Overwrites any previous progress message. /// /// The format specifier for the message /// Arguments for the status message public void SetProgress(string Format, params object[] Args) { StringBuilder FullMessage = new StringBuilder(Message); FullMessage.Append(' '); FullMessage.AppendFormat(Format, Args); Log.UpdateStatus(FullMessage.ToString()); } /// /// Pops the status message from the log. /// public void Dispose() { if(Message != null) { Log.PopStatus(); Message = null; } } } }