Ejemplo n.º 1
0
        protected virtual DataSet LoadFromFile()
        {
            if (m_FileName == null)
            {
                throw new ApplicationException("FileName is null");
            }

            System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
            xmlDoc.Load(m_FileName);

            System.Xml.XmlNamespaceManager namespaceMan = new System.Xml.XmlNamespaceManager(xmlDoc.NameTable);
            namespaceMan.AddNamespace("fileds", c_DataNamespace);

            System.Xml.XmlNode tmp = xmlDoc.DocumentElement.SelectSingleNode("fileds:header", namespaceMan);
            if (tmp == null)
            {
                throw new ApplicationException("File header not found");
            }
            System.Xml.XmlElement header = (System.Xml.XmlElement)tmp;

            //File Version
            string strFileVersion = header.GetAttribute(c_FileVersion);
            int    fileVersion    = int.Parse(strFileVersion);

            if (fileVersion == c_FileVersionNumber)
            {
                string strDataFormat = header.GetAttribute(c_DataFormat);
                mFileDataFormat = (StreamDataSetFormat)int.Parse(strDataFormat);
            }
            else if (fileVersion == 0)
            {
                mFileDataFormat = StreamDataSetFormat.XML;
            }
            else if (fileVersion > c_FileVersionNumber)
            {
                throw new ApplicationException("File Version not supported, expected: " + c_FileVersionNumber.ToString());
            }

            //Data Version
            string  strDataVersion = header.GetAttribute(c_DataVersion);
            int     dataVersion    = int.Parse(strDataVersion);
            DataSet dataSet        = CreateData(dataVersion);

            //Data
            tmp = xmlDoc.DocumentElement.SelectSingleNode("fileds:data", namespaceMan);
            if (tmp == null)
            {
                throw new ApplicationException("File data not found");
            }
            System.Xml.XmlElement xmlDataNode = (System.Xml.XmlElement)tmp;

            byte[] xmlBuffer = System.Convert.FromBase64String(xmlDataNode.InnerText);
            using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(xmlBuffer))
            {
                StreamDataSet.Read(memStream, dataSet, mFileDataFormat, MergeReadedSchema);
                //dataSet.ReadXml(memStream);
            }

            return(dataSet);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Read from the stream and populate the dataset using the specified format.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <param name="format"></param>
        /// <param name="mergeSchema">True to merge the schema, otherwise it is used the schema of the dataset</param>
		public static void Read(System.IO.Stream source, System.Data.DataSet destination, StreamDataSetFormat format, bool mergeSchema)
		{
			bool oldEnforce = destination.EnforceConstraints;
			destination.EnforceConstraints = false;
			try
			{
				switch (format)
				{
					case StreamDataSetFormat.XML:
						if (mergeSchema)
							destination.ReadXml(source, System.Data.XmlReadMode.ReadSchema);
						else
							destination.ReadXml(source, System.Data.XmlReadMode.IgnoreSchema);
						break;
					case StreamDataSetFormat.Binary:
						BinReadDataSetFromStream(source, destination, mergeSchema);
						break;
					default:
						throw new ApplicationException("StreamDataSet Format not supported");
				}
			}
			finally
			{
				destination.EnforceConstraints = oldEnforce;
			}
		}
Ejemplo n.º 3
0
        /// <summary>
        /// Write the dataset to the stream using the specified format.
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="format"></param>
		public static void Write(System.IO.Stream destination, System.Data.DataSet source, StreamDataSetFormat format)
		{
			switch (format)
			{
				case StreamDataSetFormat.XML:
					source.WriteXml(destination, System.Data.XmlWriteMode.WriteSchema);
					break;
				case StreamDataSetFormat.Binary:
					BinWriteDataSetToStream(destination, source);
					break;
				default:
					throw new ApplicationException("StreamDataSet Format not supported");
			}
		}
Ejemplo n.º 4
0
        /// <summary>
        /// Read from the stream and populate the dataset using the specified format.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <param name="format"></param>
        /// <param name="mergeSchema">True to merge the schema, otherwise it is used the schema of the dataset</param>
        public static void Read(System.IO.Stream source, System.Data.DataSet destination, StreamDataSetFormat format, bool mergeSchema)
        {
            bool oldEnforce = destination.EnforceConstraints;

            destination.EnforceConstraints = false;
            try
            {
                switch (format)
                {
                case StreamDataSetFormat.XML:
                    if (mergeSchema)
                    {
                        destination.ReadXml(source, System.Data.XmlReadMode.ReadSchema);
                    }
                    else
                    {
                        destination.ReadXml(source, System.Data.XmlReadMode.IgnoreSchema);
                    }
                    break;

                case StreamDataSetFormat.Binary:
                    BinReadDataSetFromStream(source, destination, mergeSchema);
                    break;

                default:
                    throw new ApplicationException("StreamDataSet Format not supported");
                }
            }
            finally
            {
                destination.EnforceConstraints = oldEnforce;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Write the dataset to the stream using the specified format.
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="format"></param>
        public static void Write(System.IO.Stream destination, System.Data.DataSet source, StreamDataSetFormat format)
        {
            switch (format)
            {
            case StreamDataSetFormat.XML:
                source.WriteXml(destination, System.Data.XmlWriteMode.WriteSchema);
                break;

            case StreamDataSetFormat.Binary:
                BinWriteDataSetToStream(destination, source);
                break;

            default:
                throw new ApplicationException("StreamDataSet Format not supported");
            }
        }
Ejemplo n.º 6
0
		protected virtual DataSet LoadFromFile()
		{
			if (m_FileName == null)
				throw new ApplicationException("FileName is null");

			System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
			xmlDoc.Load(m_FileName);

			System.Xml.XmlNamespaceManager namespaceMan = new System.Xml.XmlNamespaceManager(xmlDoc.NameTable);
			namespaceMan.AddNamespace("fileds", c_DataNamespace);

			System.Xml.XmlNode tmp = xmlDoc.DocumentElement.SelectSingleNode("fileds:header", namespaceMan);
			if (tmp == null)
				throw new ApplicationException("File header not found");
			System.Xml.XmlElement header = (System.Xml.XmlElement)tmp;

			//File Version
			string strFileVersion = header.GetAttribute(c_FileVersion);
			int fileVersion = int.Parse( strFileVersion );
			if (fileVersion == c_FileVersionNumber)
			{
				string strDataFormat = header.GetAttribute(c_DataFormat);
				mFileDataFormat = (StreamDataSetFormat)int.Parse(strDataFormat);
			}
			else if (fileVersion == 0)
			{
				mFileDataFormat = StreamDataSetFormat.XML;
			}
			else if (fileVersion > c_FileVersionNumber)
				throw new ApplicationException("File Version not supported, expected: " + c_FileVersionNumber.ToString());

			//Data Version
			string strDataVersion = header.GetAttribute(c_DataVersion);
			int dataVersion = int.Parse( strDataVersion );
			DataSet dataSet = CreateData(dataVersion);

			//Data
			tmp = xmlDoc.DocumentElement.SelectSingleNode("fileds:data", namespaceMan);
			if (tmp == null)
				throw new ApplicationException("File data not found");
			System.Xml.XmlElement xmlDataNode = (System.Xml.XmlElement)tmp;

			byte[] xmlBuffer = System.Convert.FromBase64String( xmlDataNode.InnerText );
			using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(xmlBuffer))
			{
				StreamDataSet.Read(memStream, dataSet, mFileDataFormat, MergeReadedSchema);
				//dataSet.ReadXml(memStream);
			}

			return dataSet;
		}