Example #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);
            }
        }
Example #2
0
        /// <summary>
        /// Parses the current JsonColumnSchema information of the current JsonTableSchema record contained in the JsonDataSetSchema data stream
        /// linked o the JsonDataSetSchemaParser class.  The function will read the column schema and extract the column information into the
        /// JstonColumnSchema object passed to the function.  All field schema properties and values will be converted into the appropriate format and
        /// loaded into the JsonColumnSchema object associatd with the current field of the current table being parsed in the JsonDataSchemaParser
        /// class.
        /// </summary>
        /// <param name="schemaJsonCol">A reference to the JsonColumnSchema object to be loaded with the column schema information from the
        /// JsonDataSetSchema file being parsed in the class.</param>
        /// <param name="iCurParseIndex">The current index of the JsonDataSetSchema data stream being parsed.</param>
        /// <returns></returns>
        protected virtual bool ParseJsonColumnSchema(ref JsonColumnSchema schemaJsonCol, ref int iCurParseIndex)
        {
            try
            {
                schemaJsonCol = new JsonColumnSchema();

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

                while (blColSchemaItemFound)
                {
                    iCurParseIndex = m_strJsonDSSchema.IndexOf('\"', iCurParseIndex) + 1;
                    iEndParseIndex = m_strJsonDSSchema.IndexOf('\"', iCurParseIndex);
                    string strColSchemaItem = m_strJsonDSSchema.Substring(iCurParseIndex, iEndParseIndex - iCurParseIndex).ToUpper();
                    iCurParseIndex = m_strJsonDSSchema.IndexOf(':', iCurParseIndex) + 1;

                    switch (strColSchemaItem)
                    {
                    case "COLUMNNAME":
                    case "DATATYPE":
                    case "CAPTION":
                    case "EXPRESSION":
                    case "DATETIMEMODE":
                        iCurParseIndex = m_strJsonDSSchema.IndexOf('\"', iCurParseIndex) + 1;
                        iEndParseIndex = m_strJsonDSSchema.IndexOf('\"', iCurParseIndex);
                        strExtractData = m_strJsonDSSchema.Substring(iCurParseIndex, iEndParseIndex - iCurParseIndex);

                        if (strColSchemaItem == "COLUMNNAME")
                        {
                            schemaJsonCol.ColumnName = strExtractData;
                        }
                        else if (strColSchemaItem == "DATATYPE")
                        {
                            schemaJsonCol.DataType = JsonDataUtils.ConvertFromJsonDataType(strExtractData);
                        }
                        else if (strColSchemaItem == "CAPTION")
                        {
                            schemaJsonCol.Caption = strExtractData;
                        }
                        else if (strColSchemaItem == "EXPRESSION")
                        {
                            schemaJsonCol.Expression = strExtractData;
                        }
                        else if (strColSchemaItem == "DATETIMEMODE")
                        {
                            schemaJsonCol.DateTimeMode = JsonDataUtils.ConvertToADODataSetDateTimeEnum(strExtractData);
                        }

                        iCurParseIndex = iEndParseIndex + 1;

                        break;

                    case "PRIMARYKEY":
                    case "UNIQUE":
                    case "ALLOWDBNULL":
                    case "AUTOINCREMENT":
                    case "READONLY":
                        while (m_strJsonDSSchema[iCurParseIndex] != 'T' && m_strJsonDSSchema[iCurParseIndex] != 't' &&
                               m_strJsonDSSchema[iCurParseIndex] != 'F' && m_strJsonDSSchema[iCurParseIndex] != 'f')
                        {
                            iCurParseIndex++;
                        }

                        bool blValue;

                        if (m_strJsonDSSchema[iCurParseIndex].ToString().ToUpper() == "T")
                        {
                            blValue         = true;
                            iCurParseIndex += "true".Length;
                        }
                        else
                        {
                            blValue         = false;
                            iCurParseIndex += "false".Length;
                        }    //end if

                        if (strColSchemaItem == "PRIMARYKEY")
                        {
                            schemaJsonCol.PrimaryKey = blValue;
                        }
                        else if (strColSchemaItem == "UNIQUE")
                        {
                            schemaJsonCol.Unique = blValue;
                        }
                        else if (strColSchemaItem == "ALLOWDBNULL")
                        {
                            schemaJsonCol.AllowDBNull = blValue;
                        }
                        else if (strColSchemaItem == "AUTOINCREMENT")
                        {
                            schemaJsonCol.AutoIncrement = blValue;
                        }
                        else if (strColSchemaItem == "READONLY")
                        {
                            schemaJsonCol.ReadOnly = blValue;
                        }
                        break;

                    case "MAXLENGTH":
                    case "AUTOINCREMENTSEED":
                    case "AUTOINCREMENTSTEP":
                        while (m_strJsonDSSchema[iCurParseIndex] == ' ' || m_strJsonDSSchema[iCurParseIndex] == '\"')
                        {
                            iCurParseIndex++;
                        }

                        string strVal = "";

                        while (char.IsNumber(m_strJsonDSSchema[iCurParseIndex]))
                        {
                            strVal += m_strJsonDSSchema[iCurParseIndex];
                            iCurParseIndex++;
                        }    //end while

                        schemaJsonCol.MaxLength = Convert.ToInt32(strVal);

                        break;

                    case "DEFAULTVALUE":
                        while (m_strJsonDSSchema[iCurParseIndex] != ' ')
                        {
                            iCurParseIndex++;
                        }

                        string strDefaultValue = "";
                        bool   blDataFound     = true;

                        while (blDataFound)
                        {
                            if (m_strJsonDSSchema[iCurParseIndex] != ',' && m_strJsonDSSchema[iCurParseIndex] != '}' &&
                                m_strJsonDSSchema[iCurParseIndex] != ' ')
                            {
                                strDefaultValue += m_strJsonDSSchema[iCurParseIndex];
                            }
                            else
                            {
                                blDataFound = false;
                            }
                        }    //end while

                        schemaJsonCol.DefaultValue = JsonDataSetParser.ParseVarTypeJsonData(strDefaultValue);

                        break;
                    }//end switch

                    if (m_strJsonDSSchema.IndexOf(',', iCurParseIndex) != -1)
                    {
                        if (m_strJsonDSSchema.IndexOf(',', iCurParseIndex) < m_strJsonDSSchema.IndexOf('}', iCurParseIndex))
                        {
                            iCurParseIndex = m_strJsonDSSchema.IndexOf(',', iCurParseIndex) + 1;
                        }
                        else
                        {
                            blColSchemaItemFound = false;
                        }
                    }
                    else
                    {
                        blColSchemaItemFound = false;
                    }

                    if (!blColSchemaItemFound)
                    {
                        iCurParseIndex = m_strJsonDSSchema.IndexOf('}', iCurParseIndex) + 1;
                    } //end if
                }     //end while

                bool blColFound = MoveNextSchemaRecord(ref iCurParseIndex);

                return(blColFound);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in ParseJsonColumnSchema function of JsonDataSetSchemaParser class.");
                return(false);
            }
        }