Пример #1
0
 public WpfKnownType(XamlSchemaContext schema,
     int bamlNumber, 
     string name,
     Type underlyingType)
     : this(schema, bamlNumber, name, underlyingType, true, true)
 { 
 }
        public DynamicActivityXamlReader(bool isBuilder, XamlReader innerReader, XamlSchemaContext schemaContext)
            : base()
        {
            this.isBuilder = isBuilder;
            this.innerReader = innerReader;
            this.schemaContext = schemaContext ?? innerReader.SchemaContext;

            this.xamlTypeXamlType = this.schemaContext.GetXamlType(typeof(XamlType));
            this.typeXamlType = this.schemaContext.GetXamlType(typeof(Type));

            this.baseActivityXamlType = this.schemaContext.GetXamlType(typeof(Activity));
            this.activityPropertyXamlType = this.schemaContext.GetXamlType(typeof(DynamicActivityProperty));
            this.activityPropertyType = this.activityPropertyXamlType.GetMember("Type");
            this.activityPropertyName = this.activityPropertyXamlType.GetMember("Name");
            this.activityPropertyValue = this.activityPropertyXamlType.GetMember("Value");
            this.activityPropertyAttributes = this.activityPropertyXamlType.GetMember("Attributes");

            this.namespaceTable = new NamespaceTable();
            this.frontLoadedDirectives = true;

            // we pump items through this node-list when rewriting
            this.nodeQueue = new XamlNodeQueue(this.schemaContext);
            this.nodeReader = this.nodeQueue.Reader;
            IXamlLineInfo lineInfo = innerReader as IXamlLineInfo;
            if (lineInfo != null && lineInfo.HasLineInfo)
            {
                this.innerReaderLineInfo = lineInfo;
                this.nodeReaderLineInfo = (IXamlLineInfo)nodeQueue.Reader;
                this.hasLineInfo = true;
            }
        }
 public ReaderDelegate(XamlSchemaContext schemaContext, XamlNodeNextDelegate next, bool hasLineInfo) : base(schemaContext)
 {
     this._nextDelegate = next;
     base._currentNode = new XamlNode(XamlNode.InternalNodeType.StartOfStream);
     base._currentLineInfo = null;
     base._hasLineInfo = hasLineInfo;
 }
Пример #4
0
		public void ReadWriteListShouldRoundtrip()
		{
			var sc = new XamlSchemaContext();
			var list = new XamlNodeList(sc);

			var reader = new XamlObjectReader(new TestClass4 { Foo = "foo", Bar = "bar" }, sc);
			XamlServices.Transform(reader, list.Writer);

			var writer = new XamlObjectWriter(sc);
			var listReader = list.GetReader();
			XamlServices.Transform(listReader, writer);

			Assert.IsNotNull(writer.Result, "#1");
			Assert.IsInstanceOf<TestClass4>(writer.Result, "#2");

			Assert.AreEqual("foo", ((TestClass4)writer.Result).Foo, "#3");
			Assert.AreEqual("bar", ((TestClass4)writer.Result).Bar, "#4");

			// try reading a 2nd time, we should not get the same reader
			writer = new XamlObjectWriter(sc);
			var listReader2 = list.GetReader();
			Assert.AreNotSame(listReader, listReader2, "#5");
			XamlServices.Transform(listReader2, writer);

			Assert.IsNotNull(writer.Result, "#6");
			Assert.IsInstanceOf<TestClass4>(writer.Result, "#7");

			Assert.AreEqual("foo", ((TestClass4)writer.Result).Foo, "#8");
			Assert.AreEqual("bar", ((TestClass4)writer.Result).Bar, "#9");
		}
 public XamlNsReplacingType(Type underlyingType, XamlSchemaContext context, string localAssemblyName, string realAssemblyName)
     : base(underlyingType, context)
 {
     this.localAssemblyName = localAssemblyName;
     this.realAssemblyName = realAssemblyName;
     namespaces = null;
 }
Пример #6
0
		public XamlObjectWriter (XamlSchemaContext schemaContext, XamlObjectWriterSettings settings)
		{
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			this.sctx = schemaContext;
			this.settings = settings ?? new XamlObjectWriterSettings ();
		}
Пример #7
0
		public XamlWriterInternalBase (XamlSchemaContext schemaContext, XamlWriterStateManager manager)
		{
			this.sctx = schemaContext;
			this.manager = manager;
			var p = new PrefixLookup (sctx) { IsCollectingNamespaces = true }; // it does not raise unknown namespace error.
			service_provider = new ValueSerializerContext (p, schemaContext, AmbientProvider);
		}
Пример #8
0
		public XamlObjectReader (object instance, XamlSchemaContext schemaContext, XamlObjectReaderSettings settings)
		{
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			// FIXME: special case? or can it be generalized? In .NET, For Type instance Instance returns TypeExtension at root StartObject, while for Array it remains to return Array.
			if (instance is Type)
				instance = new TypeExtension ((Type) instance);

			// See also Instance property for this weirdness.
			this.root_raw = instance;
			instance = TypeExtensionMethods.GetExtensionWrapped (instance);
			this.root = instance;

			sctx = schemaContext;
//			this.settings = settings;

			// check type validity. Note that some checks also needs done at Read() phase. (it is likely FIXME:)
			if (instance != null) {
				var type = new InstanceContext (instance).GetRawValue ().GetType ();
				if (!type.IsPublic)
					throw new XamlObjectReaderException (String.Format ("instance type '{0}' must be public and non-nested.", type));
				var xt = SchemaContext.GetXamlType (type);
				if (xt.ConstructionRequiresArguments && !xt.GetConstructorArguments ().Any () && xt.TypeConverter == null)
					throw new XamlObjectReaderException (String.Format ("instance type '{0}' has no default constructor.", type));
			}

			value_serializer_context = new ValueSerializerContext (new PrefixLookup (sctx), sctx, null);
			new XamlObjectNodeIterator (instance, sctx, value_serializer_context).PrepareReading ();
		}
Пример #9
0
 public AmbientPropertyValue GetFirstAmbientValue(IEnumerable<XamlType> ceilingTypes, params XamlMember[] properties)
 {
     var context = new XamlSchemaContext();
     var type = context.GetXamlType(typeof (Setter));
     var member = type.GetMember("TargetType");
     return new AmbientPropertyValue(member, typeof (Button));
 }
 public DynamicActivityXamlReader(bool isBuilder, XamlReader innerReader, XamlSchemaContext schemaContext)
 {
     this.isBuilder = isBuilder;
     this.innerReader = innerReader;
     this.schemaContext = schemaContext ?? innerReader.SchemaContext;
     this.xamlTypeXamlType = this.schemaContext.GetXamlType(typeof(XamlType));
     this.typeXamlType = this.schemaContext.GetXamlType(typeof(System.Type));
     this.baseActivityXamlType = this.schemaContext.GetXamlType(typeof(Activity));
     this.activityPropertyXamlType = this.schemaContext.GetXamlType(typeof(DynamicActivityProperty));
     this.activityPropertyType = this.activityPropertyXamlType.GetMember("Type");
     this.activityPropertyName = this.activityPropertyXamlType.GetMember("Name");
     this.activityPropertyValue = this.activityPropertyXamlType.GetMember("Value");
     this.activityPropertyAttributes = this.activityPropertyXamlType.GetMember("Attributes");
     this.namespaceTable = new NamespaceTable();
     this.frontLoadedDirectives = true;
     this.nodeQueue = new XamlNodeQueue(this.schemaContext);
     this.nodeReader = this.nodeQueue.Reader;
     IXamlLineInfo info = innerReader as IXamlLineInfo;
     if ((info != null) && info.HasLineInfo)
     {
         this.innerReaderLineInfo = info;
         this.nodeReaderLineInfo = (IXamlLineInfo) this.nodeQueue.Reader;
         this.hasLineInfo = true;
     }
 }
Пример #11
0
		public XamlObjectReader (object instance, XamlSchemaContext schemaContext, XamlObjectReaderSettings settings)
		{
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			// FIXME: special case? or can it be generalized? In .NET, For Type instance Instance returns TypeExtension at root StartObject, while for Array it remains to return Array.
			if (instance is Type)
				instance = new TypeExtension ((Type) instance);

			this.root = instance;
			sctx = schemaContext;
			this.settings = settings;

			prefix_lookup = new PrefixLookup (sctx);

			// check type validity. Note that some checks also needs done at Read() phase. (it is likely FIXME:)
			if (instance != null) {
				var type = new InstanceContext (instance).GetWrappedValue ().GetType ();
				if (!type.IsPublic)
					throw new XamlObjectReaderException (String.Format ("instance type '{0}' must be public and non-nested.", type));
				var xt = SchemaContext.GetXamlType (type);
				if (xt.ConstructionRequiresArguments && !xt.GetConstructorArguments ().Any () && xt.TypeConverter == null)
					throw new XamlObjectReaderException (String.Format ("instance type '{0}' has no default constructor.", type));
			}

			new XamlObjectNodeIterator (instance, sctx, prefix_lookup).CollectNamespaces ();
		}
Пример #12
0
		public XamlNodeQueue (XamlSchemaContext schemaContext)
		{
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			this.ctx = schemaContext;
			reader = new XamlNodeQueueReader (this);
			writer = new XamlNodeQueueWriter (this);
		}
 public XamlObjectWriter(XamlSchemaContext schemaContext, XamlObjectWriterSettings settings)
 {
     if (schemaContext == null)
     {
         throw new ArgumentNullException("schemaContext");
     }
     this.Initialize(schemaContext, null, settings);
 }
 public XamlNodeList(XamlSchemaContext schemaContext, int size)
 {
     if (schemaContext == null)
     {
         throw new ArgumentNullException("schemaContext");
     }
     this.Initialize(schemaContext, size);
 }
Пример #15
0
		public void WriterShouldThrowExceptionIfNotClosed()
		{
			var sc = new XamlSchemaContext();
			var list = new XamlNodeList(sc);
			list.Writer.WriteStartObject(sc.GetXamlType(typeof(TestClass4)));
			list.Writer.WriteEndObject();
			Assert.Throws<XamlException> (() => list.GetReader());
		}
Пример #16
0
 public XamlDomMember(XamlMember xamlMember)
 {
     _member = xamlMember;
     if (xamlMember != null)
     {
         _schemaContext = xamlMember.Type.SchemaContext;
     }
 }
 protected ReaderBaseDelegate(XamlSchemaContext schemaContext)
 {
     if (schemaContext == null)
     {
         throw new ArgumentNullException("schemaContext");
     }
     this._schemaContext = schemaContext;
 }
Пример #18
0
		public void ConstructorNullAssemblies ()
		{
			// allowed.
			var ctx = new XamlSchemaContext ((Assembly []) null);
			Assert.IsFalse (ctx.FullyQualifyAssemblyNamesInClrNamespaces, "#1");
			Assert.IsFalse (ctx.SupportMarkupExtensionsWithDuplicateArity, "#2");
			Assert.IsNull (ctx.ReferenceAssemblies, "#3");
		}
 public TypeDescriptorXamlType(Type type, XamlSchemaContext schemaContext, ICustomTypeDescriptor typeDescriptor)
     : base(type, schemaContext)
 {
     Descriptor = typeDescriptor ?? TypeDescriptor.GetProvider(type).GetTypeDescriptor(type);
     if (Descriptor == null)
     {
         throw new InvalidOperationException(string.Format("TypeDescriptionProvider.GetTypeDescriptor returned null for {0}", type));
     }
 }
Пример #20
0
        static App()
        {
            ctx = new XamlSchemaContext(new XamlSchemaContextSettings
            {
                SupportMarkupExtensionsWithDuplicateArity = true,
            });

            settings = Settings.Load();
        }
Пример #21
0
        public static XamlMember ToWpf(this XamlMemberBase member, XamlSchemaContext context)
        {
            if (member.IsDirective)
            {
                return GetDirective(member, context);
            }

            return GetMember((MutableXamlMember) member, context);
        }
 public ReaderMultiIndexDelegate(XamlSchemaContext schemaContext, XamlNodeIndexDelegate indexDelegate, int count, bool hasLineInfo) : base(schemaContext)
 {
     this._indexDelegate = indexDelegate;
     this._count = count;
     this._idx = -1;
     base._currentNode = s_StartOfStream;
     base._currentLineInfo = null;
     base._hasLineInfo = hasLineInfo;
 }
Пример #23
0
        public static XamlType ToWpf(this Typing.XamlType xamlType, XamlSchemaContext context)
        {
            if (typeof(IMarkupExtension).IsAssignableFrom(xamlType.UnderlyingType))
            {
                return new XamlType(typeof(Binding), context);
            }

            return new XamlType(xamlType.UnderlyingType, context);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationService"/> class.
 /// </summary>
 public ConfigurationService()
 {
     var settings = new NinjectSettings
                        {
                            LoadExtensions = false
                        };
     this.kernel = new StandardKernel(settings, new CoreModule());
     this.context = new CoreXamlSchemaContext(this.kernel);
 }
Пример #25
0
		public XamlObjectWriter (XamlSchemaContext schemaContext, XamlObjectWriterSettings settings)
		{
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			this.sctx = schemaContext;
			this.settings = settings ?? new XamlObjectWriterSettings ();
			var manager = new XamlWriterStateManager<XamlObjectWriterException, XamlObjectWriterException> (false);
			intl = new XamlObjectWriterInternal (this, sctx, manager);
		}
Пример #26
0
 public WpfXamlMember(RoutedEvent re, 
     EventInfo eventInfo,
     XamlSchemaContext schemaContext, 
     bool useV3Rules) 
     : base(eventInfo, schemaContext)
 { 
     RoutedEvent = re;
     _useV3Rules = useV3Rules;
     _underlyingMemberIsKnown = true;
 } 
Пример #27
0
 public WpfXamlMember(RoutedEvent re,
     MethodInfo setter,
     XamlSchemaContext schemaContext, 
     bool useV3Rules)
     : base(re.Name, setter, schemaContext) 
 { 
     RoutedEvent = re;
     _useV3Rules = useV3Rules; 
     _underlyingMemberIsKnown = true;
 }
 public XamlNamespace(XamlSchemaContext schemaContext, string clrNs, string assemblyName)
 {
     this.SchemaContext = schemaContext;
     this._assemblyNamespaces = this.GetClrNamespacePair(clrNs, assemblyName);
     if (this._assemblyNamespaces != null)
     {
         this.Initialize();
     }
     this.IsClrNamespace = true;
 }
Пример #29
0
 public WpfXamlMember(DependencyProperty dp, 
     PropertyInfo property,
     XamlSchemaContext schemaContext,
     bool useV3Rules)
     : base (property, schemaContext) 
 {
     DependencyProperty = dp; 
     _useV3Rules = useV3Rules; 
     _underlyingMemberIsKnown = true;
 } 
 public XamlNodeQueue(XamlSchemaContext schemaContext)
 {
     if (schemaContext == null)
     {
         throw new ArgumentNullException("schemaContext");
     }
     this._nodeQueue = new Queue<XamlNode>();
     this._endOfStreamNode = new XamlNode(XamlNode.InternalNodeType.EndOfStream);
     this._writer = new WriterDelegate(new XamlNodeAddDelegate(this.Add), new XamlLineInfoAddDelegate(this.AddLineInfo), schemaContext);
 }
Пример #31
0
        }//end

        //从[xaml]字串得到[ActivityBuilder]对象
        public static string xamlFromActivityBuilder(ActivityBuilder activityBuilder)
        {
            string xamlString = "";

            StringBuilder stringBuilder = new StringBuilder();

            System.IO.StringWriter stringWriter = new System.IO.StringWriter(stringBuilder);

            System.Xaml.XamlSchemaContext xamlSchemaContext = new System.Xaml.XamlSchemaContext();

            System.Xaml.XamlXmlWriter xamlXmlWriter = new System.Xaml.XamlXmlWriter(stringWriter, xamlSchemaContext);


            System.Xaml.XamlWriter xamlWriter = System.Activities.XamlIntegration.ActivityXamlServices.CreateBuilderWriter(xamlXmlWriter);

            System.Xaml.XamlServices.Save(xamlWriter, activityBuilder);

            xamlString = stringBuilder.ToString();

            return(xamlString);
        }
Пример #32
0
        static void testReadXaml()
        {
            string[] resources    = typeof(SESampleProcess2).Assembly.GetManifestResourceNames();
            string   resourceName = null;

            for (int i = 0; (i < resources.Length); i = (i + 1))
            {
                resourceName = resources[i];
                if ((resourceName.Contains(".SESampleProcess2.g.xaml") || resourceName.Equals("SESampleProcess2.g.xaml")))
                {
                    break;
                }
            }
            //resourceName=@"D:\WorkSpaces\Tracking\TrackingStateMachine\SESampleProcess2.xaml";



            //System.IO.Stream initializeXaml = new FileStream(resourceName,FileMode.Open);// typeof(SESampleProcess2).Assembly.GetManifestResourceStream(resourceName);
            System.IO.Stream initializeXaml = typeof(SESampleProcess2).Assembly.GetManifestResourceStream(resourceName);
            StreamReader     sr             = new StreamReader(initializeXaml);

            Console.WriteLine(sr.ReadToEnd());
            //System.Xml.XmlReader xmlReader = null;
            System.Xaml.XamlReader reader = null;

            System.Xaml.XamlSchemaContext schemaContext = XamlStaticHelperNamespace._XamlStaticHelper.SchemaContext;
            //xmlReader = System.Xml.XmlReader.Create(initializeXaml);
            System.Xaml.XamlXmlReaderSettings readerSettings = new System.Xaml.XamlXmlReaderSettings();
            readerSettings.LocalAssembly = System.Reflection.Assembly.GetExecutingAssembly();

            reader = new XamlXmlReader(initializeXaml, schemaContext, readerSettings);

            Activity     a  = ActivityXamlServices.Load(reader);
            StateMachine sm = (StateMachine)a;

            Console.WriteLine();
            //ShitProcess sp = new ShitProcess();
            //SESampleProcess2 ss = new SESampleProcess2();
            //StateMachine sm = new StateMachine();


            //string[] resources = typeof(SESampleProcess2).Assembly.GetManifestResourceNames();
            //string resourceName = null;
            //for (int i = 0; (i < resources.Length); i = (i + 1))
            //{
            //    resourceName = resources[i];
            //    if ((resourceName.Contains(".SESampleProcess2.g.xaml") || resourceName.Equals("SESampleProcess2.g.xaml")))
            //    {
            //        break;
            //    }
            //}
            //System.IO.Stream initializeXaml = typeof(SESampleProcess2).Assembly.GetManifestResourceStream(resourceName);
            //Console.WriteLine(initializeXaml.ToString());
            //System.Xml.XmlReader xmlReader = null;
            //System.Xaml.XamlReader reader = null;
            //System.Xaml.XamlObjectWriter objectWriter = null;
            //try
            //{
            //    System.Xaml.XamlSchemaContext schemaContext = XamlStaticHelperNamespace._XamlStaticHelper.SchemaContext;
            //    xmlReader = System.Xml.XmlReader.Create(initializeXaml);
            //    System.Xaml.XamlXmlReaderSettings readerSettings = new System.Xaml.XamlXmlReaderSettings();
            //    readerSettings.LocalAssembly = System.Reflection.Assembly.GetExecutingAssembly();
            //    readerSettings.AllowProtectedMembersOnRoot = true;
            //    reader = new System.Xaml.XamlXmlReader(xmlReader, schemaContext, readerSettings);
            //    System.Xaml.XamlObjectWriterSettings writerSettings = new System.Xaml.XamlObjectWriterSettings();
            //    writerSettings.RootObjectInstance = sm;
            //    writerSettings.AccessLevel = System.Xaml.Permissions.XamlAccessLevel.PrivateAccessTo(typeof(SESampleProcess2));
            //    objectWriter = new System.Xaml.XamlObjectWriter(schemaContext, writerSettings);
            //    System.Xaml.XamlServices.Transform(reader, objectWriter);
            //}
            //finally
            //{
            //    if ((xmlReader != null))
            //    {
            //        ((System.IDisposable)(xmlReader)).Dispose();
            //    }
            //    if ((reader != null))
            //    {
            //        ((System.IDisposable)(reader)).Dispose();
            //    }
            //    if ((objectWriter != null))
            //    {
            //        ((System.IDisposable)(objectWriter)).Dispose();
            //    }
            //}

            Console.WriteLine();
            //string resourceName = this.FindResource();
            //System.IO.Stream initializeXaml = typeof(SESampleProcess2).Assembly.GetManifestResourceStream(resourceName);
        }