# HG changeset patch # User cin # Date 2018-04-20 16:05:12 # Node ID 6b3e5c48131b1871dcbb966038b9e7b1d75b43c4 # Parent 254d1f255d8771fb39c9e9fd67db70909d077408 Working on Unity xml configuration diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -23,3 +23,5 @@ Implab.Format.Test/obj/ packages/ Implab.Playground/obj/ Implab.Playground/bin/ +Implab.ServiceHost/bin/ +Implab.ServiceHost/obj/ diff --git a/.vscode/launch.json b/.vscode/launch.json --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,5 @@ "**/.DS_Store": true, "**/bin": true, "**/obj": true - }, - "omnisharp.useMono": true + } } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -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 diff --git a/Implab.Playground/Implab.Playground.csproj b/Implab.Playground/Implab.Playground.csproj --- a/Implab.Playground/Implab.Playground.csproj +++ b/Implab.Playground/Implab.Playground.csproj @@ -1,20 +1,25 @@ - - - netcoreapp2.0;net46 - /usr/lib/mono/4.6-api/ - - - - netcoreapp2.0;net46 - - - - Exe - false - - - - - - - + + + netcoreapp2.0 + /usr/lib/mono/4.6-api/ + + + + netcoreapp2.0;net46 + + + + Exe + false + + + + + + + + + + + + diff --git a/Implab.Playground/Program.cs b/Implab.Playground/Program.cs --- a/Implab.Playground/Program.cs +++ b/Implab.Playground/Program.cs @@ -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; + + public class Foo { + public int IntValue { get; set; } + + public string StringValue { get; set; } + + } + + public class Container { + 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.TraceSource; - source.Switch.Level = SourceLevels.All; - - source.Listeners.Add(listener); + var container = new UnityContainer(); - var t = Environment.TickCount; + var containerConfig = SerializationHelpers.DeserializeFromFile("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"); - } - } } } diff --git a/Implab.Playground/data/sample.xml b/Implab.Playground/data/sample.xml new file mode 100644 --- /dev/null +++ b/Implab.Playground/data/sample.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Implab.ServiceHost/Implab.ServiceHost.csproj b/Implab.ServiceHost/Implab.ServiceHost.csproj new file mode 100644 --- /dev/null +++ b/Implab.ServiceHost/Implab.ServiceHost.csproj @@ -0,0 +1,16 @@ + + + + netstandard2.0;net46 + /usr/lib/mono/4.6-api/ + + + + + + + + + + + diff --git a/Implab.ServiceHost/Unity/ContainerElement.cs b/Implab.ServiceHost/Unity/ContainerElement.cs new file mode 100644 --- /dev/null +++ b/Implab.ServiceHost/Unity/ContainerElement.cs @@ -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 Registrations {get; set; } = new List(); + + public XmlSchema GetSchema() { + return null; + } + + public void ReadXml(XmlReader reader) { + while(reader.Read() && reader.NodeType != XmlNodeType.EndElement) { + var registration = SerializationHelpers.Deserialize(reader); + Registrations.Add(registration); + } + } + + public void WriteXml(XmlWriter writer) { + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Implab.ServiceHost/Unity/Schema.cs b/Implab.ServiceHost/Unity/Schema.cs new file mode 100644 --- /dev/null +++ b/Implab.ServiceHost/Unity/Schema.cs @@ -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 diff --git a/Implab.ServiceHost/Unity/ServiceElement.cs b/Implab.ServiceHost/Unity/ServiceElement.cs new file mode 100644 --- /dev/null +++ b/Implab.ServiceHost/Unity/ServiceElement.cs @@ -0,0 +1,28 @@ +using System; +using System.Xml.Serialization; + +namespace Implab.ServiceHost.Unity { + + [XmlRoot("register", Namespace = Schema.ContainerConfigurationNamespace)] + public class ServiceElement { + /// + /// An optional name for a registration in the container + /// + [XmlAttribute("name")] + public string Name { get; set; } + + /// + /// An optional type specification for the service registration, + /// must be assignable from the type specified by + /// + [XmlAttribute("provides")] + public string ProvidesType { get; set; } + + /// + /// The type which is registered as a service in the container. + /// + [XmlAttribute("type")] + public string ImplementedType { get; set; } + } + +} \ No newline at end of file diff --git a/Implab.ServiceHost/Unity/TypeReference.cs b/Implab.ServiceHost/Unity/TypeReference.cs new file mode 100644 --- /dev/null +++ b/Implab.ServiceHost/Unity/TypeReference.cs @@ -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 diff --git a/Implab.ServiceHost/Unity/TypeReferenceParser.cs b/Implab.ServiceHost/Unity/TypeReferenceParser.cs new file mode 100644 --- /dev/null +++ b/Implab.ServiceHost/Unity/TypeReferenceParser.cs @@ -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 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 diff --git a/Implab.Test/Implab.Test.csproj b/Implab.Test/Implab.Test.csproj --- a/Implab.Test/Implab.Test.csproj +++ b/Implab.Test/Implab.Test.csproj @@ -1,6 +1,6 @@ - netcoreapp2.0 + netcoreapp2.0;net46 /usr/lib/mono/4.5/ diff --git a/Implab.sln b/Implab.sln --- a/Implab.sln +++ b/Implab.sln @@ -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 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A 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 @@ Global {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