public XmlNode Serialize(object value)
        {
            XmlSerializer ser = new XmlSerializer(value.GetType());

            // Serialize object to xml
            StringWriter sw = new StringWriter( System.Globalization.CultureInfo.CurrentUICulture );
            XmlTextWriter writer = new XmlTextWriter( sw );
            ser.Serialize( writer, value );
            writer.Flush();

            // Return as a XmlNode
            XmlDocument doc = new XmlDocument();
            doc.LoadXml( writer.ToString() );
            return doc.DocumentElement;
        }
Ejemplo n.º 2
0
        public static string GenerateEntityXml(string outputPath, EntityInfo entity)
        {
            string ret = String.Empty;

            if (entity == null || !Directory.Exists(outputPath))
            {
                return(ret);
            }

            Log4Helper.Write("GenerateEntityXml", String.Format("Process of entity {0} starts at {1}.", entity.ClassName, System.DateTime.Now.ToString("s")), LogSeverity.Info);

            using (System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(System.IO.Path.Combine(outputPath, String.Concat(entity.ClassName, ".xml")), System.Text.Encoding.UTF8))
            {
                xtw.Formatting = System.Xml.Formatting.Indented;
                xtw.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");

                //generate entity calss
                xtw.WriteStartElement("entity");
                xtw.WriteAttributeString("namespace", entity.NameSpace);
                xtw.WriteAttributeString("name", entity.ClassName);

                #region columns/properties
                //generate property node
                xtw.WriteStartElement("fields");
                foreach (FieldInfo field in entity.Fileds)
                {
                    xtw.WriteStartElement("property");
                    xtw.WriteAttributeString("type", field.Type);
                    xtw.WriteAttributeString("name", field.Name);
                    xtw.WriteAttributeString("privateFieldName", field.PrivateFieldName);
                    xtw.WriteAttributeString("paramName", field.ParamName);
                    xtw.WriteAttributeString("propetyName", field.PropertyName);
                    xtw.WriteAttributeString("csharpType", field.CSharpType);
                    xtw.WriteEndElement();
                }
                xtw.WriteEndElement();
                #endregion
                ret = xtw.ToString();
                xtw.WriteEndElement();
                xtw.Flush();
                xtw.Close();
            }

            Log4Helper.Write("GenerateEntityXmlFromTable", String.Format("Process of table {0} ends at {1}.", entity.ClassName, System.DateTime.Now.ToString("s")), LogSeverity.Info);
            return(ret);
        }
Ejemplo n.º 3
0
		/// <summary>
		/// Takes the contents of an <see cref="IUPnPMedia"/> object
		/// casts the data into its XML string form and returns it.
		/// </summary>
		/// <param name="entry">the object to extract</param>
		/// <returns>everything under the item or container element</returns>
		private string GrabInnerText(IUPnPMedia entry)
		{
			StringBuilder sb = new StringBuilder(1000);
			StringWriter sw = new StringWriter(sb);
			XmlTextWriter xmlWriter = new XmlTextWriter(sw);

			// set up the ToXml() method to only provide the InnerText of the element
			entry.ToXml(ToXmlFormatter.DefaultFormatter, MediaObject.ToXmlData_AllInnerTextOnly, xmlWriter);
			xmlWriter.Flush();

			string result = xmlWriter.ToString();
			xmlWriter.Close();

			return result;
		}
Ejemplo n.º 4
0
        public static string GenerateEntityXml(string outputPath, EntityInfo entity)
        {
            string ret = String.Empty;

            if (entity == null || !Directory.Exists(outputPath))
                return ret;

            Log4Helper.Write("GenerateEntityXml", String.Format("Process of entity {0} starts at {1}.", entity.ClassName, System.DateTime.Now.ToString("s")), LogSeverity.Info);

            using (System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(System.IO.Path.Combine(outputPath, String.Concat(entity.ClassName, ".xml")), System.Text.Encoding.UTF8))
            {
                xtw.Formatting = System.Xml.Formatting.Indented;
                xtw.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");

                //generate entity calss
                xtw.WriteStartElement("entity");
                xtw.WriteAttributeString("namespace", entity.NameSpace);
                xtw.WriteAttributeString("name", entity.ClassName);

                #region columns/properties
                //generate property node
                xtw.WriteStartElement("fields");
                foreach (FieldInfo field in entity.Fileds)
                {
                    xtw.WriteStartElement("property");
                    xtw.WriteAttributeString("type", field.Type);
                    xtw.WriteAttributeString("name", field.Name);
                    xtw.WriteAttributeString("privateFieldName", field.PrivateFieldName);
                    xtw.WriteAttributeString("paramName", field.ParamName);
                    xtw.WriteAttributeString("propetyName", field.PropertyName);
                    xtw.WriteAttributeString("csharpType", field.CSharpType);
                    xtw.WriteEndElement();
                }
                xtw.WriteEndElement();
                #endregion
                ret = xtw.ToString();
                xtw.WriteEndElement();
                xtw.Flush();
                xtw.Close();
            }

            Log4Helper.Write("GenerateEntityXmlFromTable", String.Format("Process of table {0} ends at {1}.", entity.ClassName, System.DateTime.Now.ToString("s")), LogSeverity.Info);
            return ret;
        }
Ejemplo n.º 5
0
	public virtual String Render() {
	    try {
		StringWriter sw = new StringWriter();
		XmlTextWriter tw = new XmlTextWriter(sw);
		element.WriteContentTo(tw);
		return tw.ToString();
	    } catch (System.Exception e) {}

	    return "";
	}
Ejemplo n.º 6
0
        private void SaveQueryXML(string directory, string fileName)
        {
            XmlDocument xd = new XmlDocument();
            TextWriter tw = new StringWriter();

            //userQuery.Serialize();

            if (operatorListGraphic.Count != 0)
            {
                //MessageBox.Show(operatorListGraphic.Count.ToString());
                for (int i = 0; i < operatorListGraphic.Count; i++)
                {
                    switch (operatorListGraphic[i].Type.ToString())
                    {
                        case "Select":
                            MessageBox.Show("Select");
                            Query s = new OpGenerate(100);
                            Query q = new OpSelect("$1.1 > 4", s);

                            q.SerializeOp(tw);
                            XmlTextWriter xw = new XmlTextWriter(tw);
                            MessageBox.Show(tw.ToString());
                            MessageBox.Show(xw.ToString());
                            break;
                        case "Project":
                            MessageBox.Show("Project");
                            break;
                        case "Union":
                            MessageBox.Show("Union");
                            break;
                        case "Intersection":
                            MessageBox.Show("Intersection");
                            break;
                        case "Join":
                            MessageBox.Show("Join");
                            break;
                        case "Difference":
                            MessageBox.Show("Difference");
                            break;
                        case "Generate":
                            MessageBox.Show("Generate");
                            break;
                        case "Sort":
                            MessageBox.Show("Sort");
                            break;
                        case "GroupBy":
                            MessageBox.Show("Group-by");
                            break;
                        case "DupElim":
                            MessageBox.Show("Duplicate Elimination");
                            break;
                        case "InputStream":
                            MessageBox.Show("Input Stream");
                            break;
                        case "OutputStream":
                            MessageBox.Show("Output Stream");
                            break;
                        default:
                            break;
                    };
                }
            }
            else
            {
                //Write empty XML file.
                MessageBox.Show("No Operators in Build Area!");
            }
        }
Ejemplo n.º 7
-1
        public void Serialization()
        {
            try {
                XmlDiff diff = new XmlDiff();
                TemplateBox templateBox = new TemplateBox(TemplatingResources.TemplatesDefault);
                String result = templateBox.Serialize();
                //Utils.WriteToFile(@"C:\temp\templates.xml", result);

                diff.IgnoreChildOrder = true;
                diff.IgnoreComments = true;
                diff.IgnoreDtd = true;
                diff.IgnoreNamespaces = true;
                diff.IgnorePI = true;
                diff.IgnorePrefixes = true;
                diff.IgnoreWhitespace = true;
                diff.IgnoreXmlDecl = true;

                StringWriter diffgramString = new StringWriter();
                XmlTextWriter diffgramXml = new XmlTextWriter(diffgramString);
                bool diffBool = diff.Compare(new XmlTextReader(new StringReader(result)), new XmlTextReader(new StringReader(TemplatingResources.TemplatesDefault)), diffgramXml);
                //MessageBox.Show(diffgramString.ToString());
                Assert.True(diffBool, diffgramXml.ToString());

            } catch (Exception e) {
                Assert.Fail("Exception: " + e.GetType().Name + "\n" + e.Message + "\n" + e.StackTrace);
            }
        }