Removed specific methods for root instance

This commit is contained in:
José Manuel Nieto Sánchez 2016-01-10 19:57:23 +01:00
Родитель f49b7fac7f
Коммит fa428fce05
24 изменённых файлов: 54 добавлений и 240 удалений

Просмотреть файл

@ -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);
}
}
}

Просмотреть файл

@ -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<DataTemplate>(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;

Просмотреть файл

@ -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);
}
}
}

Просмотреть файл

@ -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 });
}
}
}

Просмотреть файл

@ -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);
}
}
}

Просмотреть файл

@ -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);
}
}
}

Просмотреть файл

@ -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 });
}
}
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -4,6 +4,6 @@ namespace OmniXaml
public interface IObjectAssemblerFactory
{
IObjectAssembler CreateAssembler(ObjectAssemblerSettings settings);
IObjectAssembler CreateAssembler(Settings settings);
}
}

Просмотреть файл

@ -4,8 +4,6 @@ namespace OmniXaml
public interface IParserFactory
{
IParser CreateForReadingFree();
IParser CreateForReadingSpecificInstance(object rootInstance);
IParser Create(ObjectAssemblerSettings settings);
IParser Create(Settings settings);
}
}

Просмотреть файл

@ -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 });
}
}
}

Просмотреть файл

@ -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<Level>(), typeSource, topDownValueContext)
{
Guard.ThrowIfNull(typeSource, nameof(typeSource));

Просмотреть файл

@ -1,7 +0,0 @@
namespace OmniXaml.ObjectAssembler
{
public class ObjectAssemblerSettings
{
public object RootInstance { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,8 @@
namespace OmniXaml.ObjectAssembler
{
public class Settings
{
public object RootInstance { get; set; }
public IInstanceLifeCycleListener InstanceLifeCycleListener { get; set; }
}
}

Просмотреть файл

@ -40,6 +40,7 @@
</Compile>
<Compile Include="DefaultParserFactory.cs" />
<Compile Include="DefaultLoader.cs" />
<Compile Include="IInstanceLifeCycleListener.cs" />
<Compile Include="INameScope.cs" />
<Compile Include="InstanceLifeCycleHandler.cs" />
<Compile Include="ILoader.cs" />
@ -50,7 +51,7 @@
<Compile Include="ObjectAssembler\InstanceLifeCycleNotifier.cs" />
<Compile Include="ObjectAssembler\InstanceProperties.cs" />
<Compile Include="ObjectAssembler\NullLevel.cs" />
<Compile Include="ObjectAssembler\ObjectAssemblerSettings.cs" />
<Compile Include="ObjectAssembler\Settings.cs" />
<Compile Include="ObjectAssembler\PreviousLevelWrapper.cs" />
<Compile Include="ObjectAssembler\XamlSetValueEventArgs.cs" />
<Compile Include="Attributes\ContentPropertyAttribute.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);
}

Просмотреть файл

@ -14,7 +14,7 @@
this.runtimeTypeSource = runtimeTypeSource;
}
public IObjectAssembler CreateAssembler(ObjectAssemblerSettings settings)
public IObjectAssembler CreateAssembler(Settings settings)
{
var mapping = new DeferredLoaderMapping();
mapping.Map<DataTemplate>(template => template.Content, new DummyDeferredLoader());

Просмотреть файл

@ -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<DataTemplate>(template => template.Content, new DummyDeferredLoader());
var templateAwareObjectAssembler = new TemplateHostingObjectAssembler(objectAssembler, mapping);
return templateAwareObjectAssembler;
}
}
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -44,8 +44,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DefaultParserFactory.cs" />
<Compile Include="DefaultLoader.cs" />
<Compile Include="Model\Zoo.cs" />
<Compile Include="Model\Animal.cs" />
<Compile Include="Program.cs" />

Просмотреть файл

@ -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();
}
}
}

Просмотреть файл

@ -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 });
}
}
}

Просмотреть файл

@ -5,7 +5,7 @@
using OmniXaml;
using OmniXaml.Services.DotNetFx;
static class Program
internal static class Program
{
private static void Main()
{