/// <summary> /// Parses and deserializes the JsonTableSchema data stream into a DataTable object with the schema information stored in the data stream. /// The JsonDataSetSchemaParser class will be used to extract all the schema data in the stream into a JsonTableSchema object which then /// will be deserialized and used to initialize the schema of the DataTable object. /// </summary> /// <param name="streamSchema">The stream that will access the JsonTableSchema file data.</param> /// <returns></returns> public virtual DataTable DeserializeJsonTableSchema(Stream streamSchema) { JsonDataSetSchemaParser jsParser = null; try { jsParser = new JsonDataSetSchemaParser(streamSchema); JsonTableSchema tblSchema = jsParser.ParseJsonTableSchema(); if (tblSchema == null) { throw new InvalidDataException("Json Data Schema file invalid. Failed to parse Json Schema file."); } DataTable dtTable = DeserializeJsonTableSchema(tblSchema); return(dtTable); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in DeserializeJsonTableSchema Overload 2 function of JsonDataSetSchemaSerializer class."); return(null); } finally { if (jsParser != null) { jsParser.Dispose(); } } }
/// <summary> /// Parses and deserializes the JsonDataSetSchema data stream into a DataSet object with the schema information stored in the data stream. /// The JsonDataSetSchemaParser class will be used to extract all the schema data in the stream into a JsonDataSetSchema object which then /// will be deserialized and used to initialize the schema of the DataSet object. /// </summary> /// <param name="streamSchema">The stream that will access the JsonDataSetSchema file data.</param> /// <param name="dsData">A reference to a DataSet that will be initialized with the schema data contained in the JsonDataSetSchema data stream.</param> /// <returns></returns> public virtual bool DeserializeJsonDataSetSchema(Stream streamSchema, ref DataSet dsData) { JsonDataSetSchemaParser jsParser = null; try { jsParser = new JsonDataSetSchemaParser(streamSchema); JsonDataSetSchema dataSchema = jsParser.ParseJsonSchema(); if (dataSchema == null) { throw new InvalidDataException("Json Data Schema file invalid. Failed to parse Json Schema file."); } dsData = new DataSet(); dsData.DataSetName = dataSchema.DataSetName; foreach (JsonTableSchema tblSchema in dataSchema.Tables) { DataTable dtTable = DeserializeJsonTableSchema(tblSchema); dsData.Tables.Add(dtTable); }//next tblSchema return(true); } catch (Exception err) { ErrorHandler.ShowErrorMessage(err, "Error in DeserializeJsonDataSetSchema Overload 1 function of JsonDataSetSchemaSerializer class."); return(false); } finally { if (jsParser != null) { jsParser.Dispose(); } } }