Mercurial > pub > ImplabNet
changeset 267:6b3e5c48131b v3
Working on Unity xml configuration
author | cin |
---|---|
date | Fri, 20 Apr 2018 19:05:12 +0300 |
parents | 254d1f255d87 |
children | 0be8a6ae8307 |
files | .hgignore .vscode/launch.json .vscode/settings.json .vscode/tasks.json Implab.Playground/Implab.Playground.csproj Implab.Playground/Program.cs Implab.Playground/data/sample.xml Implab.ServiceHost/Implab.ServiceHost.csproj Implab.ServiceHost/Unity/ContainerElement.cs Implab.ServiceHost/Unity/Schema.cs Implab.ServiceHost/Unity/ServiceElement.cs Implab.ServiceHost/Unity/TypeReference.cs Implab.ServiceHost/Unity/TypeReferenceParser.cs Implab.Test/Implab.Test.csproj Implab.sln |
diffstat | 15 files changed, 338 insertions(+), 115 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Mon Apr 16 19:45:18 2018 +0300 +++ b/.hgignore Fri Apr 20 19:05:12 2018 +0300 @@ -23,3 +23,5 @@ packages/ Implab.Playground/obj/ Implab.Playground/bin/ +Implab.ServiceHost/bin/ +Implab.ServiceHost/obj/
--- a/.vscode/launch.json Mon Apr 16 19:45:18 2018 +0300 +++ b/.vscode/launch.json Fri Apr 20 19:05:12 2018 +0300 @@ -1,39 +1,18 @@ { "version": "0.2.0", "configurations": [ - { - "name": "Launch webserver", - "type": "mono", + "name": ".NET Core Launch (console)", + "type": "coreclr", "request": "launch", - "program": "/usr/lib/mono/4.5/xsp4.exe", - "args":[ - "--root=.", - "--port=8081", - "-v", - "--printlog" - ], "preLaunchTask": "build", - "cwd": "${workspaceRoot}/Pallada.PoiskAvia.Web", - "runtimeExecutable": null, - "env": {}, - "console": "integratedTerminal" - },{ - "name": "Launch model tests", - "type": "mono", - "request": "launch", - "program": "${env:HOME}/.nuget/packages/nunit.consolerunner/3.7.0/tools/nunit3-console.exe", + "program": "${workspaceRoot}/Implab.Playground/bin/Debug/netcoreapp2.0/Implab.Playground.dll", "args": [ - "${workspaceRoot}/Pallada.PoiskAvia.Model.Test/bin/Debug/net45/Pallada.PoiskAvia.Model.Test.mono.dll", - "--where=\"cat==Debug\"", - "--labels='On'", - "--inprocess", - "--workers=1" + "-f", "netcoreapp2.0" ], - "preLaunchTask": "build", - "console": "internalConsole", - "internalConsoleOptions": "openOnSessionStart", - "cwd": "${workspaceRoot}/Pallada.PoiskAvia.Model.Test/" + "cwd": "${workspaceRoot}/Implab.Playground", + "stopAtEntry": false, + "console": "internalConsole" } ] } \ No newline at end of file
--- a/.vscode/settings.json Mon Apr 16 19:45:18 2018 +0300 +++ b/.vscode/settings.json Fri Apr 20 19:05:12 2018 +0300 @@ -8,6 +8,5 @@ "**/.DS_Store": true, "**/bin": true, "**/obj": true - }, - "omnisharp.useMono": true + } } \ No newline at end of file
--- a/.vscode/tasks.json Mon Apr 16 19:45:18 2018 +0300 +++ b/.vscode/tasks.json Fri Apr 20 19:05:12 2018 +0300 @@ -2,26 +2,20 @@ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "0.1.0", - "command": "msbuild", + "command": "dotnet", "args": [ - // Ask msbuild to generate full paths for file names. - "/property:GenerateFullPaths=true" ], - "taskSelector": "/t:", "showOutput": "silent", "tasks": [ { "taskName": "build", - "suppressTaskName": true, // Show the output window only if unrecognized errors occur. "showOutput": "always", // Use the standard MS compiler pattern to detect errors, warnings and infos "problemMatcher": "$msCompile", "args" : [ - "/t:restore;build", - "/p:Configuration=DebugMono", - "Pallada.PoiskAvia.mono.sln" + "/p:Configuration=Debug" ] }, { @@ -29,27 +23,15 @@ // Show the output window only if unrecognized errors occur. "showOutput": "always", // Use the standard MS compiler pattern to detect errors, warnings and infos - "problemMatcher": "$msCompile", - - "args" : [ - "/p:Configuration=DebugMono", - "Pallada.PoiskAvia.mono.sln" - ] + "problemMatcher": "$msCompile" }, { - "taskName": "runtests", + "taskName": "test", "isTestCommand": true, - "suppressTaskName": true, // Show the output window only if unrecognized errors occur. "showOutput": "always", // Use the standard MS compiler pattern to detect errors, warnings and infos - "problemMatcher": "$msCompile", - - "args" : [ - "/t:runtests", - "/p:Configuration=DebugMono", - "Pallada.PoiskAvia.mono.sln" - ] + "problemMatcher": "$msCompile" } ] } \ No newline at end of file
--- a/Implab.Playground/Implab.Playground.csproj Mon Apr 16 19:45:18 2018 +0300 +++ b/Implab.Playground/Implab.Playground.csproj Fri Apr 20 19:05:12 2018 +0300 @@ -1,20 +1,25 @@ -<Project Sdk="Microsoft.NET.Sdk"> - <PropertyGroup Condition="'$(OSTYPE)'=='linux'"> - <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks> - <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.6-api/</FrameworkPathOverride> - </PropertyGroup> - - <PropertyGroup Condition="'$(OSTYPE)'=='windows'"> - <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks> - </PropertyGroup> - - <PropertyGroup> - <OutputType>Exe</OutputType> - <IsPackable>false</IsPackable> - </PropertyGroup> - - <ItemGroup> - <ProjectReference Include="../Implab/Implab.csproj"/> - </ItemGroup> - -</Project> +<Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup Condition="'$(OSTYPE)'=='linux'"> + <TargetFramework>netcoreapp2.0</TargetFramework> + <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.6-api/</FrameworkPathOverride> + </PropertyGroup> + + <PropertyGroup Condition="'$(OSTYPE)'=='windows'"> + <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks> + </PropertyGroup> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <IsPackable>false</IsPackable> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="../Implab/Implab.csproj" /> + <ProjectReference Include="..\Implab.ServiceHost\Implab.ServiceHost.csproj" /> + </ItemGroup> + + <ItemGroup> + <PackageReference Include="Unity" Version="5.8.5" /> + </ItemGroup> + +</Project>
--- a/Implab.Playground/Program.cs Mon Apr 16 19:45:18 2018 +0300 +++ b/Implab.Playground/Program.cs Fri Apr 20 19:05:12 2018 +0300 @@ -1,54 +1,40 @@ -using Implab.Diagnostics; -using Implab.Formats.Json; -using Implab.Parallels; +using System; +using Implab.ServiceHost.Unity; using Implab.Xml; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Xml; -using System.Xml.Serialization; +using Unity; +using Unity.Injection; namespace Implab.Playground { - using System.Diagnostics; - using static Trace<Program>; + + public class Foo { + public int IntValue { get; set; } + + public string StringValue { get; set; } + + } + + public class Container<T> { + public Container() { + + } + + public Container(T instance) { + Instance = instance; + } + + public T Instance { get; set; } + } public class Program { static void Main(string[] args) { - var listener = new SimpleTraceListener(Console.Out); - - var source = Trace<Program>.TraceSource; - source.Switch.Level = SourceLevels.All; - - source.Listeners.Add(listener); + var container = new UnityContainer(); - var t = Environment.TickCount; + var containerConfig = SerializationHelpers.DeserializeFromFile<ContainerElement>("data/sample.xml"); - Main().Wait(); - - Console.WriteLine($"Done: {Environment.TickCount - t} ms"); - Console.ReadKey(); + Console.WriteLine($"container: {containerConfig.Registrations.Count}"); } - static async Task Main() { - using (LogicalOperation(nameof(Main))) { - Log("Start"); - await SomeAsync(); - Log("End"); - } - } - static async Task SomeAsync() { - using (LogicalOperation(nameof(SomeAsync))) { - Log("Do prepare"); - await Task.Yield(); - Log("Yield"); - } - } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab.Playground/data/sample.xml Fri Apr 20 19:05:12 2018 +0300 @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<container xmlns="http://implab.org/schemas/servicehost/unity.v1.xsd"> + <!-- foo1 --> + <register name="foo1" provides="IFoo" type="Foo"> + </register> + + <!-- foo2 --> + <register name="foo2" provides="IFoo" type="Foo"> + </register> +</container> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab.ServiceHost/Implab.ServiceHost.csproj Fri Apr 20 19:05:12 2018 +0300 @@ -0,0 +1,16 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFrameworks>netstandard2.0;net46</TargetFrameworks> + <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.6-api/</FrameworkPathOverride> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Unity" Version="5.8.5" /> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\Implab\Implab.csproj" /> + </ItemGroup> + +</Project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab.ServiceHost/Unity/ContainerElement.cs Fri Apr 20 19:05:12 2018 +0300 @@ -0,0 +1,28 @@ +using Implab.Xml; +using System.Collections.Generic; +using System.Xml; +using System.Xml.Schema; +using System.Xml.Serialization; + +namespace Implab.ServiceHost.Unity { + [XmlRoot("container", Namespace = Schema.ContainerConfigurationNamespace)] + public class ContainerElement : IXmlSerializable { + + public List<ServiceElement> Registrations {get; set; } = new List<ServiceElement>(); + + public XmlSchema GetSchema() { + return null; + } + + public void ReadXml(XmlReader reader) { + while(reader.Read() && reader.NodeType != XmlNodeType.EndElement) { + var registration = SerializationHelpers.Deserialize<ServiceElement>(reader); + Registrations.Add(registration); + } + } + + public void WriteXml(XmlWriter writer) { + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab.ServiceHost/Unity/Schema.cs Fri Apr 20 19:05:12 2018 +0300 @@ -0,0 +1,5 @@ +namespace Implab.ServiceHost.Unity { + public static class Schema { + public const string ContainerConfigurationNamespace = "http://implab.org/schemas/servicehost/unity.v1.xsd"; + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab.ServiceHost/Unity/ServiceElement.cs Fri Apr 20 19:05:12 2018 +0300 @@ -0,0 +1,28 @@ +using System; +using System.Xml.Serialization; + +namespace Implab.ServiceHost.Unity { + + [XmlRoot("register", Namespace = Schema.ContainerConfigurationNamespace)] + public class ServiceElement { + /// <summary> + /// An optional name for a registration in the container + /// </summary> + [XmlAttribute("name")] + public string Name { get; set; } + + /// <summary> + /// An optional type specification for the service registration, + /// must be assignable from the type specified by <see cref="ImplementedType"/> + /// </summary> + [XmlAttribute("provides")] + public string ProvidesType { get; set; } + + /// <summary> + /// The type which is registered as a service in the container. + /// </summary> + [XmlAttribute("type")] + public string ImplementedType { get; set; } + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab.ServiceHost/Unity/TypeReference.cs Fri Apr 20 19:05:12 2018 +0300 @@ -0,0 +1,9 @@ +namespace Implab.ServiceHost.Unity { + public class TypeReference { + public string TypeName { get; set; } + + public string Namespace { get; set; } + + public TypeReference[] GenericParameters { get; set; } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Implab.ServiceHost/Unity/TypeReferenceParser.cs Fri Apr 20 19:05:12 2018 +0300 @@ -0,0 +1,156 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace Implab.ServiceHost.Unity { + public class TypeReferenceParser { + enum TokenType { + None, + + Word, + + Dot, + + Comma, + + OpenList, + + CloseList, + + Eof + } + + readonly Regex _tokens = new Regex(@"(\w+)|\s*([\.{},])\s*"); + + TokenType m_token; + + string m_tokenValue; + + int m_pos; + + readonly string m_text; + + TokenType Token { get { return m_token; } } + + string TokenValue { get { return m_tokenValue; } } + + public TypeReferenceParser(string text) { + Safe.ArgumentNotEmpty(text, nameof(text)); + m_text = text; + } + + bool ReadToken() { + if (m_pos >= m_text.Length) { + m_token = TokenType.Eof; + m_tokenValue = null; + return false; + } + + var m = _tokens.Match(m_text, m_pos); + + if (m.Success) { + m_pos += m.Length; + if (m.Groups[1].Success) { + m_token = TokenType.Word; + m_tokenValue = m.Groups[1].Value; + } else if (m.Groups[2].Success) { + m_tokenValue = null; + switch (m.Groups[2].Value) { + case "{": + m_token = TokenType.OpenList; + break; + case "}": + m_token = TokenType.CloseList; + break; + case ".": + m_token = TokenType.Dot; + break; + case ",": + m_token = TokenType.Comma; + break; + } + } + return true; + } + throw new FormatException($"Failed to parse '{m_text}' at pos {m_pos}"); + } + + public TypeRerefence Pase() { + + } + + string[] ReadTypeName() { + var parts = new List<string>(); + + string current = null; + bool stop = false; + while ((!stop) && ReadToken()) { + switch (Token) { + case TokenType.Word: + if (current != null) + ThrowUnexpectedToken(); + current = TokenValue; + break; + case TokenType.Dot: + if (current == null) + ThrowUnexpectedToken(); + parts.Add(current); + current = null; + break; + default: + stop = true; + break; + } + } + if (current != null) + parts.Add(current); + + if (parts.Count == 0) + return null; + + return parts.ToArray(); + } + + TypeReference ReadTypeReference() { + + var parts = ReadTypeName(); + if (parts == null) + return null; + + var typeReference = new TypeReference { + Namespace = string.Join(",", parts, 0, parts.Length - 1), + TypeName = parts[parts.Length - 1] + }; + + switch (Token) { + case TokenType.Eof: + break; + case TokenType.OpenList: + typeReference.GenericParameters = ReadTypeReferenceList(); + if(Token != TokenType.CloseList) + ThrowUnexpectedToken(); + break; + default: + ThrowUnexpectedToken(); + break; + } + + return typeReference; + } + + TypeReference[] ReadTypeReferenceList() { + throw new NotImplementedException(); + } + + void ReadDot() { + if (!ReadToken() || Token != TokenType.Dot) + ThrowUnexpectedToken(); + } + + void ThrowUnexpectedToken() { + throw new FormatException($"Unexpected '{Token}' at {m_pos}"); + } + + + } +} \ No newline at end of file
--- a/Implab.Test/Implab.Test.csproj Mon Apr 16 19:45:18 2018 +0300 +++ b/Implab.Test/Implab.Test.csproj Fri Apr 20 19:05:12 2018 +0300 @@ -1,6 +1,6 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup Condition="'$(OSTYPE)'=='linux'"> - <TargetFrameworks>netcoreapp2.0</TargetFrameworks> + <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks> <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.5/</FrameworkPathOverride> </PropertyGroup>
--- a/Implab.sln Mon Apr 16 19:45:18 2018 +0300 +++ b/Implab.sln Fri Apr 20 19:05:12 2018 +0300 @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27428.2005 @@ -9,10 +9,16 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.Playground", "Implab.Playground\Implab.Playground.csproj", "{100DFEB0-75BE-436F-ADDF-1F46EF433F46}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.ServiceHost", "Implab.ServiceHost\Implab.ServiceHost.csproj", "{8B79FCBE-50DD-40A0-9B5E-E572072E4868}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {FF2052B6-9C8F-4022-A347-F07ABF635885}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -27,6 +33,18 @@ {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Debug|Any CPU.Build.0 = Debug|Any CPU {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Release|Any CPU.ActiveCfg = Release|Any CPU {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Release|Any CPU.Build.0 = Release|Any CPU + {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Debug|x64.ActiveCfg = Debug|x64 + {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Debug|x64.Build.0 = Debug|x64 + {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Debug|x86.ActiveCfg = Debug|x86 + {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Debug|x86.Build.0 = Debug|x86 + {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Release|Any CPU.Build.0 = Release|Any CPU + {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Release|x64.ActiveCfg = Release|x64 + {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Release|x64.Build.0 = Release|x64 + {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Release|x86.ActiveCfg = Release|x86 + {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE