Refactoring

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

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

@ -28,7 +28,7 @@ namespace ConfigurationTests
Console.WriteLine($"\tAppName: {config.Service.AppName}"); Console.WriteLine($"\tAppName: {config.Service.AppName}");
Console.WriteLine($"\tServiceGroup: {config.Service.ServiceGroup}"); Console.WriteLine($"\tServiceGroup: {config.Service.ServiceGroup}");
Console.WriteLine($"\tServiceType: {config.Service.ServiceType}"); Console.WriteLine($"\tServiceType: {config.Service.ServiceType}");
Console.ReadKey(); Console.ReadKey();
} }
} }

@ -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 Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using ZeroLevel;
using System.Linq;
using System.Reflection;
using System.Text;
using ZeroLevel.Services.Web; using ZeroLevel.Services.Web;
namespace TestApp namespace TestApp

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

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

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

@ -31,7 +31,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZeroLevel.SQL", "ZeroLevel.
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZeroNetworkMonitor", "ZeroNetworkMonitor\ZeroNetworkMonitor.csproj", "{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZeroNetworkMonitor", "ZeroNetworkMonitor\ZeroNetworkMonitor.csproj", "{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}"
EndProject 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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|x64.Build.0 = Release|Any CPU
{E37785CE-E75A-49FB-B17F-16A0F2C6D656}.Release|x86.ActiveCfg = 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 {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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

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

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

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

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

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

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

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

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

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

@ -1,7 +1,5 @@
using System; using System;
using ZeroLevel.Logging; using ZeroLevel.Logging;
using ZeroLevel.Services.Logging;
using ZeroLevel.Services.Logging.Implementation;
namespace ZeroLevel namespace ZeroLevel
{ {
@ -20,20 +18,7 @@ namespace ZeroLevel
_router = new LogRouter(); _router = new LogRouter();
} }
#endregion Ctor #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 #region Logging
@ -254,5 +239,18 @@ namespace ZeroLevel
} }
#endregion Disposable #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; using System;
namespace ZeroLevel.Services.Logging namespace ZeroLevel.Logging
{ {
/// <summary> /// <summary>
/// Enum contains possible types of messages to write to the log /// Enum contains possible types of messages to write to the log

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

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

@ -1,9 +1,10 @@
using System; using System;
using System.Collections.Concurrent; 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 = private readonly BlockingCollection<Tuple<LogLevel, string>> _messageQueue =
new BlockingCollection<Tuple<LogLevel, string>>(); new BlockingCollection<Tuple<LogLevel, string>>();

Loading…
Cancel
Save

Powered by TurnKey Linux.