public GncCommodity(GncBook book, XElement xml) : this(book) { _space = xml.ChkElement(GncName.Cmdty("space")).Value; _name = xml.ChkElement(GncName.Cmdty("id")).Value; _identifier = MakeIdentifier(_space, _name); }
public GncCommodity(GncBook book, string identifier = null, string space = null, string name = null) { _book = book; _identifier = identifier; _space = space; _name = name; _exrate = new GncTimeSeries(); }
public GncTransaction(GncBook book) { _book = book; _guid = null; _datePosted = new DateTime(); _dateEntered = new DateTimeOffset(); _num = ""; _description = null; _splits = new Dictionary <string, GncSplit>(); }
public GncAccount(GncBook book, XElement xml) : this(book) { _name = xml.ChkElement(GncName.Act("name")).Value; _guid = xml.ChkElement(GncName.Act("id")).Value; _parentGuid = xml.ValueOrDefault(GncName.Act("parent"), (string)null); _commodity = book.GetCommodity(GncCommodity.MakeIdentifier(xml.Element(GncName.Act("commodity")))); if (_commodity == null && xml.Element(GncName.Act("type"))?.Value == "ROOT") { _commodity = _book.BaseCurrency; } string scu = xml.ValueOrDefault(GncName.Act("commodity-scu"), "1"); _commodityDecimals = scu.Count(c => c == '0'); if (scu != "1" + new string('0', _commodityDecimals)) { throw new Exception("Could not parse commodity-scu: expected a power of 10."); } _commodityScu = int.Parse(scu); _description = xml.ValueOrDefault(GncName.Act("description"), (string)null); }
public void LoadFromFile(string file, string baseCurrency, string balsnapPrefix) { Clear(); _balsnapPrefix = balsnapPrefix; XDocument doc; _modifiedTimestamp = File.GetLastWriteTimeUtc(file); try { using (var gz = new GZipStream(File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read), CompressionMode.Decompress)) using (var sr = new StreamReader(gz)) doc = XDocument.Load(sr); } catch { try { doc = XDocument.Load(file); } catch (Exception E) { throw new GncException("Cannot parse XML file: " + E.Message); } } if (doc.Root.Name != "gnc-v2") { throw new GncException("Cannot load file: root node name is not \"gnc-v2\""); } foreach (var el in doc.Root.Elements(GncName.Gnc("book"))) { GncBook book = new GncBook(this, el, baseCurrency); _books.Add(book.Guid, book); if (Book == null) { _book = book; } else { throw new GncException("Multiple books in the file; this is currently entirely untested."); } } }
public GncTransaction(GncBook book, XElement xml) : this(book) { _guid = xml.ChkElement(GncName.Trn("id")).Value; _datePosted = DateTimeOffset.Parse(xml.ChkElement(GncName.Trn("date-posted")).ChkElement(GncName.Ts("date")).Value).Date.AssumeUtc(); _dateEntered = DateTimeOffset.Parse(xml.ChkElement(GncName.Trn("date-entered")).ChkElement(GncName.Ts("date")).Value).UtcDateTime; _num = xml.ValueOrDefault(GncName.Trn("num"), ""); _description = xml.ChkElement(GncName.Trn("description")).Value; _commodity = _book.GetCommodity(GncCommodity.MakeIdentifier(xml.ChkElement(GncName.Trn("currency")))); foreach (var el in xml.ChkElement(GncName.Trn("splits")).Elements(GncName.Trn("split"))) { try { GncSplit split = new GncSplit(this, el); _splits.Add(split.Guid, split); } catch (Exception e) { throw new Exception($"Could not read split for transaction: {_datePosted}, descr {_description}, {e.Message} ({_guid})", e); } } }
public void Clear() { _books = new Dictionary <string, GncBook>(); _book = null; }
public GncAccount(GncBook book) { _book = book; }