////////////////////////////////////////////////////////////////////////////////// // // // Copyright © 2005-2020 nzsjb // // // // This Program is free software; you can redistribute it and/or modify // // it under the terms of the GNU General Public License as published by // // the Free Software Foundation; either version 2, or (at your option) // // any later version. // // // // This Program is distributed in the hope that it will be useful, // // but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU General Public License for more details. // // // // You should have received a copy of the GNU General Public License // // along with GNU Make; see the file COPYING. If not, write to // // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. // // http://www.gnu.org/copyleft/gpl.html // // // ////////////////////////////////////////////////////////////////////////////////// using System; using System.Collections.ObjectModel; namespace DomainObjects { /// /// The class that describes a trace parameter entry. /// public class TraceEntry { /// /// Get the last error message. /// public static string LastError { get { return (lastError); } } /// /// Get the entry name. /// public TraceName Name { get; private set; } /// /// Get or set the number entry parameter. /// public int NumberParameter { get { if (!numberParameterSet) throw (new InvalidOperationException("TraceEntry number parameter not set")); return (numberParameter); } set { numberParameter = value; numberParameterSet = true; } } /// /// Get or set the string entry parameter. /// public string StringParameter { get { if (!stringParameterSet) throw (new InvalidOperationException("TraceEntry string parameter not set")); return (stringParameter); } set { stringParameter = value; stringParameterSet = true; } } /// /// Return true if the entry number parameter has been set; false otherwise. /// public bool NumberParameterSet { get { return (numberParameterSet); } } /// /// Return true if the entry string parameter has been set; false otherwise. /// public bool StringParameterSet { get { return (stringParameterSet); } } private int numberParameter; private bool numberParameterSet; private string stringParameter; private bool stringParameterSet; private static string lastError; private TraceEntry() { } /// /// Initialize a new instance of the TraceEntry class with a name. /// /// The name of the entry. public TraceEntry(TraceName name) { Name = name; } /// /// Initialize a new entry of the TraceEntry class with a name and number parameter. /// /// /// public TraceEntry(TraceName name, int parameter) : this(name) { NumberParameter = parameter; } /// /// Initialize a new entry of the TraceEntry class with a name and string parameter. /// /// /// public TraceEntry(TraceName name, string parameter) : this(name) { StringParameter = parameter; } /// /// Get a string representation of the instance. /// /// A string representing the instance. public override string ToString() { if (numberParameterSet) return (Name.ToString() + "-" + NumberParameter); else { if (stringParameterSet) return (Name.ToString() + "-" + '"' + StringParameter + '"'); else return (Name.ToString()); } } /// /// Copy the instance. /// /// A new instance of the TraceEntry class with the same values as this instance. public TraceEntry Clone() { TraceEntry newEntry = new TraceEntry(Name); if (numberParameterSet) newEntry.NumberParameter = NumberParameter; if (stringParameterSet) newEntry.StringParameter = StringParameter; return (newEntry); } /// /// Get an instance of the TraceEntry from a parameter file entry. /// /// The parameter file entry. /// A new instance of the class. public static TraceEntry GetInstance(string parameter) { string[] parameterParts = parameter.Split(new char[] { '-' }); if (parameterParts.Length == 2 && string.IsNullOrWhiteSpace(parameterParts[1])) return(null); try { TraceEntry traceEntry = new TraceEntry((TraceName)Enum.Parse(typeof(TraceName), parameterParts[0].Trim(), true)); if (parameterParts.Length == 2) { if (parameterParts[1].Trim()[0] != '"') { try { traceEntry.NumberParameter = Int32.Parse(parameterParts[1]); } catch (FormatException) { lastError = "The Trace name '" + parameterParts[0].Trim() + "' has a parameter in the wrong format."; return (null); } catch (OverflowException) { lastError = "The Trace name '" + parameterParts[0].Trim() + "' has a parameter out of range."; return (null); } } else { if (parameterParts[1].Trim().Length < 3 || parameterParts[1].Trim()[parameterParts[1].Length - 1] != '"') return (null); traceEntry.StringParameter = parameterParts[1].Trim().Substring(1, parameterParts[1].Length - 2); } } return (traceEntry); } catch (ArgumentException) { lastError = "The Trace ID '" + parameter.Trim() + "' is undefined and will be ignored."; return (null); } } /// /// Check if a trace name is present. /// /// The name of the trace entry. /// True if the trace name is present; false otherwise. public static bool IsDefined(TraceName traceName) { return false; } /// /// Find a trace entry. /// /// The name of the trace entry. /// The trace entry if it is found; otherwise null public static TraceEntry FindEntry(TraceName traceName) { return (FindEntry(traceName, false)); } /// /// Find a trace entry. /// /// The name of the trace entry. /// True if a parameter must be present; false otherwise. /// The trace entry if it is found; otherwise null public static TraceEntry FindEntry(TraceName traceName, bool withParameter) { //feyris-tan: We don't use these in skyscraper, so we'll just always return null return null; } /// /// Find a trace entry. /// /// The list of trace entries to search. /// The string representation of the debug entry. /// The trace entry if it is found; otherwise null public static TraceEntry FindEntry(Collection traceEntries, string identifier) { if (traceEntries == null) return (null); foreach (TraceEntry traceEntry in traceEntries) { if (traceEntry.ToString().ToUpperInvariant() == identifier.ToUpperInvariant()) return (traceEntry); } return (null); } } }