##// END OF EJS Templates
Working on Unity xml configuration
cin -
r267:6b3e5c48131b v3
parent child
Show More
@@ -0,0 +1,10
1 <?xml version="1.0" encoding="UTF-8"?>
2 <container xmlns="http://implab.org/schemas/servicehost/unity.v1.xsd">
3 <!-- foo1 -->
4 <register name="foo1" provides="IFoo" type="Foo">
5 </register>
6
7 <!-- foo2 -->
8 <register name="foo2" provides="IFoo" type="Foo">
9 </register>
10 </container> No newline at end of file
@@ -0,0 +1,16
1 <Project Sdk="Microsoft.NET.Sdk">
2
3 <PropertyGroup>
4 <TargetFrameworks>netstandard2.0;net46</TargetFrameworks>
5 <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.6-api/</FrameworkPathOverride>
6 </PropertyGroup>
7
8 <ItemGroup>
9 <PackageReference Include="Unity" Version="5.8.5" />
10 </ItemGroup>
11
12 <ItemGroup>
13 <ProjectReference Include="..\Implab\Implab.csproj" />
14 </ItemGroup>
15
16 </Project>
@@ -0,0 +1,28
1 using Implab.Xml;
2 using System.Collections.Generic;
3 using System.Xml;
4 using System.Xml.Schema;
5 using System.Xml.Serialization;
6
7 namespace Implab.ServiceHost.Unity {
8 [XmlRoot("container", Namespace = Schema.ContainerConfigurationNamespace)]
9 public class ContainerElement : IXmlSerializable {
10
11 public List<ServiceElement> Registrations {get; set; } = new List<ServiceElement>();
12
13 public XmlSchema GetSchema() {
14 return null;
15 }
16
17 public void ReadXml(XmlReader reader) {
18 while(reader.Read() && reader.NodeType != XmlNodeType.EndElement) {
19 var registration = SerializationHelpers.Deserialize<ServiceElement>(reader);
20 Registrations.Add(registration);
21 }
22 }
23
24 public void WriteXml(XmlWriter writer) {
25 throw new System.NotImplementedException();
26 }
27 }
28 } No newline at end of file
@@ -0,0 +1,5
1 namespace Implab.ServiceHost.Unity {
2 public static class Schema {
3 public const string ContainerConfigurationNamespace = "http://implab.org/schemas/servicehost/unity.v1.xsd";
4 }
5 } No newline at end of file
@@ -0,0 +1,28
1 using System;
2 using System.Xml.Serialization;
3
4 namespace Implab.ServiceHost.Unity {
5
6 [XmlRoot("register", Namespace = Schema.ContainerConfigurationNamespace)]
7 public class ServiceElement {
8 /// <summary>
9 /// An optional name for a registration in the container
10 /// </summary>
11 [XmlAttribute("name")]
12 public string Name { get; set; }
13
14 /// <summary>
15 /// An optional type specification for the service registration,
16 /// must be assignable from the type specified by <see cref="ImplementedType"/>
17 /// </summary>
18 [XmlAttribute("provides")]
19 public string ProvidesType { get; set; }
20
21 /// <summary>
22 /// The type which is registered as a service in the container.
23 /// </summary>
24 [XmlAttribute("type")]
25 public string ImplementedType { get; set; }
26 }
27
28 } No newline at end of file
@@ -0,0 +1,9
1 namespace Implab.ServiceHost.Unity {
2 public class TypeReference {
3 public string TypeName { get; set; }
4
5 public string Namespace { get; set; }
6
7 public TypeReference[] GenericParameters { get; set; }
8 }
9 } No newline at end of file
@@ -0,0 +1,156
1 using System;
2 using System.Collections.Generic;
3 using System.Text.RegularExpressions;
4
5 namespace Implab.ServiceHost.Unity {
6 public class TypeReferenceParser {
7 enum TokenType {
8 None,
9
10 Word,
11
12 Dot,
13
14 Comma,
15
16 OpenList,
17
18 CloseList,
19
20 Eof
21 }
22
23 readonly Regex _tokens = new Regex(@"(\w+)|\s*([\.{},])\s*");
24
25 TokenType m_token;
26
27 string m_tokenValue;
28
29 int m_pos;
30
31 readonly string m_text;
32
33 TokenType Token { get { return m_token; } }
34
35 string TokenValue { get { return m_tokenValue; } }
36
37 public TypeReferenceParser(string text) {
38 Safe.ArgumentNotEmpty(text, nameof(text));
39 m_text = text;
40 }
41
42 bool ReadToken() {
43 if (m_pos >= m_text.Length) {
44 m_token = TokenType.Eof;
45 m_tokenValue = null;
46 return false;
47 }
48
49 var m = _tokens.Match(m_text, m_pos);
50
51 if (m.Success) {
52 m_pos += m.Length;
53 if (m.Groups[1].Success) {
54 m_token = TokenType.Word;
55 m_tokenValue = m.Groups[1].Value;
56 } else if (m.Groups[2].Success) {
57 m_tokenValue = null;
58 switch (m.Groups[2].Value) {
59 case "{":
60 m_token = TokenType.OpenList;
61 break;
62 case "}":
63 m_token = TokenType.CloseList;
64 break;
65 case ".":
66 m_token = TokenType.Dot;
67 break;
68 case ",":
69 m_token = TokenType.Comma;
70 break;
71 }
72 }
73 return true;
74 }
75 throw new FormatException($"Failed to parse '{m_text}' at pos {m_pos}");
76 }
77
78 public TypeRerefence Pase() {
79
80 }
81
82 string[] ReadTypeName() {
83 var parts = new List<string>();
84
85 string current = null;
86 bool stop = false;
87 while ((!stop) && ReadToken()) {
88 switch (Token) {
89 case TokenType.Word:
90 if (current != null)
91 ThrowUnexpectedToken();
92 current = TokenValue;
93 break;
94 case TokenType.Dot:
95 if (current == null)
96 ThrowUnexpectedToken();
97 parts.Add(current);
98 current = null;
99 break;
100 default:
101 stop = true;
102 break;
103 }
104 }
105 if (current != null)
106 parts.Add(current);
107
108 if (parts.Count == 0)
109 return null;
110
111 return parts.ToArray();
112 }
113
114 TypeReference ReadTypeReference() {
115
116 var parts = ReadTypeName();
117 if (parts == null)
118 return null;
119
120 var typeReference = new TypeReference {
121 Namespace = string.Join(",", parts, 0, parts.Length - 1),
122 TypeName = parts[parts.Length - 1]
123 };
124
125 switch (Token) {
126 case TokenType.Eof:
127 break;
128 case TokenType.OpenList:
129 typeReference.GenericParameters = ReadTypeReferenceList();
130 if(Token != TokenType.CloseList)
131 ThrowUnexpectedToken();
132 break;
133 default:
134 ThrowUnexpectedToken();
135 break;
136 }
137
138 return typeReference;
139 }
140
141 TypeReference[] ReadTypeReferenceList() {
142 throw new NotImplementedException();
143 }
144
145 void ReadDot() {
146 if (!ReadToken() || Token != TokenType.Dot)
147 ThrowUnexpectedToken();
148 }
149
150 void ThrowUnexpectedToken() {
151 throw new FormatException($"Unexpected '{Token}' at {m_pos}");
152 }
153
154
155 }
156 } No newline at end of file
@@ -1,25 +1,27
1 1 syntax: glob
2 2 Implab.Test/bin/
3 3 *.user
4 4 Implab.Test/obj/
5 5 *.userprefs
6 6 Implab/bin/
7 7 Implab/obj/
8 8 TestResults/
9 9 Implab.Fx/obj/
10 10 Implab.Fx/bin/
11 11 Implab.Fx.Test/bin/
12 12 Implab.Fx.Test/obj/
13 13 _ReSharper.Implab/
14 14 Implab.Diagnostics.Interactive/bin/
15 15 Implab.Diagnostics.Interactive/obj/
16 16 MonoPlay/bin/
17 17 MonoPlay/obj/
18 18 Implab.Test/Implab.Format.Test/bin/
19 19 Implab.Test/Implab.Format.Test/obj/
20 20 *.suo
21 21 Implab.Format.Test/bin/
22 22 Implab.Format.Test/obj/
23 23 packages/
24 24 Implab.Playground/obj/
25 25 Implab.Playground/bin/
26 Implab.ServiceHost/bin/
27 Implab.ServiceHost/obj/
@@ -1,39 +1,18
1 1 {
2 2 "version": "0.2.0",
3 3 "configurations": [
4
5 4 {
6 "name": "Launch webserver",
7 "type": "mono",
5 "name": ".NET Core Launch (console)",
6 "type": "coreclr",
8 7 "request": "launch",
9 "program": "/usr/lib/mono/4.5/xsp4.exe",
10 "args":[
11 "--root=.",
12 "--port=8081",
13 "-v",
14 "--printlog"
15 ],
16 8 "preLaunchTask": "build",
17 "cwd": "${workspaceRoot}/Pallada.PoiskAvia.Web",
18 "runtimeExecutable": null,
19 "env": {},
20 "console": "integratedTerminal"
21 },{
22 "name": "Launch model tests",
23 "type": "mono",
24 "request": "launch",
25 "program": "${env:HOME}/.nuget/packages/nunit.consolerunner/3.7.0/tools/nunit3-console.exe",
9 "program": "${workspaceRoot}/Implab.Playground/bin/Debug/netcoreapp2.0/Implab.Playground.dll",
26 10 "args": [
27 "${workspaceRoot}/Pallada.PoiskAvia.Model.Test/bin/Debug/net45/Pallada.PoiskAvia.Model.Test.mono.dll",
28 "--where=\"cat==Debug\"",
29 "--labels='On'",
30 "--inprocess",
31 "--workers=1"
11 "-f", "netcoreapp2.0"
32 12 ],
33 "preLaunchTask": "build",
34 "console": "internalConsole",
35 "internalConsoleOptions": "openOnSessionStart",
36 "cwd": "${workspaceRoot}/Pallada.PoiskAvia.Model.Test/"
13 "cwd": "${workspaceRoot}/Implab.Playground",
14 "stopAtEntry": false,
15 "console": "internalConsole"
37 16 }
38 17 ]
39 18 } No newline at end of file
@@ -1,13 +1,12
1 1 // ΠŸΠΎΠΌΠ΅ΡΡ‚ΠΈΡ‚Π΅ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ Π² этот Ρ„Π°ΠΉΠ», Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΠ΅Ρ€Π΅Π·Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΈ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠ΅ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹.
2 2 {
3 3 "files.exclude": {
4 4 "**/.git": true,
5 5 "**/.svn": true,
6 6 "**/.hg": true,
7 7 "**/CVS": true,
8 8 "**/.DS_Store": true,
9 9 "**/bin": true,
10 10 "**/obj": true
11 },
12 "omnisharp.useMono": true
11 }
13 12 } No newline at end of file
@@ -1,55 +1,37
1 1 {
2 2 // See https://go.microsoft.com/fwlink/?LinkId=733558
3 3 // for the documentation about the tasks.json format
4 4 "version": "0.1.0",
5 "command": "msbuild",
5 "command": "dotnet",
6 6 "args": [
7 // Ask msbuild to generate full paths for file names.
8 "/property:GenerateFullPaths=true"
9 7 ],
10 "taskSelector": "/t:",
11 8 "showOutput": "silent",
12 9 "tasks": [
13 10 {
14 11 "taskName": "build",
15 "suppressTaskName": true,
16 12 // Show the output window only if unrecognized errors occur.
17 13 "showOutput": "always",
18 14 // Use the standard MS compiler pattern to detect errors, warnings and infos
19 15 "problemMatcher": "$msCompile",
20 16
21 17 "args" : [
22 "/t:restore;build",
23 "/p:Configuration=DebugMono",
24 "Pallada.PoiskAvia.mono.sln"
18 "/p:Configuration=Debug"
25 19 ]
26 20 },
27 21 {
28 22 "taskName": "clean",
29 23 // Show the output window only if unrecognized errors occur.
30 24 "showOutput": "always",
31 25 // Use the standard MS compiler pattern to detect errors, warnings and infos
32 "problemMatcher": "$msCompile",
33
34 "args" : [
35 "/p:Configuration=DebugMono",
36 "Pallada.PoiskAvia.mono.sln"
37 ]
26 "problemMatcher": "$msCompile"
38 27 },
39 28 {
40 "taskName": "runtests",
29 "taskName": "test",
41 30 "isTestCommand": true,
42 "suppressTaskName": true,
43 31 // Show the output window only if unrecognized errors occur.
44 32 "showOutput": "always",
45 33 // Use the standard MS compiler pattern to detect errors, warnings and infos
46 "problemMatcher": "$msCompile",
47
48 "args" : [
49 "/t:runtests",
50 "/p:Configuration=DebugMono",
51 "Pallada.PoiskAvia.mono.sln"
52 ]
34 "problemMatcher": "$msCompile"
53 35 }
54 36 ]
55 37 } No newline at end of file
@@ -1,20 +1,25
1 1 ο»Ώ<Project Sdk="Microsoft.NET.Sdk">
2 2 <PropertyGroup Condition="'$(OSTYPE)'=='linux'">
3 <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
3 <TargetFramework>netcoreapp2.0</TargetFramework>
4 4 <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.6-api/</FrameworkPathOverride>
5 5 </PropertyGroup>
6 6
7 7 <PropertyGroup Condition="'$(OSTYPE)'=='windows'">
8 8 <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
9 9 </PropertyGroup>
10 10
11 11 <PropertyGroup>
12 12 <OutputType>Exe</OutputType>
13 13 <IsPackable>false</IsPackable>
14 14 </PropertyGroup>
15 15
16 16 <ItemGroup>
17 17 <ProjectReference Include="../Implab/Implab.csproj"/>
18 <ProjectReference Include="..\Implab.ServiceHost\Implab.ServiceHost.csproj" />
19 </ItemGroup>
20
21 <ItemGroup>
22 <PackageReference Include="Unity" Version="5.8.5" />
18 23 </ItemGroup>
19 24
20 25 </Project>
@@ -1,54 +1,40
1 using Implab.Diagnostics;
2 using Implab.Formats.Json;
3 using Implab.Parallels;
1 using System;
2 using Implab.ServiceHost.Unity;
4 3 using Implab.Xml;
5 using System;
6 using System.Collections.Concurrent;
7 using System.Collections.Generic;
8 using System.IO;
9 using System.Linq;
10 using System.Text;
11 using System.Threading;
12 using System.Threading.Tasks;
13 using System.Xml;
14 using System.Xml.Serialization;
4 using Unity;
5 using Unity.Injection;
15 6
16 7 namespace Implab.Playground {
17 using System.Diagnostics;
18 using static Trace<Program>;
8
9 public class Foo {
10 public int IntValue { get; set; }
11
12 public string StringValue { get; set; }
13
14 }
15
16 public class Container<T> {
17 public Container() {
18
19 }
20
21 public Container(T instance) {
22 Instance = instance;
23 }
24
25 public T Instance { get; set; }
26 }
19 27
20 28 public class Program {
21 29
22 30 static void Main(string[] args) {
23 var listener = new SimpleTraceListener(Console.Out);
24
25 var source = Trace<Program>.TraceSource;
26 source.Switch.Level = SourceLevels.All;
27
28 source.Listeners.Add(listener);
31 var container = new UnityContainer();
29 32
30 var t = Environment.TickCount;
33 var containerConfig = SerializationHelpers.DeserializeFromFile<ContainerElement>("data/sample.xml");
31 34
32 Main().Wait();
33
34 Console.WriteLine($"Done: {Environment.TickCount - t} ms");
35 Console.ReadKey();
35 Console.WriteLine($"container: {containerConfig.Registrations.Count}");
36 36 }
37 37
38 static async Task Main() {
39 using (LogicalOperation(nameof(Main))) {
40 Log("Start");
41 await SomeAsync();
42 Log("End");
38
43 39 }
44 40 }
45
46 static async Task SomeAsync() {
47 using (LogicalOperation(nameof(SomeAsync))) {
48 Log("Do prepare");
49 await Task.Yield();
50 Log("Yield");
51 }
52 }
53 }
54 }
@@ -1,23 +1,23
1 1 <Project Sdk="Microsoft.NET.Sdk">
2 2 <PropertyGroup Condition="'$(OSTYPE)'=='linux'">
3 <TargetFrameworks>netcoreapp2.0</TargetFrameworks>
3 <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
4 4 <FrameworkPathOverride Condition="'$(TargetFramework)'=='net46'">/usr/lib/mono/4.5/</FrameworkPathOverride>
5 5 </PropertyGroup>
6 6
7 7 <PropertyGroup Condition="'$(OSTYPE)'=='windows'">
8 8 <TargetFrameworks>netcoreapp2.0;net46</TargetFrameworks>
9 9 </PropertyGroup>
10 10
11 11 <PropertyGroup>
12 12 <IsPackable>false</IsPackable>
13 13 </PropertyGroup>
14 14
15 15 <ItemGroup>
16 16 <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0-preview-20180109-01" />
17 17 <PackageReference Include="xunit" Version="2.3.1" />
18 18 <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
19 19 <ProjectReference Include="../Implab/Implab.csproj"/>
20 20 <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
21 21 </ItemGroup>
22 22
23 23 </Project>
@@ -1,37 +1,55
1 ο»Ώ
1
2 2 Microsoft Visual Studio Solution File, Format Version 12.00
3 3 # Visual Studio 15
4 4 VisualStudioVersion = 15.0.27428.2005
5 5 MinimumVisualStudioVersion = 10.0.40219.1
6 6 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Implab", "Implab\Implab.csproj", "{FF2052B6-9C8F-4022-A347-F07ABF635885}"
7 7 EndProject
8 8 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Implab.Test", "Implab.Test\Implab.Test.csproj", "{6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}"
9 9 EndProject
10 10 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.Playground", "Implab.Playground\Implab.Playground.csproj", "{100DFEB0-75BE-436F-ADDF-1F46EF433F46}"
11 11 EndProject
12 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Implab.ServiceHost", "Implab.ServiceHost\Implab.ServiceHost.csproj", "{8B79FCBE-50DD-40A0-9B5E-E572072E4868}"
13 EndProject
12 14 Global
13 15 GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 16 Debug|Any CPU = Debug|Any CPU
15 17 Release|Any CPU = Release|Any CPU
18 Debug|x64 = Debug|x64
19 Debug|x86 = Debug|x86
20 Release|x64 = Release|x64
21 Release|x86 = Release|x86
16 22 EndGlobalSection
17 23 GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 24 {FF2052B6-9C8F-4022-A347-F07ABF635885}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 25 {FF2052B6-9C8F-4022-A347-F07ABF635885}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 26 {FF2052B6-9C8F-4022-A347-F07ABF635885}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 27 {FF2052B6-9C8F-4022-A347-F07ABF635885}.Release|Any CPU.Build.0 = Release|Any CPU
22 28 {6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 29 {6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 30 {6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 31 {6CD0DA18-8D9B-4AA8-A3DC-17322E27335E}.Release|Any CPU.Build.0 = Release|Any CPU
26 32 {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 33 {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 34 {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 35 {100DFEB0-75BE-436F-ADDF-1F46EF433F46}.Release|Any CPU.Build.0 = Release|Any CPU
36 {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Debug|x64.ActiveCfg = Debug|x64
39 {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Debug|x64.Build.0 = Debug|x64
40 {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Debug|x86.ActiveCfg = Debug|x86
41 {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Debug|x86.Build.0 = Debug|x86
42 {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Release|Any CPU.Build.0 = Release|Any CPU
44 {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Release|x64.ActiveCfg = Release|x64
45 {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Release|x64.Build.0 = Release|x64
46 {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Release|x86.ActiveCfg = Release|x86
47 {8B79FCBE-50DD-40A0-9B5E-E572072E4868}.Release|x86.Build.0 = Release|x86
30 48 EndGlobalSection
31 49 GlobalSection(SolutionProperties) = preSolution
32 50 HideSolutionNode = FALSE
33 51 EndGlobalSection
34 52 GlobalSection(ExtensibilityGlobals) = postSolution
35 53 SolutionGuid = {36D837FC-4CDD-4AEA-87BF-F130FEB22E02}
36 54 EndGlobalSection
37 55 EndGlobal
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved
author

ok, latest stable version should be in default

You need to be logged in to leave comments. Login now