public void FetchOneMemento()
        {
            InstanceMemento memento = _source.GetMemento("Instance1");

            Assert.AreEqual("red", memento.GetProperty("color"));
            Assert.AreEqual("Instance1", memento.InstanceKey);
        }
Example #2
0
        public void GetRedInstance()
        {
            InstanceMemento memento = _source.GetMemento("Red");

            Assert.IsNotNull(memento);
            Assert.AreEqual("Red", memento.GetProperty("Color"));
        }
        public void GetNonTemplatedInstance()
        {
            InstanceMemento memento = _templatedSource.GetMemento("Nadine");

            Assert.AreEqual("80", memento.GetProperty("Age"));
            Assert.AreEqual("Blue", memento.GetProperty("EyeColor"));
        }
        protected override InstanceMemento[] fetchInternalMementos()
        {
            var returnValue = new InstanceMemento[_mementos.Count];
            _mementos.Values.CopyTo(returnValue, 0);

            return returnValue;
        }
Example #5
0
        public override InstanceMemento Substitute(InstanceMemento memento)
        {
            var     templater       = new XmlTemplater(_element);
            XmlNode substitutedNode = templater.SubstituteTemplates(_element, memento);

            return(new XmlAttributeInstanceMemento(substitutedNode));
        }
Example #6
0
        protected override InstanceMemento retrieveMemento(string instanceKey)
        {
            string          fileName = _embeddedFiles[instanceKey];
            InstanceMemento memento  = fetchMementoFromEmbeddedFile(fileName, instanceKey);

            return(memento);
        }
        public override InstanceMemento Substitute(InstanceMemento memento)
        {
            var     templater       = new XmlTemplater(_innerNode);
            XmlNode substitutedNode = templater.SubstituteTemplates(_innerNode, memento);

            return(new XmlNodeInstanceMemento(substitutedNode, _typeAttribute, _keyAttribute));
        }
Example #8
0
        protected override InstanceMemento[] fetchInternalMementos()
        {
            var returnValue = new InstanceMemento[_mementos.Count];

            _mementos.Values.CopyTo(returnValue, 0);

            return(returnValue);
        }
        public void FetchMachineNotFound()
        {
            source.SetMachineName("fake-machine");
            InstanceMemento memento = source.GetMemento("FavoriteColor");

            Assertion.AssertNotNull(memento);
            Assertion.AssertEquals("Default's favorite color is red", "Orange", memento.GetProperty("Color"));
        }
        public void Fetch2()
        {
            source.SetMachineName("localhost");
            InstanceMemento memento = source.GetMemento("FavoriteColor");

            Assertion.AssertNotNull(memento);
            Assertion.AssertEquals("Localhost's favorite color is red", "Red", memento.GetProperty("Color"));
        }
        public void Fetch1()
        {
            source.SetMachineName("server");
            InstanceMemento memento = source.GetMemento("FavoriteColor");

            Assertion.AssertNotNull(memento);
            Assertion.AssertEquals("Server's favorite color is blue", "Blue", memento.GetProperty("Color"));
        }
        public void CanImpliedNOTInlineSourceBuildMemento()
        {
            PluginFamily family = graph.FindFamily(typeof(Parent));

            InstanceMemento memento = family.GetMemento("Jerry");

            Assert.IsNotNull(memento);
        }
        public void CanImpliedInlineSourceBuildMemento()
        {
            PluginFamily family = graph.FindFamily(typeof(Rule));

            InstanceMemento memento = family.GetMemento("Red");

            Assert.IsNotNull(memento);
        }
Example #14
0
 private void attachInstances(PluginFamily family, XmlElement familyElement, IGraphBuilder builder)
 {
     familyElement.ForEachChild(INSTANCE_NODE).Do(element =>
     {
         InstanceMemento memento = _mementoCreator.CreateMemento(element);
         family.AddInstance(memento);
     });
 }
        public void CanDefinedSourceBuildMemento()
        {
            PluginFamily family = graph.FindFamily(typeof(IWidget));

            InstanceMemento memento = family.GetMemento("Red");

            Assert.IsNotNull(memento);
        }
 public InstanceMementoPropertyReader(ConfiguredInstance instance, InstanceMemento memento,
                                      PluginGraph pluginGraph, Type pluginType)
 {
     _instance    = instance;
     _memento     = memento;
     _pluginGraph = pluginGraph;
     _pluginType  = pluginType;
 }
 public InstanceMementoPropertyReader(ConfiguredInstance instance, InstanceMemento memento,
     PluginGraph pluginGraph, Type pluginType)
 {
     _instance = instance;
     _memento = memento;
     _pluginGraph = pluginGraph;
     _pluginType = pluginType;
 }
        public void GetChildMemento()
        {
            InstanceMemento child = memento.GetChildMemento("Child1");

            Assert.IsNotNull(child);

            Assert.AreEqual("Child1", child.ConcreteKey, "Type is Child1");
            Assert.AreEqual("D", child.GetProperty("Prop4"), "Prop4");
        }
        public void GetTemplatedMementoFromNodeNormalizedTemplate()
        {
            InstanceMemento templateMemento = _nodeTemplateSource.GetMemento("Grandmother");

            Assert.IsNotNull(templateMemento);
            InstanceMemento combinedMemento = templateMemento.Substitute(_referringMemento);

            validateCombinedMemento(combinedMemento);
        }
Example #20
0
        protected override sealed InstanceMemento[] fetchInternalMementos()
        {
            Hashtable mementos    = mementoHashtable;
            var       returnValue = new InstanceMemento[mementos.Count];

            mementos.Values.CopyTo(returnValue, 0);

            return(returnValue);
        }
Example #21
0
        public void AddDefaultMemento(InstanceMemento memento)
        {
            if (string.IsNullOrEmpty(memento.InstanceKey))
            {
                memento.InstanceKey = "DefaultInstanceOf" + PluginType.AssemblyQualifiedName;
            }

            AddInstance(memento);
            DefaultInstanceKey = memento.InstanceKey;
        }
        private void validateCombinedMemento(InstanceMemento combinedMemento)
        {
            Assert.AreEqual("70", combinedMemento.GetProperty("Age"));
            Assert.AreEqual("Green", combinedMemento.GetProperty("EyeColor"));

            InstanceMemento grandChildMemeto =
                combinedMemento.GetChildMemento("MyChild").GetChildMemento("MyGrandChild");

            Assert.AreEqual("1992", grandChildMemeto.GetProperty("BirthYear"));
        }
Example #23
0
        public void ParseInstanceElement(XmlElement element)
        {
            var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE));

            _builder.ConfigureFamily(pluginTypePath, family =>
            {
                InstanceMemento memento =
                    _mementoCreator.CreateMemento(element);
                family.AddInstance(memento);
            });
        }
Example #24
0
        public void ParseInstanceElement(XmlElement element)
        {
            var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE));

            _builder.ConfigureFamily(pluginTypePath, family => {
                InstanceMemento memento = ConfigurationParser.CreateMemento(element);
                var instance            = memento.ToInstance(this, family.PluginType);

                family.AddInstance(instance);
            });
        }
 public object BuildInstance(InstanceMemento Memento)
 {
     return(new ComplexRule(
                Memento.GetProperty("String"),
                Memento.GetProperty("String2"),
                int.Parse(Memento.GetProperty("Int")),
                long.Parse(Memento.GetProperty("Long")),
                byte.Parse(Memento.GetProperty("Byte")),
                double.Parse(Memento.GetProperty("Double")),
                bool.Parse(Memento.GetProperty("Bool"))));
 }
 public object BuildInstance(InstanceMemento Memento)
 {
     return new ComplexRule(
         Memento.GetProperty("String"),
         Memento.GetProperty("String2"),
         int.Parse(Memento.GetProperty("Int")),
         long.Parse(Memento.GetProperty("Long")),
         byte.Parse(Memento.GetProperty("Byte")),
         double.Parse(Memento.GetProperty("Double")),
         bool.Parse(Memento.GetProperty("Bool")));
 }
Example #27
0
        protected override InstanceMemento[] fetchInternalMementos()
        {
            InstanceMemento[] rawMementos = _innerSource.GetAllMementos();
            var returnValue = new InstanceMemento[rawMementos.Length];

            for (int i = 0; i < returnValue.Length; i++)
            {
                returnValue[i] = resolveMemento(rawMementos[i]);
            }

            return returnValue;
        }
Example #28
0
 public void WithSystemObject <T>(InstanceMemento memento, string context, Action <T> action)
 {
     try
     {
         var systemObject = (T)buildSystemObject(typeof(T), memento);
         action(systemObject);
     }
     catch (Exception ex)
     {
         _pluginGraph.Log.RegisterError(130, ex, context);
     }
 }
        protected override InstanceMemento[] fetchInternalMementos()
        {
            InstanceMemento[] rawMementos = _innerSource.GetAllMementos();
            var returnValue = new InstanceMemento[rawMementos.Length];

            for (int i = 0; i < returnValue.Length; i++)
            {
                returnValue[i] = resolveMemento(rawMementos[i]);
            }

            return returnValue;
        }
        public void SetUp()
        {
            DataMother.WriteDocument(FILE_NAME);

            _nodeTemplateSource = new XmlFileMementoSource(FILE_NAME, "NodeTemplates", "Parent");
            _attTemplateSource = new XmlAttributeFileMementoSource(FILE_NAME, "AttTemplates", "Parent");
            _source = new XmlAttributeFileMementoSource(FILE_NAME, "Parents", "Parent");

            _referringMemento = _source.GetMemento("Jackie");

            _templatedSource = new TemplatedMementoSource(_source, _attTemplateSource);
        }
        protected override InstanceMemento getChild(string Key)
        {
            InstanceMemento returnValue = null;

            XmlNode nodeChild = getChildNode(Key);

            if (nodeChild != null)
            {
                returnValue = new XmlNodeInstanceMemento(nodeChild, _typeAttribute, _keyAttribute);
            }

            return(returnValue);
        }
        protected override InstanceMemento[] fetchInternalMementos()
        {
            string[] fileNames = Directory.GetFiles(_directory, "*." + _extension);
            var      list      = new ArrayList();

            foreach (string fileName in fileNames)
            {
                InstanceMemento memento = loadMementoFromFile(fileName);
                list.Add(memento);
            }

            return((InstanceMemento[])list.ToArray(typeof(InstanceMemento)));
        }
        protected override InstanceMemento[] fetchInternalMementos()
        {
            var returnValue = new InstanceMemento[_embeddedFiles.Count];
            int i = 0;
            foreach (string key in _embeddedFiles.AllKeys)
            {
                string fileName = _embeddedFiles[key];
                InstanceMemento memento = fetchMementoFromEmbeddedFile(fileName, key);
                returnValue[i++] = memento;
            }

            return returnValue;
        }
Example #34
0
        protected override InstanceMemento[] fetchInternalMementos()
        {
            var returnValue = new InstanceMemento[_embeddedFiles.Count];
            int i           = 0;

            foreach (string key in _embeddedFiles.AllKeys)
            {
                string          fileName = _embeddedFiles[key];
                InstanceMemento memento  = fetchMementoFromEmbeddedFile(fileName, key);
                returnValue[i++] = memento;
            }

            return(returnValue);
        }
Example #35
0
        public XmlNode SubstituteTemplates(XmlNode node, InstanceMemento memento)
        {
            var builder = new StringBuilder(_templateXml);
            foreach (string substitution in _substitutions)
            {
                string substitutionValue = memento.GetProperty(substitution);
                makeSubstitution(substitution, substitutionValue, builder);
            }

            var document = new XmlDocument();
            document.LoadXml(builder.ToString());

            return document.DocumentElement;
        }
        private void copyChildArray(string name, Type childType)
        {
            InstanceMemento[] mementoes = _memento.GetChildrenArray(name) ?? new InstanceMemento[0];

            var children = new Instance[mementoes.Length];

            for (int i = 0; i < mementoes.Length; i++)
            {
                InstanceMemento memento = mementoes[i];
                children[i] = memento.ReadInstance(_pluginGraph, childType);
            }

            _instance.SetCollection(name, children);
        }
Example #37
0
        public void ParseDefaultElement(XmlElement element)
        {
            var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE));


            _builder.ConfigureFamily(pluginTypePath, family =>
            {
                InstanceScope scope = findScope(element);
                family.SetScopeTo(scope);

                InstanceMemento memento = _mementoCreator.CreateMemento(element);
                family.AddDefaultMemento(memento);
            });
        }
        private InstanceMemento resolveMemento(InstanceMemento rawMemento)
        {
            InstanceMemento returnValue = null;

            string templateName = rawMemento.TemplateName;
            if (templateName == string.Empty)
            {
                returnValue = rawMemento;
            }
            else
            {
                InstanceMemento templateMemento = _templateSource.GetMemento(templateName);

                if (templateMemento == null)
                {
                    throw new StructureMapException(250, templateName);
                }

                returnValue = templateMemento.Substitute(rawMemento);
            }

            return returnValue;
        }
        private void validateCombinedMemento(InstanceMemento combinedMemento)
        {
            Assert.AreEqual("70", combinedMemento.GetProperty("Age"));
            Assert.AreEqual("Green", combinedMemento.GetProperty("EyeColor"));

            InstanceMemento grandChildMemeto =
                combinedMemento.GetChildMemento("MyChild").GetChildMemento("MyGrandChild");
            Assert.AreEqual("1992", grandChildMemeto.GetProperty("BirthYear"));
        }
 private void read(InstanceMemento memento, PluginGraph graph, Type pluginType)
 {
     var reader = new InstanceMementoPropertyReader(this, memento, graph, pluginType);
     plugin.VisitArguments(reader);
 }
 public InstanceMementoPropertyReader(IConfiguredInstance instance, InstanceMemento memento)
 {
     _instance = instance;
     _memento = memento;
 }
 public override InstanceMemento ResolveMemento(InstanceMemento memento)
 {
     InstanceMemento intermediateMemento = base.ResolveMemento(memento);
     return resolveMemento(intermediateMemento);
 }
    public void AddDefaultMemento(InstanceMemento memento)
    {
        if (string.IsNullOrEmpty(memento.InstanceKey))
            {
                memento.InstanceKey = "DefaultInstanceOf" + PluginType.AssemblyQualifiedName;
            }

            AddInstance(memento);
            DefaultInstanceKey = memento.InstanceKey;
    }
 public override InstanceMemento Substitute(InstanceMemento memento)
 {
     var templater = new XmlTemplater(_innerNode);
     XmlNode substitutedNode = templater.SubstituteTemplates(_innerNode, memento);
     return new XmlNodeInstanceMemento(substitutedNode, _typeAttribute, _keyAttribute);
 }
        protected override sealed InstanceMemento[] fetchInternalMementos()
        {
            Hashtable mementos = mementoHashtable;
            var returnValue = new InstanceMemento[mementos.Count];
            mementos.Values.CopyTo(returnValue, 0);

            return returnValue;
        }
 public void AddMemento(InstanceMemento Memento)
 {
     _mementos.Add(Memento.InstanceKey, Memento);
 }
 public InstanceMementoPropertyReader(IConfiguredInstance instance, InstanceMemento memento, IPluginFactory pluginFactory)
 {
     _instance = instance;
     _memento = memento;
     _pluginFactory = pluginFactory;
 }
        public override InstanceMemento Substitute(InstanceMemento memento)
        {
            var templater = new XmlTemplater(_element);
            XmlNode substitutedNode = templater.SubstituteTemplates(_element, memento);

            return new XmlAttributeInstanceMemento(substitutedNode);
        }
 public ConfiguredInstance(InstanceMemento memento, PluginGraph graph, Type pluginType)
     : base(memento.FindPlugin(graph.FindFamily(pluginType)))
 {
     read(memento, graph, pluginType);
 }
 public void AddInstance(InstanceMemento memento)
 {
     _mementoList.Add(memento);
 }