private void ReadStreamAux(Stream stream) { if (ThrowErrors) { Callbacks.SieException += throwCallbackException; } #region Initialize lists FNAMN = new SieCompany(); KONTO = new Dictionary <string, SieAccount>(); DIM = new Dictionary <string, SieDimension>(); OIB = new List <SiePeriodValue>(); OUB = new List <SiePeriodValue>(); PSALDO = new List <SiePeriodValue>(); PBUDGET = new List <SiePeriodValue>(); PROGRAM = new List <string>(); RAR = new Dictionary <int, SieBookingYear>(); IB = new List <SiePeriodValue>(); UB = new List <SiePeriodValue>(); RES = new List <SiePeriodValue>(); VER = new List <SieVoucher>(); ValidationExceptions = new List <Exception>(); InitializeDimensions(); #endregion //Initialize listst using (var sr = new StreamReader(stream, Encoding.GetEncoding(437))) { if (parseLines(sr)) { return; } } validateDocument(); }
public void ReadDocument(string fileName) { _fileName = fileName; if (ThrowErrors) { Callbacks.SieException += throwCallbackException; } #region Initialize lists FNAMN = new SieCompany(); KONTO = new Dictionary <string, SieAccount>(); DIM = new Dictionary <string, SieDimension>(); OIB = new List <SiePeriodValue>(); OUB = new List <SiePeriodValue>(); PSALDO = new List <SiePeriodValue>(); PBUDGET = new List <SiePeriodValue>(); PROGRAM = new List <string>(); RAR = new Dictionary <int, SieBookingYear>(); IB = new List <SiePeriodValue>(); UB = new List <SiePeriodValue>(); RES = new List <SiePeriodValue>(); VER = new List <SieVoucher>(); ValidationExceptions = new List <Exception>(); InitializeDimensions(); #endregion //Initialize listst SieVoucher curVoucher = null; bool firstLine = true; foreach (var line in File.ReadLines(_fileName, Encoding.GetEncoding(437))) { Callbacks.CallbackLine(line); var di = new SieDataItem(line, this); if (firstLine) { firstLine = false; if (di.ItemType != "#FLAGGA") { Callbacks.CallbackException(new SieInvalidFileException(_fileName)); return; } } if (CRC.Started && di.ItemType != "#KSUMMA") { CRC.AddData(di); } SiePeriodValue pv = null; switch (di.ItemType) { case "#ADRESS": FNAMN.Contact = di.GetString(0); FNAMN.Street = di.GetString(1); FNAMN.ZipCity = di.GetString(2); FNAMN.Phone = di.GetString(3); break; case "#BKOD": FNAMN.SNI = di.GetInt(0); break; case "#BTRANS": if (!IgnoreBTRANS) { parseTRANS(di, curVoucher); } break; case "#DIM": parseDimension(di); break; case "#ENHET": parseENHET(di); break; case "#FLAGGA": FLAGGA = di.GetInt(0); break; case "#FNAMN": FNAMN.Name = di.GetString(0); break; case "#FNR": FNAMN.Code = di.GetString(0); break; case "#FORMAT": FORMAT = di.GetString(0); break; case "#FTYP": FNAMN.OrgType = di.GetString(0); break; case "#GEN": GEN_DATE = di.GetDate(0); GEN_NAMN = di.GetString(1); break; case "#IB": parseIB(di); break; case "#KONTO": parseKONTO(di); break; case "#KSUMMA": if (CRC.Started) { parseKSUMMA(di); } else { CRC.Start(); } break; case "#KTYP": parseKTYP(di); break; case "#KPTYP": KPTYP = di.GetString(0); break; case "#OBJEKT": parseOBJEKT(di); break; case "#OIB": pv = parseOIB_OUB(di); Callbacks.CallbackOIB(pv); if (!StreamValues) { OIB.Add(pv); } break; case "#OUB": pv = parseOIB_OUB(di); Callbacks.CallbackOUB(pv); if (!StreamValues) { OUB.Add(pv); } break; case "#ORGNR": FNAMN.OrgIdentifier = di.GetString(0); break; case "#OMFATTN": OMFATTN = di.GetDate(0); break; case "#PBUDGET": pv = parsePBUDGET_PSALDO(di); if (pv != null) { Callbacks.CallbackPBUDGET(pv); if (!StreamValues) { PBUDGET.Add(pv); } } break; case "#PROGRAM": PROGRAM = di.Data; break; case "#PROSA": PROSA = di.GetString(0); break; case "#PSALDO": pv = parsePBUDGET_PSALDO(di); if (pv != null) { Callbacks.CallbackPSALDO(pv); if (!StreamValues) { PSALDO.Add(pv); } } break; case "#RAR": parseRAR(di); break; case "#RTRANS": if (!IgnoreBTRANS) { parseTRANS(di, curVoucher); } break; case "#SIETYP": SIETYP = di.GetInt(0); break; case "#SRU": parseSRU(di); break; case "#TAXAR": TAXAR = di.GetInt(0); break; case "#UB": parseUB(di); break; case "#TRANS": parseTRANS(di, curVoucher); break; case "#RES": parseRES(di); break; case "#VALUTA": VALUTA = di.GetString(0); break; case "#VER": curVoucher = parseVER(di); break; case "": //Empty line break; case "{": break; case "}": if (curVoucher != null) { closeVoucher(curVoucher); } curVoucher = null; break; default: Callbacks.CallbackException(new NotImplementedException(di.ItemType)); break; } } validateDocument(); }