diff --git a/Source/OmniXaml.Services/AutoInflatingTypeFactory.cs b/Source/OmniXaml.Services/AutoInflatingTypeFactory.cs index 5832f8a..78db384 100644 --- a/Source/OmniXaml.Services/AutoInflatingTypeFactory.cs +++ b/Source/OmniXaml.Services/AutoInflatingTypeFactory.cs @@ -5,6 +5,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Reflection; + using ObjectAssembler; public class AutoInflatingTypeFactory : ITypeFactory { @@ -39,7 +40,7 @@ { var instance = innerTypeFactory.Create(type, args); var loader = xamlLoaderFactory(this); - var inflated = loader.Load(stream, instance); + var inflated = loader.Load(stream, new Settings { RootInstance = instance }); return inflated; } } @@ -62,6 +63,4 @@ return this.Create(type); } } - - } \ No newline at end of file diff --git a/Source/OmniXaml.Wpf/ObjectAssembler.cs b/Source/OmniXaml.Wpf/ObjectAssembler.cs index 299d420..a6149ff 100644 --- a/Source/OmniXaml.Wpf/ObjectAssembler.cs +++ b/Source/OmniXaml.Wpf/ObjectAssembler.cs @@ -10,13 +10,13 @@ public ITopDownValueContext TopDownValueContext => objectAssembler.TopDownValueContext; private readonly TemplateHostingObjectAssembler objectAssembler; - public ObjectAssembler(IRuntimeTypeSource typeSource, ITopDownValueContext topDownValueContext, ObjectAssemblerSettings objectAssemblerSettings = null) + public ObjectAssembler(IRuntimeTypeSource typeSource, ITopDownValueContext topDownValueContext, Settings settings = null) { TypeSource = typeSource; var mapping = new DeferredLoaderMapping(); mapping.Map(template => template.AlternateTemplateContent, new DeferredLoader()); - objectAssembler = new TemplateHostingObjectAssembler(new OmniXaml.ObjectAssembler.ObjectAssembler(typeSource, topDownValueContext, objectAssemblerSettings), mapping); + objectAssembler = new TemplateHostingObjectAssembler(new OmniXaml.ObjectAssembler.ObjectAssembler(typeSource, topDownValueContext, settings), mapping); } public object Result => objectAssembler.Result; diff --git a/Source/OmniXaml.Wpf/WpfLoader.cs b/Source/OmniXaml.Wpf/WpfLoader.cs index d0e4af5..4518871 100644 --- a/Source/OmniXaml.Wpf/WpfLoader.cs +++ b/Source/OmniXaml.Wpf/WpfLoader.cs @@ -1,6 +1,7 @@ namespace OmniXaml.Wpf { using System.IO; + using OmniXaml.ObjectAssembler; public class WpfLoader : ILoader { @@ -16,14 +17,9 @@ namespace OmniXaml.Wpf return innerLoader.Load(stream); } - public object Load(Stream stream, object rootInstance) + public object Load(Stream stream, Settings settings) { - return innerLoader.Load(stream, rootInstance); - } - - public object Load(Stream stream, LoadSettings loadSettings) - { - throw new System.NotImplementedException(); + return innerLoader.Load(stream, settings); } } } \ No newline at end of file diff --git a/Source/OmniXaml.Wpf/WpfParserFactory.cs b/Source/OmniXaml.Wpf/WpfParserFactory.cs index 5228e2c..ca5ac1a 100644 --- a/Source/OmniXaml.Wpf/WpfParserFactory.cs +++ b/Source/OmniXaml.Wpf/WpfParserFactory.cs @@ -13,13 +13,6 @@ namespace OmniXaml.Wpf runtimeTypeSource = new WpfRuntimeTypeSource(); } - public IParser CreateForReadingFree() - { - var objectAssemblerForUndefinedRoot = GetObjectAssemblerForUndefinedRoot(); - - return CreateParser(objectAssemblerForUndefinedRoot); - } - private IParser CreateParser(IObjectAssembler objectAssemblerForUndefinedRoot) { var xamlInstructionParser = new OrderAwareInstructionParser(new InstructionParser(runtimeTypeSource)); @@ -37,14 +30,7 @@ namespace OmniXaml.Wpf return new ObjectAssembler(runtimeTypeSource, new TopDownValueContext()); } - public IParser CreateForReadingSpecificInstance(object rootInstance) - { - var objectAssemblerForUndefinedRoot = GetObjectAssemblerForSpecificRoot(rootInstance); - - return CreateParser(objectAssemblerForUndefinedRoot); - } - - public IParser Create(ObjectAssemblerSettings settings) + public IParser Create(Settings settings) { var objectAssemblerForUndefinedRoot = new ObjectAssembler(runtimeTypeSource, new TopDownValueContext(), settings); @@ -53,7 +39,7 @@ namespace OmniXaml.Wpf private IObjectAssembler GetObjectAssemblerForSpecificRoot(object rootInstance) { - return new ObjectAssembler(runtimeTypeSource, new TopDownValueContext(), new ObjectAssemblerSettings { RootInstance = rootInstance }); + return new ObjectAssembler(runtimeTypeSource, new TopDownValueContext(), new Settings { RootInstance = rootInstance }); } } } \ No newline at end of file diff --git a/Source/OmniXaml/DefaultLoader.cs b/Source/OmniXaml/DefaultLoader.cs index 3dab9e5..467dca5 100644 --- a/Source/OmniXaml/DefaultLoader.cs +++ b/Source/OmniXaml/DefaultLoader.cs @@ -1,17 +1,16 @@ namespace OmniXaml { using System.IO; + using ObjectAssembler; - internal class DefaultLoader : ILoader + public class DefaultLoader : ILoader { - private readonly IRuntimeTypeSource runtimeTypeSource; private readonly XmlLoader xmlLoader; public DefaultLoader(IRuntimeTypeSource runtimeTypeSource) { - this.runtimeTypeSource = runtimeTypeSource; - IParserFactory pfb= new DefaultParserFactory(runtimeTypeSource); - xmlLoader = new XmlLoader(pfb); + IParserFactory parserFactory = new DefaultParserFactory(runtimeTypeSource); + xmlLoader = new XmlLoader(parserFactory); } public object Load(Stream stream) @@ -19,14 +18,9 @@ return xmlLoader.Load(stream); } - public object Load(Stream stream, object instance) + public object Load(Stream stream, Settings settings) { - return xmlLoader.Load(stream, instance); - } - - public object Load(Stream stream, LoadSettings loadSettings) - { - throw new System.NotImplementedException(); + return xmlLoader.Load(stream, settings); } } } \ No newline at end of file diff --git a/Source/OmniXaml/DefaultObjectAssemblerFactory.cs b/Source/OmniXaml/DefaultObjectAssemblerFactory.cs index 9289357..c286a1e 100644 --- a/Source/OmniXaml/DefaultObjectAssemblerFactory.cs +++ b/Source/OmniXaml/DefaultObjectAssemblerFactory.cs @@ -11,9 +11,9 @@ namespace OmniXaml this.typeSource = typeSource; } - public IObjectAssembler CreateAssembler(ObjectAssemblerSettings objectAssemblerSettings) + public IObjectAssembler CreateAssembler(Settings settings) { - return new ObjectAssembler.ObjectAssembler(typeSource, new TopDownValueContext(), objectAssemblerSettings); + return new ObjectAssembler.ObjectAssembler(typeSource, new TopDownValueContext(), settings); } } } \ No newline at end of file diff --git a/Source/OmniXaml/DefaultParserFactory.cs b/Source/OmniXaml/DefaultParserFactory.cs index 4d94b05..8125f08 100644 --- a/Source/OmniXaml/DefaultParserFactory.cs +++ b/Source/OmniXaml/DefaultParserFactory.cs @@ -13,13 +13,6 @@ this.runtimeTypeSource = runtimeTypeSource; } - public IParser CreateForReadingFree() - { - var objectAssemblerForUndefinedRoot = GetObjectAssemblerForUndefinedRoot(); - - return CreateParser(objectAssemblerForUndefinedRoot); - } - private IParser CreateParser(IObjectAssembler objectAssemblerForUndefinedRoot) { var xamlInstructionParser = new OrderAwareInstructionParser(new InstructionParser(runtimeTypeSource)); @@ -32,28 +25,11 @@ return new XmlParser(phaseParserKit); } - private IObjectAssembler GetObjectAssemblerForUndefinedRoot() - { - return new ObjectAssembler.ObjectAssembler(runtimeTypeSource, new TopDownValueContext()); - } - - public IParser CreateForReadingSpecificInstance(object rootInstance) - { - var objectAssemblerForUndefinedRoot = GetObjectAssemblerForSpecificRoot(rootInstance); - - return CreateParser(objectAssemblerForUndefinedRoot); - } - - public IParser Create(ObjectAssemblerSettings settings) + public IParser Create(Settings settings) { var objectAssemblerForUndefinedRoot = new ObjectAssembler.ObjectAssembler(runtimeTypeSource, new TopDownValueContext(), settings); return CreateParser(objectAssemblerForUndefinedRoot); } - - private IObjectAssembler GetObjectAssemblerForSpecificRoot(object rootInstance) - { - return new ObjectAssembler.ObjectAssembler(runtimeTypeSource, new TopDownValueContext(), new ObjectAssemblerSettings { RootInstance = rootInstance }); - } } } \ No newline at end of file diff --git a/Source/OmniXaml/IInstanceLifeCycleListener.cs b/Source/OmniXaml/IInstanceLifeCycleListener.cs new file mode 100644 index 0000000..09f8400 --- /dev/null +++ b/Source/OmniXaml/IInstanceLifeCycleListener.cs @@ -0,0 +1,10 @@ +namespace OmniXaml +{ + public interface IInstanceLifeCycleListener + { + void OnBegin(object instance); + void OnAfterProperites(object instance); + void OnAssociatedToParent(object instance); + void OnEnd(object instance); + } +} \ No newline at end of file diff --git a/Source/OmniXaml/ILoader.cs b/Source/OmniXaml/ILoader.cs index 31fa6ff..5743cfc 100644 --- a/Source/OmniXaml/ILoader.cs +++ b/Source/OmniXaml/ILoader.cs @@ -1,25 +1,11 @@ namespace OmniXaml { using System.IO; + using ObjectAssembler; public interface ILoader { object Load(Stream stream); - object Load(Stream stream, object instance); - object Load(Stream stream, LoadSettings loadSettings); - } - - public class LoadSettings - { - public object RootInstance { get; set; } - public IInstanceLifeCycleListener InstanceLifeCycleListener { get; set; } - } - - public interface IInstanceLifeCycleListener - { - void OnBegin(object instance); - void OnAfterProperites(object instance); - void OnAssociatedToParent(object instance); - void OnEnd(object instance); + object Load(Stream stream, Settings settings); } } \ No newline at end of file diff --git a/Source/OmniXaml/IObjectAssemblerFactory.cs b/Source/OmniXaml/IObjectAssemblerFactory.cs index d272dc9..4854af7 100644 --- a/Source/OmniXaml/IObjectAssemblerFactory.cs +++ b/Source/OmniXaml/IObjectAssemblerFactory.cs @@ -4,6 +4,6 @@ namespace OmniXaml public interface IObjectAssemblerFactory { - IObjectAssembler CreateAssembler(ObjectAssemblerSettings settings); + IObjectAssembler CreateAssembler(Settings settings); } } \ No newline at end of file diff --git a/Source/OmniXaml/IParserFactory.cs b/Source/OmniXaml/IParserFactory.cs index 8d5bdee..b3831da 100644 --- a/Source/OmniXaml/IParserFactory.cs +++ b/Source/OmniXaml/IParserFactory.cs @@ -4,8 +4,6 @@ namespace OmniXaml public interface IParserFactory { - IParser CreateForReadingFree(); - IParser CreateForReadingSpecificInstance(object rootInstance); - IParser Create(ObjectAssemblerSettings settings); + IParser Create(Settings settings); } } \ No newline at end of file diff --git a/Source/OmniXaml/LoadMixin.cs b/Source/OmniXaml/LoadMixin.cs index 8f339a7..296d9d3 100644 --- a/Source/OmniXaml/LoadMixin.cs +++ b/Source/OmniXaml/LoadMixin.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using Glass; + using ObjectAssembler; using Parsers; using Parsers.ProtoParser; @@ -28,7 +29,7 @@ { using (var stream = xml.FromUTF8ToStream()) { - return loader.Load(stream, instance); + return loader.Load(stream, new Settings { RootInstance = instance }); } } } diff --git a/Source/OmniXaml/ObjectAssembler/ObjectAssembler.cs b/Source/OmniXaml/ObjectAssembler/ObjectAssembler.cs index 8798089..b9a474a 100644 --- a/Source/OmniXaml/ObjectAssembler/ObjectAssembler.cs +++ b/Source/OmniXaml/ObjectAssembler/ObjectAssembler.cs @@ -12,7 +12,7 @@ namespace OmniXaml.ObjectAssembler private readonly XamlType rootInstanceXamlType; public ITopDownValueContext TopDownValueContext { get; } - public ObjectAssembler(IRuntimeTypeSource typeSource, ITopDownValueContext topDownValueContext, ObjectAssemblerSettings settings = null) + public ObjectAssembler(IRuntimeTypeSource typeSource, ITopDownValueContext topDownValueContext, Settings settings = null) : this(new StackingLinkedList(), typeSource, topDownValueContext) { Guard.ThrowIfNull(typeSource, nameof(typeSource)); diff --git a/Source/OmniXaml/ObjectAssembler/ObjectAssemblerSettings.cs b/Source/OmniXaml/ObjectAssembler/ObjectAssemblerSettings.cs deleted file mode 100644 index 416b560..0000000 --- a/Source/OmniXaml/ObjectAssembler/ObjectAssemblerSettings.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace OmniXaml.ObjectAssembler -{ - public class ObjectAssemblerSettings - { - public object RootInstance { get; set; } - } -} \ No newline at end of file diff --git a/Source/OmniXaml/ObjectAssembler/Settings.cs b/Source/OmniXaml/ObjectAssembler/Settings.cs new file mode 100644 index 0000000..d33ee80 --- /dev/null +++ b/Source/OmniXaml/ObjectAssembler/Settings.cs @@ -0,0 +1,8 @@ +namespace OmniXaml.ObjectAssembler +{ + public class Settings + { + public object RootInstance { get; set; } + public IInstanceLifeCycleListener InstanceLifeCycleListener { get; set; } + } +} \ No newline at end of file diff --git a/Source/OmniXaml/OmniXaml.csproj b/Source/OmniXaml/OmniXaml.csproj index 9894115..71af6f1 100644 --- a/Source/OmniXaml/OmniXaml.csproj +++ b/Source/OmniXaml/OmniXaml.csproj @@ -40,6 +40,7 @@ + @@ -50,7 +51,7 @@ - + diff --git a/Source/OmniXaml/XmlLoader.cs b/Source/OmniXaml/XmlLoader.cs index 4fe6c2d..c26ecc6 100644 --- a/Source/OmniXaml/XmlLoader.cs +++ b/Source/OmniXaml/XmlLoader.cs @@ -2,6 +2,7 @@ namespace OmniXaml { using System; using System.IO; + using ObjectAssembler; using Parsers.ProtoParser; public class XmlLoader : ILoader @@ -16,20 +17,12 @@ namespace OmniXaml public object Load(Stream stream) { - return Load(stream, parserFactory.CreateForReadingFree()); + return Load(stream, parserFactory.Create(new Settings())); } - public object Load(Stream stream, object instance) + public object Load(Stream stream, Settings loadSettings) { - return Load(stream, parserFactory.CreateForReadingSpecificInstance(instance)); - } - - public object Load(Stream stream, LoadSettings loadSettings) - { - var parser = loadSettings.RootInstance == null - ? parserFactory.CreateForReadingFree() - : parserFactory.CreateForReadingSpecificInstance(loadSettings.RootInstance); - + var parser = parserFactory.Create(loadSettings); return Load(stream, parser); } diff --git a/Source/Tests/OmniXaml.AppServices.Tests/DummyAssemblerFactory.cs b/Source/Tests/OmniXaml.AppServices.Tests/DummyAssemblerFactory.cs index 47a710b..5e864a6 100644 --- a/Source/Tests/OmniXaml.AppServices.Tests/DummyAssemblerFactory.cs +++ b/Source/Tests/OmniXaml.AppServices.Tests/DummyAssemblerFactory.cs @@ -14,7 +14,7 @@ this.runtimeTypeSource = runtimeTypeSource; } - public IObjectAssembler CreateAssembler(ObjectAssemblerSettings settings) + public IObjectAssembler CreateAssembler(Settings settings) { var mapping = new DeferredLoaderMapping(); mapping.Map(template => template.Content, new DummyDeferredLoader()); diff --git a/Source/Tests/OmniXaml.Test.Common.NetCore/DummyParserFactory.cs b/Source/Tests/OmniXaml.Test.Common.NetCore/DummyParserFactory.cs index 079179a..81ad400 100644 --- a/Source/Tests/OmniXaml.Test.Common.NetCore/DummyParserFactory.cs +++ b/Source/Tests/OmniXaml.Test.Common.NetCore/DummyParserFactory.cs @@ -15,13 +15,6 @@ namespace OmniXaml.Tests.Common.NetCore this.runtimeTypeSource = runtimeTypeSource; } - public IParser CreateForReadingFree() - { - var objectAssemblerForUndefinedRoot = GetObjectAssemblerForUndefinedRoot(); - - return CreateParser(objectAssemblerForUndefinedRoot); - } - private IParser CreateParser(IObjectAssembler objectAssemblerForUndefinedRoot) { var phaseParserKit = new PhaseParserKit( @@ -32,26 +25,14 @@ namespace OmniXaml.Tests.Common.NetCore return new XmlParser(phaseParserKit); } - private ObjectAssembler GetObjectAssemblerForUndefinedRoot() - { - return new ObjectAssembler(runtimeTypeSource, new TopDownValueContext()); - } - - public IParser CreateForReadingSpecificInstance(object rootInstance) - { - var objectAssemblerForUndefinedRoot = GetObjectAssemblerForSpecificRoot(rootInstance); - - return CreateParser(objectAssemblerForUndefinedRoot); - } - - public IParser Create(ObjectAssemblerSettings settings) + public IParser Create(Settings settings) { var objectAssemblerForUndefinedRoot = CreateObjectAssembler(settings); return CreateParser(objectAssemblerForUndefinedRoot); } - private IObjectAssembler CreateObjectAssembler(ObjectAssemblerSettings settings) + private IObjectAssembler CreateObjectAssembler(Settings settings) { var objectAssembler = new ObjectAssembler(runtimeTypeSource, new TopDownValueContext(), settings); @@ -61,16 +42,5 @@ namespace OmniXaml.Tests.Common.NetCore var templateAwareObjectAssembler = new TemplateHostingObjectAssembler(objectAssembler, mapping); return templateAwareObjectAssembler; } - - private IObjectAssembler GetObjectAssemblerForSpecificRoot(object rootInstance) - { - var objectAssembler = new ObjectAssembler(runtimeTypeSource, new TopDownValueContext(), new ObjectAssemblerSettings { RootInstance = rootInstance }); - - var mapping = new DeferredLoaderMapping(); - mapping.Map(template => template.Content, new DummyDeferredLoader()); - - var templateAwareObjectAssembler = new TemplateHostingObjectAssembler(objectAssembler, mapping); - return templateAwareObjectAssembler; - } } } \ No newline at end of file diff --git a/Source/Tests/OmniXaml.Tests/ObjectAssemblerTests.cs b/Source/Tests/OmniXaml.Tests/ObjectAssemblerTests.cs index 3bc1575..0726933 100644 --- a/Source/Tests/OmniXaml.Tests/ObjectAssemblerTests.cs +++ b/Source/Tests/OmniXaml.Tests/ObjectAssemblerTests.cs @@ -36,7 +36,7 @@ public IObjectAssembler CreateSutForLoadingSpecificInstance(object instance) { - var settings = new ObjectAssemblerSettings { RootInstance = instance }; + var settings = new Settings { RootInstance = instance }; var assembler = new ObjectAssembler(TypeRuntimeTypeSource, new TopDownValueContext(), settings); return assembler; } diff --git a/Source/Tests/TestApplications/BasicModel/BasicModel.csproj b/Source/Tests/TestApplications/BasicModel/BasicModel.csproj index 2e9a5d8..203fdc9 100644 --- a/Source/Tests/TestApplications/BasicModel/BasicModel.csproj +++ b/Source/Tests/TestApplications/BasicModel/BasicModel.csproj @@ -44,8 +44,6 @@ - - diff --git a/Source/Tests/TestApplications/BasicModel/DefaultLoader.cs b/Source/Tests/TestApplications/BasicModel/DefaultLoader.cs deleted file mode 100644 index 6c357a5..0000000 --- a/Source/Tests/TestApplications/BasicModel/DefaultLoader.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace SampleOmniXAML -{ - using System.IO; - using OmniXaml; - - internal class DefaultLoader : ILoader - { - private readonly XmlLoader xmlLoader; - - public DefaultLoader(IRuntimeTypeSource typeSource) - { - IParserFactory parserFactory= new DefaultParserFactory(typeSource); - xmlLoader = new XmlLoader(parserFactory); - } - - public object Load(Stream stream) - { - return xmlLoader.Load(stream); - } - - public object Load(Stream stream, object instance) - { - return xmlLoader.Load(stream, instance); - } - - public object Load(Stream stream, LoadSettings loadSettings) - { - throw new System.NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Source/Tests/TestApplications/BasicModel/DefaultParserFactory.cs b/Source/Tests/TestApplications/BasicModel/DefaultParserFactory.cs deleted file mode 100644 index 44ecbe8..0000000 --- a/Source/Tests/TestApplications/BasicModel/DefaultParserFactory.cs +++ /dev/null @@ -1,64 +0,0 @@ -namespace SampleOmniXAML -{ - using OmniXaml; - using OmniXaml.ObjectAssembler; - using OmniXaml.Parsers.Parser; - using OmniXaml.Parsers.ProtoParser; - - public class DefaultParserFactory : IParserFactory - { - private readonly IRuntimeTypeSource typeSource; - - public DefaultParserFactory() - { - } - - public DefaultParserFactory(IRuntimeTypeSource typeSource) - { - this.typeSource = typeSource; - } - - public IParser CreateForReadingFree() - { - var objectAssemblerForUndefinedRoot = GetObjectAssemblerForUndefinedRoot(); - - return CreateParser(objectAssemblerForUndefinedRoot); - } - - private IParser CreateParser(IObjectAssembler objectAssemblerForUndefinedRoot) - { - var xamlInstructionParser = new OrderAwareInstructionParser(new InstructionParser(typeSource)); - - var phaseParserKit = new PhaseParserKit( - new ProtoInstructionParser(typeSource), - xamlInstructionParser, - objectAssemblerForUndefinedRoot); - - return new XmlParser(phaseParserKit); - } - - private IObjectAssembler GetObjectAssemblerForUndefinedRoot() - { - return new ObjectAssembler(typeSource, new TopDownValueContext()); - } - - public IParser CreateForReadingSpecificInstance(object rootInstance) - { - var objectAssemblerForUndefinedRoot = GetObjectAssemblerForSpecificRoot(rootInstance); - - return CreateParser(objectAssemblerForUndefinedRoot); - } - - public IParser Create(ObjectAssemblerSettings settings) - { - var objectAssemblerForUndefinedRoot = new ObjectAssembler(typeSource, new TopDownValueContext(), new ObjectAssemblerSettings { RootInstance = settings.RootInstance }); - - return CreateParser(objectAssemblerForUndefinedRoot); - } - - private IObjectAssembler GetObjectAssemblerForSpecificRoot(object rootInstance) - { - return new ObjectAssembler(typeSource, new TopDownValueContext(), new ObjectAssemblerSettings { RootInstance = rootInstance }); - } - } -} \ No newline at end of file diff --git a/Source/Tests/TestApplications/BasicModel/Program.cs b/Source/Tests/TestApplications/BasicModel/Program.cs index a1d454c..b89f5b0 100644 --- a/Source/Tests/TestApplications/BasicModel/Program.cs +++ b/Source/Tests/TestApplications/BasicModel/Program.cs @@ -5,7 +5,7 @@ using OmniXaml; using OmniXaml.Services.DotNetFx; - static class Program + internal static class Program { private static void Main() {