public Verify ( Location location, bool reVerify ) : bool | ||
location | Location | A |
reVerify | bool | if set to |
return | bool |
/// <summary> /// Job that updates the JobPulse setting with the current date/time. /// This will allow us to notify an admin if the jobs stop running. /// /// Called by the <see cref="IScheduler" /> when a /// <see cref="ITrigger" /> fires that is associated with /// the <see cref="IJob" />. /// </summary> public virtual void Execute(IJobExecutionContext context) { // get the job map JobDataMap dataMap = context.JobDetail.JobDataMap; int maxRecords = Int32.Parse( dataMap.GetString( "MaxRecordsPerRun" ) ); int throttlePeriod = Int32.Parse( dataMap.GetString( "ThrottlePeriod" ) ); int retryPeriod = Int32.Parse( dataMap.GetString( "RetryPeriod" ) ); DateTime retryDate = DateTime.Now.Subtract(new TimeSpan(retryPeriod, 0, 0, 0)); var rockContext = new Rock.Data.RockContext(); LocationService locationService = new LocationService(rockContext); var addresses = locationService.Queryable() .Where( l => ( (l.IsGeoPointLocked == null || l.IsGeoPointLocked == false) // don't ever try locked address && (l.IsActive == true && l.Street1 != null && l.PostalCode != null) // or incomplete addresses && ( (l.GeocodedDateTime == null && (l.GeocodeAttemptedDateTime == null || l.GeocodeAttemptedDateTime < retryDate)) // has not been attempted to be geocoded since retry date || (l.StandardizedDateTime == null && (l.StandardizeAttemptedDateTime == null || l.StandardizeAttemptedDateTime < retryDate)) // has not been attempted to be standardize since retry date ) )) .Take( maxRecords ).ToList(); foreach ( var address in addresses ) { locationService.Verify( address, false ); // currently not reverifying rockContext.SaveChanges(); System.Threading.Thread.Sleep( throttlePeriod ); } }
/// <summary> /// Handles the Click event of the btnStandardize control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnStandardize_Click( object sender, EventArgs e ) { int locationId = hfLocationId.Value.AsInteger(); var rockContext = new RockContext(); var service = new LocationService( rockContext ); var location = service.Get( locationId ); if (location == null) { // if they are adding a new named location, there won't be a location record yet, so just make a new one for the verification location = new Location(); } acAddress.GetValues( location ); service.Verify( location, true ); acAddress.SetValues( location ); geopPoint.SetValue( location.GeoPoint ); lStandardizationUpdate.Text = String.Format( "<div class='alert alert-info'>Standardization Result: {0}<br/>Geocoding Result: {1}</div>", location.StandardizeAttemptedResult.IfEmpty( "No Result" ), location.GeocodeAttemptedResult.IfEmpty( "No Result" ) ); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click( object sender, EventArgs e ) { Campus campus; var rockContext = new RockContext(); var campusService = new CampusService( rockContext ); var locationService = new LocationService( rockContext ); var locationCampusValue = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.LOCATION_TYPE_CAMPUS.AsGuid()); int campusId = int.Parse( hfCampusId.Value ); if ( campusId == 0 ) { campus = new Campus(); campusService.Add( campus); } else { campus = campusService.Get( campusId ); } campus.Name = tbCampusName.Text; campus.IsActive = cbIsActive.Checked; campus.Description = tbDescription.Text; campus.Url = tbUrl.Text; campus.PhoneNumber = tbPhoneNumber.Text; if ( campus.Location == null ) { var location = locationService.Queryable() .Where( l => l.Name.Equals( campus.Name, StringComparison.OrdinalIgnoreCase ) && l.LocationTypeValueId == locationCampusValue.Id ) .FirstOrDefault(); if (location == null) { location = new Location(); locationService.Add( location ); } campus.Location = location; } campus.Location.Name = campus.Name; campus.Location.LocationTypeValueId = locationCampusValue.Id; string preValue = campus.Location.GetFullStreetAddress(); acAddress.GetValues( campus.Location ); string postValue = campus.Location.GetFullStreetAddress(); campus.ShortCode = tbCampusCode.Text; var personService = new PersonService( rockContext ); var leaderPerson = personService.Get( ppCampusLeader.SelectedValue ?? 0 ); campus.LeaderPersonAliasId = leaderPerson != null ? leaderPerson.PrimaryAliasId : null; campus.ServiceTimes = kvlServiceTimes.Value; campus.LoadAttributes( rockContext ); Rock.Attribute.Helper.GetEditValues( phAttributes, campus ); if ( !campus.IsValid && campus.Location.IsValid) { // Controls will render the error messages return; } rockContext.WrapTransaction( () => { rockContext.SaveChanges(); campus.SaveAttributeValues( rockContext ); if (preValue != postValue && !string.IsNullOrWhiteSpace(campus.Location.Street1)) { locationService.Verify(campus.Location, true); } } ); Rock.Web.Cache.CampusCache.Flush( campus.Id ); NavigateToParentPage(); }
void rptrAddresses_ItemCommand( object source, RepeaterCommandEventArgs e ) { int locationId = int.MinValue; if ( int.TryParse( e.CommandArgument.ToString(), out locationId ) ) { var rockContext = new RockContext(); var service = new LocationService( rockContext ); var location = service.Get( locationId ); switch ( e.CommandName ) { case "verify": service.Verify( location, true ); break; } rockContext.SaveChanges(); } BindFamilies(); }
/// <summary> /// Handles the Click event of the btnStandardize control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnStandardize_Click( object sender, EventArgs e ) { int locationId = int.Parse( hfLocationId.Value ); var rockContext = new RockContext(); var service = new LocationService( rockContext ); var location = service.Get( locationId ); acAddress.GetValues( location ); service.Verify( location, true ); acAddress.SetValues( location ); geopPoint.SetValue( location.GeoPoint ); lStandardizationUpdate.Text = String.Format( "<div class='alert alert-info'>Standardization Result: {0}<br/>Geocoding Result: {1}</div>", location.StandardizeAttemptedResult.IfEmpty( "No Result" ), location.GeocodeAttemptedResult.IfEmpty( "No Result" ) ); }
/// <summary> /// Job that updates the JobPulse setting with the current date/time. /// This will allow us to notify an admin if the jobs stop running. /// /// Called by the <see cref="IScheduler" /> when a /// <see cref="ITrigger" /> fires that is associated with /// the <see cref="IJob" />. /// </summary> public virtual void Execute(IJobExecutionContext context) { // get the job map JobDataMap dataMap = context.JobDetail.JobDataMap; int maxRecords = Int32.Parse( dataMap.GetString( "MaxRecordsPerRun" ) ); int throttlePeriod = Int32.Parse( dataMap.GetString( "ThrottlePeriod" ) ); int retryPeriod = Int32.Parse( dataMap.GetString( "RetryPeriod" ) ); DateTime retryDate = DateTime.Now.Subtract(new TimeSpan(retryPeriod, 0, 0, 0)); var rockContext = new Rock.Data.RockContext(); LocationService locationService = new LocationService(rockContext); var addresses = locationService.Queryable() .Where( l => ( ( l.IsGeoPointLocked == null || l.IsGeoPointLocked == false ) &&// don't ever try locked address l.IsActive == true && l.Street1 != null && l.Street1 != "" && l.City != null && l.City != "" && ( ( l.GeocodedDateTime == null && ( l.GeocodeAttemptedDateTime == null || l.GeocodeAttemptedDateTime < retryDate ) ) || // has not been attempted to be geocoded since retry date ( l.StandardizedDateTime == null && ( l.StandardizeAttemptedDateTime == null || l.StandardizeAttemptedDateTime < retryDate ) ) // has not been attempted to be standardize since retry date ) ) ) .Take( maxRecords ).ToList(); int attempts = 0; int successes = 0; foreach ( var address in addresses ) { attempts++; if ( locationService.Verify( address, true ) ) { successes++; } rockContext.SaveChanges(); System.Threading.Thread.Sleep( throttlePeriod ); } context.Result = string.Format( "{0:N0} address verifications attempted; {1:N0} successfully verified", attempts, successes ); }
/// <summary> /// Handles the ItemCommand event of the rptrAddresses control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="RepeaterCommandEventArgs"/> instance containing the event data.</param> protected void rptrAddresses_ItemCommand( object source, RepeaterCommandEventArgs e ) { int locationId = int.MinValue; if ( int.TryParse( e.CommandArgument.ToString(), out locationId ) ) { using ( var rockContext = new RockContext() ) { var service = new LocationService( rockContext ); var location = service.Get( locationId ); if ( location != null ) { switch ( e.CommandName ) { case "verify": { service.Verify( location, true ); rockContext.SaveChanges(); break; } case "settings": { NavigateToLinkedPage( "LocationDetailPage", new Dictionary<string, string> { { "LocationId", location.Id.ToString() }, { "PersonId", Person.Id.ToString() } } ); break; } } } } } BindGroups(); }