Refactoring

pull/1/head
Ogoun 5 years ago
parent f7c4655d38
commit e56cdfd501

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ZeroLevel\ZeroLevel.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="config.ini">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

@ -0,0 +1,59 @@
using System;
using ZeroLevel;
using ZeroLevel.Patterns.DependencyInjection;
using ZeroLevel.Services.Reflection;
namespace DependencyInjectionTests
{
public interface IDependencyContract
{
bool Invoke();
}
public class DependencyImplementation
: IDependencyContract
{
public bool Invoke() => true;
}
public interface IMyContract
{
string Run();
}
public class MyImplementation
: IMyContract
{
[Resolve]
private IDependencyContract _dependency;
[Parameter("delimeter")]
private string _delimeter;
[Resolve]
private IConfiguration _config;
public string Run() => $"{_config.First("var")}{_delimeter}{_dependency.Invoke()}";
}
class Program
{
static void Main(string[] args)
{
var config = Configuration.Create();
config.Append("var", "bool isWorking");
Injector.Default.Register<IDependencyContract, DependencyImplementation>();
Injector.Default.Register<IMyContract, MyImplementation>();
Injector.Default.Register<IConfiguration>(config);
Injector.Default.Save<string>("delimeter", " = ");
var instance = new MyImplementation();
Injector.Default.Compose(instance);
Console.WriteLine(instance.Run());
Console.ReadKey();
Injector.Dispose();
}
}
}

@ -1,9 +1,6 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using ZeroLevel;
using ZeroLevel.Services.Web;
namespace TestApp

@ -1,4 +1,5 @@
using ZeroLevel;
using ZeroLevel.Logging;
namespace Consumer
{
@ -7,7 +8,7 @@ namespace Consumer
static void Main(string[] args)
{
Bootstrap.Startup<ConsumerService>(args)
.EnableConsoleLog(ZeroLevel.Services.Logging.LogLevel.FullStandart)
.EnableConsoleLog(LogLevel.FullStandart)
.UseDiscovery()
.Run()
.WaitWhileStatus(ZeroServiceStatus.Running)

@ -1,4 +1,5 @@
using ZeroLevel;
using ZeroLevel.Logging;
namespace Processor
{
@ -7,7 +8,7 @@ namespace Processor
static void Main(string[] args)
{
Bootstrap.Startup<ProcessorService>(args)
.EnableConsoleLog(ZeroLevel.Services.Logging.LogLevel.FullStandart)
.EnableConsoleLog(LogLevel.FullStandart)
.UseDiscovery()
.Run()
.WaitWhileStatus(ZeroServiceStatus.Running)

@ -7,7 +7,7 @@ namespace Source
static void Main(string[] args)
{
Bootstrap.Startup<SourceService>(args)
.EnableConsoleLog(ZeroLevel.Services.Logging.LogLevel.FullStandart)
.EnableConsoleLog(ZeroLevel.Logging.LogLevel.FullStandart)
.UseDiscovery()
.Run()
.WaitWhileStatus(ZeroServiceStatus.Running)

@ -31,7 +31,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZeroLevel.SQL", "ZeroLevel.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZeroNetworkMonitor", "ZeroNetworkMonitor\ZeroNetworkMonitor.csproj", "{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfigurationTests", "ConfigurationTests\ConfigurationTests.csproj", "{E37785CE-E75A-49FB-B17F-16A0F2C6D656}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfigurationTests", "ConfigurationTests\ConfigurationTests.csproj", "{E37785CE-E75A-49FB-B17F-16A0F2C6D656}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyInjectionTests", "DependencyInjectionTests\DependencyInjectionTests.csproj", "{665B38E3-A5F2-4AD0-946B-209D80C1AA40}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -199,6 +201,18 @@ Global
{E37785CE-E75A-49FB-B17F-16A0F2C6D656}.Release|x64.Build.0 = Release|Any CPU
{E37785CE-E75A-49FB-B17F-16A0F2C6D656}.Release|x86.ActiveCfg = Release|Any CPU
{E37785CE-E75A-49FB-B17F-16A0F2C6D656}.Release|x86.Build.0 = Release|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Debug|x64.ActiveCfg = Debug|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Debug|x64.Build.0 = Debug|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Debug|x86.ActiveCfg = Debug|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Debug|x86.Build.0 = Debug|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Release|Any CPU.Build.0 = Release|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Release|x64.ActiveCfg = Release|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Release|x64.Build.0 = Release|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Release|x86.ActiveCfg = Release|Any CPU
{665B38E3-A5F2-4AD0-946B-209D80C1AA40}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -1,11 +1,9 @@
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using ZeroLevel.Logging;
using ZeroLevel.Network;
using ZeroLevel.Services;
using ZeroLevel.Services.Logging;
namespace ZeroLevel
{

@ -1287,9 +1287,7 @@ namespace ZeroLevel.Patterns.DependencyInjection
public object Get(Type type, string key)
{
MethodInfo method = typeof(IEverythingStorage).GetMethod("Get");
MethodInfo genericMethod = method.MakeGenericMethod(type);
return genericMethod.Invoke(_everything.Value, new object[] { key });
return _everything.Value.Get(type, key);
}
public void SaveOrUpdate<T>(string key, T value)

@ -1,5 +1,6 @@
using System;
using System.Threading;
using ZeroLevel.Logging;
using ZeroLevel.Services.Collections;
namespace ZeroLevel.Services.Logging

@ -1,4 +1,6 @@
namespace ZeroLevel.Services.Logging
using ZeroLevel.Logging;
namespace ZeroLevel.Logging
{
public interface ILogComposer
{

@ -1,6 +1,7 @@
using System;
using ZeroLevel.Logging;
namespace ZeroLevel.Services.Logging
namespace ZeroLevel.Logging
{
/// <summary>
/// Message queue for logging

@ -1,6 +1,6 @@
using System;
namespace ZeroLevel.Services.Logging
namespace ZeroLevel.Logging
{
public interface ILogger : IDisposable
{

@ -1,6 +1,7 @@
using System;
using ZeroLevel.Services.Logging;
namespace ZeroLevel.Services.Logging.Implementation
namespace ZeroLevel.Logging
{
public sealed class ConsoleLogger
: ILogger

@ -1,6 +1,6 @@
using System;
namespace ZeroLevel.Services.Logging.Implementation
namespace ZeroLevel.Logging
{
public sealed class DelegateLogger : ILogger
{

@ -4,7 +4,7 @@ using System.IO;
using System.Text;
using ZeroLevel.Services.Encryption;
namespace ZeroLevel.Services.Logging.Implementation
namespace ZeroLevel.Logging
{
public class EncryptedFileLogOptions
{

@ -1,7 +1,5 @@
using System;
using ZeroLevel.Logging;
using ZeroLevel.Services.Logging;
using ZeroLevel.Services.Logging.Implementation;
namespace ZeroLevel
{
@ -22,19 +20,6 @@ namespace ZeroLevel
#endregion Ctor
private static string FormatMessage(string line, params object[] args)
{
if (args == null || args.Length == 0) return line;
try
{
return string.Format(line, args);
}
catch
{
return line;
}
}
#region Logging
public static void Raw(string line, params object[] args)
@ -254,5 +239,18 @@ namespace ZeroLevel
}
#endregion Disposable
private static string FormatMessage(string line, params object[] args)
{
if (args == null || args.Length == 0) return line;
try
{
return string.Format(line, args);
}
catch
{
return line;
}
}
}
}

@ -1,6 +1,6 @@
using System;
namespace ZeroLevel.Services.Logging
namespace ZeroLevel.Logging
{
/// <summary>
/// Enum contains possible types of messages to write to the log

@ -1,6 +1,7 @@
using System.Collections.Generic;
using ZeroLevel.Logging;
namespace ZeroLevel.Services.Logging
namespace ZeroLevel.Logging
{
internal static class LogLevelNameMapping
{

@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using System.Threading;
using ZeroLevel.Services.Logging;
namespace ZeroLevel.Services.Logging
namespace ZeroLevel.Logging
{
internal sealed class LogRouter :
ILogger,

@ -1,9 +1,10 @@
using System;
using System.Collections.Concurrent;
namespace ZeroLevel.Services.Logging
namespace ZeroLevel.Logging
{
internal sealed class NoLimitedLogMessageBuffer : ILogMessageBuffer
internal sealed class NoLimitedLogMessageBuffer
: ILogMessageBuffer
{
private readonly BlockingCollection<Tuple<LogLevel, string>> _messageQueue =
new BlockingCollection<Tuple<LogLevel, string>>();

Loading…
Cancel
Save

Powered by TurnKey Linux.