Пример #1
0
        /// <summary>
        /// Parses the current JsonTableSchema information contained in the JsonDataSetSchema data stream linked to the JsonDataSetSchemaParser
        /// class.  The function will read the table schema data at the current position of the data stream into the JsonTableSchema object
        /// passed to the function.  This data can then be used to initialize the schema of a DataTable object.
        /// </summary>
        /// <param name="schemaJsonTable">The JsonTableSchema object that will </param>
        /// <param name="iCurParseIndex">The current index of the JsonDataSetSchema data stream being parsed.</param>
        /// <returns></returns>
        protected virtual bool ParseJsonTableSchema(ref JsonTableSchema schemaJsonTable, ref int iCurParseIndex)
        {
            try
            {
                schemaJsonTable = new JsonTableSchema();

                string strExtractData     = "";
                int    iEndParseIndex     = 0;
                bool   blTableSchemaFound = true;

                iCurParseIndex = m_strJsonDSSchema.IndexOf("\"Table\"", iCurParseIndex, StringComparison.OrdinalIgnoreCase);
                iCurParseIndex = m_strJsonDSSchema.IndexOf(":", iCurParseIndex);

                iCurParseIndex = m_strJsonDSSchema.IndexOf('\"', iCurParseIndex) + 1;
                iEndParseIndex = m_strJsonDSSchema.IndexOf('\"', iCurParseIndex);

                //Extracts the name of the table.
                strExtractData            = m_strJsonDSSchema.Substring(iCurParseIndex, iEndParseIndex - iCurParseIndex);
                schemaJsonTable.TableName = strExtractData;

                iCurParseIndex = m_strJsonDSSchema.IndexOf("\"Columns\"", iCurParseIndex, StringComparison.OrdinalIgnoreCase);
                iCurParseIndex = m_strJsonDSSchema.IndexOf(':', iCurParseIndex) + 1;

                if (m_strJsonDSSchema.IndexOf('[', iCurParseIndex) != -1)
                {
                    if (m_strJsonDSSchema.IndexOf('[', iCurParseIndex) < m_strJsonDSSchema.IndexOf('{', iCurParseIndex))
                    {
                        iCurParseIndex = m_strJsonDSSchema.IndexOf('[', iCurParseIndex) + 1;
                    }
                }//end if

                bool blColDetected = true;

                while (blColDetected)
                {
                    JsonColumnSchema schemaJsonCol = null;
                    blColDetected = ParseJsonColumnSchema(ref schemaJsonCol, ref iCurParseIndex);

                    schemaJsonTable.Columns.Add(schemaJsonCol);
                }//end while

                blTableSchemaFound = MoveNextSchemaRecord(ref iCurParseIndex);

                return(blTableSchemaFound);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in ParseJsonTableSchema Overload 1 function of JsonDataSetSchemaParser class.");
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Parses the buffered stream of data contained in the JsonDataSetSchemaParser class, which was loaded from a Tiferix JsonDataSetSchema
        /// file.  The function will read the schema data from the buffered schema string into the linked JsonDataSetSchema object of the parser class,
        /// which then can be used to initialize the schema of the DataSet object.
        /// </summary>
        public virtual JsonDataSetSchema ParseJsonSchema()
        {
            try
            {
                JsonDataSetSchema schemaJsonDS = new JsonDataSetSchema();

                string strExtractData = "";

                int iCurParseIndex = 0;
                int iEndParseIndex = 0;

                iCurParseIndex = m_strJsonDSSchema.IndexOf("\"DataSet\"", iCurParseIndex, StringComparison.OrdinalIgnoreCase);
                iCurParseIndex = m_strJsonDSSchema.IndexOf(':', iCurParseIndex);
                iCurParseIndex = m_strJsonDSSchema.IndexOf('\"', iCurParseIndex) + 1;
                iEndParseIndex = m_strJsonDSSchema.IndexOf('\"', iCurParseIndex);

                //Extracts the name of the DataSet.
                strExtractData           = m_strJsonDSSchema.Substring(iCurParseIndex, iEndParseIndex - iCurParseIndex);
                schemaJsonDS.DataSetName = strExtractData;

                iCurParseIndex = iEndParseIndex + 1;

                iCurParseIndex = m_strJsonDSSchema.IndexOf("\"Tables\"", iCurParseIndex, StringComparison.OrdinalIgnoreCase);
                iCurParseIndex = m_strJsonDSSchema.IndexOf(':', iCurParseIndex) + 1;

                if (m_strJsonDSSchema.IndexOf('[', iCurParseIndex) != -1)
                {
                    if (m_strJsonDSSchema.IndexOf('[', iCurParseIndex) < m_strJsonDSSchema.IndexOf('{', iCurParseIndex))
                    {
                        iCurParseIndex = m_strJsonDSSchema.IndexOf('[', iCurParseIndex) + 1;
                    }
                }//end if

                bool blTableDetected = true;

                while (blTableDetected)
                {
                    JsonTableSchema schemaJsonTable = null;
                    blTableDetected = ParseJsonTableSchema(ref schemaJsonTable, ref iCurParseIndex);

                    schemaJsonDS.Tables.Add(schemaJsonTable);
                }//end while

                return(schemaJsonDS);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in ParseJsonSchema Overload 1 function of JsonDataSetSchemaParser class.");
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// Parses the current JsonTableSchema information contained in the JsonDataSetSchema data stream linked to the JsonDataSetSchemaParser
        /// class.  The function will read the table schema data at the current position of the data stream into a newly instantiated JsonTableSchema object
        /// which will then be returned by the function.  This data can then be used to initialize the schema of a DataTable object.
        /// </summary>
        /// <returns></returns>
        public virtual JsonTableSchema ParseJsonTableSchema()
        {
            try
            {
                JsonTableSchema schemaJsonTable = null;
                int             iCurParseIndex  = 0;

                ParseJsonTableSchema(ref schemaJsonTable, ref iCurParseIndex);
                return(schemaJsonTable);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in ParseJsonTableSchema Overload 2 function of JsonDataSetSchemaParser class.");
                return(null);
            }
        }