public static void Main(string[] args) { try { Console.Write("Checking for existing key: "); string key = SessionManager.GetInstance().GameSession.Key; ok(); } catch (GameSessionRequiredException) { error(); Console.Write("Locating Guild Wars 2 process: "); Process gw2 = findProcess(m_PROCESS_NAME); if (gw2 == null) { error(); return; } else { ok(); } Console.Write("Locating game session key: "); string key = findSessionKey(gw2); if (key == null) { error(); return; } else { ok(); } SessionManager.GetInstance().GameSession = new Session(key, true); } Console.Write("Loading excel database: "); ExcelDatabase db = ExcelDatabase.LoadFromFile(m_EXCEL_DB); ok(); Console.Write("Updating listings: "); updateListings(db); ok(); Console.Write("Saving database to file: "); db.SaveToFile(m_EXCEL_DB); ok(); }
public static ExcelDatabase LoadFromFile(string file) { ExcelDatabase db = new ExcelDatabase(); if (File.Exists(file)) { Stream fileStream = File.OpenRead(file); ExcelPackage excel = new ExcelPackage(fileStream); fileStream.Close(); ExcelWorksheet sheet = excel.Workbook.Worksheets[m_WORKSHEET_NAME]; if (sheet != null) { for (int rowIdx = 2; rowIdx <= sheet.Dimension.End.Row; rowIdx++) { object oListingId = sheet.Cells[rowIdx, (int)SheetColumnIdx.LISTING_ID].Value; // long object oItemId = sheet.Cells[rowIdx, (int)SheetColumnIdx.ITEM_ID].Value; // long object oItemName = sheet.Cells[rowIdx, (int)SheetColumnIdx.ITEM_NAME].Value; // string object oItemLevel = sheet.Cells[rowIdx, (int)SheetColumnIdx.ITEM_LEVEL].Value; // int object oItemRarity = sheet.Cells[rowIdx, (int)SheetColumnIdx.ITEM_RARITY].Value; // string object oQuantity = sheet.Cells[rowIdx, (int)SheetColumnIdx.QUANTITY].Value; // long object oPrice = sheet.Cells[rowIdx, (int)SheetColumnIdx.PRICE].Value; // long object oListingTime = sheet.Cells[rowIdx, (int)SheetColumnIdx.LISTING_TIME].Value; // datetime object oFulfilledTime = sheet.Cells[rowIdx, (int)SheetColumnIdx.FULFILLED_TIME].Value; // datetime object oType = sheet.Cells[rowIdx, (int)SheetColumnIdx.TYPE].Value; // enum object oCancelled = sheet.Cells[rowIdx, (int)SheetColumnIdx.CANCELLED].Value; // bool if (oListingId == null || oItemId == null || oItemName == null || oItemLevel == null || oItemRarity == null || oQuantity == null || oPrice == null || oListingTime == null || oType == null) continue; long listingId, itemId, quantity, price; int itemLevel; double listingTimeOA; ListingInfo.ListingType type; if (!long.TryParse(oListingId.ToString(), out listingId) || !long.TryParse(oItemId.ToString(), out itemId) || !long.TryParse(oQuantity.ToString(), out quantity) || !long.TryParse(oPrice.ToString(), out price) || !int.TryParse(oItemLevel.ToString(), out itemLevel) || !double.TryParse(oListingTime.ToString(), out listingTimeOA) || !Enum.TryParse<ListingInfo.ListingType>(oType.ToString(), out type)) continue; DateTime listingTime = DateTime.FromOADate(listingTimeOA); string itemName = oItemName.ToString(); string itemRarity = oItemRarity.ToString(); // BUGFIX: rarity was being set to level for awhile, this attempts to restore the proper // rarity that was lost BugFixes.Fix_001(ref itemRarity); double fulfilledTimeOA; DateTime? fulfilledTime = null; if (oFulfilledTime != null && double.TryParse(oFulfilledTime.ToString(), out fulfilledTimeOA)) fulfilledTime = DateTime.FromOADate(fulfilledTimeOA); bool cancelled = false; if (oCancelled != null && !bool.TryParse(oCancelled.ToString(), out cancelled)) cancelled = false; db.Listings[listingId] = new ListingInfo() { ListingId = listingId, ItemId = itemId, ItemName = itemName, ItemLevel = itemLevel, ItemRarity = itemRarity, Quantity = quantity, Price = price, ListingTime = listingTime, FulfilledTime = fulfilledTime, Type = type, Cancelled = cancelled }; } } } return db; }
private static void updateListings(ExcelDatabase db) { // buckets to put orders into IDictionary<long, ListingInfo> buy_past_fulfilled = new Dictionary<long, ListingInfo>(); IDictionary<long, ListingInfo> buy_past_cancelled = new Dictionary<long, ListingInfo>(); IDictionary<long, ListingInfo> buy_now = new Dictionary<long, ListingInfo>(); IDictionary<long, ListingInfo> sell_past_fulfilled = new Dictionary<long, ListingInfo>(); IDictionary<long, ListingInfo> sell_past_cancelled = new Dictionary<long, ListingInfo>(); IDictionary<long, ListingInfo> sell_now = new Dictionary<long, ListingInfo>(); // siphon through the current database, throwing stuff into the proper buckets foreach (ListingInfo listing in db.Listings.Values) { switch (listing.Type) { case ListingInfo.ListingType.BUY: if (listing.Fulfilled) buy_past_fulfilled[listing.ListingId] = listing; else if (listing.Cancelled) buy_past_cancelled[listing.ListingId] = listing; else buy_now[listing.ListingId] = listing; break; case ListingInfo.ListingType.SELL: if (listing.Fulfilled) sell_past_fulfilled[listing.ListingId] = listing; else if (listing.Cancelled) sell_past_cancelled[listing.ListingId] = listing; else sell_now[listing.ListingId] = listing; break; default: break; } } // clear the excel database (it will be refreshed) db.Listings.Clear(); /***************************** BUY ORDERS *******************************************/ // get all of our now listings IDictionary<long, ListingInfo> buy_now_result = resultsToListingDictionary( new MeRequest(MeRequest.TimeType.NOW, MeRequest.ListingType.BUY).ExecuteAll(), MeRequest.ListingType.BUY); // get our new past listings IDictionary<long, ListingInfo> buy_past_result = resultsToListingDictionary( new MeRequest(MeRequest.TimeType.PAST, MeRequest.ListingType.BUY).GetNew(buy_past_fulfilled.Count - m_NEW_LISTING_BUFFER, 100), MeRequest.ListingType.BUY); // clear buy now and cancelled listings. we simply don't care with buy orders buy_now.Clear(); buy_past_cancelled.Clear(); // add our now buy orders foreach (ListingInfo info in buy_now_result.Values) buy_now[info.ListingId] = info; // add our new past buy orders foreach (ListingInfo info in buy_past_result.Values) buy_past_fulfilled[info.ListingId] = info; /***************************** SELL ORDERS ******************************************/ // get all of our now listings IDictionary<long, ListingInfo> sell_now_result = resultsToListingDictionary( new MeRequest(MeRequest.TimeType.NOW, MeRequest.ListingType.SELL).ExecuteAll(), MeRequest.ListingType.SELL); // get our new past listings IDictionary<long, ListingInfo> sell_past_result = resultsToListingDictionary( new MeRequest(MeRequest.TimeType.PAST, MeRequest.ListingType.SELL).GetNew(sell_past_fulfilled.Count - m_NEW_LISTING_BUFFER, 100), MeRequest.ListingType.SELL); // find our cancelled orders foreach (ListingInfo listing in sell_now.Values) { if (!sell_now_result.ContainsKey(listing.ListingId) && !sell_past_fulfilled.ContainsKey(listing.ListingId)) { listing.Cancelled = true; sell_past_cancelled[listing.ListingId] = listing; } } // clear now, any current "now" orders will be refilled sell_now.Clear(); // add our now sell orders foreach (ListingInfo info in sell_now_result.Values) sell_now[info.ListingId] = info; // add our new past sell orders foreach (ListingInfo info in sell_past_result.Values) sell_past_fulfilled[info.ListingId] = info; /***************************** COMBINE **********************************************/ foreach (ListingInfo info in buy_past_fulfilled.Values) db.Listings[info.ListingId] = info; foreach (ListingInfo info in buy_now.Values) db.Listings[info.ListingId] = info; foreach (ListingInfo info in sell_past_fulfilled.Values) db.Listings[info.ListingId] = info; foreach (ListingInfo info in sell_past_cancelled.Values) db.Listings[info.ListingId] = info; foreach (ListingInfo info in sell_now.Values) db.Listings[info.ListingId] = info; }
private static void updateListings(ExcelDatabase db) { // buckets to put orders into IDictionary <long, ListingInfo> buy_past_fulfilled = new Dictionary <long, ListingInfo>(); IDictionary <long, ListingInfo> buy_past_cancelled = new Dictionary <long, ListingInfo>(); IDictionary <long, ListingInfo> buy_now = new Dictionary <long, ListingInfo>(); IDictionary <long, ListingInfo> sell_past_fulfilled = new Dictionary <long, ListingInfo>(); IDictionary <long, ListingInfo> sell_past_cancelled = new Dictionary <long, ListingInfo>(); IDictionary <long, ListingInfo> sell_now = new Dictionary <long, ListingInfo>(); // siphon through the current database, throwing stuff into the proper buckets foreach (ListingInfo listing in db.Listings.Values) { switch (listing.Type) { case ListingInfo.ListingType.BUY: if (listing.Fulfilled) { buy_past_fulfilled[listing.ListingId] = listing; } else if (listing.Cancelled) { buy_past_cancelled[listing.ListingId] = listing; } else { buy_now[listing.ListingId] = listing; } break; case ListingInfo.ListingType.SELL: if (listing.Fulfilled) { sell_past_fulfilled[listing.ListingId] = listing; } else if (listing.Cancelled) { sell_past_cancelled[listing.ListingId] = listing; } else { sell_now[listing.ListingId] = listing; } break; default: break; } } // clear the excel database (it will be refreshed) db.Listings.Clear(); /***************************** BUY ORDERS *******************************************/ // get all of our now listings IDictionary <long, ListingInfo> buy_now_result = resultsToListingDictionary( new MeRequest(MeRequest.TimeType.NOW, MeRequest.ListingType.BUY).ExecuteAll(), MeRequest.ListingType.BUY); // get our new past listings IDictionary <long, ListingInfo> buy_past_result = resultsToListingDictionary( new MeRequest(MeRequest.TimeType.PAST, MeRequest.ListingType.BUY).GetNew(buy_past_fulfilled.Count - m_NEW_LISTING_BUFFER, 100), MeRequest.ListingType.BUY); // clear buy now and cancelled listings. we simply don't care with buy orders buy_now.Clear(); buy_past_cancelled.Clear(); // add our now buy orders foreach (ListingInfo info in buy_now_result.Values) { buy_now[info.ListingId] = info; } // add our new past buy orders foreach (ListingInfo info in buy_past_result.Values) { buy_past_fulfilled[info.ListingId] = info; } /***************************** SELL ORDERS ******************************************/ // get all of our now listings IDictionary <long, ListingInfo> sell_now_result = resultsToListingDictionary( new MeRequest(MeRequest.TimeType.NOW, MeRequest.ListingType.SELL).ExecuteAll(), MeRequest.ListingType.SELL); // get our new past listings IDictionary <long, ListingInfo> sell_past_result = resultsToListingDictionary( new MeRequest(MeRequest.TimeType.PAST, MeRequest.ListingType.SELL).GetNew(sell_past_fulfilled.Count - m_NEW_LISTING_BUFFER, 100), MeRequest.ListingType.SELL); // find our cancelled orders foreach (ListingInfo listing in sell_now.Values) { if (!sell_now_result.ContainsKey(listing.ListingId) && !sell_past_fulfilled.ContainsKey(listing.ListingId)) { listing.Cancelled = true; sell_past_cancelled[listing.ListingId] = listing; } } // clear now, any current "now" orders will be refilled sell_now.Clear(); // add our now sell orders foreach (ListingInfo info in sell_now_result.Values) { sell_now[info.ListingId] = info; } // add our new past sell orders foreach (ListingInfo info in sell_past_result.Values) { sell_past_fulfilled[info.ListingId] = info; } /***************************** COMBINE **********************************************/ foreach (ListingInfo info in buy_past_fulfilled.Values) { db.Listings[info.ListingId] = info; } foreach (ListingInfo info in buy_now.Values) { db.Listings[info.ListingId] = info; } foreach (ListingInfo info in sell_past_fulfilled.Values) { db.Listings[info.ListingId] = info; } foreach (ListingInfo info in sell_past_cancelled.Values) { db.Listings[info.ListingId] = info; } foreach (ListingInfo info in sell_now.Values) { db.Listings[info.ListingId] = info; } }
public static ExcelDatabase LoadFromFile(string file) { ExcelDatabase db = new ExcelDatabase(); if (File.Exists(file)) { Stream fileStream = File.OpenRead(file); ExcelPackage excel = new ExcelPackage(fileStream); fileStream.Close(); ExcelWorksheet sheet = excel.Workbook.Worksheets[m_WORKSHEET_NAME]; if (sheet != null) { for (int rowIdx = 2; rowIdx <= sheet.Dimension.End.Row; rowIdx++) { object oListingId = sheet.Cells[rowIdx, (int)SheetColumnIdx.LISTING_ID].Value; // long object oItemId = sheet.Cells[rowIdx, (int)SheetColumnIdx.ITEM_ID].Value; // long object oItemName = sheet.Cells[rowIdx, (int)SheetColumnIdx.ITEM_NAME].Value; // string object oItemLevel = sheet.Cells[rowIdx, (int)SheetColumnIdx.ITEM_LEVEL].Value; // int object oItemRarity = sheet.Cells[rowIdx, (int)SheetColumnIdx.ITEM_RARITY].Value; // string object oQuantity = sheet.Cells[rowIdx, (int)SheetColumnIdx.QUANTITY].Value; // long object oPrice = sheet.Cells[rowIdx, (int)SheetColumnIdx.PRICE].Value; // long object oListingTime = sheet.Cells[rowIdx, (int)SheetColumnIdx.LISTING_TIME].Value; // datetime object oFulfilledTime = sheet.Cells[rowIdx, (int)SheetColumnIdx.FULFILLED_TIME].Value; // datetime object oType = sheet.Cells[rowIdx, (int)SheetColumnIdx.TYPE].Value; // enum object oCancelled = sheet.Cells[rowIdx, (int)SheetColumnIdx.CANCELLED].Value; // bool if (oListingId == null || oItemId == null || oItemName == null || oItemLevel == null || oItemRarity == null || oQuantity == null || oPrice == null || oListingTime == null || oType == null) { continue; } long listingId, itemId, quantity, price; int itemLevel; double listingTimeOA; ListingInfo.ListingType type; if (!long.TryParse(oListingId.ToString(), out listingId) || !long.TryParse(oItemId.ToString(), out itemId) || !long.TryParse(oQuantity.ToString(), out quantity) || !long.TryParse(oPrice.ToString(), out price) || !int.TryParse(oItemLevel.ToString(), out itemLevel) || !double.TryParse(oListingTime.ToString(), out listingTimeOA) || !Enum.TryParse <ListingInfo.ListingType>(oType.ToString(), out type)) { continue; } DateTime listingTime = DateTime.FromOADate(listingTimeOA); string itemName = oItemName.ToString(); string itemRarity = oItemRarity.ToString(); // BUGFIX: rarity was being set to level for awhile, this attempts to restore the proper // rarity that was lost BugFixes.Fix_001(ref itemRarity); double fulfilledTimeOA; DateTime?fulfilledTime = null; if (oFulfilledTime != null && double.TryParse(oFulfilledTime.ToString(), out fulfilledTimeOA)) { fulfilledTime = DateTime.FromOADate(fulfilledTimeOA); } bool cancelled = false; if (oCancelled != null && !bool.TryParse(oCancelled.ToString(), out cancelled)) { cancelled = false; } db.Listings[listingId] = new ListingInfo() { ListingId = listingId, ItemId = itemId, ItemName = itemName, ItemLevel = itemLevel, ItemRarity = itemRarity, Quantity = quantity, Price = price, ListingTime = listingTime, FulfilledTime = fulfilledTime, Type = type, Cancelled = cancelled }; } } } return(db); }