EDI Fabric .ToEDI() has empty group fields - c#

I'm using EDIFabric to build up an interchange and single message. I have a very simple format I need to output to an EDI x12 string. My code populates the interchange and group properly (viewing the local variables and collections), however when I run .ToEdi() on my interchange object I'm getting back empty message groups
My Output:
"ISA*00* *00* *IS*SenderID *IS*ReceiverID *160809*1008*^*00501*000001ISA*0*P*:~GS*FA*GS_02_SenderCode*GS_03_ReceiverCode*21160809*1008*00001GS06*X*005010~ST~AK1~AK2~IK3~IK5~AK9~SE~GE*000001*00001GS06~IEA*00001*000001ISA~"
Empty when shouldn't be
ST~AK1~AK2~IK3~IK5~AK9~SE~GE
Creation class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EdiFabric.Framework.Envelopes.X12;
using EdiFabric.Definitions.Hipaa_005010_999_X231;
using EdiFabric.Framework.Messages;
using EdiFabric.Framework.Envelopes;
namespace X12PayloadProcessing
{
public class DS_M_999
{
private DS_M_999_Interchange _Interchange;
private DS_M_999_Group _Group;
private Message _EDI_Message;
private S_ISA _EDI_ISA = new S_ISA();
private S_IEA _EDI_IEA = new S_IEA();
public Interchange _EDI_Interchange = new Interchange();
private S_GE _EDI_GE = new S_GE();
private S_GS _EDI_GS = new S_GS();
private Group _EDI_Group = new Group();
private M_999 _EDI_999 = new M_999();
private S_ST _EDI_ST = new S_ST();
private S_SE _EDI_SE = new S_SE();
private S_AK1 _EDI_AK1 = new S_AK1();
private S_AK2 _EDI_AK2 = new S_AK2();
private S_AK9 _EDI_AK9 = new S_AK9();
private S_IK3 _EDI_IK3 = new S_IK3();
private S_IK5 _EDI_IK5 = new S_IK5();
private List<G_TS999_2000> _EDI_2000_List = new List<G_TS999_2000>();
private G_TS999_2000 _EDI_2000 = new G_TS999_2000();
private G_TS999_2100 _EDI_2100 = new G_TS999_2100();
private List<G_TS999_2100> _EDI_2100_List = new List<G_TS999_2100>();
public DS_M_999(DS_M_999_Group Group, DS_M_999_Interchange Interchange)
{
_Group = Group;
_Interchange = Interchange;
_EDI_Interchange.Groups = new List<Group>();
_EDI_ISA.D_744_1 = _Interchange.ISA_01_Authorization.PadRight(2).Substring(0,2);
_EDI_ISA.D_745_2 = _Interchange.ISA_02_AuthInfo.PadRight(10).Substring(0,10);
_EDI_ISA.D_746_3 = _Interchange.ISA_03_SecurityQualifier.PadRight(2).Substring(0, 2);
_EDI_ISA.D_747_4 = _Interchange.ISA_04_Password.PadRight(10).Substring(0, 10);
_EDI_ISA.D_704_5 = _Interchange.ISA_05_SenderQualifier.PadRight(2).Substring(0, 2);
_EDI_ISA.D_705_6 = _Interchange.ISA_06_SenderId.PadRight(15).Substring(0,15);
_EDI_ISA.D_704_7 = _Interchange.ISA_07_ReceiverQualifier.PadRight(2).Substring(0, 2);
_EDI_ISA.D_706_8 = _Interchange.ISA_08_ReceiverId.PadRight(15).Substring(0, 15);
_EDI_ISA.D_373_9 = _Interchange.ISA_09_DateReceived.PadRight(6).Substring(0, 6);
_EDI_ISA.D_337_10 = _Interchange.ISA_10_TimeRecieved.PadRight(4).Substring(0, 4);
_EDI_ISA.D_726_11 = _Interchange.ISA_11_RepetitionSeparator.PadRight(1).Substring(0, 1);
_EDI_ISA.D_703_12 = _Interchange.ISA_12_X12Version.PadRight(5).Substring(0, 5);
_EDI_ISA.D_709_13 = _Interchange.ISA_13_UniqueNumberCounter.PadLeft(9,'0');
_EDI_ISA.D_749_14 = _Interchange.ISA_14_AcknoledgementRequested;
_EDI_ISA.D_748_15 = _Interchange.ISA_15_UsageIndicator;
_EDI_ISA.D_701_16 = _Interchange.ISA_16_CompElementSeparator;
_EDI_IEA.D_405_1 = _Interchange.IEA_01_FunctionalGroupCounter.PadLeft(5, '0');
_EDI_IEA.D_709_2 = _Interchange.IEA_02_UniqueNumberCounter.PadLeft(9, '0');
_EDI_Interchange.Iea = _EDI_IEA;
_EDI_Interchange.Isa = _EDI_ISA;
_EDI_GE.D_97_1 = _Interchange.GE_01_TransactionSetCounter.PadLeft(6, '0');
_EDI_GE.D_28_2 = _Interchange.GE_02_UniqueNumberCounter.PadLeft(9, '0');
_EDI_Group.Ge = _EDI_GE;
_EDI_GS.D_479_1 = _Interchange.GS_01.PadRight(2).Substring(0, 2);
_EDI_GS.D_142_2 = _Interchange.GS_02_SenderCode;
_EDI_GS.D_124_3 = _Interchange.GS_03_ReceiverCode;
_EDI_GS.D_29_4 = _Interchange.GS_04_DateReceived.PadRight(6).Substring(0, 8); //datetime.ToString("yyyyMMdd")
_EDI_GS.D_30_5 = _Interchange.GS_05_TimeReceived.PadRight(4).Substring(0, 4); //datetime.ToString("HHmm")
_EDI_GS.D_28_6 = _Interchange.GS_06_UniqueNumberCounter.PadLeft(9,'0');
_EDI_GS.D_455_7 = _Interchange.GS_07_AgencyCode.PadRight(1).Substring(0, 1);
_EDI_GS.D_480_8 = _Interchange.GS_08_X12Version.PadRight(6).Substring(0, 6);
_EDI_Group.Gs = _EDI_GS;
//Set ST Block
_EDI_ST.D_ST01 = X12_ID_143.Item999;
_EDI_ST.D_ST02 = _Group.ST_02_TransactionSetCounter;
_EDI_ST.D_ST03 = X12_ID_1705.Item005010X231A1;
_EDI_999.S_ST = _EDI_ST;
//Set AK1 Block
_EDI_AK1.D_AK101 = _Group.AK_101_FunctionalIdentifier;
_EDI_AK1.D_AK102 = _Group.AK_102_GroupControlNumber;
_EDI_AK1.D_AK103 = _Group.AK_103_VersionIdentifier;
_EDI_999.S_AK1 = _EDI_AK1;
_EDI_AK2.D_AK201 = _Group.AK_201_TransactionSetIdentifier;
_EDI_AK2.D_AK202 = _Group.AK_202_ControlNumber;
_EDI_AK2.D_AK203 = _Group.AK_203_VersionIdentifier;
_EDI_2000.S_AK2 = _EDI_AK2;
//Set IK3 Block
_EDI_IK3.D_IK301 = _Group.IK_301_MissingSegment;
_EDI_IK3.D_IK302 = _Group.IK_302_PositionInTransactionSet;
_EDI_IK3.D_IK304 = X12_ID_620.Item3; // _Group.IK_304_ErrorCode;
_EDI_2100.S_IK3 = _EDI_IK3;
//Set IK5 Block
_EDI_IK5.D_IK501 = X12_ID_717.R;
_EDI_IK5.D_IK502 = X12_ID_618.Item5;
_EDI_2000.S_IK5 = _EDI_IK5;
//Set Lists
_EDI_2100_List.Add(_EDI_2100);
_EDI_2000.G_TS999_2100 = _EDI_2100_List;
_EDI_2000_List.Add(_EDI_2000);
_EDI_999.G_TS999_2000 = _EDI_2000_List;
//AK9 Block
_EDI_AK9.D_AK901 = X12_ID_715.R;//_Group.AK_901_RejectIndicator;
_EDI_AK9.D_AK902 = _Group.AK_902_NumberOfTransactionSets;
_EDI_AK9.D_AK903 = _Group.AK_903_NumberOfTransactionSets;
_EDI_AK9.D_AK904 = _Group.AK_904_NumberAccepted;
_EDI_999.S_AK9 = _EDI_AK9;
//SE Block
_EDI_SE.D_SE01 = _Group.SE_01_SegmentCounter;
_EDI_SE.D_SE02 = _Group.SE_02_TransactionSetCounter;
_EDI_999.S_SE = _EDI_SE;
_EDI_Message = new Message(_EDI_999);
_EDI_Group.Messages.Add(new Message((object)_EDI_999));
_EDI_Interchange.Groups.Add(_EDI_Group);
}
public string GetEdiString()
{
var parsedXml = _EDI_Interchange.ToEdi();
return string.Concat(parsedXml);
}
}
public class DS_M_999_Interchange
{
public string ISA_01_Authorization { get; set; } //default 00
public string ISA_02_AuthInfo { get; set; } //defualt ""
public string ISA_03_SecurityQualifier { get; set; } //default 00
public string ISA_04_Password { get; set; } //default ""
//get from 270/276
public string ISA_05_SenderQualifier { get; set; }
public string ISA_06_SenderId { get; set; }
public string ISA_07_ReceiverQualifier { get; set; }
public string ISA_08_ReceiverId { get; set; }
public string ISA_09_DateReceived { get; set; } //default YYMMDD
public string ISA_10_TimeRecieved { get; set; } //default HHMM
public string ISA_11_RepetitionSeparator { get; set; } //default ^
public string ISA_12_X12Version { get; set; } //default 00501
public string ISA_13_UniqueNumberCounter { get; set; } //will be generated by app
public string ISA_14_AcknoledgementRequested { get; set; } //default 0
public string ISA_15_UsageIndicator { get; set; } //default P
public string ISA_16_CompElementSeparator { get; set; } //default :
//Interchange GS
public string GS_01 { get; set; } //default FA
//from 270/276
public string GS_02_SenderCode { get; set; }
public string GS_03_ReceiverCode { get; set; }
public string GS_04_DateReceived { get; set; } //default CCYYMMDD
public string GS_05_TimeReceived { get; set; } //default HHMM
public string GS_06_UniqueNumberCounter { get; set; } //will be generated by app
public string GS_07_AgencyCode { get; set; } //default "X"
public string GS_08_X12Version { get; set; } //default 00501X231A1
public string GE_01_TransactionSetCounter { get; set; } //number of transaction sets output typically 1
public string GE_02_UniqueNumberCounter { get; set; } //same as GS06
public string IEA_01_FunctionalGroupCounter { get; set; } //number of functional groups typically 1
public string IEA_02_UniqueNumberCounter { get; set; } //same as ISA_13
public DS_M_999_Interchange()
{
ISA_01_Authorization = "00";
ISA_02_AuthInfo = "";
ISA_03_SecurityQualifier = "00";
ISA_04_Password = "";
ISA_09_DateReceived = DateTime.Now.ToString("yyMMdd");
ISA_10_TimeRecieved = DateTime.Now.ToString("HHMM");
ISA_11_RepetitionSeparator = "^";
ISA_12_X12Version = "005010";
ISA_13_UniqueNumberCounter = "1ISA"; //Need to generate/track
ISA_14_AcknoledgementRequested = "0";
ISA_15_UsageIndicator = "P";
ISA_16_CompElementSeparator = ":";
GS_01 = "FA";
GS_04_DateReceived = (DateTime.Now.Year / 100 + 1).ToString() + DateTime.Now.ToString("yyMMdd");
GS_05_TimeReceived = DateTime.Now.ToString("HHMM");
GS_06_UniqueNumberCounter = "1GS06"; //Need to generate/track
GS_07_AgencyCode = "X";
GS_08_X12Version = "005010X231A1";
GE_01_TransactionSetCounter = "1";
GE_02_UniqueNumberCounter = GS_06_UniqueNumberCounter;
IEA_01_FunctionalGroupCounter = "1";
IEA_02_UniqueNumberCounter = ISA_13_UniqueNumberCounter;
}
}
public class DS_M_999_Group
{
public string ST_01_TransactionSetIdentifier { get; set; } //default 999
public string ST_02_TransactionSetCounter { get; set; } //will be generated by app startiing at 0001 (always 0001 in our instance)
public string ST_03_X12Version { get; set; } //default 005010x231a1
//from 270 /276
public string AK_101_FunctionalIdentifier { get; set; }
public string AK_102_GroupControlNumber { get; set; }
public string AK_103_VersionIdentifier { get; set; }
public string AK_201_TransactionSetIdentifier { get; set; }
public string AK_202_ControlNumber { get; set; }
public string AK_203_VersionIdentifier { get; set; }
public string IK_301_MissingSegment { get; set; } //set from x12ParserHelper MissingFields
public string IK_302_PositionInTransactionSet { get; set; } //need to figure this out by parsing incoming edi
public string IK_304_ErrorCode { get; set; } //default 3
public string IK_501_RejectIndicator { get; set; } //default R
public string IK_502_RejectCode { get; set; } //default 5
public string AK_901_RejectIndicator { get; set; } //default R
//from 270/276
public string AK_902_NumberOfTransactionSets { get; set; }
public string AK_903_NumberOfTransactionSets { get; set; }
public string AK_904_NumberAccepted { get; set; } //default 0
public string SE_01_SegmentCounter { get; set; } //#of segments in tx set ST to SE
public string SE_02_TransactionSetCounter { get; set; } //same as ST02
public DS_M_999_Group()
{
ST_01_TransactionSetIdentifier = "999";
ST_02_TransactionSetCounter = "0001";
ST_03_X12Version = "005010X231A1";
IK_304_ErrorCode = "3";
IK_501_RejectIndicator = "R";
IK_502_RejectCode = "5";
AK_901_RejectIndicator = "R";
AK_904_NumberAccepted = "0";
SE_01_SegmentCounter = "1";
SE_02_TransactionSetCounter = ST_02_TransactionSetCounter;
}
}
}
Test Class:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X12PayloadProcessing;
namespace X12PayloadProcessing.Tests
{
[TestClass]
public class DS_M_999_Tests
{
[TestMethod]
public void DSM999_ToEdiStringShouldBeValid()
{
DS_M_999_Interchange Interchange = new DS_M_999_Interchange();
Interchange.ISA_05_SenderQualifier = "ISA_05_SenderQualifier";
Interchange.ISA_06_SenderId = "SenderID"; //15 space padded
Interchange.ISA_07_ReceiverQualifier = "ISA_06_ReciverQualifier";
Interchange.ISA_08_ReceiverId = "ReceiverID"; //15 space padded
Interchange.GS_02_SenderCode = "GS_02_SenderCode";
Interchange.GS_03_ReceiverCode = "GS_03_ReceiverCode";
DS_M_999_Group Group = new DS_M_999_Group();
Group.AK_101_FunctionalIdentifier = "AK_101_FunctionalIdentifier";
Group.AK_102_GroupControlNumber = "AK_102_GroupControlNumber";
Group.AK_103_VersionIdentifier = "AK_103_VersionIdentifier";
Group.AK_201_TransactionSetIdentifier = "AK_201_TransactionSetIdentifier";
Group.AK_202_ControlNumber = "AK_202_ControlNumber";
Group.AK_203_VersionIdentifier = "AK_203_VersionIdentifier";
Group.IK_301_MissingSegment = "IK_301_MissingSegment";
Group.IK_302_PositionInTransactionSet = "IK_302_PositionInTransactionSet";
Group.AK_902_NumberOfTransactionSets = "AK_902_NumberOfTransactionSets";
Group.AK_903_NumberOfTransactionSets = "AK_903_NumberOfTransactionSets";
DS_M_999 DS_M_999 = new DS_M_999(Group, Interchange);
string ediString = DS_M_999.GetEdiString();
var x = DS_M_999._EDI_Interchange.ToEdi();
Assert.IsNotNull(ediString);
}
}
}
The test will pass as is, but it's not generating the expected EDI output. Obewon Kenobe Please help, your our only hope.

The problem seems to be in the creation of the GS, where in D_480_8 the full version number needs to be set, so that this:
_EDI_GS.D_480_8 = _Interchange.GS_08_X12Version.PadRight(6).Substring(0, 6);
should be changed to this:
_EDI_GS.D_480_8 = _Interchange.GS_08_X12Version;
It's the way the parser determines the correct type - it pulls out the X231A1 part (or the Origin) from the GS instead of the ST or MessageContext.

I found the issue to be lying in the SDK code that got translated into my own code base. The GS.D_480_8 SHOULD NOT be padded as in
_EDI_GS.D_480_8 = _Interchange.GS_08_X12Version.PadRight(6).Substring(0, 6);
The SDK File in question is GRP.cs code:
public void Version(string versionNo)
{
versionNo = versionNo.PadRight(6);
Group.Gs.D_480_8 = versionNo.Substring(0, 6);
}
My particular file was a GS08 version of 12 chars long which when not all present the EDIFabric framework was not handling.

Related

powershell cmdlet in visual studio 2017, deserialization method

I have got a problem with undestanding powershell cmdlet.
Task is, to deserialize a xml file. I have got a folder with a lot of xml files, I would like to read in an filter certain information using the deserializiation method. My supervisor mentioned that I should use powershell cmdlet... but I haven't heard anything of it before. So what is the benefit? And how do I create such a cmdlet.
That is my code so far:
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;
using System.Management.Automation;
namespace EdocX
{
[Cmdlet(VerbsCommon.Get, "test", SupportsShouldProcess = true)]
public class program : Cmdlet
{
public static string dirPath = #"N:\EGS_SDRE\OB\19_Schnittstellen_eDocX_ITAS\06_Matching EdocX-Objektbrief\01_exemplarische_XMLs_fuer_den_Import\RWA-Anlage"
public static List<string> dirs = new List<string>(Directory.GetFiles(dirPath, "*.xml"));
public static (string[], string[], string[,], string[,], string[,]) deserializeobject(string filename)
{
// Liste Prüfgrundlagen
List<string> pg = new List<string>();
pg.Add("GaVO");
pg.Add("VkVO");
pg.Add("VStättVO");
pg.Add("SPrüfV");
pg.Add("BetrVO");
pg.Add("BbgSGPrüfV");
pg.Add("BremAnlPrüfV");
pg.Add("PVO");
pg.Add("TPrüfVO");
pg.Add("BauPrüfVO M-V");
pg.Add("DVO-NBauO");
pg.Add("PrüfVO NRW");
pg.Add("HTechAnlV RP");
pg.Add("TPrüfVO");
pg.Add("SächsTechPrüfVO");
pg.Add("TAnlVO");
pg.Add("PrüfVO");
pg.Add("ThürTechPrüfVO");
// Auftraggeber - Var
string[] Auftraggeber;
string Name_AG = "";
string Stadt_AG = "";
string PLZ_AG = "";
string Straße_AG = "";
string Hausnummer_AG = "";
string Region_AG = "";
string PARNR_AG = "";
// Aufstellungsort - Var
string[] Aufstellungsort;
string Name_AO = "";
string Stadt_AO = "";
string PLZ_AO = "";
string Straße_AO = "";
string Hausnummer_AO = "";
string Region_AO = "";
string Land_AO = "";
// Anlage - Var
string[,] Anlagen;
string Materialnummer = "";
string EQnummer = "";
string Anlagentyp = "RWA-Anlage";
string[] InterneBezeichnung;
string[] Hersteller;
// Vorgang rückgemeldet - Var
string[,] Vorgang_rückgemeldet;
string Typ_VR = "Prüfung";
string Dienstleister = "TÜV SÜD Industrie Service GmbH";
string Durchführungsdatum = "";
string Maengel = "";
string Bemerkungstexte = "";
string Pruefgrundlage_VR = "";
// Vorgang zukünftig - Var
string[,] Vorgang_zukünftig;
string Typ_VZ = "Prüfung";
string Fälligkeit = "";
string Pruefgrundlage_VZ = "";
//****************************************************************************************************
//********************************************SERIALIZATION*******************************************
// new instance of XMLSerializer --> specifiying type
var serializer = new XmlSerializer(typeof(Document));
// read the XML document
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var encoding = Encoding.GetEncoding("Windows-1252");
using (var sr = new StreamReader(filename, encoding, true))
using (var reader = XmlReader.Create(sr))
{
// restore the object's state using the deserialize method
var i = (Document)serializer.Deserialize(reader);
//---------------------------------------Auftraggeber-----------------------------------------------
int count_Z1ZRMPA = i.IDOC.Z1ZRMDB.Z1ZRMPA.Count;
for (int c = 0; c < count_Z1ZRMPA; c++)
{
if (i.IDOC.Z1ZRMDB.Z1ZRMPA[c].TITLE == "Auftraggeber")
{
Name_AG = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].NAME1 + i.IDOC.Z1ZRMDB.Z1ZRMPA[c].NAME2;
Stadt_AG = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].CITY1;
PLZ_AG = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].POST_CODE1;
Straße_AG = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].STREET;
Hausnummer_AG = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].HOUSE_NUM1;
Region_AG = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].REGION;
PARNR_AG = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].PARNR;
}
//---------------------------------------Aufstellungsort----------------------------------------
if (i.IDOC.Z1ZRMDB.Z1ZRMPA[c].TITLE == "Aufstellungsort")
{
Name_AO = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].NAME1 + i.IDOC.Z1ZRMDB.Z1ZRMPA[c].NAME2;
Stadt_AO = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].CITY1;
PLZ_AO = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].POST_CODE1;
Straße_AO = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].STREET;
Hausnummer_AO = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].HOUSE_NUM1;
Region_AO = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].REGION;
Land_AO = i.IDOC.Z1ZRMDB.Z1ZRMPA[c].COUNTRY;
}
}
//---------------------------------------Anlage----------------------------------------------------
Materialnummer = i.IDOC.Z1ZRMDB.MABEZ;
EQnummer = i.IDOC.Z1ZRMDB.OBJNR;
int count_ANLAGEPRFTXT = i.IDOC.Z1ZRMDB.PRFBER.PRFERG.ANLAGE.PRFTXT.Count;
int AnzahlAnlagen = count_ANLAGEPRFTXT - 1;
InterneBezeichnung = new string[AnzahlAnlagen];
Hersteller = new string[AnzahlAnlagen];
for (int c = 1; c < count_ANLAGEPRFTXT; c++)
{
InterneBezeichnung[c - 1] = i.IDOC.Z1ZRMDB.PRFBER.PRFERG.ANLAGE.PRFTXT[c].ENTRBEREICH;
Hersteller[c - 1] = i.IDOC.Z1ZRMDB.PRFBER.PRFERG.ANLAGE.PRFTXT[c].HERSTELLER;
}
//---------------------------------------Vorgang rückgemeldet-------------------------------------
Durchführungsdatum = i.IDOC.Z1ZRMDB.PRFBER.DATEN.Pruefungszeitraum;
int count_PRFTXT = i.IDOC.Z1ZRMDB.PRFBER.PRFERG.PRFTXT.Count;
for (int c = 0; c < count_PRFTXT; c++)
{
if (i.IDOC.Z1ZRMDB.PRFBER.PRFERG.PRFTXT[c].KATEGORIE == "Grundlage")
{
string Pruefgrundlage = i.IDOC.Z1ZRMDB.PRFBER.PRFERG.PRFTXT[c].Value;
int count_pg = pg.Count;
for (int cc = 0; cc < count_pg; cc++)
{
if (Pruefgrundlage.Contains(pg[cc]) == true)
{
Pruefgrundlage_VR = pg[cc];
}
}
}
if (i.IDOC.Z1ZRMDB.PRFBER.PRFERG.PRFTXT[c].ROWTYPE == "Zwischenüberschrift" && i.IDOC.Z1ZRMDB.PRFBER.PRFERG.PRFTXT[c].PATTERN == "#KATEGORIE[../#KATEGORIE='Mangel' and ../#GEWICHT[not(contains(.,'Beseitigt'))]]")
{
string Maengelabruf = i.IDOC.Z1ZRMDB.PRFBER.PRFERG.PRFTXT[c].Value;
if (Maengelabruf == "Mängel")
{
Maengel = "Mängel_ja";
}
else
{
Maengel = "Mängel_nein";
}
}
if (i.IDOC.Z1ZRMDB.PRFBER.PRFERG.PRFTXT[c].ROWTYPE == "Mangel" && i.IDOC.Z1ZRMDB.PRFBER.PRFERG.PRFTXT[c].PATTERN == "#KATEGORIE[../#KATEGORIE='Mangel' and ../#GEWICHT[not(contains(.,'Beseitigt'))]]")
{
string Bemerkungstext = i.IDOC.Z1ZRMDB.PRFBER.PRFERG.PRFTXT[c].Value;
Bemerkungstexte += " " + Bemerkungstext;
}
}
//---------------------------------------Vorgang zukünftig--------------------------------------
int count_Z1ZRMAU = i.IDOC.Z1ZRMDB.Z1ZRMAU.Count;
for (int c = 0; c < count_Z1ZRMAU; c++)
{
if (i.IDOC.Z1ZRMDB.Z1ZRMAU[c].MNAME == "Nächste Wiederkehrende Prüfung")
{
Fälligkeit = i.IDOC.Z1ZRMDB.Z1ZRMAU[c].MWERT;
}
}
for (int c = 0; c < count_PRFTXT; c++)
{
if (i.IDOC.Z1ZRMDB.PRFBER.PRFERG.PRFTXT[c].KATEGORIE == "Grundlage")
{
string Pruefgrundlage = i.IDOC.Z1ZRMDB.PRFBER.PRFERG.PRFTXT[c].Value;
int count_pg = pg.Count;
for (int cc = 0; cc < count_pg; cc++)
{
if (Pruefgrundlage.Contains(pg[cc]) == true)
{
Pruefgrundlage_VZ = pg[cc];
}
}
}
}
Auftraggeber = new string[7];
Aufstellungsort = new string[7];
Anlagen = new string[AnzahlAnlagen, 5];
Vorgang_rückgemeldet = new string[AnzahlAnlagen, 6];
Vorgang_zukünftig = new string[AnzahlAnlagen, 3];
}
Auftraggeber[0] = Name_AG;
Auftraggeber[1] = Stadt_AG;
Auftraggeber[2] = PLZ_AG;
Auftraggeber[3] = Straße_AG;
Auftraggeber[4] = Hausnummer_AG;
Auftraggeber[5] = Region_AG;
Auftraggeber[6] = PARNR_AG;
Aufstellungsort[0] = Name_AO;
Aufstellungsort[1] = Stadt_AO;
Aufstellungsort[2] = PLZ_AO;
Aufstellungsort[3] = Straße_AO;
Aufstellungsort[4] = Hausnummer_AO;
Aufstellungsort[5] = Region_AO;
Aufstellungsort[6] = Land_AO;
for (int j = 0; j < Anlagen.GetLength(0); j++)
{
Anlagen[j, 0] = Materialnummer;
Anlagen[j, 1] = EQnummer;
Anlagen[j, 2] = Anlagentyp;
Anlagen[j, 3] = InterneBezeichnung[j];
Anlagen[j, 4] = Hersteller[j];
Vorgang_rückgemeldet[j, 0] = Typ_VR;
Vorgang_rückgemeldet[j, 1] = Dienstleister;
Vorgang_rückgemeldet[j, 2] = Durchführungsdatum;
Vorgang_rückgemeldet[j, 3] = Maengel;
Vorgang_rückgemeldet[j, 4] = Bemerkungstexte;
Vorgang_rückgemeldet[j, 5] = Pruefgrundlage_VR;
Vorgang_zukünftig[j, 0] = Typ_VZ;
Vorgang_zukünftig[j, 1] = Fälligkeit;
Vorgang_zukünftig[j, 2] = Pruefgrundlage_VZ;
}
return (Auftraggeber, Aufstellungsort, Anlagen, Vorgang_rückgemeldet, Vorgang_zukünftig);
}
}
}
And here the class to simulate the xml structure:
using System;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace EdocX
{//ZRM01 Root Environment
[Serializable()]
[XmlRoot(ElementName = "ZRM01")]
public partial class Document
{
[XmlElement()]
public ZRM01IDOC IDOC { get; set; }
}
//IDOC
[Serializable()]
public partial class ZRM01IDOC
{
[XmlElement()]
public ZRM01IDOCZ1ZRMDB Z1ZRMDB { get; set; }
}
//IDOC Elements
[Serializable()]
public partial class ZRM01IDOCZ1ZRMDB
{
public string MABEZ { get; set; } // Materialnummer
public string OBJNR { get; set; } // Equipmentnummer
[XmlElement("Z1ZRMPA")]
public List<ZRM01IDOCZ1ZRMDBZ1ZRMPA> Z1ZRMPA = new List<ZRM01IDOCZ1ZRMDBZ1ZRMPA>(); //{ get; set; }
[XmlElement("Z1ZRMAU")]
public List<ZRM01IDOCZ1ZRMDBZ1ZRMAU> Z1ZRMAU = new List<ZRM01IDOCZ1ZRMDBZ1ZRMAU>();
[XmlElement()]
public ZRM01IDOCZ1ZRMDBPRFBER PRFBER { get; set; }
}
//Z1ZRMPA --> Mandant / Gebäude
[Serializable()]
public partial class ZRM01IDOCZ1ZRMDBZ1ZRMPA
{
[XmlAttribute()]
public string TITLE { get; set; } // "Auftraggeber" "Aufstellungsort"
[XmlElement()]
public string PARNR { get; set; } // Parnr. (Mandant)
[XmlElement()]
public string NAME1 { get; set; } // Name
[XmlElement()]
public string NAME2 { get; set; } // Name
[XmlElement()]
public string CITY1 { get; set; } // Stadt
[XmlElement()]
public string POST_CODE1 { get; set; } // PLZ
[XmlElement()]
public string STREET { get; set; } // Straße
[XmlElement()]
public string HOUSE_NUM1 { get; set; } // Hausnummer
[XmlElement()]
public string REGION { get; set; } // Region
[XmlElement()]
public string COUNTRY { get; set; } // Land
}
//Z1ZRMAU
[Serializable()]
public partial class ZRM01IDOCZ1ZRMDBZ1ZRMAU
{
[XmlElement()]
public string MNAME { get; set; } // "Nächste Wiederkehrende Prüfung"
[XmlElement()]
public string MWERT { get; set; } // Fälligkeit
}
//PRFBER Elemts
[Serializable()]
public partial class ZRM01IDOCZ1ZRMDBPRFBER
{
[XmlElement()]
public ZRM01IDOCZ1ZRMDBPRFBERPRFERG PRFERG { get; set; }
[XmlElement()]
public ZRM01IDOCZ1ZRMDBPRFBERDATEN DATEN { get; set; }
}
//DATEN
[Serializable()]
public partial class ZRM01IDOCZ1ZRMDBPRFBERDATEN
{
[XmlElement()]
public string Pruefungszeitraum { get; set; } //Durchführungsdatum
}
//PRFERG Elements
[Serializable()]
public partial class ZRM01IDOCZ1ZRMDBPRFBERPRFERG
{
[XmlElement()]
public ZRM01IDOCZ1ZRMDBPRFBERPRFERGANLAGE ANLAGE { get; set; }
[XmlElement("PRFTXT")]
public List<ZRM01IDOCZ1ZRMDBPRFBERPRFERGPRFTXT> PRFTXT = new List<ZRM01IDOCZ1ZRMDBPRFBERPRFERGPRFTXT>();
}
//ANLAGE
[Serializable()]
public partial class ZRM01IDOCZ1ZRMDBPRFBERPRFERGANLAGE
{
[XmlElement("PRFTXT")]
public List<ZRM01IDOCZ1ZRMDBPRFBERPRFERGANLAGEPRFTXT> PRFTXT = new List<ZRM01IDOCZ1ZRMDBPRFBERPRFERGANLAGEPRFTXT>();
}
//PRFTXT
[Serializable()]
public partial class ZRM01IDOCZ1ZRMDBPRFBERPRFERGANLAGEPRFTXT
{
[XmlAttribute()]
public string REF { get; set; } // Anzahl Anlagen
[XmlAttribute()]
public string HERSTELLER { get; set; } // Hersteller Anlage
[XmlAttribute()]
public string ENTRBEREICH { get; set; } // Interne Bezeichnung Anlage
}
//PRFTXT
[Serializable()]
public partial class ZRM01IDOCZ1ZRMDBPRFBERPRFERGPRFTXT
{
[XmlAttribute()]
public string KATEGORIE { get; set; } // A"Grundlage" < ... >
[XmlText()]
public string Value { get; set; }
[XmlAttribute()]
public string ROWTYPE { get; set; } // "Zwischenüberschrift" (für Mangel ja/nein) "Mangel" (für Bemerkungstext)
[XmlAttribute()]
public string PATTERN { get; set; } // "#KATEGORIE[../#KATEGORIE='Mangel' and ../#GEWICHT[not(contains(.,'Beseitigt'))]]" < Mängel > bzw < ... >
}
}
I'm very thankful for help!

Best way to write application data to a file in WPF

I am using the Caliburn.Micro MVVM pattern.
I am writing an application that has 2 DataGrids, one holds a BindableCollection of RepairOrder, the other a BindableCollection WriteOff.
BindableCollection_WriteOff is property of BindableCollection_RepairOrder. (See the below code).
I need to find a way to write all the RepairOrder including the WriteOff associated with each RO. Besides RepairOrder class holding the WriteOff class, the WriteOff class does not have a way to tie the WriteOff to a RepairOrder.
Repair Order Class:
public class RepairOrder
{
public string Schedule { get; set; }
public string ControlNumber { get; set; }
public int Age { get; set; }
public double Value { get; set; }
public string Note { get; set; }
public double OrgValue { get; set; }
private List<WriteOff> _myWriteOffs;
public List<WriteOff> GetMyWriteOffs()
{
return _myWriteOffs;
}
public void AddMyWriteOff(WriteOff value)
{ _myWriteOffs.Add(value); }
public void DeleteMyWriteOff(WriteOff value)
{ _myWriteOffs.Remove(value); }
public RepairOrder(string CN, string SC, double VL)
{
ControlNumber = CN;
Schedule = SC;
Value = Math.Round(VL, 2);
Note = null;
_myWriteOffs = new List<WriteOff>();
}
public RepairOrder()
{
_myWriteOffs = new List<WriteOff>();
}
public static RepairOrder FromCSV(string CSVLine, string Sched)
{
string[] values = CSVLine.Split(',');
RepairOrder rep = new RepairOrder();
rep.ControlNumber = values[2];
rep.Value = Math.Round(double.Parse(values[5]),2);
rep.Age = int.Parse(values[4]);
rep.Schedule = Sched;
return rep;
}
}
Write Off Class:
public class WriteOff
{
private string _store;
public string Account { get; set; }
public string Description { get; set; }
public double WriteOffAmount { get; set; }
public string Schedule { get; set; }
public string Store
{
get {
if (String.IsNullOrEmpty(_store)) return "";
string temp = _store.Substring(0, 3);
return temp;
}
set { _store = value; }
}
public string Note { get; set; }
public WriteOff(string Acct, string Desc, double Amount, string _store)
{
Account = Acct;
Description = Desc;
WriteOffAmount = Amount;
Store = _store;
}
public string GetWOAccount() {
string SchedAccountNumber = "";
//{ "Navistar", "Cummins", "Misc", "Kenworth", "Mack/Volvo" }
switch (Account)
{
case "Navistar":
SchedAccountNumber = "222000";
break;
case "Cummins":
SchedAccountNumber = "223000";
break;
case "Misc":
SchedAccountNumber = "224500";
break;
default:
SchedAccountNumber = "";
break;
}
return SchedAccountNumber;
}
}

Create XML from a class where List<ItemDetails> is an entity

ANSWER:
Changed the class as suggested by Tim and it worked like a charm.
public class DatiBeniServizi1
{
[XmlElement]
public List<DettaglioLinee> DettaglioLinee { get; set; }
public DatiRiepilogo1 DatiRiepilogo { get; set; }
}
I'm trying to create an XML using a class. Below is the class
public class DatiBeniServizi1
{
public List<DettaglioLinee> DettaglioLinee { get; set; }
public DatiRiepilogo1 DatiRiepilogo { get; set; }
}
public class DettaglioLinee
{
public int NumeroLinea { get; set; }
public string Descrizione { get; set; }
public int Quantita { get; set; }
public decimal PrezzoUnitario { get; set; }
public decimal PrezzoTotale { get; set; }
public decimal AliquotaIVA { get; set; }
public string Natura { get; set; }
}
public class DatiRiepilogo1
{
public decimal AliquotaIVA { get; set; }
public string Natura { get; set; }
public decimal ImponibileImporto { get; set; }
public decimal Imposta { get; set; }
public string RiferimentoNormativo { get; set; }
}
and the code to generate XML
private DatiBeniServizi1 GetXMLExportInvoiceItemDetails(DataTable dtItemDetails, DataTable dtBatches)
{
DatiBeniServizi1 DatiBeniServizi12 = new DatiBeniServizi1();
List<DettaglioLinee> ItemDetails = new List<DettaglioLinee>();
int i = 1;
foreach (DataRow row in dtItemDetails.Rows)
{
DataRow[] rowList = dtBatches.Select("BatchItemID='" + row["ItemID"].ToString() + "'");
string BatchDetails = string.Empty;
if (rowList.Any())
{
foreach (DataRow dr in rowList)
{
BatchDetails = BatchDetails + " - " + "Batch No: " + dr["BatchNo"].ToString() + " Exp: " + Convert.ToDateTime(dr["Expiry Date"]).ToString("dd/MM/yy");
}
}
ItemDetails.Add(new DettaglioLinee
{
NumeroLinea = i,
Descrizione = row["Description"].ToString() + BatchDetails,
Quantita = Convert.ToInt32(row["Qty"]),
PrezzoUnitario = Convert.ToDecimal(row["Sell Price"]),
PrezzoTotale = Convert.ToDecimal(row["Amount"]),
AliquotaIVA = 0.00m,
Natura = "N4"
});
i++;
}
DatiBeniServizi12 = new DatiBeniServizi1
{
DettaglioLinee = ItemDetails,
DatiRiepilogo = new DatiRiepilogo1
{
AliquotaIVA = 0.00m,
Natura = "N4",
ImponibileImporto = Convert.ToDecimal(gvQuotationDetails.Rows[QuoteIndex].Cells["TotalQuoteAmount"].EditedFormattedValue),
Imposta = 0.00m,
RiferimentoNormativo = "rif normativo"
}
};
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("xsd", "http://www.w3.org/2001/XMLSchema");
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
ns.Add("versione", "FPA12");
XmlSerializer serializer = new XmlSerializer(typeof(FatturaElettronica), "http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2");
serializer.Serialize(System.IO.File.Create(#"C:\JD Pics\Schema_fatturapa_v1.3.xml"),DatiBeniServizi12,ns);
}
Final Output is
<DatiBeniServizi>
**<DettaglioLinee>
<DettaglioLinee>**
<NumeroLinea>1</NumeroLinea>
<Descrizione>ACARBOSE TAB 100MG 90 - Batch No: 854697 Exp: 15/11/20</Descrizione>
<Quantita>5</Quantita>
<PrezzoUnitario>30.50</PrezzoUnitario>
<PrezzoTotale>152.50</PrezzoTotale>
<AliquotaIVA>0.00</AliquotaIVA>
<Natura>N4</Natura>
</DettaglioLinee>
<DettaglioLinee>
<NumeroLinea>2</NumeroLinea>
<Descrizione>AEROCHAMBER PLUS DEVICE INFANT/MASK - Batch No: 748569 Exp: 23/11/20 - Batch No: 45789 Exp: 23/11/20</Descrizione>
<Quantita>400</Quantita>
<PrezzoUnitario>1.13</PrezzoUnitario>
<PrezzoTotale>452.00</PrezzoTotale>
<AliquotaIVA>0.00</AliquotaIVA>
<Natura>N4</Natura>
**</DettaglioLinee>
</DettaglioLinee>**
<DatiRiepilogo>
<AliquotaIVA>0.00</AliquotaIVA>
<Natura>N4</Natura>
<ImponibileImporto>604.50</ImponibileImporto>
<Imposta>0.00</Imposta>
<RiferimentoNormativo>rif normativo</RiferimentoNormativo>
</DatiRiepilogo>
</DatiBeniServizi>
So from the above XML everything is fine as per our requirement except the one highlighted in **
<DettaglioLinee>
<DettaglioLinee>
As you can see the node is repeated which is not the requirement.
This should work. It causes the list to be output in a flat structure - without the enclosing DettaglioLinee elements
[XmlElement]
List<DettaglioLinee> ItemDetails = new List<DettaglioLinee>();

JSON format writing to file

I want to write my items by JSON format, but My files empty. Here is my two class:
public class DocPart
{
public string Title { get; set; }
public bool Checked { get; set; }
}
public class DocConfig
{
public List<DocPart> Parts { get; set; }
public static DocConfig LoadFromString(string jsonData)
{
var config = new DocConfig();
config.Parts = new List<DocPart>();
var part = new DocPart
{
Title = "chapter1",
"chapter2",
Checked = checkBox1.Checked,
checkbox2.Checked
};
config.Parts.Add(part);
var configString = config.SaveToString();
File.WriteAllText(#"C:\link to my file", configString);
var configString = File.ReadAllText(#"C:\link to my file");
var config = DocConfig.LoadFromString(configString);
foreach (var part in config.Parts)
{
if (part.Title == "chapter1")
chekbox1.Checked = part.Checked;
if (part.Title == "chapter2")
checkbox2.Checked = part.Checked;
var serializer = new DataContractJsonSerializer(typeof(DocConfig));
var ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonData));
var config = (DocConfig)serializer.ReadObject(ms);
return config;
}
}
public string SaveToString()
{
var serializer = new DataContractJsonSerializer(typeof(DocConfig));
var ms = new MemoryStream();
serializer.WriteObject(ms, this);
return Encoding.UTF8.GetString(ms.ToArray());
}
}
So I run my program, everything looks okey, but my file is still empty without any JSON format data. Maybe you could help me?
Thanks.
public class DocPart
{
public string Title { get; set; }
public bool Checked { get; set; }
}
public class DocConfig
{
public List<DocPart> Parts { get; set; }
public static DocConfig LoadFromString()
{
var config = new DocConfig();
config.Parts = new List<DocPart>();
var part1 = new DocPart
{
Title = "chapter1",
Checked = checkBox1.Checked
};
config.Parts.Add(part1);
var part2 = new DocPart
{
Title = "chapter2",
Checked = checkBox2.Checked
};
config.Parts.Add(part2);
var configString = config.SaveToString();
File.WriteAllText(#"d:\temp\test.json", configString);
configString = File.ReadAllText(#"d:\temp\test.json");
var ms = new MemoryStream(Encoding.UTF8.GetBytes(configString));
var serializer = new DataContractJsonSerializer(typeof(DocConfig));
config = (DocConfig)serializer.ReadObject(ms);
foreach (var part in config.Parts)
{
if (part.Title == "chapter1")
{
chekbox1.Checked = part.Checked;
Debug.WriteLine("chapter1" + part.Checked);
}
if (part.Title == "chapter2")
{
checkbox2.Checked = part.Checked;
Debug.WriteLine("chapter2" + part.Checked);
}
}
return config;
}
public string SaveToString()
{
var serializer = new DataContractJsonSerializer(typeof(DocConfig));
var ms = new MemoryStream();
serializer.WriteObject(ms, this);
return Encoding.UTF8.GetString(ms.ToArray());
}
}
Here's a really simple example I mocked up for you...
void Main()
{
const string filePath = #"C:\FilePath\json.txt";
const string testJson = #"{""glossary"": {""title"": ""example glossary"", ""GlossDiv"": {""title"": ""S"", ""GlossList"": {""GlossEntry"": {""ID"": ""SGML"", ""SortAs"": ""SGML"", ""GlossTerm"": ""Standard Generalized Markup Language"", ""Acronym"": ""SGML"", ""Abbrev"": ""ISO 8879:1986"", ""GlossDef"": {""para"": ""A meta-markup language, used to create markup languages such as DocBook."", ""GlossSeeAlso"": [""GML"", ""XML""]}, ""GlossSee"": ""markup""}}}}}";
// Now we have our Json Object...
SampleJson sample = JsonConvert.DeserializeObject<SampleJson>(testJson);
// We convert it back into a string with indentation...
string jsonString = JsonConvert.SerializeObject(sample, Newtonsoft.Json.Formatting.Indented);
// Now simply save to file...
using (StreamWriter writer = new StreamWriter(filePath))
{
writer.WriteLine(jsonString);
}
Process.Start(filePath);
}
// The following classes are what the `testJson` string is deserialized into.
public class GlossDef
{
[JsonProperty("para")]
public string Para { get; set; }
[JsonProperty("GlossSeeAlso")]
public string[] GlossSeeAlso { get; set; }
}
public class GlossEntry
{
[JsonProperty("ID")]
public string ID { get; set; }
[JsonProperty("SortAs")]
public string SortAs { get; set; }
[JsonProperty("GlossTerm")]
public string GlossTerm { get; set; }
[JsonProperty("Acronym")]
public string Acronym { get; set; }
[JsonProperty("Abbrev")]
public string Abbrev { get; set; }
[JsonProperty("GlossDef")]
public GlossDef GlossDef { get; set; }
[JsonProperty("GlossSee")]
public string GlossSee { get; set; }
}
public class GlossList
{
[JsonProperty("GlossEntry")]
public GlossEntry GlossEntry { get; set; }
}
public class GlossDiv
{
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("GlossList")]
public GlossList GlossList { get; set; }
}
public class Glossary
{
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("GlossDiv")]
public GlossDiv GlossDiv { get; set; }
}
public class SampleJson
{
[JsonProperty("glossary")]
public Glossary Glossary { get; set; }
}

protobuf-net Sub-message not read correctly

I'm currently testing protobuf-net (latest version), but intermittently I'm getting "Sub-message not read correctly" exception while deserializing. So far there's no apparent pattern to reproduce this error, and the data is always the same.
I googled this error and so far people reported this error only when dealing with big data (>20MB), which I'm not doing.
Can anyone point out whether this is a bug (and if it is, any possible solution to fix/circumvent this?), or am I missing some steps? Below is the code I'm using:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using ProtoBuf;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
const string message = "Cycle {0}: {1:N2} ms - avg: {2:N2} ms - min: {3:N2} - max: {4:N2}";
const int loop = 1000;
var counter = new Stopwatch();
var average = 0d;
var min = double.MaxValue;
var max = double.MinValue;
for (int i = 0;; i++)
{
var classThree = Create();
counter.Reset();
counter.Start();
Parallel.For(0, loop, j =>
{
using (var ms = new MemoryStream())
{
Serializer.Serialize(ms, classThree);
using (var ms2 = new MemoryStream(ms.ToArray()))
{
var des = Serializer.Deserialize<ClassThree>(ms2);
var aaa = des;
}
}
});
counter.Stop();
var elapsed = counter.Elapsed.TotalMilliseconds;
average += elapsed;
min = Math.Min(min, elapsed);
max = Math.Max(max, elapsed);
var currentAverage = average / (i + 1);
Console.Clear();
Console.WriteLine(message, i, elapsed, currentAverage, min, max);
Thread.Sleep(0);
}
}
private static ClassThree Create()
{
var classOne = new ClassSix()
{
// properties
p_i1 = -123,
p_i2 = 456,
p_l1 = -456,
p_l2 = 123,
p_s = "str",
p_f = 12.34f,
p_d = 56.78d,
p_bl = true,
p_dt = DateTime.Now.AddMonths(-1),
p_m = 90.12m,
p_b1 = 12,
p_b2 = -34,
p_c = 'c',
p_s1 = -21,
p_s2 = 43,
p_ts = new TimeSpan(12, 34, 56),
p_id = Guid.NewGuid(),
p_uri = new Uri("http://www.google.com"),
p_ba = new[] { (byte)1, (byte)3, (byte)2 },
p_t = typeof(ClassTwo),
p_sa = new[] { "aaa", "bbb", "ccc" },
p_ia = new[] { 7, 4, 9 },
p_e1 = EnumOne.Three,
p_e2 = EnumTwo.One | EnumTwo.Two,
p_list = new List<ClassFive>(new[]
{
new ClassFive()
{
i = 1,
s = "1"
},
new ClassFive()
{
i = 2,
s = "2"
}
}),
// fields
f_i1 = -123,
f_i2 = 456,
f_l1 = -456,
f_l2 = 123,
f_s = "str",
f_f = 12.34f,
f_d = 56.78d,
f_bl = true,
f_dt = DateTime.Now.AddMonths(-1),
f_m = 90.12m,
f_b1 = 12,
f_b2 = -34,
f_c = 'c',
f_s1 = -21,
f_s2 = 43,
f_ts = new TimeSpan(12, 34, 56),
f_id = Guid.NewGuid(),
f_uri = new Uri("http://www.google.com"),
f_ba = new[] { (byte)1, (byte)3, (byte)2 },
f_t = typeof(ClassTwo),
f_sa = new[] { "aaa", "bbb", "ccc" },
f_ia = new[] { 7, 4, 9 },
f_e1 = EnumOne.Three,
f_e2 = EnumTwo.One | EnumTwo.Two,
f_list = new List<ClassFive>(new[]
{
new ClassFive()
{
i = 1,
s = "1"
},
new ClassFive()
{
i = 2,
s = "2"
}
})
};
var classThree = new ClassThree()
{
ss = "333",
one = classOne,
two = classOne
};
return classThree;
}
}
public enum EnumOne
{
One = 1,
Two = 2,
Three = 3
}
[Flags]
public enum EnumTwo
{
One = 1,
Two = 2,
Three = 4
}
[ProtoContract, ProtoInclude(51, typeof(ClassSix))]
public class ClassOne
{
// properties
[ProtoMember(1)]
public int p_i1 { set; get; }
[ProtoMember(2)]
public uint p_i2 { set; get; }
[ProtoMember(3)]
public long p_l1 { set; get; }
[ProtoMember(4)]
public ulong p_l2 { set; get; }
[ProtoMember(5)]
public string p_s { set; get; }
[ProtoMember(6)]
public float p_f { set; get; }
[ProtoMember(7)]
public double p_d { set; get; }
[ProtoMember(8)]
public bool p_bl { set; get; }
[ProtoMember(9)]
public DateTime p_dt { set; get; }
[ProtoMember(10)]
public decimal p_m { set; get; }
[ProtoMember(11)]
public byte p_b1 { set; get; }
[ProtoMember(12)]
public sbyte p_b2 { set; get; }
[ProtoMember(13)]
public char p_c { set; get; }
[ProtoMember(14)]
public short p_s1 { set; get; }
[ProtoMember(15)]
public ushort p_s2 { set; get; }
[ProtoMember(16)]
public TimeSpan p_ts { set; get; }
[ProtoMember(17)]
public Guid p_id { set; get; }
[ProtoMember(18)]
public Uri p_uri { set; get; }
[ProtoMember(19)]
public byte[] p_ba { set; get; }
[ProtoMember(20)]
public Type p_t { set; get; }
[ProtoMember(21)]
public string[] p_sa { set; get; }
[ProtoMember(22)]
public int[] p_ia { set; get; }
[ProtoMember(23)]
public EnumOne p_e1 { set; get; }
[ProtoMember(24)]
public EnumTwo p_e2 { set; get; }
[ProtoMember(25)]
public List<ClassFive> p_list { set; get; }
// fields
[ProtoMember(26)]
public int f_i1 = 0;
[ProtoMember(27)]
public uint f_i2 = 0;
[ProtoMember(28)]
public long f_l1 = 0L;
[ProtoMember(29)]
public ulong f_l2 = 0UL;
[ProtoMember(30)]
public string f_s = string.Empty;
[ProtoMember(31)]
public float f_f = 0f;
[ProtoMember(32)]
public double f_d = 0d;
[ProtoMember(33)]
public bool f_bl = false;
[ProtoMember(34)]
public DateTime f_dt = DateTime.MinValue;
[ProtoMember(35)]
public decimal f_m = 0m;
[ProtoMember(36)]
public byte f_b1 = 0;
[ProtoMember(37)]
public sbyte f_b2 = 0;
[ProtoMember(38)]
public char f_c = (char)0;
[ProtoMember(39)]
public short f_s1 = 0;
[ProtoMember(40)]
public ushort f_s2 = 0;
[ProtoMember(41)]
public TimeSpan f_ts = TimeSpan.Zero;
[ProtoMember(42)]
public Guid f_id = Guid.Empty;
[ProtoMember(43)]
public Uri f_uri = null;
[ProtoMember(44)]
public byte[] f_ba = null;
[ProtoMember(45)]
public Type f_t = null;
[ProtoMember(46)]
public string[] f_sa = null;
[ProtoMember(47)]
public int[] f_ia = null;
[ProtoMember(48)]
public EnumOne f_e1 = 0;
[ProtoMember(49)]
public EnumTwo f_e2 = 0;
[ProtoMember(50)]
public List<ClassFive> f_list = null;
}
[ProtoContract]
public class ClassSix : ClassOne
{
}
[ProtoContract]
public class ClassTwo
{
}
[ProtoContract]
public interface IClass
{
[ProtoMember(1)]
string ss
{
set;
get;
}
[ProtoMember(2)]
ClassOne one
{
set;
get;
}
}
[ProtoContract]
public class ClassThree : IClass
{
[ProtoMember(1)]
public string ss { set; get; }
[ProtoMember(2)]
public ClassOne one { set; get; }
[ProtoMember(3)]
public ClassSix two { set; get; }
}
[ProtoContract]
public class ClassFour
{
[ProtoMember(1)]
public string ss { set; get; }
[ProtoMember(2)]
public ClassOne one { set; get; }
}
[ProtoContract]
public class ClassFive
{
[ProtoMember(1)]
public int i { set; get; }
[ProtoMember(2)]
public string s { set; get; }
}
}
Updated to rev. 669 and so far haven't encounter the error again. So I'm reporting this as fixed for now.

Categories

Resources