AddressLookupStore.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using InABox.Core;
  2. using NPOI.HSSF.Record;
  3. using NPOI.OpenXmlFormats.Spreadsheet;
  4. namespace InABox.Database.Stores;
  5. public class AddressLookupStore : Store<AddressLookup>
  6. {
  7. private static List<AddressLookup> _cache= new();
  8. private static IQueryProviderFactory? _queryProviderFactory = null;
  9. public override void Init()
  10. {
  11. base.Init();
  12. // // Load the cache file into memory
  13. // string cachefile = Path.Combine(CoreUtils.GetPath(), "GNAF_CORE.psv");
  14. // if (File.Exists(cachefile))
  15. // {
  16. // DateTime start = DateTime.Now;
  17. // Logger.Send(LogType.Information,"",$"Loading Address Lookup File: {cachefile}");
  18. // using (StreamReader sr = new(cachefile))
  19. // {
  20. // var headers = sr.ReadLine().Split('|').ToList();
  21. // int streetfield = headers.IndexOf("ADDRESS_LABEL");
  22. // int statefield = headers.IndexOf("STATE");
  23. // int latfield = headers.IndexOf("LATITUDE");
  24. // int lngfield = headers.IndexOf("LONGITUDE");
  25. // while (!sr.EndOfStream)
  26. // {
  27. // var line = sr.ReadLine().Split('|').ToArray();
  28. // if (string.Equals(line[statefield], "WA"))
  29. // {
  30. // _cache.Add(new AddressLookup()
  31. // {
  32. // Address = line[streetfield],
  33. // Latitude = double.Parse(line[latfield]),
  34. // Longitude = double.Parse(line[lngfield])
  35. // });
  36. //
  37. // }
  38. // }
  39. // }
  40. // Logger.Send(LogType.Information,"",$"Found {_cache.Count} addresses in {(DateTime.Now - start):g}");
  41. // }
  42. // else
  43. // Logger.Send(LogType.Information,"",$"Address Lookup File: {cachefile} not found!");
  44. }
  45. // protected override CoreTable OnQuery(Filter<AddressLookup>? filter, Columns<AddressLookup>? columns, SortOrder<AddressLookup>? sort, CoreRange? range)
  46. // {
  47. // _queryProviderFactory ??= this.GetQueryProviderFactory();
  48. // var result = new CoreTable();
  49. // var cols = columns ?? Columns.All<AddressLookup>();
  50. // result.Columns.AddRange(cols.Select(x => new CoreColumn(x.Property)));
  51. // foreach (var lookup in _cache)
  52. // {
  53. // if (filter == null || filter.Match(lookup, _queryProviderFactory))
  54. // {
  55. // var row = result.NewRow();
  56. // result.LoadRow(lookup);
  57. // result.Rows.Add(row);
  58. // }
  59. // }
  60. // return result;
  61. // }
  62. }