using System;
namespace VoiceAttack_Plugin_HelloWorld
{
///
/// A class for methods providing a means to long strings of data to the VoiceAttack Event Log without being truncated.
///
public static class Logging
{
///
/// A method to write very long messages to the VoiceAttack Event Log, wrapping text
/// which exceeds the minimum width of the window to a new event log entry on a new line.
///
/// Use this method by passing the VA proxy object, the string to write, and the color (or "blank" for no color)
///
/// The dynamic object which provides VoiceAttack attributes and functionality for this plugin.
/// The text string containing the message to write to the Event Log without truncation.
/// The color of the square to the left of each Event Log entry.
public static void WriteToLog_Long(dynamic VA, string longString, string colorString)
{
try
{
int maxWidth = 91;
string[] lines = longString.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
foreach (string line in lines)
{
if (line.Length <= maxWidth)
{
VA.WriteToLog(line, colorString);
continue;
}
int index = 0;
while (index < line.Length)
{
try
{
int length = Math.Min(maxWidth, line.Length - index);
if (length == maxWidth)
{
// Check if the line should wrap at a whitespace
int lastSpaceIndex = line.LastIndexOf(' ', index + length, length);
if (lastSpaceIndex != -1 && lastSpaceIndex != index + length)
{
length = lastSpaceIndex - index;
}
}
VA.WriteToLog(line.Substring(index, length), colorString);
index += length;
// Ignore whitespace at the beginning of a new line
while (index < line.Length && char.IsWhiteSpace(line[index]))
{
index++;
}
}
catch (ArgumentOutOfRangeException)
{
// Catch ArgumentOutOfRangeException and continue the loop
VA.WriteToLog("VoiceAttack Plugin Error: ArgumentOutOfRangeException caught at WriteToLog_Long() method", "red");
continue;
}
}
}
}
catch
{
VA.WriteToLog("VoiceAttack Plugin Error: Failure ignored at WriteToLog_Long() method", "red");
}
}
}
}