Exemple #1
0
        public override InstanceMemento[] GetChildrenArray(string Key)
        {
            XmlNode childrenNode = _element[Key];

            if (childrenNode == null)
            {
                return(null);
            }

            var list    = new ArrayList();
            var element = (XmlElement)childrenNode.FirstChild;

            while (element != null)
            {
                if (element.NodeType == XmlNodeType.Element)
                {
                    InstanceMemento childMemento = new XmlAttributeInstanceMemento(element);
                    list.Add(childMemento);
                }

                element = (XmlElement)element.NextSibling;
            }

            return((InstanceMemento[])list.ToArray(typeof(InstanceMemento)));
        }
        public void GetLargeStringInAttributeMemento()
        {
            XmlDocument document = DataMother.GetXmlDocument("CDataTest.xml");
            XmlNode node = document.DocumentElement.LastChild;

            var memento = new XmlAttributeInstanceMemento(node);
            Assert.AreEqual("select * from table", memento.GetProperty("bigProp"));
        }
        public override InstanceMemento[] GetChildrenArray(string Key)
        {
            XmlNode childrenNode = _element[Key];
            if (childrenNode == null)
            {
                return null;
            }

            var list = new ArrayList();
            var element = (XmlElement) childrenNode.FirstChild;
            while (element != null)
            {
                if (element.NodeType == XmlNodeType.Element)
                {
                    InstanceMemento childMemento = new XmlAttributeInstanceMemento(element);
                    list.Add(childMemento);
                }

                element = (XmlElement) element.NextSibling;
            }

            return (InstanceMemento[]) list.ToArray(typeof (InstanceMemento));
        }
 public void SetUp()
 {
     string xml = "<Instance Type=\"Color\" Key=\"Red\" color=\"red\"/>";
     _memento = buildMemento(xml);
 }
        public void Read_in_a_class_with_primitive_arrays()
        {
            string xml = @"
            <Instance>
            <numbers Values='1,2,3'/>
            <strings Values='1,2,3'/>
            </Instance>
            ";

            XmlElement element = DataMother.BuildDocument(xml).DocumentElement;
            element.SetAttribute("PluggedType", typeof (ClassWithStringAndIntArray).AssemblyQualifiedName);

            var memento = new XmlAttributeInstanceMemento(element);
            var graph = new PluginGraph();
            Instance instance = memento.ReadInstance(new SimplePluginFactory(), typeof (ClassWithStringAndIntArray));

            var theObject = (ClassWithStringAndIntArray) instance.Build(typeof (ClassWithStringAndIntArray),
                                                                        BuildSession.ForPluginGraph(graph));

            theObject.Numbers.ShouldEqual(new[] {1, 2, 3});
            theObject.Strings.ShouldEqual(new[] {"1", "2", "3"});

            Debug.WriteLine(theObject.GetType().AssemblyQualifiedName);
        }
        public void Read_in_a_dictionary_type_from_an_attribute_normalized_memento()
        {
            string xml =
                @"
            <root>
            <dictionary>
            <Pair Key='color' Value='red'/>
            <Pair Key='state' Value='texas'/>
            <Pair Key='direction' Value='north'/>
            </dictionary>
            </root>
            ";

            XmlElement element = DataMother.BuildDocument(xml).DocumentElement;
            element.SetAttribute("PluggedType", typeof (ClassWithDictionary).AssemblyQualifiedName);

            var memento = new XmlAttributeInstanceMemento(element);

            Instance instance = memento.ReadInstance(new SimplePluginFactory(), typeof(ClassWithDictionary));

            var theObject =
                (ClassWithDictionary) instance.Build(typeof (ClassWithDictionary), BuildSession.Empty());

            theObject.Dictionary["color"].ShouldEqual("red");
            theObject.Dictionary["state"].ShouldEqual("texas");
            theObject.Dictionary["direction"].ShouldEqual("north");
        }
Exemple #7
0
        private void attachInterceptors(PluginFamily family, XmlElement familyElement)
        {
            string contextBase = string.Format("creating an InstanceInterceptor for {0}\n",
                                               family.PluginType.AssemblyQualifiedName);
            familyElement.ForEachChild("*/Interceptor").Do(element =>
            {
                var interceptorMemento = new XmlAttributeInstanceMemento(element);
                string context = contextBase + element.OuterXml;

                _builder.WithSystemObject<ILifecycle>(
                    interceptorMemento,
                    context,
                    lifecycle => family.SetScopeTo(lifecycle));
            });
        }
Exemple #8
0
        private void attachMementoSource(PluginFamily family, XmlElement familyElement)
        {
            familyElement.IfHasNode(MEMENTO_SOURCE_NODE).Do(node =>
            {
                InstanceMemento sourceMemento = new XmlAttributeInstanceMemento(node);

                string context = string.Format("MementoSource for {0}\n{1}",
                                               family.PluginType.AssemblyQualifiedName, node.OuterXml);
                _builder.WithSystemObject<MementoSource>(sourceMemento, context,
                                                         source => family.AddMementoSource(source));
            });
        }