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); }
private Readable SendRequest(Writeable payload) { // build the request header PlayerRqst request = CreateHeader(payload); // build request data MemoryStream requestStream = new MemoryStream(); XmlDataWriter requestWriter = new XmlDataWriter(requestStream); requestWriter.WriteObject(request.GetType().Name, request); requestWriter.Flush(); if (Logger.Enabled) { Logger.LogInfo(this, "SendRequest", String.Format("Request: {0}", Encoding.UTF8.GetString(requestStream.ToArray()))); } // send request MemoryStream responseStream = SendRequestViaHttp(requestStream); if (Logger.Enabled) { Logger.LogInfo(this, "SendRequest", String.Format("Response: {0}", Encoding.UTF8.GetString(responseStream.ToArray()))); } // read response XmlDataReader responseReader = new XmlDataReader(responseStream); PlayerResp response = (PlayerResp)responseReader.ReadObject("PlayerResp", PlayerResp.CtorDataReader); // parse response header return(ParseHeader(response)); }
public void Returns_empty_string_if_input_is_null_for_multiple_rows() { var sut = new XmlDataWriter(new XmlConversionOptions()); IEnumerable <InterpretedDataRow> data = null; var result = sut.WriteData(data); Assert.Equal(StructuredDataFormat.Xml, result.Format); Assert.Equal(string.Empty, result.Contents); }
private void gridPreview_SelectionChanged(object sender, EventArgs e) { try { if (chkCalculated.Checked) { txtValue.Text = XmlDataWriter.TransformName(gridPreview.CurrentCell.OwningColumn.DataPropertyName); } } catch (Exception ex) { Utils.HandleError(ex); } }
/// <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()) }))); }
/* Save, file is read-only*/ private void WriteDataFile(Stream stream, Config config) { stream.Seek(0, SeekOrigin.Begin); stream.SetLength(0); XmlDataWriter writer = new XmlDataWriter(stream); try { writer.PrettyPrint = true; writer.WriteObject(ConfigElement, config); } finally { writer.Close(); } }
public void XmlReadWrite_XmlSerializationHlLoopTest() { using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.856.Crossdock.OK.edi")) { EdiDataReader r = new EdiDataReader(); EdiBatch b = r.FromStream(s); XmlDataWriter w = new XmlDataWriter(); string data = w.WriteToString(b); XmlDocument xdoc = ValidateBySchema(data); //check parsed seg count int?segCount = xdoc.SelectNodes("//EdiSegment")?.Count; Assert.AreEqual(61, segCount); } }
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(); }
public override void Run(JobSettings settings, string environment, IErrorHandler errorHandler) { using (var connection = new SqlConnection(settings.ConnectionString)) { connection.Open(); foreach (var table in settings.Tables) { using (var cmd = connection.CreateCommand()) { table.Initialize(connection, settings, errorHandler); cmd.CommandText = $"SELECT * FROM {table.QualifiedName}"; var diffGenerator = new DiffGenerator(); var file = Path.Combine(settings.Path, table.Name + ".xml"); try { File.Move(file, file + ".old"); using (var source = cmd.ExecuteReader()) using (var target = new XmlRecordDataReader(file + ".old", table)) using (var writer = new XmlDataWriter(table, settings)) { diffGenerator.GenerateDifference(source, target, table, writer, settings); } File.Delete(file + ".old"); } finally { if (File.Exists(file + ".old"))//If the old file still exists then something went wrong. Revert back to the original { if (File.Exists(file)) { File.Delete(file); } File.Move(file + ".old", file); } } } } } }
public void XmlReadWrite_XmlSerializationTest() { using (Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.940.OK.edi")) { EdiDataReader r = new EdiDataReader(); EdiBatch b = r.FromStream(s); XmlDataWriter w = new XmlDataWriter(); string data = w.WriteToString(b); Stream stream = w.WriteToStream(b); Assert.IsNotNull(stream); Assert.AreEqual(0, stream.Position); Assert.IsTrue(stream.CanRead); XmlDocument xdoc = ValidateBySchema(data); //check parsed seg count int?segCount = xdoc.SelectNodes("//EdiSegment")?.Count; Assert.AreEqual(33, segCount); } }
/// <summary> /// Scripts a database to disk for use in creating a brand new db. This /// method scripts the entire object, i.e. no differntial or comparisons /// are done. /// </summary> /// <param name="connectionInfo">The db connection parameters.</param> /// <param name="scriptingOptions">The export scripting settings.</param> public virtual void Script(IConnectionSettings connectionInfo, IScriptingOptions scriptingOptions) { Throw.If(connectionInfo, "connectionInfo").IsNull(); Throw.If(scriptingOptions, "scriptingOptions").IsNull(); messageManager.OnScriptMessage("Starting database scripting."); IDatabase db = DatabaseConnectionFactory.CreateDbConnection(connectionInfo); List <ITable> tablesToScript = new List <ITable>(); foreach (DbObjectName tableName in scriptingOptions.TablesToScript) { ITable table = db.Tables[tableName.ShortName]; if (table == null) { throw new SqlMigrationException( string.Format("Unable to find the table {0} in database {1} on server.", tableName, connectionInfo.Database)); } tablesToScript.Add(table); } IScriptWriter writer = CreateScriptWriter(scriptingOptions, connectionInfo); int totalObjects = CalculateScriptObjectCount(scriptingOptions); int exportCount = 0; if (scriptingOptions.ScriptSchema) { foreach (ITable table in tablesToScript) { ScriptTableSchema(table, writer); OnProgressEvent(++exportCount, totalObjects); } } if (scriptingOptions.ScriptIndexes) { foreach (ITable table in tablesToScript) { ScriptTableIndexes(table, writer); OnProgressEvent(++exportCount, totalObjects); } } if (scriptingOptions.ScriptData || scriptingOptions.ScriptDataAsXml) { IScriptWriter dataWriter = writer; IDataMigrator dataMigrator = new DataMigrator(); if (scriptingOptions.ScriptDataAsXml) { dataMigrator = new XmlDataMigrator(); dataWriter = new XmlDataWriter(scriptingOptions.ExportDirectory, messageManager); } foreach (ITable table in tablesToScript) { ScriptTableData(dataMigrator, table, dataWriter); OnProgressEvent(++exportCount, totalObjects); } } if (scriptingOptions.ScriptForeignKeys) { foreach (ITable table in tablesToScript) { ScriptTableForeignKeys(table, writer); OnProgressEvent(++exportCount, totalObjects); } } foreach (DbObjectName sprocName in scriptingOptions.SprocsToScript) { IProcedure sproc = db.Procedures[sprocName.ShortName]; if (sproc == null) { throw new SqlMigrationException( string.Format("Unable to find the procedure {0} in database {1} on server.", sprocName, connectionInfo.Database)); } ScriptSproc(sproc, writer); OnProgressEvent(++exportCount, totalObjects); } foreach (DbObjectName viewName in scriptingOptions.ViewsToScript) { IView view = db.Views[viewName.ShortName]; if (view == null) { throw new SqlMigrationException( string.Format("Unable to find the view {0} in database {1} on server.", viewName, connectionInfo.Database)); } ScriptView(view, writer); OnProgressEvent(++exportCount, totalObjects); } messageManager.OnScriptMessage("Finished database scripting."); }