private void InitCollection() { _list = new List<StockWrapper>(); _itemKeyDic = new MultiSortedDictionary<string, StockWrapper>(); _invenKeyDic = new MultiSortedDictionary<string, StockWrapper>(); InOutStock[] stocks = null; using (var db = LexDb.GetDbInstance()) { stocks = db.LoadAll<InOutStock>(); } #if DEBUG foreach (var stock in stocks) { Debug.Assert(stock.ID != null); Debug.Assert(stock.ItemID != null); Debug.Assert(stock.SpecificationID != null); Debug.Assert(stock.StockType != IOStockType.NONE); } #endif _list.AddRange(stocks.Select(x => new StockWrapper(x))); _itemKeyDic = new MultiSortedDictionary<string, StockWrapper>(); foreach (var item in _list) { _itemKeyDic.Add(item.Item.ID, item); _invenKeyDic.Add(item.Inventory.ID, item); } }
private void InitCollection() { _list = new List<InventoryWrapper>(); _IDDic = new SortedDictionary<string, InventoryWrapper>(); _specificationKeyDic = new SortedDictionary<string, InventoryWrapper>(); _itemKeyDic = new MultiSortedDictionary<string, InventoryWrapper>(); Inventory[] invens = null; using (var db = LexDb.GetDbInstance()) { invens = db.LoadAll<Inventory>(); } #if DEBUG //아래 3조건은 올바른 입력 아래에서 절대 일어날 수 없는 케이스이다. foreach (var inven in invens) { Debug.Assert(inven.ID != null); Debug.Assert(inven.ItemID != null); Debug.Assert(inven.SpecificationID != null); } #endif _list.AddRange(invens.Select(x => new InventoryWrapper(x))); foreach (var inventoryWrapper in _list) { _IDDic.Add(inventoryWrapper.ID, inventoryWrapper); _specificationKeyDic.Add(inventoryWrapper.Specification.ID, inventoryWrapper); _itemKeyDic.Add(inventoryWrapper.Item.ID, inventoryWrapper); } }
public void Close() { Reset(); this.db = null; this.block_num = null; }
public void SaveBlockUrls() { Logger.Log("saving block urls"); XmlDocument doc = new XmlDocument(); doc.Load(GetConfigFilePath()); XmlNodeList nodes = doc.GetElementsByTagName("Config"); XmlElement root; if (nodes.Count != 0) { root = nodes.Item(0) as XmlElement; } else // doesn't exist { root = doc.CreateElement("Config"); doc.AppendChild(root); } // save current int i = 0; // sort blockurls by datetime in descending order MultiSortedDictionary<long, string> sortedBlockUrls = new MultiSortedDictionary<long, string>(new LongReverseComparer()); foreach (KeyValuePair<string, long> kvp in blockUrls) { sortedBlockUrls.Add(kvp.Value, kvp.Key); } // add from sorted foreach(long dt in sortedBlockUrls.Keys) { foreach (string url in sortedBlockUrls[dt]) { if (i >= maxNumOfBlockUrls) break; string name = BlockUrlPrefix + i.ToString(); Logger.DLog("save block url, {0} - {1}", name, url); nodes = doc.GetElementsByTagName(name); if (nodes.Count != 0) { XmlElement elem = nodes.Item(0) as XmlElement; elem.Attributes.Item(0).Value = url; } else { XmlElement elem = doc.CreateElement(name); root.AppendChild(elem); elem.SetAttribute("Url", url); elem.SetAttribute("DateTime", dt.ToString()); } i++; } } // clear old for (i = blockUrls.Count; i < maxNumOfBlockUrls; i++) { string name = BlockUrlPrefix + i.ToString(); Logger.DLog("remove block url, {0}", name); nodes = doc.GetElementsByTagName(name); if (nodes.Count != 0) { XmlElement elem = nodes.Item(0) as XmlElement; root.RemoveChild(elem); } } doc.Save(GetConfigFilePath()); Logger.Log("saving block urls DONE."); }