public static PersistentVM LoadStateFromFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new ArgumentException(Resources.MissingPersistentVMFile, "filePath");
            }

            XmlAttributeOverrides overrides = new XmlAttributeOverrides();
            XmlAttributes ignoreAttrib = new XmlAttributes();
            ignoreAttrib.XmlIgnore = true;
            overrides.Add(typeof(DataVirtualHardDisk), "MediaLink", ignoreAttrib);
            overrides.Add(typeof(DataVirtualHardDisk), "SourceMediaLink", ignoreAttrib);
            overrides.Add(typeof(OSVirtualHardDisk), "MediaLink", ignoreAttrib);
            overrides.Add(typeof(OSVirtualHardDisk), "SourceImageName", ignoreAttrib);

            var serializer = new System.Xml.Serialization.XmlSerializer(typeof(PersistentVM), overrides, new Type[] { typeof(NetworkConfigurationSet) }, null, null);

            PersistentVM role = null;
            
            using (var stream = new FileStream(filePath, FileMode.Open))
            {
                role = serializer.Deserialize(stream) as PersistentVM;
            }

            return role;
        }
        /// <summary>
        /// Serializes an object into an XML document
        /// </summary>
        /// <param name="obj">object to serialize</param>
        /// <param name="rootAttribute">root attribute to use</param>
        /// <param name="namespacePrefixes">namespace prefixes</param>
        /// <returns>a string that contains the XML document</returns>
        public static string Serialize(object obj, XmlRootAttribute rootAttribute, params XmlQualifiedName[] namespacePrefixes)
        {
            if (obj == null)
            {
                return null;
            }

            using (var textWriter = new StringWriterUTF8())
            {
                var type = obj.GetType();
                var xmlAttributeOverrides = new XmlAttributeOverrides();
                if (rootAttribute != null)
                {
                    var xmlAttributes = new XmlAttributes();
                    xmlAttributes.XmlRoot = rootAttribute;
                    xmlAttributeOverrides.Add(type, xmlAttributes);
                }
                using (var xmWriter = XmlWriter.Create(textWriter, new XmlWriterSettings() { OmitXmlDeclaration = true }))
                {
                    var namespaces = new XmlSerializerNamespaces();
                    if (namespacePrefixes != null)
                    {
                        foreach (var ns in namespacePrefixes)
                        {
                            namespaces.Add(ns.Name, ns.Namespace);
                        }
                    }
                    new XmlSerializer(type, xmlAttributeOverrides).Serialize(xmWriter, obj, namespaces);
                }
                return textWriter.ToString();
            }
        }
        public static XmlAttributeOverrides Create(Type objectType)
        {
            XmlAttributeOverrides xOver = null;

            if (!table.TryGetValue(objectType, out xOver))
            {
                // Create XmlAttributeOverrides object.
                xOver = new XmlAttributeOverrides();

                /* Create an XmlTypeAttribute and change the name of the XML type. */
                XmlTypeAttribute xType = new XmlTypeAttribute();
                xType.TypeName = objectType.Name;

                // Set the XmlTypeAttribute to the XmlType property.
                XmlAttributes attrs = new XmlAttributes();
                attrs.XmlType = xType;

                /* Add the XmlAttributes to the XmlAttributeOverrides,
                   specifying the member to override. */
                xOver.Add(objectType, attrs);

                table.MergeSafe(objectType, xOver);
            }

            return xOver;
        }
Exemple #4
0
        public static XmlAttributeOverrides GetExportedDefinitionsOverrides(XmlAttributeOverrides DefinitionsOverrides)
        {
            var _container = PluginContainer.GetOvalCompositionContainer();

            var testTypes = _container.GetExports<TestType>().Select(exp => exp.Value.GetType());
            var objectTypes = _container.GetExports<ObjectType>().Select(exp => exp.Value.GetType());
            var stateTypes = _container.GetExports<StateType>().Select(exp => exp.Value.GetType());

            XmlAttributes testAttributes = new XmlAttributes();
            foreach (var testType in testTypes)
            {
                var xmlAttrs = (testType.GetCustomAttributes(typeof(XmlRootAttribute), false) as XmlRootAttribute[]).SingleOrDefault();
                testAttributes.XmlArrayItems.Add(new XmlArrayItemAttribute(xmlAttrs.ElementName, testType) { Namespace = xmlAttrs.Namespace });
            }
            DefinitionsOverrides.Add(typeof(oval_definitions), "tests", testAttributes);
            XmlAttributes objectAttributes = new XmlAttributes();
            foreach (var objectType in objectTypes)
            {
                var xmlAttrs = (objectType.GetCustomAttributes(typeof(XmlRootAttribute), false) as XmlRootAttribute[]).SingleOrDefault();
                objectAttributes.XmlArrayItems.Add(new XmlArrayItemAttribute(xmlAttrs.ElementName, objectType) { Namespace = xmlAttrs.Namespace });
            }
            DefinitionsOverrides.Add(typeof(oval_definitions), "objects", objectAttributes);

            XmlAttributes stateAttributes = new XmlAttributes();
            foreach (var stateType in stateTypes)
            {
                var xmlAttrs = (stateType.GetCustomAttributes(typeof(XmlRootAttribute), false) as XmlRootAttribute[]).SingleOrDefault();
                stateAttributes.XmlArrayItems.Add(new XmlArrayItemAttribute(xmlAttrs.ElementName, stateType) { Namespace = xmlAttrs.Namespace });
            }
            DefinitionsOverrides.Add(typeof(oval_definitions), "states", stateAttributes);

            return DefinitionsOverrides;
        }
        private async void ButtonSendErrorReport_Click(object sender, RoutedEventArgs e)
        {
            var ex = Error.ToExceptionless();
            ex.SetUserDescription(string.Empty, NoteTextBox.Text);
            ex.AddObject(HurricaneSettings.Instance.Config, "HurricaneSettings", null, null, true);

            if (HurricaneSettings.Instance.IsLoaded)
            {
                using (var sw = new StringWriter())
                {
                    XmlAttributeOverrides overrides = new XmlAttributeOverrides(); //DONT serialize the passwords and send them to me!
                    XmlAttributes attribs = new XmlAttributes {XmlIgnore = true};
                    attribs.XmlElements.Add(new XmlElementAttribute("Passwords"));
                    overrides.Add(typeof(ConfigSettings), "Passwords", attribs);

                    var xmls = new XmlSerializer(typeof(ConfigSettings), overrides);
                    xmls.Serialize(sw, HurricaneSettings.Instance.Config);

                    var doc = new XmlDocument();
                    doc.LoadXml(sw.ToString());
                    ex.SetProperty("HurricaneSettings", JsonConvert.SerializeXmlNode(doc));
                }
            }

            ex.Submit();
            ((Button)sender).IsEnabled = false;
            StatusProgressBar.IsIndeterminate = true;
            await ExceptionlessClient.Default.ProcessQueueAsync();
            StatusProgressBar.IsIndeterminate = false;
            Application.Current.Shutdown();
        }
Exemple #6
0
 /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.XmlSerializer"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public XmlSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace) {
     XmlReflectionImporter importer = new XmlReflectionImporter(overrides, defaultNamespace);
     for (int i = 0; i < extraTypes.Length; i++)
         importer.IncludeType(extraTypes[i]);
     tempAssembly = GenerateTempAssembly(importer.ImportTypeMapping(type, root));
     this.events.sender = this;
 }
        private static string SerializeToXml(TransportMessage transportMessage)
        {
            var overrides = new XmlAttributeOverrides();
            var attrs = new XmlAttributes {XmlIgnore = true};

            // Exclude non-serializable members
            overrides.Add(typeof (TransportMessage), "Body", attrs);
            overrides.Add(typeof (TransportMessage), "ReplyToAddress", attrs);
            overrides.Add(typeof (TransportMessage), "Headers", attrs);

            var sb = new StringBuilder();
            var xws = new XmlWriterSettings { Encoding = Encoding.Unicode };
            var xw = XmlWriter.Create(sb, xws);
            var xs = new XmlSerializer(typeof (TransportMessage), overrides);
            xs.Serialize(xw, transportMessage);

            var xdoc = XDocument.Parse(sb.ToString());
            var body = new XElement("Body");
            var cdata = new XCData(Encoding.UTF8.GetString(transportMessage.Body));
            body.Add(cdata);
            xdoc.SafeElement("TransportMessage").Add(body);

            sb.Clear();
            var sw = new StringWriter(sb);
            xdoc.Save(sw);

            return sb.ToString();
        }
Exemple #8
0
        //SerialSample4\form1.cs
        private void button1_Click(object sender, System.EventArgs e)
        {
            //create the XmlAttributes boject
              XmlAttributes attrs=new XmlAttributes();
              //add the types of the objects that will be serialized
              attrs.XmlElements.Add(new XmlElementAttribute("Book",typeof(BookProduct)));
              attrs.XmlElements.Add(new XmlElementAttribute("Product",typeof(Product)));
              XmlAttributeOverrides attrOver=new XmlAttributeOverrides();
              //add to the attributes collection
              attrOver.Add(typeof(Inventory),"InventoryItems",attrs);
              //create the Product and Book objects
              Product newProd=new Product();
              BookProduct newBook=new BookProduct();

              newProd.ProductID=100;
              newProd.ProductName="Product Thing";
              newProd.SupplierID=10;

              newBook.ProductID=101;
              newBook.ProductName="How to Use Your New Product Thing";
              newBook.SupplierID=10;
              newBook.ISBN="123456789";

              Product[] addProd={newProd,newBook};

              Inventory inv=new Inventory();
              inv.InventoryItems=addProd;
              TextWriter tr=new StreamWriter("..\\..\\..\\inventory.xml");
              XmlSerializer sr=new XmlSerializer(typeof(Inventory),attrOver);

              sr.Serialize(tr,inv);
              tr.Close();
            MessageBox.Show("Serialized!");
        }
Exemple #9
0
		public static PersistentVM LoadStateFromFile(string filePath)
		{
			PersistentVM persistentVM;
			if (File.Exists(filePath))
			{
				XmlAttributeOverrides xmlAttributeOverride = new XmlAttributeOverrides();
				XmlAttributes xmlAttribute = new XmlAttributes();
				xmlAttribute.XmlIgnore = true;
				xmlAttributeOverride.Add(typeof(DataVirtualHardDisk), "MediaLink", xmlAttribute);
				xmlAttributeOverride.Add(typeof(DataVirtualHardDisk), "SourceMediaLink", xmlAttribute);
				xmlAttributeOverride.Add(typeof(OSVirtualHardDisk), "MediaLink", xmlAttribute);
				xmlAttributeOverride.Add(typeof(OSVirtualHardDisk), "SourceImageName", xmlAttribute);
				Type[] typeArray = new Type[1];
				typeArray[0] = typeof(NetworkConfigurationSet);
				XmlSerializer xmlSerializer = new XmlSerializer(typeof(PersistentVM), xmlAttributeOverride, typeArray, null, null);
				using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
				{
					persistentVM = xmlSerializer.Deserialize(fileStream) as PersistentVM;
				}
				return persistentVM;
			}
			else
			{
				throw new ArgumentException("The file to load the role does not exist", "filePath");
			}
		}
 protected virtual void OnCreateXmlSerializer(XmlAttributeOverrides overrides, List<Type> additionalTypes, List<Type> additionalControls)
 {
     if (GetType().Assembly != typeof(IWindowlessControl).Assembly)
     {
         AddAssemblyControlsToList(GetType().Assembly, additionalControls);
     }
 }
Exemple #11
0
		internal static void DifferentThumbprint(XmlAttributeOverrides ov1, XmlAttributeOverrides ov2)
		{
			string print1 = XmlAttributeOverridesThumbprinter.GetThumbprint(ov1);
			string print2 = XmlAttributeOverridesThumbprinter.GetThumbprint(ov2);

			Assert.IsFalse(print1 == print2);
		}
		public void TwoDifferentEmptyObjects()
		{
			XmlAttributeOverrides ov1 = new XmlAttributeOverrides();
			XmlAttributeOverrides ov2 = new XmlAttributeOverrides();

			ThumbprintHelpers.SameThumbprint(ov1, ov2);
		}
        public static T ParseXML <T>(this string @this) where T : class
        {
            if (string.IsNullOrWhiteSpace(@this))
            {
                return((T)Activator.CreateInstance(typeof(T)));
            }

            if ([email protected]("<?xml version=\"1.0\" encoding=\"utf-16\"?>"))
            {
                @this = "<?xml version=\"1.0\" encoding=\"utf-16\"?>" + @this;
            }

            string kUtf8BOM = System.Text.Encoding.UTF8.GetString(System.Text.Encoding.UTF8.GetPreamble());

            if (@this.StartsWith(kUtf8BOM))
            {
                @this = @this.Remove(0, kUtf8BOM.Length);
            }
            if (@this.StartsWith("?xm"))
            {
                @this = "<" + @this;
            }

            StringReader  Stream = null;
            XmlTextReader Reader = null;

            try
            {
                System.Xml.Serialization.XmlAttributeOverrides xOver = new System.Xml.Serialization.XmlAttributeOverrides();
                System.Xml.Serialization.XmlAttributes         attrs = new System.Xml.Serialization.XmlAttributes();
                foreach (var Ig in typeof(T).GetProperties().Where(c => !c.PropertyType.IsSerializable || c.PropertyType.FullName.StartsWith("DynamicBusiness.BPMS.BusinessLogic") || c.PropertyType.FullName.StartsWith("DynamicBusiness.BPMS.Engine")).Select(c => c.Name))
                {
                    attrs           = new System.Xml.Serialization.XmlAttributes();
                    attrs.XmlIgnore = true;
                    xOver.Add(typeof(T), Ig, attrs);
                }

                XmlSerializer Serializer = new XmlSerializer(typeof(T), xOver);
                Stream = new StringReader(@this);
                Reader = new XmlTextReader(Stream);

                // covert reader to object
                return((T)Serializer.Deserialize(Reader));
            }
            catch (Exception ex)
            {
                return(default(T));
            }
            finally
            {
                if (Stream != null)
                {
                    Stream.Close();
                }
                if (Reader != null)
                {
                    Reader.Close();
                }
            }
        }
Exemple #14
0
        public byte[] getRequestContent( string doctype, string root, Type type, object obj)
        {
            XmlSerializer serializer = null;
            if (root == null)
            {
                //... root element will be the object type name
                serializer = new XmlSerializer(type);
            }
            else
            {
                //... root element set explicitely
                var xattribs = new XmlAttributes();
                var xroot = new XmlRootAttribute(root);
                xattribs.XmlRoot = xroot;
                var xoverrides = new XmlAttributeOverrides();
                xoverrides.Add(type, xattribs);
                serializer = new XmlSerializer(type, xoverrides);
            }
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = false;
            settings.OmitXmlDeclaration = false;
            settings.Encoding = new UTF8Encoding(false/*no BOM*/, true/*throw if input illegal*/);

            XmlSerializerNamespaces xmlNameSpace = new XmlSerializerNamespaces();
            xmlNameSpace.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            xmlNameSpace.Add("noNamespaceSchemaLocation", m_schemadir + "/" + doctype + "." + m_schemaext);

            StringWriter sw = new StringWriter();
            XmlWriter xw = XmlWriter.Create( sw, settings);
            xw.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");

            serializer.Serialize(xw, obj, xmlNameSpace);

            return settings.Encoding.GetBytes( sw.ToString());
        }
		/// <summary>
		/// Creates a signature for the passed in XmlAttributeOverrides
		/// </summary>
		/// <param name="overrides"></param>
		/// <returns>An instance indpendent signature of the XmlAttributeOverrides</returns>
		public static string GetOverridesSignature(XmlAttributeOverrides overrides)
		{
			// GetHashCode looks at something other than the content
			// of XmlOverrideAttributes and comes up with different
			// hash values for two instances that would produce
			// the same XML is the were applied to the XmlSerializer.
			// Therefore I need to do something more intelligent
			// to normalize the content of XmlAttributeOverrides
			// or extract a thumbpront that only accounts for the
			// attributes in XmlAttributeOverrides.

			// The main problems is that 
			// I can only access the hashtables that store the 
			// overriding attributes through reflection, i.e.
			// I can't run the XmlSerializerCache in a partially
			// trusted security context.
			//
			// Also, the extra computation to create a purely
			// content-based thumbprint not offset the savings.
			// 
			// If none if these were an issue I'd simply say:
			// return overrides.GetHashCode().ToString();

			string thumbPrint = null;
			if (null != overrides)
			{
				thumbPrint = XmlAttributeOverridesThumbprinter.GetThumbprint(overrides);
			}
			return thumbPrint;
		}
		public void SameEmptyObjectTwice()
		{
			// the same object should most certainly
			// result in the same signature, even when it's empty
			XmlAttributeOverrides ov = new XmlAttributeOverrides();
			ThumbprintHelpers.SameThumbprint(ov, ov);
		}
Exemple #17
0
        public static byte[] getRequestContent(string doctype, string root, Type type, object obj)
        {
            var xattribs = new XmlAttributes();
            var xroot = new XmlRootAttribute(root);
            xattribs.XmlRoot = xroot;
            var xoverrides = new XmlAttributeOverrides();
            //... have to use XmlAttributeOverrides because .NET insists on the object name as root element name otherwise ([XmlRoot(..)] has no effect)
            xoverrides.Add(type, xattribs);

            XmlSerializer serializer = new XmlSerializer(type, xoverrides);
            StringWriter sw = new StringWriter();
            XmlWriterSettings wsettings = new XmlWriterSettings();
            wsettings.OmitXmlDeclaration = false;
            wsettings.Encoding = new UTF8Encoding();
            XmlWriter xw = XmlWriter.Create(sw, wsettings);
            xw.WriteProcessingInstruction("xml", "version='1.0' standalone='no'");
            //... have to write header by hand (OmitXmlDeclaration=false has no effect)
            xw.WriteDocType(root, null, doctype + ".sfrm", null);

            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
            ns.Add("", "");
            //... trick to avoid printing of xmlns:xsi xmlns:xsd attributes of the root element

            serializer.Serialize(xw, obj, ns);
            return sw.ToArray();
        }
 public static XmlSerializer Create(Type type, XmlAttributeOverrides overrides)
 {
     Type realType = GetRealType(type);
     XmlSerializer xs = _factory.CreateSerializer(realType, overrides);
     if (xs == null)
         xs = new XmlSerializer(realType, overrides);
     return xs;
 }
		public void SetUp()
		{
			ov1 = new XmlAttributeOverrides();
			ov2 = new XmlAttributeOverrides();

			atts1 = new XmlAttributes();
			atts2 = new XmlAttributes();
		}
Exemple #20
0
		internal static void SameThumbprint(XmlAttributeOverrides ov1, XmlAttributeOverrides ov2)
		{
			string print1 = XmlAttributeOverridesThumbprinter.GetThumbprint(ov1);
			string print2 = XmlAttributeOverridesThumbprinter.GetThumbprint(ov2);

			//Console.WriteLine("p1 {0}, p2 {1}", print1, print2);
			Assert.AreEqual(print1, print2);
		}
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:System.Xml.Serialization.XmlSerializer"/> class that can serialize objects of type <see cref="T:System.Object"/> into XML document instances, and deserialize XML document instances into objects of type <see cref="T:System.Object"/>. Each object to be serialized can itself contain instances of classes, which this overload overrides with other classes. This overload also specifies the default namespace for all the XML elements and the class to use as the XML root element.
 /// </summary>
 /// <param name="type">The type of the object that this <see cref="T:System.Xml.Serialization.XmlSerializer"/> can serialize. </param><param name="overrides">An <see cref="T:System.Xml.Serialization.XmlAttributeOverrides"/> that extends or overrides the behavior of the class specified in the <paramref name="type"/> parameter. </param><param name="extraTypes">A <see cref="T:System.Type"/> array of additional object types to serialize. </param><param name="root">An <see cref="T:System.Xml.Serialization.XmlRootAttribute"/> that defines the XML root element properties. </param><param name="defaultNamespace">The default namespace of all XML elements in the XML document. </param>
 public XmlSerializerWrap(Type type,
                          XmlAttributeOverrides overrides,
                          Type[] extraTypes,
                          XmlRootAttribute root,
                          string defaultNamespace)
 {
     this.XmlSerializerInstance = new XmlSerializer(type, overrides, extraTypes, root, defaultNamespace);
 }
		private XmlTypeMapping Map(Type t, XmlAttributeOverrides overrides)
		{
			XmlReflectionImporter ri = new XmlReflectionImporter(overrides);
			XmlTypeMapping tm = ri.ImportTypeMapping(t);
			//Debug.Print(tm);

			return tm;
		}
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:System.Xml.Serialization.XmlSerializer"/> class that can serialize objects of type <see cref="T:System.Object"/> into XML document instances, and deserialize XML document instances into objects of type <see cref="T:System.Object"/>. Each object to be serialized can itself contain instances of classes, which this overload overrides with other classes. This overload also specifies the default namespace for all the XML elements and the class to use as the XML root element.
 /// </summary>
 /// <param name="type">The type of the object that this <see cref="T:System.Xml.Serialization.XmlSerializer"/> can serialize. </param><param name="overrides">An <see cref="T:System.Xml.Serialization.XmlAttributeOverrides"/> that extends or overrides the behavior of the class specified in the <paramref name="type"/> parameter. </param><param name="extraTypes">A <see cref="T:System.Type"/> array of additional object types to serialize. </param><param name="root">An <see cref="T:System.Xml.Serialization.XmlRootAttribute"/> that defines the XML root element properties. </param><param name="defaultNamespace">The default namespace of all XML elements in the XML document. </param>
 public IXmlSerializer Create(Type type,
                              XmlAttributeOverrides overrides,
                              Type[] extraTypes,
                              XmlRootAttribute root,
                              string defaultNamespace)
 {
     return new XmlSerializerWrap(type, overrides, extraTypes, root, defaultNamespace);
 }
Exemple #24
0
        public static void SerializeToFile(string filePath, Object obj, XmlRootAttribute root, XmlAttributeOverrides overrides)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType(), overrides, null, root, string.Empty);

            StreamWriter streamWriter = new StreamWriter(filePath, false, new UTF8Encoding());
            xmlSerializer.Serialize(streamWriter, obj);

            streamWriter.Close();
        }
		public void SameObjectWithRootAttribute()
		{
			XmlAttributeOverrides ov = new XmlAttributeOverrides();
			XmlAttributes atts = new XmlAttributes();
			atts.XmlRoot = new XmlRootAttribute("myRoot");
			ov.Add(typeof(SerializeMe), atts);

			ThumbprintHelpers.SameThumbprint(ov, ov);
		}
		private XmlSchemas Export (Type type, XmlAttributeOverrides overrides, string defaultNamespace)
		{
			XmlReflectionImporter ri = new XmlReflectionImporter (overrides, defaultNamespace);
			XmlSchemas schemas = new XmlSchemas ();
			XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
			XmlTypeMapping tm = ri.ImportTypeMapping (type);
			sx.ExportTypeMapping (tm);
			return schemas;
		}
 /// <include file='doc\XmlReflectionImporter.uex' path='docs/doc[@for="XmlReflectionImporter.XmlReflectionImporter3"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public XmlReflectionImporter(XmlAttributeOverrides attributeOverrides, string defaultNamespace) {
     if (defaultNamespace == null)
         defaultNamespace = String.Empty;
     if (attributeOverrides == null)
         attributeOverrides = new XmlAttributeOverrides();
     this.attributeOverrides = attributeOverrides;
     this.defaultNs = defaultNamespace;
     this.typeScope = new TypeScope();
     this.modelScope = new ModelScope(this.typeScope);
 }
        public static ModuleConfiguration Load(string fileName, List<Type> displayList, List<Type> deviceList,
                                               List<Type> sourceList, List<Type> mappingList)
        {
            string configurationSchemaFile = Path.ChangeExtension(fileName, "xsd");
            try
            {
                XmlAttributeOverrides ovr = new XmlAttributeOverrides();

                XmlAttributes attrsDevice = new XmlAttributes();
                XmlAttributes attrsSource = new XmlAttributes();
                XmlAttributes attrsDisplay = new XmlAttributes();
                XmlAttributes attrsMapping = new XmlAttributes();

                attrsMapping.XmlArrayItems.Add(new XmlArrayItemAttribute(typeof (Mapping)));

                foreach (Type type in sourceList)
                    attrsSource.XmlArrayItems.Add(new XmlArrayItemAttribute(type));
                foreach (Type type in deviceList)
                    attrsDevice.XmlArrayItems.Add(new XmlArrayItemAttribute(type));
                foreach (Type type in displayList)
                    attrsDisplay.XmlArrayItems.Add(new XmlArrayItemAttribute(type));
                foreach (Type type in mappingList)
                    attrsMapping.XmlArrayItems.Add(new XmlArrayItemAttribute(type));

                ovr.Add(typeof (ModuleConfiguration), "DeviceList", attrsDevice);
                ovr.Add(typeof (ModuleConfiguration), "SourceList", attrsSource);
                ovr.Add(typeof (ModuleConfiguration), "DisplayList", attrsDisplay);
                ovr.Add(typeof (DisplayType), "MappingList", attrsMapping);

                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ValidationType = ValidationType.Schema;
                settings.Schemas.Add("urn:configuration-schema", configurationSchemaFile);
                // Проводим валидацию, отдельно от десереализации, потому-что если вместе то валится
                using (XmlReader reader = XmlReader.Create(fileName, settings))
                    while (reader.Read())
                    {
                    }
                // Проводим десереализации без валидации, потому-что если вместе то валится
                XmlSerializer serializer = new XmlSerializer(typeof (ModuleConfiguration), ovr);
                using (XmlReader reader = XmlReader.Create(fileName))
                    return (ModuleConfiguration) serializer.Deserialize(reader);
            }
            catch (FileNotFoundException ex)
            {
                throw new ModuleConfigurationException(ex.FileName);
            }
            catch (XmlSchemaException ex)
            {
                throw new ModuleConfigurationException(new Uri(ex.SourceUri).AbsolutePath, ex);    //configurationSchemaFile
            }
            catch (XmlException ex)
            {
                throw new ModuleConfigurationException(new Uri(ex.SourceUri).AbsolutePath, ex);
            }
        }
Exemple #29
0
        public void WriteTo(TextWriter tw)
        {
            XmlAttributeOverrides overrides = new XmlAttributeOverrides();
            XmlAttributes attrs = new XmlAttributes {XmlIgnore = true};

            overrides.Add(Object.GetType(), "Id", attributes: attrs);

            XmlSerializer xs = new XmlSerializer(Object.GetType(), overrides);

            xs.Serialize(tw, Object);
        }
Exemple #30
0
        private void InitializeSerializer()
        {
            XmlAttributes attrs = new XmlAttributes();
            XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();
            attrOverrides.Add(typeof(string), "File", attrs);
            attrOverrides.Add(typeof(List<string>), "Columns", attrs);
            attrOverrides.Add(typeof(List<List<string>>), "Rows", attrs);

            m_compositionXmlSerializer = new XmlSerializer(typeof(List<List<string>>), attrOverrides);

            m_mapSerializer = new TmxMapSerializer.Serializer.TmxMapSerializer();
        }
		public XmlReflectionImporter (XmlAttributeOverrides attributeOverrides, string defaultNamespace)
		{
			if (defaultNamespace == null)
				this.initialDefaultNamespace = String.Empty;
			else
				this.initialDefaultNamespace = defaultNamespace;

			if (attributeOverrides == null)
				this.attributeOverrides = new XmlAttributeOverrides();
			else
				this.attributeOverrides = attributeOverrides;
		}
        public static string BuildXml <T>(this T BusinessObject) where T : class
        {
            MemoryStream Stream = null;
            TextWriter   Writer = null;

            try
            {
                System.Xml.Serialization.XmlAttributeOverrides xOver = new System.Xml.Serialization.XmlAttributeOverrides();
                System.Xml.Serialization.XmlAttributes         attrs = new System.Xml.Serialization.XmlAttributes();

                foreach (var Ig in typeof(T).GetProperties().Where(c =>
                                                                   !c.PropertyType.IsSerializable ||
                                                                   c.PropertyType.FullName.StartsWith("DynamicBusiness.BPMS.BusinessLogic")).Select(c => c.Name))
                {
                    attrs           = new System.Xml.Serialization.XmlAttributes();
                    attrs.XmlIgnore = true;
                    xOver.Add(typeof(T), Ig, attrs);
                }

                Stream = new MemoryStream();
                Writer = new StreamWriter(Stream, Encoding.Unicode);

                XmlSerializer Serializer = new XmlSerializer(typeof(T), xOver);
                Serializer.Serialize(Writer, BusinessObject);

                int    Count    = (int)Stream.Length;
                byte[] BytesArr = new byte[Count];

                Stream.Seek(0, SeekOrigin.Begin);
                Stream.Read(BytesArr, 0, Count);

                UnicodeEncoding utf = new UnicodeEncoding();
                return(System.Web.HttpUtility.HtmlDecode(utf.GetString(BytesArr).Trim()));

                //return utf.GetString(BytesArr).Trim();
            }
            catch (Exception exc)
            {
                DotNetNuke.Services.Exceptions.Exceptions.LogException(exc);
                return(string.Empty);
            }
            finally
            {
                if (Stream != null)
                {
                    Stream.Close();
                }
                if (Writer != null)
                {
                    Writer.Close();
                }
            }
        }
 public XmlSerializer(System.Type type, System.Xml.Serialization.XmlAttributeOverrides overrides, System.Type[] extraTypes, System.Xml.Serialization.XmlRootAttribute root, string defaultNamespace)
 {
 }
 public XmlSerializer(System.Type type, System.Xml.Serialization.XmlAttributeOverrides overrides)
 {
 }
Exemple #35
0
        public XmlSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace, string location)
#pragma warning disable 618 // Passing through null evidence to keep the .ctor code centralized
            : this(type, overrides, extraTypes, root, defaultNamespace, location, null)
        {
#pragma warning restore 618
        }
 public XmlSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace, string location, Evidence evidence)
 {
 }
Exemple #37
0
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 internal XmlSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace, object location, object evidence)
 {
     Init(type, overrides, extraTypes, root, defaultNamespace, location, evidence);
 }
Exemple #39
0
 /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.XmlSerializer4"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public XmlSerializer(Type type, XmlAttributeOverrides overrides) : this(type, overrides, Array.Empty <Type>(), null, null, null)
 {
 }
 /// <include file='doc\XmlSerializerFactory.uex' path='docs/doc[@for="XmlSerializerFactory.CreateSerializer"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public XmlSerializer CreateSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace)
 {
     return(CreateSerializer(type, overrides, extraTypes, root, defaultNamespace, null));
 }
 /// <include file='doc\XmlSerializerFactory.uex' path='docs/doc[@for="XmlSerializerFactory.CreateSerializer4"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public XmlSerializer CreateSerializer(Type type, XmlAttributeOverrides overrides)
 {
     return(CreateSerializer(type, overrides, new Type[0], null, null, null));
 }
Exemple #42
0
 /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.XmlSerializer"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public XmlSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace) :
     this(type, overrides, extraTypes, root, defaultNamespace, null)
 {
 }
Exemple #43
0
 public XmlSerializer(Type type, XmlAttributeOverrides overrides)
     : this(type, overrides, null, null, null)
 {
 }
 public ChoNullNSXmlSerializer(Type type, XmlAttributeOverrides overrides)
     : base(type, overrides)
 {
 }
 public ChoNullNSXmlSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace)
     : base(type, overrides, extraTypes, root, defaultNamespace)
 {
 }