Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed static classes #489

Open
wants to merge 10 commits into
base: development
Choose a base branch
from
180 changes: 94 additions & 86 deletions PoGo.PokeMobBot.CLI/ConsoleEventListener.cs

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions PoGo.PokeMobBot.CLI/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ namespace PoGo.PokeMobBot.CLI
public class ConsoleLogger : ILogger
{
private readonly LogLevel _maxLogLevel;
private ISession _session;
private readonly LoggingStrings _loggingStrings;

/// <summary>
/// To create a ConsoleLogger, we must define a maximum log level.
/// All levels above won't be logged.
/// </summary>
/// <param name="maxLogLevel"></param>
internal ConsoleLogger(LogLevel maxLogLevel)
public ConsoleLogger(LogLevel maxLogLevel, LoggingStrings loggingStrings)
{
_maxLogLevel = maxLogLevel;
_loggingStrings = loggingStrings;
}

public void SetSession(ISession session)
public void SetSession()
{
_session = session;
// Create the logging strings here.
LoggingStrings.SetStrings(_session);
_loggingStrings.SetStrings();
}

/// <summary>
Expand All @@ -55,67 +55,67 @@ public void Write(string message, LogLevel level = LogLevel.Info, ConsoleColor c
{
case LogLevel.Error:
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Error}) (v{Assembly.GetExecutingAssembly().GetName().Version}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Error}) (v{Assembly.GetExecutingAssembly().GetName().Version}) {message}");
break;
case LogLevel.Warning:
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Attention}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Attention}) {message}");
break;
case LogLevel.Info:
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Info}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Info}) {message}");
break;
case LogLevel.Pokestop:
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Pokestop}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Pokestop}) {message}");
break;
case LogLevel.Farming:
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Farming}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Farming}) {message}");
break;
case LogLevel.Recycling:
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Recycling}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Recycling}) {message}");
break;
case LogLevel.Caught:
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Pkmn}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Pkmn}) {message}");
break;
case LogLevel.Escape:
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Pkmn}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Pkmn}) {message}");
break;
case LogLevel.Flee:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Pkmn}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Pkmn}) {message}");
break;
case LogLevel.Transfer:
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Transfered}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Transfered}) {message}");
break;
case LogLevel.Evolve:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Evolved}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Evolved}) {message}");
break;
case LogLevel.Berry:
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Berry}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Berry}) {message}");
break;
case LogLevel.Egg:
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Egg}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Egg}) {message}");
break;
case LogLevel.Debug:
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Debug}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Debug}) {message}");
break;
case LogLevel.Update:
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Update}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Update}) {message}");
break;
default:
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Error}) {message}");
Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({_loggingStrings.Error}) {message}");
break;
}
}
Expand Down
64 changes: 35 additions & 29 deletions PoGo.PokeMobBot.CLI/Models/LoggingStrings.cs
Original file line number Diff line number Diff line change
@@ -1,88 +1,94 @@
using PoGo.PokeMobBot.Logic.Common;
using PoGo.PokeMobBot.Logic.State;

namespace PoGo.PokeMobBot.CLI.Models
{
internal class LoggingStrings
public class LoggingStrings
{
internal static string Attention;
private readonly ITranslation _translation;

internal static string Berry;
internal string Attention;

internal static string Debug;
internal string Berry;

internal static string Egg;
internal string Debug;

internal static string Error;
internal string Egg;

internal static string Evolved;
internal string Error;

internal static string Farming;
internal string Evolved;

internal static string Info;
internal string Farming;

internal static string Pkmn;
internal string Info;

internal static string Pokestop;
internal string Pkmn;

internal static string Recycling;
internal string Pokestop;

internal static string Transfered;
internal string Recycling;

internal static string Update;
internal string Transfered;

internal static void SetStrings(ISession session)
internal string Update;

public LoggingStrings(ITranslation translation)
{
_translation = translation;
}

internal void SetStrings()
{
Attention =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryAttention) ?? "ATTENTION";

Berry =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryBerry) ?? "BERRY";

Debug =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryDebug) ?? "DEBUG";

Egg =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryEgg) ?? "EGG";

Error =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryError) ?? "ERROR";

Evolved =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryEvolved) ?? "EVOLVED";

Farming =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryFarming) ?? "FARMING";

Info =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryInfo) ?? "INFO";

Pkmn =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryPkmn) ?? "PKMN";

Pokestop =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryPokestop) ?? "POKESTOP";

Recycling =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryRecycling) ?? "RECYCLING";

Transfered =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryTransfered) ?? "TRANSFERED";

Update =
session?.Translation.GetTranslation(
_translation?.GetTranslation(
TranslationString.LogEntryUpdate) ?? "UPDATE";
}
}
Expand Down
12 changes: 8 additions & 4 deletions PoGo.PokeMobBot.CLI/PoGo.PokeMobBot.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Ninject, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
<HintPath>..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="POGOProtos, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\POGOProtos.1.5.0\lib\net45\POGOProtos.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -205,14 +209,14 @@
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\NecroBot\Pokemon-Go-Rocket-API\PokemonGo.RocketAPI\PokemonGo.RocketAPI.csproj">
<Project>{05d2da44-1b8e-4cf7-94ed-4d52451cd095}</Project>
<Name>PokemonGo.RocketAPI</Name>
</ProjectReference>
<ProjectReference Include="..\PoGo.PokeMobBot.Logic\PoGo.PokeMobBot.Logic.csproj">
<Project>{0739E40D-C589-4AEB-93E5-EE8CD6773C60}</Project>
<Name>PoGo.PokeMobBot.Logic</Name>
</ProjectReference>
<ProjectReference Include="..\Pokemon-Go-Rocket-API\PokemonGo.RocketAPI\PokemonGo.RocketAPI.csproj">
<Project>{05d2da44-1b8e-4cf7-94ed-4d52451cd095}</Project>
<Name>PokemonGo.RocketAPI</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
Expand Down
Loading