Ejemplo n.º 1
0
        public static string WriteXml(this DataSet dataSet, XmlWriteMode writeMode)
        {
            string xmlSerializedDataSet;

            dataSet.WriteXml(writeMode, out xmlSerializedDataSet);
            return(xmlSerializedDataSet);
        }
Ejemplo n.º 2
0
 public static void WriteCompressedXml(this DataSet dataset, Stream stream, XmlWriteMode mode)
 {
     using (GZipStream compressStream = new GZipStream(stream, CompressionMode.Compress))
     {
         dataSet.WriteXml(compressStream, mode);
     }
 }
Ejemplo n.º 3
0
        public void CacheDataSet(DataSet ds, string name, XmlWriteMode mode)
        {
            string path = GetHashFilename(name);

            // ds.WriteXml(path, mode);
            EncryptDSAes(path, ds, mode);
        }
Ejemplo n.º 4
0
        public static void WriteXml(this DataSet dataSet, XmlWriteMode writeMode, out string xmlSerializedDataSet)
        {
            var sw = new StringWriter();

            dataSet.WriteXml(sw, writeMode);
            xmlSerializedDataSet = sw.ToString();
        }
 internal static void WriteTableList(XmlWriter writer, XmlWriteMode mode, List <DataTable> tables, DataRowVersion version)
 {
     foreach (DataTable table in tables)
     {
         DataSet.WriteTable(writer, table, mode, version);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 테이블을 XML 문자열로 변경해서 리턴함.
        /// </summary>
        /// <param name="ds"></param>
        /// <param name="WriteMode">XmlWriteMode.IgnoreSchema를 쓰면 스키마 없는 간단한 XML 형식을 리턴함.</param>
        /// <returns></returns>
        public static string WriteXmlString(DataSet ds, XmlWriteMode WriteMode)
        {
            StringWriter sw = new StringWriter();

            ds.WriteXml(sw, WriteMode);
            return(sw.ToString());
        }
Ejemplo n.º 7
0
        public void EncryptDSAes(string path, DataSet ds, XmlWriteMode mode)
        {
            System.Security.Cryptography.MD5 md5Hash = System.Security.Cryptography.MD5.Create();

            // Convert the input string to a byte array and compute the hash.
            byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(path));

            // Create an AesManaged object
            // with the specified key and IV.
            using (AesManaged aesAlg = new AesManaged())
            {
                aesAlg.Key = data;
                aesAlg.IV  = data;

                // Create a decrytor to perform the stream transform.
                ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);

                // Create the streams used for encryption.
                using (System.IO.FileStream msEncrypt = new System.IO.FileStream(path, System.IO.FileMode.Create))
                {
                    using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                    {
                        ds.WriteXml(csEncrypt, mode);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        virtual public string ToXml(XmlWriteMode mode)
        {
            DataSet dataSet = new DataSet();

            dataSet.Tables.Add(_dataTable);
            StringWriter writer = new StringWriter();

            dataSet.WriteXml(writer, mode);
            dataSet.Tables.Clear();
            return(writer.ToString());
        }
Ejemplo n.º 9
0
 /// <summary> Writes the current data to the specified file as remarked XML </summary>
 /// <param name="fileName"> The file name (including the path) to which to write </param>
 /// <param name="writeMode"> One of the System.XmlWriteMode values.  Use WriteSchema to write the schema </param>
 /// <example> For a complete example, see the example under the main <see cref="RemarkedDataSet"/> class. </example>
 public void WriteRemarkedXml(string fileName, XmlWriteMode writeMode)
 {
     // See if schema should be included
     if (writeMode.Equals(XmlWriteMode.WriteSchema))
     {
         WriteRemarkedXml(fileName, true);
     }
     else
     {
         WriteRemarkedXml(fileName, false);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// DataTable 내용을 Xml Text로 변경한다.
        /// </summary>
        /// <param name="table">Instance of DataTable</param>
        /// <param name="writeMode">Xml Text 생성 모드</param>
        /// <returns>생성된 Xml 문자열</returns>
        public static string ToXmlText(DataTable table, XmlWriteMode writeMode = XmlWriteMode.WriteSchema) {
            table.ShouldNotBeNull("table");

            if(IsDebugEnabled)
                log.Debug("Convert DataTable to Xml Text. table=[{0}], writeMode=[{1}]", table.TableName, writeMode);

            var sb = new StringBuilder();

            using(var writer = new StringWriter(sb))
                table.WriteXml(writer, writeMode);

            return sb.ToString();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 把DataSet打成XML字符串
        /// </summary>
        /// <param name="ds">要处理的DataSet</param>
        /// <param name="mode">指定如何从 System.Data.DataSet 写入 XML 数据和关系架构</param>
        /// <returns></returns>
        public static string DataSetToXML(DataSet ds, XmlWriteMode mode)
        {
            string ret = null;

            using (MemoryStream stm = new MemoryStream())
            {
                XmlTextWriter writer = new XmlTextWriter(stm, System.Text.Encoding.UTF8);
                ds.WriteXml(writer, mode);
                byte[] buffer = stm.ToArray();
                ret = System.Text.Encoding.UTF8.GetString(buffer);
            }
            return(ret);
        }
Ejemplo n.º 12
0
        public void escribir(string Peticion, string Status)
        {
            XmlWriteMode xml = new XmlWriteMode();
            //Creamos el nodo que deseamos insertar.
            XmlNode empleado = crearNodoXml(DateTime.Now.ToString(), Peticion, Status);

            //Obtenemos el nodo raiz del documento.
            XmlNode nodoRaiz = documento.DocumentElement;

            //Insertamos el nodo empleado al final del archivo
            nodoRaiz.InsertAfter(empleado, nodoRaiz.LastChild);

            documento.Save("C:\\logBusqueda.xml");
        }
Ejemplo n.º 13
0
        public void escribir(string Peticion, string Status)
        {
            XmlWriteMode xml = new XmlWriteMode();
            //Creamos el nodo que deseamos insertar.
            XmlNode empleado = crearNodoXml(DateTime.Now.ToString(),Peticion,Status);

            //Obtenemos el nodo raiz del documento.
            XmlNode nodoRaiz = documento.DocumentElement;

            //Insertamos el nodo empleado al final del archivo
            nodoRaiz.InsertAfter(empleado, nodoRaiz.LastChild);   

            documento.Save("C:\\logBusqueda.xml");
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Writes the Data from DataSet into a XML File
        /// </summary>
        /// <param name="dataSet">DataSet</param>
        /// <param name="FileName">File Path</param>
        /// <param name="XmlWriteMode">Write Mode</param>
        /// <returns></returns>
        public static bool WriteDataSetToXML(DataSet dataSet, StreamWriter FileName, XmlWriteMode XmlWriteMode)
        {
            bool isReturn = false;

            try
            {
                dataSet.WriteXml(FileName, XmlWriteMode);
                isReturn = true;
            }
            catch (Exception e)
            {
                isReturn = false;
            }
            return(isReturn);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// DataTable 내용을 Xml Text로 변경한다.
        /// </summary>
        /// <param name="table">Instance of DataTable</param>
        /// <param name="writeMode">Xml Text 생성 모드</param>
        /// <returns>생성된 Xml 문자열</returns>
        public static string ToXmlText(DataTable table, XmlWriteMode writeMode = XmlWriteMode.WriteSchema)
        {
            table.ShouldNotBeNull("table");

            if (IsDebugEnabled)
            {
                log.Debug("Convert DataTable to Xml Text. table=[{0}], writeMode=[{1}]", table.TableName, writeMode);
            }

            var sb = new StringBuilder();

            using (var writer = new StringWriter(sb))
                table.WriteXml(writer, writeMode);

            return(sb.ToString());
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 找回缓存参数集合
        /// </summary>
        /// <param name="cacheKey">用于找回参数的关键字</param>
        /// <returns>缓存的参数集合</returns>
        public static SqlParameter[] GetCachedParameters(string cacheKey)
        {
            string cachedParms = cacheKey;

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

            SqlParameter[] clonedParms = new SqlParameter[cachedParms.Length];

            for (int i = 0, j = cachedParms.Length; i < j; i++)
            {
                XmlWriteMode xm = new XmlWriteMode();
            }

            return(clonedParms);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 获取存取在DataSet的数据的xml表现形式
        /// </summary>
        /// <param name="dataSet">数据源DataSet</param>
        /// <param name="mappingType">映射DataColumn的方式</param>
        /// <param name="xmlWriteMode">指定如何从DataSet写入xml数据和关系架构</param>
        /// <returns>DataSet中的数据的xml表现形式</returns>
        public static string GetXml(this DataSet dataSet, MappingType mappingType, XmlWriteMode xmlWriteMode)
        {
            FrameDataSetExtends.SetDataSetColumnElementToAttribute(dataSet, mappingType);
            MemoryStream ms  = new MemoryStream();
            XmlDocument  dom = new XmlDocument();

            try
            {
                dataSet.WriteXml(ms, xmlWriteMode);
                ms.Flush();
                ms.Seek(0, SeekOrigin.Begin);
                dom.Load(ms);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                ms.Close();
            }

            return(dom.InnerXml);
        }
Ejemplo n.º 18
0
 public XmlExport(string ExportDir, XmlWriteMode writemode = XmlWriteMode.WriteSchema)
 {
     WriteMode       = writemode;
     ExportDirectory = ExportDir;
 }
Ejemplo n.º 19
0
		internal static void WriteStartElement (XmlWriter writer, XmlWriteMode mode, string nspc, string prefix, string name)
		{
			writer.WriteStartElement (prefix, name, nspc);
		}
Ejemplo n.º 20
0
 /// <summary>
 ///     Writes the current data, and optionally the schema, for the <see cref="T:System.Data.DataTable"/> using the specified 
 ///     <see cref="T:System.Xml.XmlWriter"/> and <see cref="T:System.Data.XmlWriteMode"/>. To write the schema, set the value for the 
 ///     <paramref name="mode"/> parameter to WriteSchema.
 /// </summary>
 /// <param name="writer">
 ///     The <see cref="T:System.Xml.XmlWriter"/> used to write the document.
 /// </param>
 /// <param name="mode">
 ///     One of the <see cref="T:System.Data.XmlWriteMode"/> values.
 /// </param>
 public void WriteXml(XmlWriter writer,
                      XmlWriteMode mode)
 {
     this.DataTableInstance.WriteXml(writer, mode);
 }
Ejemplo n.º 21
0
 /// <summary>
 ///     Writes the current data, and optionally the schema, for the <see cref="T:System.Data.DataTable"/> using the specified file and 
 ///     <see cref="T:System.Data.XmlWriteMode"/>. To write the schema, set the value for the <paramref name="mode"/> parameter to WriteSchema.
 /// </summary>
 /// <param name="fileName">
 ///     The name of the file to which the data will be written.
 /// </param>
 /// <param name="mode">
 ///     One of the <see cref="T:System.Data.XmlWriteMode"/> values.
 /// </param>
 public void WriteXml(string fileName,
                      XmlWriteMode mode)
 {
     this.DataTableInstance.WriteXml(fileName, mode);
 }
Ejemplo n.º 22
0
		public void WriteXml (TextWriter writer, XmlWriteMode mode)
		{
			XmlTextWriter xwriter = new XmlTextWriter (writer);
			xwriter.Formatting = Formatting.Indented;
			WriteXml (xwriter, mode);
		}
Ejemplo n.º 23
0
 /// <summary>
 ///     Writes the current data, and optionally the schema, for the <see cref="T:System.Data.DataTable"/> to the specified file using the specified <see cref="T:System.Data.XmlWriteMode"/>. To write the schema, set the value for the <paramref name="mode"/> parameter to WriteSchema.
 /// </summary>
 /// <param name="stream">
 ///     The stream to which the data will be written.
 /// </param>
 /// <param name="mode">
 ///     One of the <see cref="T:System.Data.XmlWriteMode"/> values.
 /// </param>
 public void WriteXml(Stream stream,
                      XmlWriteMode mode)
 {
     this.DataTableInstance.WriteXml(stream, mode);
 }
Ejemplo n.º 24
0
 public void WriteXml(XmlWriter writer, XmlWriteMode mode)
 {
     WriteXml(writer, mode, false);
 }
Ejemplo n.º 25
0
		public void WriteXml (string fileName, XmlWriteMode mode)
		{
			XmlTextWriter writer = new XmlTextWriter (fileName, null);
			writer.Formatting = Formatting.Indented;
			writer.WriteStartDocument (true);

			try {
				WriteXml (writer, mode);
			} finally {
				writer.WriteEndDocument ();
				writer.Close ();
			}
		}
Ejemplo n.º 26
0
 public virtual void WriteXml(XmlWriter writer, XmlWriteMode mode)
 {
     _sourcedataset.WriteXml(writer, mode);
 }
Ejemplo n.º 27
0
        public void WriteXml(Stream stream, XmlWriteMode mode, bool writeHierarchy)
        {
            if (stream != null) {
                XmlTextWriter w =  new XmlTextWriter(stream, null) ;
                w.Formatting = Formatting.Indented;

                WriteXml( w, mode, writeHierarchy);
            }
        }
Ejemplo n.º 28
0
 /// <summary>
 /// 获取存取在DataSet的数据的xml表现形式,并将列映射为xml中的属性
 /// </summary>
 /// <param name="dataSet">>数据源DataSet</param>
 /// <param name="xmlWriteMode">指定如何从DataSet写入XML数据和关系架构</param>
 /// <returns>DataSet中的数据的xml表现形式</returns>
 public static string GetXmlColumnToAtribute(this DataSet dataSet, XmlWriteMode xmlWriteMode)
 {
     return(GetXml(dataSet, MappingType.Attribute, xmlWriteMode));
 }
Ejemplo n.º 29
0
 public virtual void WriteXml(string fileName, XmlWriteMode mode)
 {
     _sourcedataset.WriteXml(fileName, mode);
 }
    // This method is modelled after the DataSet's WriteXml functionality.
    internal static void WriteTables(XmlWriter writer,
                                     XmlWriteMode mode,
                                     List <DataTable> tables,
                                     List <DataRelation> relations,
                                     string mainDataTable,
                                     string dataSetName)
    {
        if (mode == XmlWriteMode.DiffGram)
        {
            foreach (DataTable table in tables)
            {
                table.SetRowsID();
            }
            DataSet.WriteDiffGramElement(writer);
        }

        bool shouldOutputContent = (mode != XmlWriteMode.DiffGram);

        for (int n = 0; n < tables.Count && !shouldOutputContent; n++)
        {
            shouldOutputContent = tables[n].Rows.Count > 0;
        }

        if (shouldOutputContent)
        {
            // We assume that tables[0] is the main table being written.
            // We happen to know that the code above us does things that way.
            DataSet.WriteStartElement(writer, mode, tables[0].Namespace, tables[0].Prefix, XmlHelper.Encode(dataSetName));

            if (mode == XmlWriteMode.WriteSchema)
            {
                DataTable [] _tables = new DataTable[tables.Count];
                tables.CopyTo(_tables);
                DataRelation[] _relations = new DataRelation[relations.Count];
                relations.CopyTo(_relations);
                DataTable dt = _tables [0];
                new XmlSchemaWriter(writer,
                                    _tables,
                                    _relations,
                                    mainDataTable,
                                    dataSetName,
                                    dt.LocaleSpecified ? dt.Locale : null
                                    ).WriteSchema();
            }

            WriteTableList(writer, mode, tables, DataRowVersion.Default);

            writer.WriteEndElement();
        }

        if (mode == XmlWriteMode.DiffGram)
        {
            List <DataTable> changedTables = new List <DataTable>();
            foreach (DataTable table in tables)
            {
                DataTable changed = table.GetChanges(DataRowState.Modified | DataRowState.Deleted);
                if (changed != null && changed.Rows.Count > 0)
                {
                    changedTables.Add(changed);
                }
            }
            if (changedTables.Count > 0)
            {
                DataSet.WriteStartElement(writer, XmlWriteMode.DiffGram, XmlConstants.DiffgrNamespace, XmlConstants.DiffgrPrefix, "before");
                WriteTableList(writer, mode, changedTables, DataRowVersion.Original);
                writer.WriteEndElement();
            }

            writer.WriteEndElement(); // diffgr:diffgram
        }

        writer.Flush();
    }
Ejemplo n.º 31
0
		internal static void WriteAttributeString (XmlWriter writer, XmlWriteMode mode, string nspc, string prefix, string name, string stringValue)
		{
			switch ( mode) {
			//	case XmlWriteMode.WriteSchema:
			//		writer.WriteAttributeString (prefix, name, nspc);
			//		break;
				case XmlWriteMode.DiffGram:
					writer.WriteAttributeString (prefix, name, nspc,stringValue);
					break;
				default:
					writer.WriteAttributeString (name, stringValue);
					break;
			};
		}
Ejemplo n.º 32
0
 public void WriteXml(String fileName, XmlWriteMode mode)
 {
     WriteXml(fileName, mode, false);
 }
Ejemplo n.º 33
0
		internal void WriteIndividualTableContent (XmlWriter writer, DataTable table, XmlWriteMode mode)
		{
			if (mode == XmlWriteMode.DiffGram) {
				table.SetRowsID ();
				WriteDiffGramElement (writer);
			}

			WriteStartElement (writer, mode, Namespace, Prefix, XmlHelper.Encode (DataSetName));

			WriteTable (writer, table, mode, DataRowVersion.Default);

			if (mode == XmlWriteMode.DiffGram) {
				writer.WriteEndElement (); //DataSet name
				if (HasChanges (DataRowState.Modified | DataRowState.Deleted)) {

					DataSet beforeDS = GetChanges (DataRowState.Modified | DataRowState.Deleted);
					WriteStartElement (writer, XmlWriteMode.DiffGram, XmlConstants.DiffgrNamespace, XmlConstants.DiffgrPrefix, "before");
					WriteTable (writer, beforeDS.Tables [table.TableName], mode, DataRowVersion.Original);
					writer.WriteEndElement ();
				}
			}
			writer.WriteEndElement (); // DataSet name or diffgr:diffgram
		}
Ejemplo n.º 34
0
 public virtual void WriteXml(Stream stream, XmlWriteMode mode)
 {
     _sourcedataset.WriteXml(stream, mode);
 }
Ejemplo n.º 35
0
		public void WriteXml (Stream stream, XmlWriteMode mode)
		{
			XmlTextWriter writer = new XmlTextWriter (stream, null);
			writer.Formatting = Formatting.Indented;
			WriteXml (writer, mode);
		}
Ejemplo n.º 36
0
		internal static void WriteTable (XmlWriter writer,
			DataRow [] rows,
			XmlWriteMode mode,
			DataRowVersion version, bool skipIfNested)
		{
			if (rows.Length == 0) return;
			DataTable table = rows[0].Table;

			if (table.TableName == null || table.TableName == "")
				throw new InvalidOperationException("Cannot serialize the DataTable. DataTable name is not set.");

			//The columns can be attributes, hidden, elements, or simple content
			//There can be 0-1 simple content cols or 0-* elements
			System.Collections.ArrayList atts;
			System.Collections.ArrayList elements;
			DataColumn simple = null;

			SplitColumns (table, out atts, out elements, out simple);
			//sort out the namespacing

			foreach (DataRow row in rows) {
				if (skipIfNested) {
					// Skip rows that is a child of any tables.
					bool skip = false;
					for (int i = 0; i < table.ParentRelations.Count; i++) {
						DataRelation prel = table.ParentRelations [i];
						if (!prel.Nested)
							continue;
						if (row.GetParentRow (prel) != null) {
							skip = true;
							continue;
						}
					}
					if (skip)
						continue;
				}

				if (!row.HasVersion(version) ||
				   (mode == XmlWriteMode.DiffGram && row.RowState == DataRowState.Unchanged
				      && version == DataRowVersion.Original))
					continue;

				// First check are all the rows null. If they are we just write empty element
				bool AllNulls = true;
				foreach (DataColumn dc in table.Columns) {
					if (row [dc.ColumnName, version] != DBNull.Value) {
						AllNulls = false;
						break;
					}
				}

				// If all of the columns were null, we have to write empty element
				if (AllNulls) {
					writer.WriteElementString (XmlHelper.Encode (table.TableName), "");
					continue;
				}

				WriteTableElement (writer, mode, table, row, version);

				foreach (DataColumn col in atts)
					WriteColumnAsAttribute (writer, mode, col, row, version);

				if (simple != null) {
					writer.WriteString (WriteObjectXml (row[simple, version]));
				} else {
					foreach (DataColumn col in elements)
						WriteColumnAsElement (writer, mode, col, row, version);
				}

				foreach (DataRelation relation in table.ChildRelations) {
					if (relation.Nested)
						WriteTable (writer, row.GetChildRows (relation), mode, version, false);
				}

				writer.WriteEndElement ();
			}

		}
Ejemplo n.º 37
0
		public void WriteXml (XmlWriter writer, XmlWriteMode mode)
		{
			if (mode == XmlWriteMode.DiffGram) {
				SetRowsID();
				WriteDiffGramElement(writer);
			}

			// It should not write when there is no content to be written
			bool shouldOutputContent = (mode != XmlWriteMode.DiffGram);
			for (int n = 0; n < tableCollection.Count && !shouldOutputContent; n++)
				shouldOutputContent = tableCollection [n].Rows.Count > 0;

			if (shouldOutputContent) {
				WriteStartElement (writer, mode, Namespace, Prefix, XmlHelper.Encode (DataSetName));

				if (mode == XmlWriteMode.WriteSchema)
					DoWriteXmlSchema (writer);

				WriteTables (writer, mode, Tables, DataRowVersion.Default);
				writer.WriteEndElement ();
			}

			if (mode == XmlWriteMode.DiffGram) {
				if (HasChanges(DataRowState.Modified | DataRowState.Deleted)) {
					DataSet beforeDS = GetChanges (DataRowState.Modified | DataRowState.Deleted);
					WriteStartElement (writer, XmlWriteMode.DiffGram, XmlConstants.DiffgrNamespace, XmlConstants.DiffgrPrefix, "before");
					WriteTables (writer, mode, beforeDS.Tables, DataRowVersion.Original);
					writer.WriteEndElement ();
				}
			}

			if (mode == XmlWriteMode.DiffGram)
				writer.WriteEndElement (); // diffgr:diffgram

			writer.Flush ();
		}
Ejemplo n.º 38
0
		internal static void WriteColumnAsElement (XmlWriter writer, XmlWriteMode mode, DataColumn col, DataRow row, DataRowVersion version)
		{
			string colnspc = null;
			object rowObject = row [col, version];

			if (rowObject == null || rowObject == DBNull.Value)
				return;

			if (col.Namespace != String.Empty)
				colnspc = col.Namespace;

			//TODO check if I can get away with write element string
			WriteStartElement (writer, mode, colnspc, col.Prefix, XmlHelper.Encode (col.ColumnName));	
			if (typeof (IXmlSerializable).IsAssignableFrom (col.DataType) 
			    || col.DataType == typeof (object)) {
				IXmlSerializable serializableObj = rowObject as IXmlSerializable;
				if (serializableObj == null)
					throw new InvalidOperationException ();
				((IXmlSerializable)rowObject).WriteXml (writer);				
			} else {
				writer.WriteString (WriteObjectXml (rowObject));
			}

			writer.WriteEndElement ();
		}
Ejemplo n.º 39
0
 /// <summary>
 ///     Writes the current data, and optionally the schema, for the <see cref="T:System.Data.DataTable"/> to the specified file using the specified <see cref="T:System.Data.XmlWriteMode"/>. To write the schema, set the value for the <paramref name="mode"/> parameter to WriteSchema. To save the data for the table and all its descendants, set the <paramref name="writeHierarchy"/> parameter to true.
 /// </summary>
 /// <param name="stream">
 ///     The stream to which the data will be written.
 /// </param>
 /// <param name="mode">
 ///     One of the <see cref="T:System.Data.XmlWriteMode"/> values. 
 /// </param>
 /// <param name="writeHierarchy">
 ///     If true, write the contents of the current table and all its descendants. If false (the default value), write the data for the current table only.
 /// </param>
 public void WriteXml(Stream stream,
                      XmlWriteMode mode,
                      bool writeHierarchy)
 {
     this.DataTableInstance.WriteXml(stream, mode, writeHierarchy);
 }
Ejemplo n.º 40
0
		internal static void WriteColumnAsAttribute (XmlWriter writer, XmlWriteMode mode, DataColumn col, DataRow row, DataRowVersion version)
		{
			if (!row.IsNull (col))
				WriteAttributeString (writer, mode, col.Namespace, col.Prefix, XmlHelper.Encode (col.ColumnName), WriteObjectXml (row[col, version]));
		}
Ejemplo n.º 41
0
 /// <summary>
 ///     Writes the current data, and optionally the schema, for the <see cref="T:System.Data.DataTable"/> using the specified 
 ///     <see cref="T:System.Xml.XmlWriter"/> and <see cref="T:System.Data.XmlWriteMode"/>. To write the schema, set the value for the 
 ///     <paramref name="mode"/> parameter to WriteSchema. To save the data for the table and all its descendants, set the 
 ///     <paramref name="writeHierarchy"/> parameter to true.
 /// </summary>
 /// <param name="writer">
 ///     The <see cref="T:System.Xml.XmlWriter"/> used to write the document.
 /// </param>
 /// <param name="mode">
 ///     One of the <see cref="T:System.Data.XmlWriteMode"/> values.
 /// </param>
 /// <param name="writeHierarchy">
 ///     If true, write the contents of the current table and all its descendants. If false (the default value), write the data for the current table only.
 /// </param>
 public void WriteXml(XmlWriter writer,
                      XmlWriteMode mode,
                      bool writeHierarchy)
 {
     this.DataTableInstance.WriteXml(writer, mode, writeHierarchy);
 }
Ejemplo n.º 42
0
		internal static void WriteTableElement (XmlWriter writer, XmlWriteMode mode, DataTable table, DataRow row, DataRowVersion version)
		{
			//sort out the namespacing
			string nspc = (table.Namespace.Length > 0 || table.DataSet == null) ? table.Namespace : table.DataSet.Namespace;

			WriteStartElement (writer, mode, nspc, table.Prefix, XmlHelper.Encode (table.TableName));

			if (mode == XmlWriteMode.DiffGram) {
				WriteAttributeString (writer, mode, XmlConstants.DiffgrNamespace, XmlConstants.DiffgrPrefix, "id", table.TableName + (row.XmlRowID + 1));
				WriteAttributeString (writer, mode, XmlConstants.MsdataNamespace, XmlConstants.MsdataPrefix, "rowOrder", XmlConvert.ToString (row.XmlRowID));
				string modeName = null;
				if (row.RowState == DataRowState.Modified)
					modeName = "modified";
				else if (row.RowState == DataRowState.Added)
					modeName = "inserted";

				if (version != DataRowVersion.Original && modeName != null)
					WriteAttributeString (writer, mode, XmlConstants.DiffgrNamespace, XmlConstants.DiffgrPrefix, "hasChanges", modeName);
			}
		}
Ejemplo n.º 43
0
 /// <summary>
 ///     Writes the current data, and optionally the schema, for the <see cref="T:System.Data.DataTable"/> using the specified file and 
 ///     <see cref="T:System.Data.XmlWriteMode"/>. To write the schema, set the value for the <paramref name="mode"/> parameter to WriteSchema. 
 ///     To save the data for the table and all its descendants, set the <paramref name="writeHierarchy"/> parameter to true.
 /// </summary>
 /// <param name="fileName">
 ///     The name of the file to which the data will be written.
 /// </param>
 /// <param name="mode">
 ///     One of the <see cref="T:System.Data.XmlWriteMode"/> values.
 /// </param>
 /// <param name="writeHierarchy">
 ///     If true, write the contents of the current table and all its descendants. If false (the default value), write the data for the current table only.
 /// </param>
 public void WriteXml(string fileName,
                      XmlWriteMode mode,
                      bool writeHierarchy)
 {
     this.DataTableInstance.WriteXml(fileName, mode, writeHierarchy);
 }
        private static string WriteXmlWithSchema(Action <TextWriter, XmlWriteMode> writeMethod, XmlWriteMode xmlWriteMode = XmlWriteMode.WriteSchema)
        {
            StringWriter writer = new StringWriter();

            writeMethod(writer, xmlWriteMode);
            return(writer.ToString());
        }
Ejemplo n.º 45
0
 public void WriteXml(Stream stream, XmlWriteMode mode)
 {
     WriteXml(stream, mode, false);
 }
 public void WriteXml(string fileName, XmlWriteMode mode)
 {
     IntPtr ptr;
     Bid.ScopeEnter(out ptr, "<ds.DataSet.WriteXml|API> %d#, fileName='%ls', mode=%d{ds.XmlWriteMode}\n", this.ObjectID, fileName, (int) mode);
     XmlTextWriter xmlw = new XmlTextWriter(fileName, null);
     try
     {
         xmlw.Formatting = Formatting.Indented;
         xmlw.WriteStartDocument(true);
         if (xmlw != null)
         {
             if (mode == XmlWriteMode.DiffGram)
             {
                 new NewDiffgramGen(this).Save(xmlw);
             }
             else
             {
                 new XmlDataTreeWriter(this).Save(xmlw, mode == XmlWriteMode.WriteSchema);
             }
         }
         xmlw.WriteEndDocument();
     }
     finally
     {
         xmlw.Close();
         Bid.ScopeLeave(ref ptr);
     }
 }
Ejemplo n.º 47
0
        public void WriteXml(TextWriter writer, XmlWriteMode mode, bool writeHierarchy)
        {
            if (writer != null) {
                XmlTextWriter w =  new XmlTextWriter(writer) ;
                w.Formatting = Formatting.Indented;

                WriteXml(w, mode, writeHierarchy);
            }
        }
 public void WriteXml(XmlWriter writer, XmlWriteMode mode)
 {
     IntPtr ptr;
     Bid.ScopeEnter(out ptr, "<ds.DataSet.WriteXml|API> %d#, mode=%d{ds.XmlWriteMode}\n", this.ObjectID, (int) mode);
     try
     {
         if (writer != null)
         {
             if (mode == XmlWriteMode.DiffGram)
             {
                 new NewDiffgramGen(this).Save(writer);
             }
             else
             {
                 new XmlDataTreeWriter(this).Save(writer, mode == XmlWriteMode.WriteSchema);
             }
         }
     }
     finally
     {
         Bid.ScopeLeave(ref ptr);
     }
 }
Ejemplo n.º 49
0
        public void WriteXml(XmlWriter writer, XmlWriteMode mode, bool writeHierarchy)
        {
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<ds.DataTable.WriteXml|API> %d#, mode=%d{ds.XmlWriteMode}\n", ObjectID,  (int)mode);
            try{
                if (this.tableName.Length == 0) {
                    throw ExceptionBuilder.CanNotSerializeDataTableWithEmptyName();
                }
                // Generate SchemaTree and write it out
                if (writer != null) {

                    if (mode == XmlWriteMode.DiffGram) { // FIX THIS
                        // Create and save the updates
                        new NewDiffgramGen(this, writeHierarchy).Save(writer, this);
                    }
                    else {
                        // Create and save xml data
                        if (mode == XmlWriteMode.WriteSchema) {
                            DataSet ds = null;
                            string tablenamespace = this.tableNamespace;
                            if (null == this.DataSet) {
                                ds = new DataSet();
                                // if user set values on DataTable, it isn't necessary
                                // to set them on the DataSet because they won't be inherited
                                // but it is simpler to set them in both places

                                // if user did not set values on DataTable, it is required
                                // to set them on the DataSet so the table will inherit
                                // the value already on the Datatable
                                ds.SetLocaleValue(_culture, _cultureUserSet);
                                ds.CaseSensitive = this.CaseSensitive;
                                ds.Namespace = this.Namespace;
                                ds.RemotingFormat = this.RemotingFormat;
                                ds.Tables.Add(this);
                            }

                            if (writer != null) {
                                XmlDataTreeWriter xmldataWriter = new XmlDataTreeWriter(this, writeHierarchy);
                                xmldataWriter.Save(writer, /*mode == XmlWriteMode.WriteSchema*/true);
                            }
                            if (null != ds) {
                                ds.Tables.Remove(this);
                                this.tableNamespace = tablenamespace;
                            }
                        }
                        else {
                            XmlDataTreeWriter xmldataWriter = new XmlDataTreeWriter(this, writeHierarchy);
                            xmldataWriter.Save(writer,/*mode == XmlWriteMode.WriteSchema*/ false);
                        }
                    }
                }
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
Ejemplo n.º 50
0
		private void WriteTables (XmlWriter writer, XmlWriteMode mode, DataTableCollection tableCollection, DataRowVersion version)
		{
			//WriteTable takes care of skipping a table if it has a
			//Nested Parent Relationship
			foreach (DataTable table in tableCollection)
				WriteTable ( writer, table, mode, version);
		}
Ejemplo n.º 51
0
        public void WriteXml(String fileName, XmlWriteMode mode, bool writeHierarchy)
        {
            IntPtr hscp;
            Bid.ScopeEnter(out hscp, "<ds.DataTable.WriteXml|API> %d#, fileName='%ls', mode=%d{ds.XmlWriteMode}\n", ObjectID, fileName, (int)mode);
            try {
                using(XmlTextWriter xw = new XmlTextWriter( fileName, null )) {
                    xw.Formatting = Formatting.Indented;
                    xw.WriteStartDocument(true);

                    WriteXml(xw, mode, writeHierarchy);

                    xw.WriteEndDocument();
                }
            }
            finally {
                Bid.ScopeLeave(ref hscp);
            }
        }
Ejemplo n.º 52
0
		internal static void WriteTable (XmlWriter writer, DataTable table, XmlWriteMode mode, DataRowVersion version)
		{
			DataRow[] rows = table.NewRowArray(table.Rows.Count);
			table.Rows.CopyTo (rows, 0);
			WriteTable (writer, rows, mode, version, true);
		}