private List <PushpinModel> GetVoterList() { VoterFileDataContext _voterDB = new mapapp.data.VoterFileDataContext(string.Format(mapapp.data.VoterFileDataContext.DBConnectionString, App.thisApp._settings.DbFileName)); System.Diagnostics.Debug.Assert(_voterDB.DatabaseExists()); List <PushpinModel> _list = new List <PushpinModel>(); if (!(App.thisApp._settings.DbStatus == DbState.Loaded)) { App.Log("Database not ready to load voters yet."); return(_list); } IEnumerable <VoterFileEntry> data = from VoterFileEntry voter in _voterDB.AllVoters select voter; PushpinModel _pin; int _counter = 0; foreach (VoterFileEntry _v in data) { _pin = new PushpinModel(_v); if (0.0 == _pin.Location.Latitude || 0.0 == _pin.Location.Longitude) { App.Log("Skipping voter with no location:" + _pin.Address); continue; } _counter++; if (!_pin.Location.IsUnknown) { _pin.Visibility = Visibility.Visible; _list.Add(_pin); } else { System.Diagnostics.Debug.WriteLine("Error: A pin doesn't have a location: " + _pin.Content); // This pin doesn't have valid location info - Set the location for the pushpin to the center of the street or precinct StreetPinModel _street = (from StreetPinModel _st in Streets where _st.Content == _pin.Street select _st).FirstOrDefault(); if (_street != null) { _pin.Location = _street.Center; App.Log(string.Format("Voter at {0} lacks location, setting to center of {1} street.", _pin.Address, _street.Content)); _list.Add(_pin); } } } if (_list.Count == 0 || _counter == 0) { App.Log("There are no voters around here!"); } else { System.Diagnostics.Debug.WriteLine("Found {0} voters near here.", _counter); } _voterDB.Dispose(); return(_list); }
private void Street_Hold(object sender, System.Windows.Input.GestureEventArgs e) { if (sender is Pushpin) { Pushpin pinHeld = sender as Pushpin; if (pinHeld.DataContext is StreetPinModel) { StreetPinModel pinModel = pinHeld.DataContext as StreetPinModel; _StreetFilter = pinModel.StreetEntry.Name; Zoom = 15.0; // Force zoom to be just outside of the "showStreets" range Map.ZoomLevel = Zoom; Center = pinModel.Center; ShowPushpins = true; ShowPrecincts = false; ShowStreets = false; App.Log(string.Format("{0} street selected", _StreetFilter)); wait.Set(); } } }
private void LoadStreets() { VoterFileDataContext _voterDB = new mapapp.data.VoterFileDataContext(string.Format(mapapp.data.VoterFileDataContext.DBConnectionString, App.thisApp._settings.DbFileName)); System.Diagnostics.Debug.Assert(_voterDB.DatabaseExists()); if (!(App.thisApp._settings.DbStatus == DbState.Loaded)) { App.Log("Database not ready to load streets yet."); return; } IEnumerable <StreetTableEntry> streets = (from street in _voterDB.Streets select street); foreach (StreetTableEntry street in streets) { App.Log(" Adding street: " + street.Name); StreetPinModel pPin = new StreetPinModel(street); Streets.Add(pPin); } _voterDB.Dispose(); }
public void BackgroundThread() { // LoadPushPins(); App.Log("Started background thread..."); LocationRect _lastRect = null; double _lastZoom = 0.0; while (wait.WaitOne()) { App.Log(" Wait completed at top of background thread loop."); wait.Reset(); if (running == false) { App.Log(" Exiting background thread."); wait.Close(); wait.Dispose(); return; } try { if (Precincts.Count == 0) { App.Log(" Invoking LoadPrecincts..."); Dispatcher.BeginInvoke(LoadPrecincts); } if (Streets.Count == 0) { App.Log(" Invoking LoadStreets..."); Dispatcher.BeginInvoke(LoadStreets); } LocationRect lr = Map.BoundingRectangle; if (lr.Equals(_lastRect)) // NOTE: the rect can only be equal if both center and zoom level are unchanged. { App.Log(" We haven't moved, continuing..."); continue; } bool bfullcontent = false; if (_showDetails) { bfullcontent = true; } App.Log(" Made it through prelims - still here."); IEnumerable <PushpinModel> selectedVoters = listModels.AsEnumerable(); if (true) // (!_dataView.IsWithinView(lr)) NOTE: Quick hack for TechRoanoke conference { App.Log(" Calling GetVoterList..."); selectedVoters = GetVoterList(); App.Log(String.Format(" {0} voters are in current voter list.", selectedVoters.Count())); App.Log(" GetVoterList call completed."); } else { App.Log(" Still within current dataview, skipping call to GetLocalVoters."); if (lr.Center == _lastRect.Center && zoomlevel == _lastZoom) { App.Log(" Still in same location. continuing..."); continue; } } _lastRect = lr; _lastZoom = zoomlevel; // Now filter on precinct if set if (_PrecinctFilter != "") { // _dataViewPins = from <PushpinModel> voter in _dataViewPins where voter. selectedVoters = from PushpinModel aVoter in selectedVoters where aVoter.Precinct == _PrecinctFilter select aVoter; App.Log(String.Format(" {0} voters are in {1} precinct.", selectedVoters.Count(), _PrecinctFilter)); } // Now filter on street if selected if (_StreetFilter != "") { selectedVoters = from PushpinModel aVoter in selectedVoters where aVoter.Street == _StreetFilter select aVoter; App.Log(String.Format(" {0} voters are in {1} precinct and live on {2}.", selectedVoters.Count(), _PrecinctFilter, _StreetFilter)); } // If resulting list is still more than preset limit (do 300 for now) then filter to nearest 300 if (selectedVoters.Count() > _MaxVotersInView) { _dataViewPins = GetViewVoterList(lr.Center, selectedVoters); } else { _dataViewPins = selectedVoters.ToList(); } List <PushpinModel> l = new List <PushpinModel>(_dataViewPins.AsEnumerable()); int total = 0; if (wait.WaitOne(0)) { App.Log(" Wait was not signaled, continuing."); continue; } App.Log(" Adding filtered pushpins to listModel."); listModels.Clear(); foreach (PushpinModel p in l) { total++; if (bfullcontent) { p.Content = p.FullName + "\r" + p.VoterFile.Address + " " + p.VoterFile.Address2; } else { p.Content = p.VoterFile.LastName; } if (p.Location.IsUnknown || p.Location.Latitude < 25.3 || p.Location.Longitude > -67.0) { // This pin doesn't have valid location info - Set the location for the pushpin to the center of the street or precinct StreetPinModel _street = (from StreetPinModel _st in Streets where _st.Content == p.Street select _st).FirstOrDefault(); if (_street != null) { p.Location = _street.Center; App.Log(string.Format("Voter at {0} lacks location, setting to center of {1} street.", p.Address, _street.Content)); } } listModels.Add(p); if (wait.WaitOne(0)) { break; } } } catch (ThreadAbortException) { running = false; wait.Close(); wait.Dispose(); return; } catch (Exception ex) { App.Log("Something went wrong in the background thread. " + ex.ToString()); } if (wait.WaitOne(0)) { App.Log(" Wait was not signaled, continuing (4)."); continue; } App.Log(" Invoking UpdatePins..."); Dispatcher.BeginInvoke(UpdatePins); } running = false; wait.Close(); wait.Dispose(); return; }