/// <summary> /// Serializes the specified object. /// </summary> /// <param name="obj">The object.</param> /// <param name="stream">The stream.</param> public void Serialize(object obj, Stream stream) { var interpertor = new Interpreter(); //Creates internal object model from an object, which XmlStreamWrite will write into a stream BaseDescriptor descriptor = interpertor.Interpret(obj, MemberFilter); StreamFactory.CreateWriter().Write(stream, descriptor); }
/// <summary> /// Ruft die Meldedatei mit einem bestimmten Dateinamen aus dem Deuev-Ordner ab /// </summary> /// <param name="fileName"> /// Dateiname der Meldedatei /// </param> /// <param name="name"> /// Name in der Meldungen.xml /// </param> /// <returns> /// Meldedatei als DeuevMessageData-Objekt /// </returns> private DsraMessageData GetMessageFromFile(string fileName, string name) { var input = string.Join(string.Empty, File.ReadAllLines(fileName).Select(x => x + Environment.NewLine)); var output = new StringWriter(); var writer = StreamFactory.CreateWriter(name, output); var reader = StreamFactory.CreateReader(name, new StringReader(input)); var deuevMessage = new DsraMessageData(); try { var streamObject = reader.Read(); do { var vosz = Assert.IsType <VOSZ>(streamObject); deuevMessage.VOSZ.Add(vosz); writer.Write(vosz); streamObject = reader.Read(); }while (reader.RecordName == "VOSZ" || reader.RecordName == "VOSZ-v01"); if (reader.RecordName == "DSKO" || reader.RecordName == "DSKO-v04") { var dsko = Assert.IsType <DSKO04>(streamObject); writer.Write(dsko); streamObject = reader.Read(); } while (reader.RecordName == "DSRA" || reader.RecordName == "DSRA-v01") { var record = Assert.IsType <DSRA01>(streamObject); deuevMessage.DSRA01.Add(record); writer.Write(record); streamObject = reader.Read(); } do { var ncsz = Assert.IsType <NCSZ>(streamObject); writer.Write(streamObject); deuevMessage.NCSZ.Add(ncsz); streamObject = reader.Read(); }while (reader.RecordName != null && (reader.RecordName == "NCSZ" || reader.RecordName == "NCSZ-v01")); Assert.Null(reader.RecordName); Assert.Equal(deuevMessage.VOSZ.Count, deuevMessage.NCSZ.Count); writer.Close(); string output2 = output.ToString(); Assert.Equal(input, output2); return(deuevMessage); } finally { reader.Close(); } }
/// <summary> /// Ruft die Meldedatei mit einem bestimmten Dateinamen aus dem Deuev-Ordner ab /// </summary> /// <param name="input">Die Meldedatei</param> /// <param name="name">Name in der Meldungen.xml</param> /// <returns>Meldedatei als DeuevMessageData-Objekt</returns> private BwnaMessageData GetMessageFromString(string input, string name) { var output = new StringWriter(); var writer = StreamFactory.CreateWriter(name, output); var reader = StreamFactory.CreateReader(name, new StringReader(input)); var deuevMessage = new BwnaMessageData(); try { var streamObject = reader.Read(); do { var vosz = Assert.IsType <VOSZ>(streamObject); deuevMessage.VOSZ.Add(vosz); writer.Write(vosz); streamObject = reader.Read(); }while (reader.RecordName == "VOSZ" || reader.RecordName == "VOSZ-v01"); var dsko = Assert.IsType <DSKO02>(streamObject); deuevMessage.DSKO = dsko; writer.Write(dsko); streamObject = reader.Read(); while (reader.RecordName == "DSBE" || reader.RecordName == "DSBE-v01") { var record = Assert.IsType <DSBE01>(streamObject); deuevMessage.DSBEv01.Add(record); writer.Write(record); streamObject = reader.Read(); } do { var ncsz = Assert.IsType <NCSZ>(streamObject); writer.Write(streamObject); deuevMessage.NCSZ.Add(ncsz); streamObject = reader.Read(); }while (reader.RecordName != null && (reader.RecordName == "NCSZ" || reader.RecordName == "NCSZ-v01")); Assert.Null(reader.RecordName); Assert.Equal(deuevMessage.VOSZ.Count, deuevMessage.NCSZ.Count); writer.Close(); string output2 = output.ToString(); Assert.Equal(input, output2); return(deuevMessage); } finally { reader.Close(); } }
/// <summary> /// Erstellt die Meldedatei anhand von <paramref name="data"/> neu. /// </summary> /// <param name="data">Die Daten die zur Erstellung der Meldedatei benutzt werden sollen</param> /// <param name="streamName">Der Name des Streams der für die Erstellung der Meldedatei benutzt werden soll</param> /// <returns>Die Meldedatei</returns> private string GetStringFromMessage(BwnaMessageData data, string streamName) { var output = new StringWriter(); var writer = StreamFactory.CreateWriter(streamName, output); foreach (var record in data.VOSZ) { writer.Write(record); } writer.Write(data.DSKO); foreach (var record in data.BW02) { writer.Write(record); } foreach (var record in data.NCSZ) { writer.Write(record); } writer.Close(); return(output.ToString()); }
/// <summary> /// Erstellt die Meldedatei anhand von <paramref name="data"/> neu. /// </summary> /// <param name="data">Die Daten die zur Erstellung der Meldedatei benutzt werden sollen</param> /// <param name="streamName">Der Name des Streams der für die Erstellung der Meldedatei benutzt werden soll</param> /// <returns>Die Meldedatei</returns> private string GetStringFromMessage(DeuevMessageData data, string streamName) { var output = new StringWriter(); using (var writer = StreamFactory.CreateWriter(streamName, output)) { foreach (var record in data.VOSZ) { writer.Write(record); } foreach (var record in data.DSKK) { writer.Write(record); } foreach (var record in data.NCSZ) { writer.Write(record); } } return(output.ToString()); }
/// <summary> /// Ruft die Meldedatei mit einem bestimmten Dateinamen aus dem Deuev-Ordner ab /// </summary> /// <param name="fileName"> /// Dateiname der Meldedatei /// </param> /// <param name="name"> /// Name in der Meldungen.xml /// </param> /// <returns> /// Meldedatei als DeuevMessageData-Objekt /// </returns> private BwnaMessageData GetMessageFromFile(string fileName, string name) { var input = LoadData(fileName).ReadToEnd(); var output = new StringWriter(); var writer = StreamFactory.CreateWriter(name, output); var reader = StreamFactory.CreateReader(name, new StringReader(input)); var deuevMessage = new BwnaMessageData(); try { var streamObject = reader.Read(); do { var vosz = Assert.IsType <VOSZ>(streamObject); deuevMessage.VOSZ.Add(vosz); writer.Write(vosz); streamObject = reader.Read(); }while (reader.RecordName == "VOSZ" || reader.RecordName == "VOSZ-v01"); var dsko = Assert.IsType <DSKO02>(streamObject); deuevMessage.DSKO = dsko; writer.Write(dsko); streamObject = reader.Read(); while (reader.RecordName == "DSER" || reader.RecordName == "DSER-v02" || reader.RecordName == "DSER-v03") { switch (name) { case "dser-agger-v02": { var record = Assert.IsType <DSER02>(streamObject); deuevMessage.DSER02.Add(record); writer.Write(record); } break; case "dser-agger-v03": { var record = Assert.IsType <DSER03>(streamObject); deuevMessage.DSER03.Add(record); writer.Write(record); } break; case "super-message": switch (reader.RecordName) { case "DSER-v02": { var record = Assert.IsType <DSER02>(streamObject); deuevMessage.DSER02.Add(record); writer.Write(record); } break; case "DSER-v03": { var record = Assert.IsType <DSER03>(streamObject); deuevMessage.DSER03.Add(record); writer.Write(record); } break; default: throw new InvalidOperationException(string.Format("Unsupported record {0}", reader.RecordName)); } break; default: throw new InvalidOperationException(string.Format("Unsupported stream {0}", name)); } streamObject = reader.Read(); } do { var ncsz = Assert.IsType <NCSZ>(streamObject); writer.Write(streamObject); deuevMessage.NCSZ.Add(ncsz); streamObject = reader.Read(); }while (reader.RecordName != null && (reader.RecordName == "NCSZ" || reader.RecordName == "NCSZ-v01")); Assert.Null(reader.RecordName); Assert.Equal(deuevMessage.VOSZ.Count, deuevMessage.NCSZ.Count); writer.Close(); string output2 = output.ToString(); Assert.Equal(input, output2); return(deuevMessage); } finally { reader.Close(); } }
private string BuildRequestFile(StreamFactory streamFactory, int fileNumber, DateTime creationTimestamp, IEnumerable <Person> personen) { var registration = Dataline.Common.Constants.SocialInsurance.Registrations.Dataline; var output = new StringWriter(); using (var writer = streamFactory.CreateWriter("dsvv-deuev-v01", output)) { var vosz = new VOSZ() { VFMM = "AGTRV", ABSN = _sender.Betriebsnummer, EPNR = DsrvConstants.Betriebsnummer, ED = LocalDateTime.FromDateTime(creationTimestamp).Date, DTNR = fileNumber, NAAB = _sender.Name1, }; writer.Write(vosz); var dsko = new DSKO04() { VF = "DEUEV", ABSN = _sender.Betriebsnummer, EPNR = DsrvConstants.Betriebsnummer, ED = creationTimestamp, ABSNER = _company.Betriebsnummer, PRODID = registration.ProductId, MODID = registration.ModificationId, NAME1 = _company.Name1, PLZ = _company.PLZ, ORT = _company.Ort, STR = _company.Strasse, ANRAP = _sender.IstFrau ? "W" : "M", NAMEAP = _sender.Ansprechpartner, TELAP = _sender.Telefon, FAXAP = _sender.Fax, EMAILAP = _sender.Email, }; writer.Write(dsko); var personCount = 0; foreach (var person in personen) { personCount += 1; var dsvv = new DSVV01() { ABSN = _sender.Betriebsnummer, EPNR = DsrvConstants.Betriebsnummer, ED = creationTimestamp, KENNZRM = DSVV01Status.Grundstellung, BBNRVU = _company.Betriebsnummer, DSID = XmlConvert.ToString(person.Id), AZVU = person.Personalnummer, MMUEB = 1, DBNA = new DBNA() { FMNA = person.Nachname, VONA = person.Vorname, }, DBGB = new DBGB() { GBDT = LocalDate.FromDateTime(person.Gebdat), GBNA = person.GeburtsName, GBOT = person.GeburtsOrt, GE = person.IstMann ? "M" : "W", }, DBAN = new DBAN() { LDKZ = person.LandKennzeichen, PLZ = person.PLZ, ORT = person.Ort, STR = person.Strasse }, }; writer.Write(dsvv); } var ncsz = new NCSZ() { VFMM = "AGTRV", ABSN = _sender.Betriebsnummer, EPNR = DsrvConstants.Betriebsnummer, ED = LocalDateTime.FromDateTime(creationTimestamp).Date, DTNR = fileNumber, ZLSZ = personCount + 1, }; writer.Write(ncsz); writer.Close(); } var records = output.ToString().Split('\n').Select(x => x.TrimEnd('\r')).Where(x => !string.IsNullOrEmpty(x)).ToArray(); Validate(records); return(string.Join("\r\n", records)); }