From 929dccb75a1405737975d76648e015a3e7c00177 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 7 Oct 2017 23:07:10 -0400 Subject: reorganise repo structure --- .../Framework/DeprecationManager.cs | 105 --------------------- 1 file changed, 105 deletions(-) delete mode 100644 src/StardewModdingAPI/Framework/DeprecationManager.cs (limited to 'src/StardewModdingAPI/Framework/DeprecationManager.cs') diff --git a/src/StardewModdingAPI/Framework/DeprecationManager.cs b/src/StardewModdingAPI/Framework/DeprecationManager.cs deleted file mode 100644 index b07c6c7d..00000000 --- a/src/StardewModdingAPI/Framework/DeprecationManager.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace StardewModdingAPI.Framework -{ - /// Manages deprecation warnings. - internal class DeprecationManager - { - /********* - ** Properties - *********/ - /// The deprecations which have already been logged (as 'mod name::noun phrase::version'). - private readonly HashSet LoggedDeprecations = new HashSet(StringComparer.InvariantCultureIgnoreCase); - - /// Encapsulates monitoring and logging for a given module. - private readonly IMonitor Monitor; - - /// Tracks the installed mods. - private readonly ModRegistry ModRegistry; - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// Encapsulates monitoring and logging for a given module. - /// Tracks the installed mods. - public DeprecationManager(IMonitor monitor, ModRegistry modRegistry) - { - this.Monitor = monitor; - this.ModRegistry = modRegistry; - } - - /// Log a deprecation warning. - /// A noun phrase describing what is deprecated. - /// The SMAPI version which deprecated it. - /// How deprecated the code is. - public void Warn(string nounPhrase, string version, DeprecationLevel severity) - { - this.Warn(this.ModRegistry.GetModFromStack(), nounPhrase, version, severity); - } - - /// Log a deprecation warning. - /// The friendly mod name which used the deprecated code. - /// A noun phrase describing what is deprecated. - /// The SMAPI version which deprecated it. - /// How deprecated the code is. - public void Warn(string source, string nounPhrase, string version, DeprecationLevel severity) - { - // ignore if already warned - if (!this.MarkWarned(source ?? "", nounPhrase, version)) - return; - - // build message - string message = $"{source ?? "An unknown mod"} uses deprecated code ({nounPhrase})."; - if (source == null) - message += $"{Environment.NewLine}{Environment.StackTrace}"; - - // log message - switch (severity) - { - case DeprecationLevel.Notice: - this.Monitor.Log(message, LogLevel.Trace); - break; - - case DeprecationLevel.Info: - this.Monitor.Log(message, LogLevel.Debug); - break; - - case DeprecationLevel.PendingRemoval: - this.Monitor.Log(message, LogLevel.Warn); - break; - - default: - throw new NotSupportedException($"Unknown deprecation level '{severity}'"); - } - } - - /// Mark a deprecation warning as already logged. - /// A noun phrase describing what is deprecated (e.g. "the Extensions.AsInt32 method"). - /// The SMAPI version which deprecated it. - /// Returns whether the deprecation was successfully marked as warned. Returns false if it was already marked. - public bool MarkWarned(string nounPhrase, string version) - { - return this.MarkWarned(this.ModRegistry.GetModFromStack(), nounPhrase, version); - } - - /// Mark a deprecation warning as already logged. - /// The friendly name of the assembly which used the deprecated code. - /// A noun phrase describing what is deprecated (e.g. "the Extensions.AsInt32 method"). - /// The SMAPI version which deprecated it. - /// Returns whether the deprecation was successfully marked as warned. Returns false if it was already marked. - public bool MarkWarned(string source, string nounPhrase, string version) - { - if (string.IsNullOrWhiteSpace(source)) - throw new InvalidOperationException("The deprecation source cannot be empty."); - - string key = $"{source}::{nounPhrase}::{version}"; - if (this.LoggedDeprecations.Contains(key)) - return false; - this.LoggedDeprecations.Add(key); - return true; - } - } -} -- cgit