/// <summary>
        /// Serializes the schema of a DataSet to a Tiferix JsonDataSetSchema stream.  The function will utilize the JsonDataWriter object to extract all
        /// data from the DataSet and write it the appropriate format into the Tiferix.JsonDataSetSchema data stream.   All .Net DataSet objects will first be
        /// extracted and serialized into JsonDataSetSchema objects which will then be written to the JsonDataSchema data stream.
        /// </summary>
        /// <param name="streamSchema">JsonDataSetSchema data stream that will be used to serialize the schema information from the DataSet.</param>
        /// <param name="dsSchema">DataSet with schema to be serialized to JsonDataSetSchema data stream.</param>
        public virtual void SerializeDataSetSchema(Stream streamSchema, DataSet dsSchema)
        {
            try
            {
                JsonDataSetSchema dataSchema = SerializeDataSetSchema(dsSchema);

                JsonDataWriter jwrtSchema = new JsonDataWriter(streamSchema);

                //Writes opening '{' object bracket of Json file.
                jwrtSchema.WriteBeginObject();

                //"DataSet": "DataSetName",
                jwrtSchema.WritePropDataValue("DataSet", dataSchema.DataSetName, true);

                //"Tables": [
                jwrtSchema.WritePropertyName("Tables");
                jwrtSchema.WriteBeginArray(true);

                //Loops through each table schema and writes it to the stream.
                for (int iTableIndex = 0; iTableIndex < dataSchema.Tables.Count; iTableIndex++)
                {
                    SerializeTableSchema(jwrtSchema, dataSchema.Tables[iTableIndex]);

                    if (iTableIndex < dataSchema.Tables.Count - 1)
                    {
                        //Writes comma field delimiter after the table end object to separate each table record.
                        jwrtSchema.WriteFieldDelimiter();
                    }
                    else
                    {
                        //The final table record will have a closing object bracket without a comma.
                        jwrtSchema.WriteNewLine();
                    }
                }//next

                //Writes closing ']' of tables array.
                jwrtSchema.WriteEndArray();

                //Writes closing '}' object bracket of Json file.
                jwrtSchema.WriteEndObject();
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in SerializeDataSetSchema Overload 2 function of JsonDataSetSchemaSerializer class.");
            }
        }
        /// <summary>
        /// Serializes the data in a DataSet to a Tiferix JsonDataSet data stream.  The function will utilize the JsonDataWriter object to extract all data from the
        /// DataSet and write it the appropriate format into the Tiferix.JsonDataSet data stream.  Before serializing the DataSet, all formatting settings must be set
        /// in the JsonDataSetSerializer class beforehand and it will be required that the same formatting settings bet set when deserializing the
        /// JsonDataSet data file.
        /// </summary>
        /// <param name="stream">JsonDataSet data stream that will be used to serialize data from the DataSet.</param>
        /// <param name="dsDataSet">The DataSet object to be serialized to JsonDataSet data stream.</param>
        public virtual void SerializeDataSet(Stream stream, DataSet dsDataSet)
        {
            try
            {
                JsonDataWriter jwrtData = new JsonDataWriter(stream, Encoding);
                InitJsonDataWriter(jwrtData);

                //Writes opening '{' object bracket of the Json file.
                jwrtData.WriteBeginObject();

                //"DataSetName": [
                jwrtData.WritePropertyName(dsDataSet.DataSetName);
                jwrtData.WriteBeginArray();

                int iTableIndex = 0;
                int iTableCount = dsDataSet.Tables.Count;

                //Loops through each data table and writes it to the stream.
                foreach (DataTable dtTable in dsDataSet.Tables)
                {
                    SerializeDataTable(jwrtData, dtTable);

                    if (iTableIndex < iTableCount - 1)
                    {
                        jwrtData.WriteFieldDelimiter(false);
                    }

                    jwrtData.WriteNewLine();

                    iTableIndex++;
                }//next dtTable

                //Writes closing ']' of tables array of the dataset.
                jwrtData.WriteEndArray();

                //Write closing '}' object bracket of the Json file.
                jwrtData.WriteEndObject();
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in SerializeDataSet Overload 1 function of JsonDataSetSerializer class.");
            }
        }
        /// <summary>
        /// An internal function that will serialize the data of each DataTable contained in the DataSet being serialized into the appropriate Table record
        /// in the JsonDataSet data stream.  The JsonDataWriter will contain the active stream of data that should be set at the position where the
        /// table record and its data will be writen in the JsonDataSet data stream.
        /// </summary>
        /// <param name="jwrtData">JsonDataWriter object used for serializing DataSet data to JsonDataSet data stream.</param>
        /// <param name="dtTable">The DataTable to be serialized to the JsonDataSet data stream.</param>
        protected virtual void SerializeDataTable(JsonDataWriter jwrtData, DataTable dtTable)
        {
            try
            {
                //Writes opening '{' object bracket of either Tables schema array (of DataSet Schema file) or of the entire table schema file.
                jwrtData.WriteBeginObject();

                //"Table Name": [
                jwrtData.WritePropertyName(dtTable.TableName);
                jwrtData.WriteBeginArray();

                int iRowIndex = 0;
                int iRowCount = dtTable.Rows.Count;

                foreach (DataRow rowData in dtTable.Rows)
                {
                    SerializeDataRowValues(jwrtData, rowData);

                    if (iRowIndex < iRowCount - 1)
                    {
                        jwrtData.WriteFieldDelimiter(false);
                    }

                    jwrtData.WriteNewLine();

                    iRowIndex++;
                }//next rowData

                //Writes closing ']' of table rows array.
                jwrtData.WriteEndArray();

                //Writes closing '}' object bracket of either a table in the Tables data array (of DataSet data file) or of the entire table data file.
                jwrtData.WriteEndObject();
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in SerializeDataTable Overload 1 function of JsonDataSetSerializer class.");
            }
        }
        /// <summary>
        /// An internal function that will use a JsonDataWriter object to serialize the data stored in a JsonTableSchema object to a JsonDataSetSchema
        /// data stream or file.  The JsonTableSchema object will have been previously loaded before the function is called and the JsonDataWriter
        /// will be positioned at the next table schema record in the data stream.
        /// </summary>
        /// <param name="jwrtSchema">JsonDataWriter object used for serializing the schema information of the DataTable to the JsonDataSetSchema
        /// data stream.</param>
        /// <param name="tblSchema">The JsonTableSchema object containing all the schema information of a DataTable to serialize to the JsonDataSetSchema
        /// data stream.</param>
        protected virtual void SerializeTableSchema(JsonDataWriter jwrtSchema, JsonTableSchema tblSchema)
        {
            try
            {
                //Writes opening '{' object bracket of either Tables schema array (of DataSet Schema file) or of the entire table schema file.
                jwrtSchema.WriteBeginObject();

                //"Table": "Table Name",
                jwrtSchema.WritePropDataValue("Table", tblSchema.TableName, true);

                //"Columns": [
                jwrtSchema.WritePropertyName("Columns");
                jwrtSchema.WriteBeginArray(true);

                //Loops through each column of the table schema and serializes the data to the stream.
                for (int iColIndex = 0; iColIndex < tblSchema.Columns.Count; iColIndex++)
                {
                    JsonColumnSchema colSchema = tblSchema.Columns[iColIndex];

                    //Write opening '{' object bracket for the column schema.
                    jwrtSchema.WriteBeginObject();

                    jwrtSchema.WritePropDataValue("ColumnName", colSchema.ColumnName, true);
                    jwrtSchema.WritePropDataValue("DataType", JsonDataUtils.ConvertToJsonDataType(colSchema.DataType), true);
                    jwrtSchema.WritePropDataValue("PrimaryKey", colSchema.PrimaryKey, true);
                    jwrtSchema.WritePropDataValue("Unique", colSchema.Unique, true);
                    jwrtSchema.WritePropDataValue("MaxLength", colSchema.MaxLength, true);
                    jwrtSchema.WritePropDataValue("AllowDBNull", colSchema.AllowDBNull, true);
                    jwrtSchema.WritePropDataValue("AutoIncrement", colSchema.AutoIncrement, true);
                    jwrtSchema.WritePropDataValue("AutoIncrementSeed", colSchema.AutoIncrementSeed, true);
                    jwrtSchema.WritePropDataValue("AutoIncrementStep", colSchema.AutoIncrementStep, true);
                    jwrtSchema.WritePropDataValue("Caption", colSchema.Caption, true);
                    jwrtSchema.WritePropDataValue("DateTimeMode", colSchema.DateTimeMode.ToString(), true);

                    if (colSchema.DefaultValue != null)
                    {
                        jwrtSchema.WritePropDataValue("DefaultValue", colSchema.DefaultValue.ToString(), true);
                    }
                    else
                    {
                        jwrtSchema.WritePropDataNullValue("DefaultValue", true);
                    }

                    jwrtSchema.WritePropDataValue("ReadOnly", colSchema.ReadOnly);

                    //Write closing '}' object bracket for the column schema.
                    jwrtSchema.WriteEndObject();

                    if (iColIndex < tblSchema.Columns.Count - 1)
                    {
                        //Writes comma field delimiter after the column end object to separate each column record.
                        jwrtSchema.WriteFieldDelimiter();
                    }
                    else
                    {
                        //The final column record will have a closing object bracket without a comma.
                        jwrtSchema.WriteNewLine();
                    }
                }//next iColIndex

                //Writes closing ']' of columns array.
                jwrtSchema.WriteEndArray();

                //Writes closing '}' object bracket of either Tables schema array (of DataSet Schema file) or of the entire table schema file.
                jwrtSchema.WriteEndObject();
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in SerializeTableSchema Overload 2 function of JsonDataSetSchemaSerializer class.");
            }
        }