コード例 #1
0
        /// <summary>
        /// Parses and deserializes a JsonTable data stream into a DataTable object that has been initialized with schema that matches the JsonDataTable
        /// data stream.  The JsonDataSetParser class will be initialized with the appropriate settings and used to read and extract all the appropriate
        /// data stored in the JsonTable data stream into the matching records of the DataTable object passed to the function.
        /// </summary>
        /// <param name="streamJson">The stream that will access the JsonTable data file data.</param>
        /// <param name="dtTable">A reference to a schema filled DataTable that will be loaded with the data from the JsonTable data file.</param>
        /// <param name="encoding">The character encoding used for the Json Table data stream being deserialized.  The default character
        /// encoding is UTF8.</param>
        /// <param name="blClearTable">Clears the DataTable to be loaded of all previous data it contains before proceeding with the deserialization
        /// operation.</param>
        public virtual bool DeserializeJsonTable(Stream streamJson, ref DataTable dtTable, Encoding encoding = null, bool blClearTable = true)
        {
            JsonDataSetParser jdsParser = null;

            try
            {
                if (blClearTable)
                {
                    dtTable.Clear();
                }

                jdsParser = new Data.JsonDataSetParser(dtTable);
                jdsParser.DateTimeFormat = DateTimeFormat;

                return(jdsParser.ParseJsonTable(streamJson, encoding));
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in DeserializeJsonTable Overload 1 function of JsonDataSetSchemaSerializer class.");
                return(false);
            }
            finally
            {
                if (jdsParser != null)
                {
                    jdsParser.Dispose();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Parses and deserializes a JsonDataSet data stream into a DataSet object that has been initialized with schema that matches the JsonDataSet
        /// data stream.  The JsonDataSetParser class will be initialized with the appropriate settings and used to read and extract all the appropriate
        /// data stored in the JsonDataSet data stream into the matching tables and records of the DataSet object passed to the function.
        /// </summary>
        /// <param name="streamJson">The stream that will access the JsonDataSet data file data.</param>
        /// <param name="dsDataSet">A reference to a schema filled DataSet that will be loaded with the data from the JsonDataSet data file.</param>
        /// <param name="encoding">The character encoding used for the Json DataSet data stream being deserialized.  The default character
        /// encoding is UTF8.</param>
        /// <param name="blClearDataSet">Clears the DataSet to be loaded of all previous data it contains before proceeding with the deserialization
        /// operation.</param>
        /// <returns></returns>
        public virtual bool DeserializeJsonDataSet(Stream streamJson, ref DataSet dsDataSet, Encoding encoding = null, bool blClearDataSet = true)
        {
            JsonDataSetParser jdsParser = null;

            try
            {
                if (blClearDataSet)
                {
                    dsDataSet.Clear();
                }

                jdsParser = new JsonDataSetParser(dsDataSet);
                jdsParser.DateTimeFormat = DateTimeFormat;

                bool blRtnVal = jdsParser.ParseJsonData(streamJson, encoding);

                return(blRtnVal);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in DeserializeJsonDataSet Overload 1 function of JsonDataSetSerializer class.");
                return(false);
            }
            finally
            {
                if (jdsParser != null)
                {
                    jdsParser.Dispose();
                }
            }
        }