1
0
Fork 0

Add LinkTable and ConsoleIO System.Console support

master v1.3.0
sheychen 2017-01-19 10:26:11 +01:00
parent aaca034ba8
commit 1c991d37b2
15 changed files with 152 additions and 5 deletions

0
.gitattributes vendored Normal file → Executable file
View File

0
.gitignore vendored Normal file → Executable file
View File

0
License.md Normal file → Executable file
View File

0
MyCommon.sln Normal file → Executable file
View File

0
MyCommon/Binary.cs Normal file → Executable file
View File

1
MyCommon/ConsoleIO.cs Normal file → Executable file
View File

@ -6,6 +6,7 @@ namespace MyCommon
/// <summary>
/// Manager Console with Async I/O
/// </summary>
/// <remarks>No Mono Proof</remarks>
public class ConsoleIO
{
private static string inputBuffer = "";

View File

@ -0,0 +1,127 @@
using System.Collections.Generic;
namespace MyCommon.Generic
{
/// <summary>
/// Two way dictionary
/// </summary>
public class LinkTable<TMain, TSecond>
{
private Dictionary<TMain, TSecond> mainTable;
private Dictionary<TSecond, TMain> secondTable;
public Dictionary<TMain, TSecond> Main { get { return mainTable; } }
public Dictionary<TSecond, TMain> Second { get { return secondTable; } }
public int Count { get { return mainTable.Count; } }
public LinkTable()
{
mainTable = new Dictionary<TMain, TSecond>();
secondTable = new Dictionary<TSecond, TMain>();
}
public void Add(TMain main, TSecond second)
{
mainTable.Add(main, second);
secondTable.Add(second, main);
}
public bool TryAdd(TMain main, TSecond second)
{
try
{
Add(main, second);
return true;
}
catch
{
return false;
}
}
public void Clear()
{
mainTable.Clear();
secondTable.Clear();
}
public bool ContainsMain(TMain main)
{
return mainTable.ContainsKey(main);
}
public bool ContainsSecond(TSecond second)
{
return secondTable.ContainsKey(second);
}
public TMain GetMain(TSecond second)
{
return secondTable[second];
}
public TSecond GetSecond(TMain main)
{
return mainTable[main];
}
public bool TryGetMain(TSecond second, out TMain main)
{
return secondTable.TryGetValue(second, out main);
}
public bool TryGetSecond(TMain main, out TSecond second)
{
return mainTable.TryGetValue(main, out second);
}
public void RemoveMain(TMain main)
{
secondTable.Remove(mainTable[main]);
mainTable.Remove(main);
}
public void RemoveSecond(TSecond second)
{
mainTable.Remove(secondTable[second]);
secondTable.Remove(second);
}
public bool TryRemoveMain(TMain main)
{
if (!mainTable.ContainsKey(main))
return false;
if (!secondTable.ContainsKey(mainTable[main]))
return false;
try
{
RemoveMain(main);
return true;
}
catch
{
return false;
}
}
public bool TryRemoveSecond(TSecond second)
{
if (!secondTable.ContainsKey(second))
return false;
if (!mainTable.ContainsKey(secondTable[second]))
return false;
try
{
RemoveSecond(second);
return true;
}
catch
{
return false;
}
}
}
}

0
MyCommon/Lang.csv Normal file → Executable file
View File

24
MyCommon/Logger.cs Normal file → Executable file
View File

@ -38,15 +38,17 @@ namespace MyCommon
public bool run { get { return _run; } }
private static bool _debug = false;
private static bool _dev = false;
private bool haveConsole = false;
public enum ConsoleTypes { Any, System, IO };
private ConsoleTypes consoleType = ConsoleTypes.Any;
/// <summary>
/// Create log file and start logger thread
/// </summary>
/// <param name="LogPath">Absolute path to logs directory</param>
public void Initialise(string LogPath, ConsoleColor[] backColor, ConsoleColor[] foreColor, logType LogLevel, bool debug, bool dev, bool haveconsole = true)
public void Initialise(string LogPath, ConsoleColor[] backColor, ConsoleColor[] foreColor, logType LogLevel, bool debug, bool dev, ConsoleTypes consoletype = ConsoleTypes.Any)
{
haveConsole = haveconsole;
consoleType = consoletype;
logPath = LogPath;
logBackColor = backColor;
logForeColor = foreColor;
@ -169,8 +171,20 @@ namespace MyCommon
private void ConsoleWrite(Log log)
{
if (haveConsole)
ConsoleIO.Write(new ColorStrings(new ColorString(DateTime.UtcNow.ToString("[yyyy-MM-dd]", CultureInfo.InvariantCulture) + ": " + log.text, logForeColor[(int)log.type], logBackColor[(int)log.type])));
string text = DateTime.UtcNow.ToString("[yyyy-MM-dd]", CultureInfo.InvariantCulture) + ": " + log.text;
switch (consoleType)
{
case ConsoleTypes.System:
Console.ResetColor();
Console.ForegroundColor = logForeColor[(int)log.type];
Console.BackgroundColor = logBackColor[(int)log.type];
Console.WriteLine(text);
break;
case ConsoleTypes.IO:
ConsoleIO.Write(new ColorStrings(new ColorString(text, logForeColor[(int)log.type], logBackColor[(int)log.type])));
break;
}
}
}
}

0
MyCommon/MultiLang.cs Normal file → Executable file
View File

View File

@ -48,10 +48,14 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Strings.cs" />
<Compile Include="XmlManager.cs" />
<Compile Include="Generic\LinkTable.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Lang.csv" />
</ItemGroup>
<ItemGroup>
<Folder Include="Generic\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

0
MyCommon/Properties/AssemblyInfo.cs Normal file → Executable file
View File

0
MyCommon/Strings.cs Normal file → Executable file
View File

0
MyCommon/XmlManager.cs Normal file → Executable file
View File

1
Readme.md Normal file → Executable file
View File

@ -7,6 +7,7 @@ MyCommon is a collection of usefull Classes
* Logger
* Strings
* XmlMananger - 13/12/2016
* LinkTable - 19/001/2017
### Prerequisities