public void NestedObjectBinding()
        {
            string xaml = @"
<Button xmlns=""clr-namespace:A2v10.System.Xaml.Tests.Mock;assembly=A2v10.System.Xaml.Tests"" 
	Content=""Text"">
	<Button.Command>
		<BindCmd Command=""Execute"" CommandName=""File""/>
	</Button.Command>
</Button>
";
            var    obj  = XamlServices.Parse(xaml, null);

            Assert.AreEqual(typeof(Button), obj.GetType());
            var btn = obj as Button;

            Assert.IsNotNull(btn);
            Assert.AreEqual("Text", btn.Content);

            var cmd = btn.GetBindingCommand("Command");

            Assert.IsNotNull(cmd);
            Assert.AreEqual(typeof(BindCmd), cmd.GetType());
            Assert.AreEqual("Execute", cmd.Command.ToString());
            Assert.AreEqual("File", cmd.CommandName);
        }
Example #2
0
 public void Evaluate(int SpreadMax)
 {
     if (!_pgready)
     {
         return;
     }
     _output.Spread.SliceCount = FSuccess.SliceCount = FError.SliceCount = FInput.SliceCount;
     for (int i = 0; i < FInput.SliceCount; i++)
     {
         if (FSet[i])
         {
             try
             {
                 var res = XamlServices.Parse(FInput[i]);
                 if (_pg.GroupType.IsInstanceOfType(res))
                 {
                     _output[i]  = res;
                     FSuccess[i] = true;
                 }
                 else
                 {
                     FSuccess[i] = false;
                 }
                 FError[i] = "";
             }
             catch (Exception e)
             {
                 FSuccess[i] = false;
                 FError[i]   = e.Message;
             }
         }
     }
 }
        public void SimpleCollection()
        {
            string xaml = @"
<Page xmlns=""clr-namespace:A2v10.System.Xaml.Tests.Mock;assembly=A2v10.System.Xaml.Tests"" Title=""PageTitle"">
	<Block If=""False"" Show=""True"">
		<Button />
		<Span>I am the span text</Span>
	</Block>
	<Block>
		I am the block text
	</Block>
</Page>
";
            var    obj  = XamlServices.Parse(xaml, null);

            Assert.AreEqual(typeof(Page), obj.GetType());
            var p = obj as Page;

            var c = p.Children;

            Assert.AreEqual(2, c.Count);

            var c1 = p.Children[0];

            Assert.AreEqual(typeof(Block), c1.GetType());

            var b1 = c1 as Block;

            Assert.AreEqual(true, b1.Show);
            Assert.AreEqual(false, b1.If);
        }
        private static string CreateSimpleValidatorText(string fieldName, object fieldValue)
        {
            var emptyValidatorString = ValidationServices.GenerateXamlValidatorText(new[]
            {
                new PropertyDefinition
                {
                    PropertyName = fieldName,
                    PropertyType = typeof(string),
                    Alias        = fieldName
                }
            });

            emptyValidatorString = Content.CleanPropertyDefinitions(emptyValidatorString);

            var validator = (XamlValidator)XamlServices.Parse(emptyValidatorString);

            validator.ValidationRules.Add(new ForMember
            {
                Definition = validator.Definitions[fieldName],
                Condition  = new ApplyValue {
                    Value = fieldValue
                }
            });

            return(Content.CleanPropertyDefinitions(XamlServices.Save(validator)));
        }
        private async Task <BudgetAnalyserStorageRoot> LoadXmlFromDiskAsync(string fileName)
        {
            object result = null;
            await Task.Run(() => result = XamlServices.Parse(LoadXamlAsString(fileName)));

            return(result as BudgetAnalyserStorageRoot);
        }
Example #6
0
        public void ProvideValueFromChildEnum()
        {
            const string xaml   = "<x:Static xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:foo='clr-namespace:MonoTests.Portable.Xaml;assembly=Portable.Xaml_test_net_4_0' Member='foo:StaticClass1+MyEnum.EnumValue2' />";
            var          result = XamlServices.Parse(xaml.UpdateXml());

            Assert.AreEqual(StaticClass1.MyEnum.EnumValue2, result);
        }
Example #7
0
        public void ProvideValueWithMemberOnly()
        {
            const string xaml   = "<x:Static xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:foo='clr-namespace:MonoTests.System.Xaml;assembly=System.Xaml.Test' Member='foo:StaticClass1.FooBar' />";
            var          result = XamlServices.Parse(xaml.UpdateXml());

            Assert.AreEqual("test", result);
        }
        public void SimpleResource()
        {
            string xaml = @"
<Page xmlns=""clr-namespace:A2v10.System.Xaml.Tests.Mock;assembly=A2v10.System.Xaml.Tests""
	xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
	xmlns:sys = ""clr-namespace:System;assembly=mscorlib"">
	<Page.Resources>
		<sys:String x:Key=""StrVal"">StringValue</sys:String>
		<Button x:Key=""Button"" Content=""Click""/>
	</Page.Resources>
</Page>
";
            var    obj  = XamlServices.Parse(xaml, null);

            Assert.AreEqual(typeof(Page), obj.GetType());
            var p = obj as Page;

            Assert.IsNotNull(p);
            var strVal = p.Resources["StrVal"];

            Assert.AreEqual("StringValue", strVal);
            var btn = p.Resources["Button"] as Button;

            Assert.IsNotNull(btn);
            Assert.AreEqual("Click", btn.Content);
        }
        public void AddOns()
        {
            string xaml = @"
<Button xmlns=""clr-namespace:A2v10.System.Xaml.Tests.Mock;assembly=A2v10.System.Xaml.Tests"">
	<Button.AddOns>
		<Span Content=""1""/>
		<Span Content=""2""/>
	</Button.AddOns>
</Button>
";
            var    obj  = XamlServices.Parse(xaml, null);

            Assert.AreEqual(typeof(Button), obj.GetType());
            var p = obj as Button;

            var c = p.AddOns;

            Assert.AreEqual(2, c.Count);

            var c1 = p.AddOns[0];

            Assert.AreEqual(typeof(Span), c1.GetType());

            var c2 = p.AddOns[1];

            Assert.AreEqual(typeof(Span), c2.GetType());
        }
		public T Load(dynamic d)
		{
			string back = StoreBack(d);
			Trace.WriteLine(back);
			Trace.WriteLine(string.Join(" ", Encoding.UTF8.GetBytes(back).Select(x => x.ToString("X2"))));
			return (T)XamlServices.Parse(back);
		}
Example #11
0
        public void Save_Workflow()
        {
            var path     = $@"..\..\..\Activities\XAMLs\{nameof(Save_Workflow)}.xaml";
            var expected = File.ReadAllText(path);

            var wf = new SequentialWorkflow {
                Title = "Test"
            };

            wf.Activities.Add(new Delay {
                Timeout = 300
            });
            var forRange = new ForRange {
                Start = 3, Count = 10
            };

            forRange.Activities.Add(new Click {
                Position = new Point(0, 123)
            });
            forRange.Activities.Add(new KeyStroke {
                Timeout = 500, Key = Keys.Control | Keys.A
            });
            wf.Activities.Add(forRange);

            Assert.AreEqual(expected, XamlServices.Save(wf));
            var o = (SequentialWorkflow)XamlServices.Parse(expected);
        }
        public void IDestinationTypeProviderTestAttributes()
        {
            string xaml = @"
<DestinationTypeProviderTestContainer DestinationType=""DT(int)"" DestinationProperty=""List(string)""  xmlns=""clr-namespace:Test.Elements;assembly=XamlTestClasses"" />
";
            DestinationTypeProviderTestContainer dest = XamlServices.Parse(xaml) as DestinationTypeProviderTestContainer;
        }
        public void NamespacePrefixValidationTest()
        {
            string xaml = @"
<NamespacePrefixValidation xmlns=""clr-namespace:Test.Elements;assembly=XamlTestClasses"" xmlns:s=""clr-namespace:System;assembly=mscorlib"">
    <NamespacePrefixValidation.BarContainer>
        <BarContainer xmlns:st=""clr-namespace:System.Threading;assembly=System"" xmlns:scg=""clr-namespace:System.Collection.Generic;assembly=System"" >
            <BarContainer.Bar>1</BarContainer.Bar>
        </BarContainer>
    </NamespacePrefixValidation.BarContainer>
    <NamespacePrefixValidation.FooContainer>
        <FooContainer xmlns:sx=""clr-namespace:System.Xaml;assembly=System.Xaml"" xmlns:s=""clr-namespace:System.Collections.Generic;assembly=System"">
            <FooContainer.Foo>4</FooContainer.Foo>
        </FooContainer>
    </NamespacePrefixValidation.FooContainer>
    <NamespacePrefixValidation.FooContainerTemplate>
        <FooContainer xmlns:sx=""clr-namespace:System.Xaml;assembly=System.Xaml"" xmlns:st=""clr-namespace:System.Threading;assembly=System"" xmlns:scg=""clr-namespace:System.Collection.Generic;assembly=System"">
            <FooContainer.Foo>6</FooContainer.Foo>
        </FooContainer>
    </NamespacePrefixValidation.FooContainerTemplate>
</NamespacePrefixValidation>
";
            NamespacePrefixValidation npv = XamlServices.Parse(xaml) as NamespacePrefixValidation;

            FooContainer container1 = npv.FooContainerTemplate();
            FooContainer container2 = npv.FooContainerTemplate();
        }
Example #14
0
        public void SimpleFlow()
        {
            var xaml = File.ReadAllText("..\\..\\..\\TestFiles\\simple.bpmn");

            var obj = XamlServices.Parse(xaml, XamlServicesOptions.BpmnXamlOptions);

            Assert.AreEqual(typeof(Definitions), obj.GetType());
            var defs = obj as Definitions;

            Assert.AreEqual("http://bpmn.io/bpmn", defs.TargetNamespace);
            Assert.AreEqual("sid-38422fae-e03e-43a3-bef4-bd33b32041b2", defs.Id);

            Assert.IsNotNull(defs.Children[0]);


            var proc = defs.Children[0] as Process;

            Assert.AreEqual("Process_1", proc.Id);
            Assert.AreEqual(false, proc.IsExecutable);

            Assert.AreEqual(1, proc.Children.Count);

            var sev = proc.Children[0] as StartEvent;

            Assert.AreEqual("StartEvent_1y45yut", sev.Id);
            Assert.AreEqual("hunger noticed", sev.Name);
            Assert.AreEqual(1, sev.Children.Count);

            var og = sev.Children[0] as Outgoing;

            Assert.AreEqual("SequenceFlow_0h21x7r", og.Text);
        }
Example #15
0
        public void ClassWithNoMemberTest()
        {
            string s = XamlServices.Save(new VSContainer {
                Vehicle = new EmptyBoat()
            });
            var c = (VSContainer)XamlServices.Parse(s);

            Assert.IsTrue(c.Vehicle is EmptyBoat);
        }
Example #16
0
        public void SimpleTest()
        {
            string      xaml       = @"<VSContainer xmlns=""clr-namespace:Test.Elements;assembly=XamlTestClasses""><VSContainer.Vehicle><Motorcycle>a motorcycle with great fuel economy at 70MPG</Motorcycle></VSContainer.Vehicle></VSContainer>";
            VSContainer c          = (VSContainer)XamlServices.Parse(xaml);
            Motorcycle  motorcycle = c.Vehicle as Motorcycle;

            Assert.IsNotNull(motorcycle);
            Assert.AreEqual(motorcycle.MPG, 70.0);
        }
        public void GenericDictionaryKeyElement()
        {
            string xaml = @"
<Dictionary x:TypeArguments=""s:Int32, s:String"" xmlns=""clr-namespace:System.Collections.Generic;assembly=mscorlib"" xmlns:s=""clr-namespace:System;assembly=mscorlib"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
    <s:String><x:Key>1</x:Key>One</s:String>
</Dictionary>
";
            Dictionary <int, string> dictionary = (Dictionary <int, string>)XamlServices.Parse(xaml);
        }
Example #18
0
        //[TestMethod]
        //public void SaveStream()
        //{
        //    Stream s = new MemoryStream();
        //    Foo f = new Foo();
        //    XamlServices.Save(s, f);
        //}
        //[TestMethod]
        //[TestExpectedException(typeof(ArgumentNullException))]
        //public void SaveStreamFailNull()
        //{
        //    Stream s = null;
        //    Foo f = new Foo();
        //    XamlServices.Save(s, f);
        //}
        //[TestMethod]
        //public void SaveTextWriter()
        //{
        //    StringBuilder sb = new StringBuilder();
        //    TextWriter tw = new StringWriter(sb);
        //    Foo f = new Foo();
        //    XamlServices.Save(tw, f);
        //}
        //[TestMethod]
        //[TestExpectedException(typeof(ArgumentNullException))]
        //public void SaveTextWriterFailNull()
        //{
        //    TextWriter tw = null;
        //    Foo f = new Foo();
        //    XamlServices.Save(tw, f);
        //}
        //[TestMethod]
        //[TestExpectedException(typeof(ArgumentNullException))]
        //public void SaveXamlWriterFailNull()
        //{
        //    XamlXmlWriter xw = null;
        //    Foo f = new Foo();
        //    XamlServices.Save(xw, f);
        //}

        //[TestMethod]
        //[TestExpectedException(typeof(ArgumentNullException))]
        //public void SaveXmlWriterFailNull()
        //{
        //    XmlWriter xw = null;
        //    Foo f = new Foo();
        //    XamlServices.Save(xw, f);
        //}

        void RoundTrip(string xaml)
        {
            object obj = XamlServices.Parse(xaml);
            var    sb  = new StringBuilder();

            XamlServices.Save(new StringWriter(sb), obj);

            Assert.AreEqual(xaml, sb.ToString());
        }
Example #19
0
        public static T DeserializeByXaml <T>(this byte[] binary)
        {
            if (binary == null)
            {
                throw new ArgumentNullException(nameof(binary));
            }

            return((T)XamlServices.Parse(binary.DecodeText(Encoding.UTF8)));
        }
        public void IDestinationTypeProviderTestCollections()
        {
            string xaml = @"
<DestinationTypeProviderTestContainer xmlns=""clr-namespace:Test.Elements;assembly=XamlTestClasses"" xmlns:s=""clr-namespace:System;assembly=mscorlib"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
    <DestinationTypeProviderTestContainer.DestinationTypeList>
        <DestinationType x:TypeArguments=""s:Int32"">DestinationType</DestinationType>
    </DestinationTypeProviderTestContainer.DestinationTypeList>
</DestinationTypeProviderTestContainer>
";
            DestinationTypeProviderTestContainer dest = XamlServices.Parse(xaml) as DestinationTypeProviderTestContainer;
        }
Example #21
0
        public static View FromXaml(string src)
        {
            var ui = XamlServices.Parse(src) as UserControl;

            ui.Dock = DockStyle.Fill;

            return(new View()
            {
                _view = ui
            });
        }
Example #22
0
        public void RoundtripTest2()
        {
            StringBuilder sb   = new StringBuilder();
            Motorboat     boat = new Cruiser {
                Description = "Sleek look"
            };

            XamlServices.Save(XmlWriter.Create(sb), new VSContainer {
                Vehicle = boat
            });
            VSContainer c = (VSContainer)XamlServices.Parse(sb.ToString());
        }