Example #1
0
        public void JsonReadWrite_JsonSerializationTest()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.940.OK.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                //Write Json using newtonsoft
                //check no exception
                JsonConvert.SerializeObject(b);
                JsonConvert.SerializeObject(b.Interchanges[0].Groups[0].Transactions[0]);

                //or use writer to write to string or stream
                JsonDataWriter w      = new JsonDataWriter();
                string         str    = w.WriteToString(b);
                Stream         stream = w.WriteToStream(b);

                Assert.IsNotNull(str);

                Assert.IsNotNull(stream);
                Assert.AreEqual(0, stream.Position);
                Assert.IsTrue(stream.CanRead);

                Assert.AreEqual(str.Length, stream.Length);
            }
        }
Example #2
0
        private void BtnEdiTest_Click(object sender, EventArgs e)
        {
            bool   _OK = readEdiTest();
            string edi =
                @"ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*>
                GS*OW*7705551212*3111350000*20000128*0557*3317*T*004010
                ST*940*0001
                W05*N*538686**001001*538686
                LX*1
                W01*12*CA*000100000010*VN*000100*UC*DEC0199******19991205
                G69*11.500 STRUD BLUBRY
                W76*56*500*LB*24*CF
                SE*7*0001
                GE*1*3317
                IEA*1*000003438";


            EdiDataReader r = new EdiDataReader();
            EdiBatch      b = r.FromString(edi);

            //Serialize the whole batch to JSON
            JsonDataWriter w1   = new JsonDataWriter();
            string         json = w1.WriteToString(b);

            //OR Serialize selected EDI message to Json
            string jsonTrans = JsonConvert.SerializeObject(b.Interchanges[0].Groups[0].Transactions[0]);

            //Serialize the whole batch to XML
            XmlDataWriter w2  = new XmlDataWriter();
            string        xml = w2.WriteToString(b);
        }
        /// <summary>
        /// Serializes the data in the current DataRow of the current DataTable to the JsonDataSet (or JsonTable) data stream being serialized in the
        /// JsonDataSetSerializer class.   The JsonDataWriter object passed to the function will be positioned at the next record of the current table
        /// being written in the JsonDataSet data stream.  This function will use the JsonDataWriter to extract the field and value data out of the
        /// current DataRow and convert it to the appropriate values to store in the JsonDataSet data stream.
        /// </summary>
        /// <param name="jwrtData">JsonDataWriter object used for serializing DataSet/DataTable data to JsonDataSet/JsonTable data stream.</param>
        /// <param name="rowData">The current row to be serialized to the JsonDataSet data stream.</param>
        protected virtual void SerializeDataRowValues(JsonDataWriter jwrtData, DataRow rowData)
        {
            try
            {
                //Write opening '{' object bracket for the data row.
                jwrtData.WriteBeginObject();

                //Loops through each column of the table schema and serializes the data to the stream.
                for (int iColIndex = 0; iColIndex < rowData.Table.Columns.Count; iColIndex++)
                {
                    jwrtData.WritePropDataValue(rowData.Table.Columns[iColIndex].ColumnName, rowData[iColIndex], false, false);

                    if (iColIndex < rowData.Table.Columns.Count - 1)
                    {
                        //Writes comma field delimiter after the column end object to separate each column of the data row.  Each field will be written on a
                        //new line.
                        jwrtData.WriteFieldDelimiter(true);
                    }
                    else
                    {
                        //The final column of the data row will have a closing object bracket without a comma.
                        jwrtData.WriteNewLine();
                    }
                }//next iColIndex

                //Write closing '}' object bracket for the row data.
                jwrtData.WriteEndObject();
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in SerializeDataRowValues function of JsonDataSetSerializer class.");
            }
        }
Example #4
0
        public string GetJSONFromEDIDoc(string ediDoc)
        {
            string edi =
                @"ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*>
                GS*OW*7705551212*3111350000*20000128*0557*3317*T*004010
                ST*940*0001
                W05*N*538686**001001*538686
                LX*1
                W01*12*CA*000100000010*VN*000100*UC*DEC0199******19991205
                G69*11.500 STRUD BLUBRY
                W76*56*500*LB*24*CF
                SE*7*0001
                GE*1*3317
                IEA*1*000003438";

            EdiDataReader ediReader = new EdiDataReader();
            EdiBatch      ediBatch  = ediReader.FromString(ediDoc);

            //Serialize the whole batch to JSON
            JsonDataWriter w1   = new JsonDataWriter();
            string         json = w1.WriteToString(ediBatch);

            ////OR Serialize selected EDI message to Json
            //string jsonTrans = JsonConvert.SerializeObject(ediBatch.Interchanges[0].Groups[0].Transactions[0]);

            ////Serialize the whole batch to XML
            //XmlDataWriter w2 = new XmlDataWriter();
            //string xml = w2.WriteToString(ediBatch);
            return(JsonConvert.SerializeObject(json));
        }
        public void Returns_expected_json_for_object()
        {
            var data = new InterpretedDataRow();

            data.AddValue("key1", "value1");
            var nested = data.GetNested("nested");

            nested.AddValue("key2", "value2");

            var newLine = Environment.NewLine;

            var expected =
                $"{{{newLine}" +
                $"  \"key1\": \"value1\",{newLine}" +
                $"  \"nested\": {{{newLine}" +
                $"    \"key2\": \"value2\"{newLine}" +
                $"  }}{newLine}" +
                $"}}";

            var sut = new JsonDataWriter();

            var result = sut.WriteData(data);

            Assert.Equal(StructuredDataFormat.Json, result.Format);
            Assert.Equal(expected, result.Contents);
        }
Example #6
0
        public void JsonReadWrite_SerializeComposite()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.850.Composite.SLN.OK.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                JsonDataWriter jsonWriter = new JsonDataWriter();
                jsonWriter.WriteToString(b);
            }
        }
Example #7
0
        public void JsonReadWrite_JsonSerializationHlLoopTest()
        {
            using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.856.Crossdock.OK.edi"))
            {
                EdiDataReader r = new EdiDataReader();
                EdiBatch      b = r.FromStream(s);

                JsonDataWriter jsonWriter = new JsonDataWriter();
                jsonWriter.WriteToString(b);
            }
        }
        public void Returns_empty_string_if_input_is_null()
        {
            var sut = new JsonDataWriter();

            InterpretedDataRow data = null;

            var result = sut.WriteData(data);

            Assert.Equal(StructuredDataFormat.Json, result.Format);
            Assert.Equal(string.Empty, result.Contents);
        }
        /// <summary>
        /// Serializes the schema of a DataTable to a Tiferix JsonTableSchema stream.  The function will utilize the JsonDataWriter object to extract all
        /// data from the DataTable and write it the appropriate format into the Tiferix.JsonTableSchema data stream.   All .Net DataTable objects will
        /// first be extracted and serialized into JsonTableSchema objects which will then be written to the JsonTableSchema data stream.
        /// </summary>
        /// <param name="streamSchema">JsonTableSchema data stream that will be used to serialize the schema information from the DataTable.</param>
        /// <param name="dtSchema">DataTable with schema to be serialized to JsonTableSchema data stream.</param>
        public virtual void SerializeTableSchema(Stream streamSchema, DataTable dtSchema)
        {
            try
            {
                JsonTableSchema tblSchema  = SerializeTableSchema(dtSchema);
                JsonDataWriter  jwrtSchema = new JsonDataWriter(streamSchema);

                SerializeTableSchema(jwrtSchema, tblSchema);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in SerializeTableSchema Overload 2 function of JsonDataSetSchemaSerializer class.");
            }
        }
        /// <summary>
        /// Serializes the data in a DataTable to a Tiferix JsonTable data stream.  The function will utilize the JsonDataWriter object to extract all data from the
        /// DataTable and write it the appropriate format into the Tiferix.JsonTable data stream.  Before serializing the DataTable, 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
        /// JsonTable data file.
        /// </summary>
        /// <param name="stream">JsonTable data stream that will be used to serialize data from the DataTable.</param>
        /// <param name="dtTable">The DataTable object to be serialized to JsonTable data stream.</param>
        public virtual void SerializeDataTable(Stream stream, DataTable dtTable)
        {
            try
            {
                JsonDataWriter jwrtData = new JsonDataWriter(stream);
                InitJsonDataWriter(jwrtData);

                SerializeDataTable(jwrtData, dtTable);
            }
            catch (Exception err)
            {
                ErrorHandler.ShowErrorMessage(err, "Error in SerializeDataTable Overload 2 function of JsonDataSetSerializer class.");
            }
        }
Example #11
0
        /// <summary>
        /// Override with IoC container resolution of DataResult
        /// </summary>
        /// <returns></returns>
        protected virtual DataResult DataResult()
        {
            bool isDebug =
                this.ControllerContext.HttpContext != null ?
                this.ControllerContext.HttpContext.IsDebuggingEnabled :
                false;

            return(new DataResult(
                       new DataWriterProvider(new IDataWriter[]
            {
                new JsonDataWriter(JsonDataWriter.CreateSettings(isDebug)),
                new XmlDataWriter(XmlDataWriter.CreateSettings(Encoding.UTF8, isDebug), new XmlSerializerNamespaces())
            })));
        }
        public static string WritePretty(object obj)
        {
            JsonWriterSettings settings = new JsonWriterSettings();

            settings.PrettyPrint = true;
            JsonFx.Json.JsonDataWriter writer = new JsonDataWriter(settings);

            StringWriter wr = new StringWriter();

            writer.Serialize(wr, obj);

            string json = wr.ToString();

            return(json);
        }
Example #13
0
        public virtual void Serialize(string key)
        {
            var result = string.Empty;

            using (var stringWriter = new StringWriter()) {
                using (var dataWriter = new JsonDataWriter(new JsonDataWriterSettings(), stringWriter)) {
                    WriteMetaData(dataWriter);
                }
                result = stringWriter.ToString();
            }
            if (result.Trim() != string.Empty)
            {
                UserConnection.SessionData[key] = result;
            }
        }
        public void Write_SingleEmptyObjectWithoutExplicitClose_JsonOfSingleObject()
        {
            string expected = "{}";

            var serializer = new JsonSerializer();

            using (var sw = new StringWriter())
            {
                using (var writer = new JsonDataWriter(sw, serializer))
                {
                    writer.Write(new object());
                }

                Assert.AreEqual(expected, sw.ToString());
            }
        }
        public void Dispose_AfterWritingSingleObject_JsonOfSingleObject()
        {
            string expected = "{}";

            var serializer = new JsonSerializer();

            using (var sw = new StringWriter())
            {
                using (var writer = new JsonDataWriter(sw, serializer))
                {
                    writer.Write(new object());
                }

                Assert.AreEqual(expected, sw.ToString());
            }
        }
 /// <summary>
 /// Initializes the JsonDataWriter object that will be used to serialize the DataSet with the default formatting, encoding and other serialization
 /// settings that will be used for serializing the DataSet data to JsonDataSet data file.
 /// </summary>
 /// <param name="jwrtData">JsonDataWriter object used for serializing DataSet/DataTable data to JsonDataSet/JsonTable data stream.</param>
 protected virtual void InitJsonDataWriter(JsonDataWriter jwrtData)
 {
     try
     {
         jwrtData.FieldDelimiter = FieldDelimiter;
         jwrtData.DateTimeFormat = DateTimeFormat;
         jwrtData.DateTimeZone   = DateTimeZone;
         jwrtData.Culture        = Culture;
         jwrtData.AutoIdent      = AutoIdent;
         jwrtData.IdentSpacing   = IdentSpacing;
         jwrtData.IdentChar      = IdentChar;
     }
     catch (Exception err)
     {
         ErrorHandler.ShowErrorMessage(err, "Error in InitJsonDataWriter function of JsonDataSetSerializer class.");
     }
 }
        /// <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.");
            }
        }
        public void Write_TwoObjects_JsonArrayWithTwoObjects()
        {
            string expected = "[{},{}]";

            var serializer = new JsonSerializer();

            using (var sw = new StringWriter())
            {
                using (var writer = new JsonDataWriter(sw, serializer))
                {
                    writer.Write(new object());
                    writer.Write(new object());
                }

                Assert.AreEqual(expected, sw.ToString());
            }
        }
        /// <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.");
            }
        }
Example #20
0
        public override void Load()
        {
            // serialization
            this.Bind <IDataWriter>().To <JsonDataWriter>().InSingletonScope();
            this.Bind <JsonWriterSettings>().ToConstant(JsonDataWriter.CreateSettings(false));
            this.Bind <IDataWriter>().To <XmlDataWriter>().InSingletonScope();
            this.Bind <XmlWriterSettings>().ToConstant(XmlDataWriter.CreateSettings(Encoding.UTF8, false));
            this.Bind <XmlSerializerNamespaces>().ToConstant(new XmlSerializerNamespaces());
            this.Bind <IDataWriterProvider>().To <DataWriterProvider>().InSingletonScope();

            this.Bind <IDataReader>().To <JsonDataReader>().InSingletonScope();
            this.Bind <JsonReaderSettings>().ToConstant(JsonDataReader.CreateSettings(true));
            this.Bind <IDataReader>().To <XmlDataReader>().InSingletonScope();
            this.Bind <XmlReaderSettings>().ToConstant(XmlDataReader.CreateSettings());
            this.Bind <IDataReaderProvider>().To <DataReaderProvider>().InSingletonScope();

            // MVC and IoC types
            this.Bind <IActionInvoker>().To <NinjectActionInvoker>().InTransientScope();
        }
Example #21
0
        private void SaveData()
        {
            if (string.IsNullOrEmpty(SelectedSkillFullPath))
            {
                return;
            }

            SkillData data = m_DataDic[SelectedSkillFullPath];

            foreach (var track in data.BeginStageData.Group.Tracks)
            {
                track.Actions.Sort((item1, item2) => { return(item1.FireTime.CompareTo(item2.FireTime)); });
            }
            foreach (var track in data.BeginStageData.BreakGroup.Tracks)
            {
                track.Actions.Sort((item1, item2) => { return(item1.FireTime.CompareTo(item2.FireTime)); });
            }
            foreach (var childData in data.ReleaseStageData.Childs)
            {
                foreach (var track in childData.Group.Tracks)
                {
                    track.Actions.Sort((item1, item2) => { return(item1.FireTime.CompareTo(item2.FireTime)); });
                }
                foreach (var track in childData.BreakGroup.Tracks)
                {
                    track.Actions.Sort((item1, item2) => { return(item1.FireTime.CompareTo(item2.FireTime)); });
                }
            }
            foreach (var track in data.EndStageData.Group.Tracks)
            {
                track.Actions.Sort((item1, item2) => { return(item1.FireTime.CompareTo(item2.FireTime)); });
            }
            foreach (var track in data.EndStageData.BreakGroup.Tracks)
            {
                track.Actions.Sort((item1, item2) => { return(item1.FireTime.CompareTo(item2.FireTime)); });
            }

            string json = JsonDataWriter.WriteObjectToJson(data);

            File.WriteAllText(SelectedSkillFullPath, json);
        }
Example #22
0
        public OutputWriter(IContext context, Channel <OutputBase> outputChannel)
        {
            _context         = context;
            _outputChannel   = outputChannel;
            _userOutput      = new JsonDataWriter <User>(_context, DataType.Users);
            _computerOutput  = new JsonDataWriter <Computer>(_context, DataType.Computers);
            _domainOutput    = new JsonDataWriter <Domain>(_context, DataType.Domains);
            _groupOutput     = new JsonDataWriter <Group>(_context, DataType.Groups);
            _gpoOutput       = new JsonDataWriter <GPO>(_context, DataType.GPOs);
            _ouOutput        = new JsonDataWriter <OU>(_context, DataType.OUs);
            _containerOutput = new JsonDataWriter <Container>(_context, DataType.Containers);

            _runTimer             = new Stopwatch();
            _statusTimer          = new Timer(_context.StatusInterval);
            _statusTimer.Elapsed += (_, _) =>
            {
                PrintStatus();
                _lastCount = _completedCount;
            };
            _statusTimer.AutoReset = true;
        }
        /// <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.");
            }
        }
Example #24
0
        private void SaveData()
        {
            if (string.IsNullOrEmpty(SelectedDataFullPath))
            {
                return;
            }

            FlyerData data = m_DataDic[SelectedDataFullPath];

            foreach (var track in data.FlyingData.Group.Tracks)
            {
                track.Actions.Sort((item1, item2) => { return(item1.FireTime.CompareTo(item2.FireTime)); });
            }
            foreach (var track in data.EndData.Group.Tracks)
            {
                track.Actions.Sort((item1, item2) => { return(item1.FireTime.CompareTo(item2.FireTime)); });
            }

            string json = JsonDataWriter.WriteObjectToJson(data);

            File.WriteAllText(SelectedDataFullPath, json);
        }
Example #25
0
 public void Setup()
 {
     _jsonWriter = new JsonDataWriter();
 }
        /// <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.");
            }
        }
Example #27
0
 public JsonDataHandler() : base()
 {
     m_DataWriter = new JsonDataWriter <T>();
     m_DataReader = new JsonDataReader <T>();
 }
Example #28
0
        /// <summary>
        /// GenerateOutputFile: Generates output file. Will over write if the file exists
        /// </summary>
        public void GenerateOutputFile()
        {
            IOutputDataWriter jsonDataReader = new JsonDataWriter();

            jsonDataReader.GenerateOutputFile(inputData, OutputFile);
        }