public void Perform(LoadPacificOceanToponyms job) { var reportBuilder = new WorkReportBuilder("Load Pacific Ocean Toponyms"); try { var geoNameIds = new[] { 8411083, 2363254 }; var pacifics = _entities.Query <GeoNamesToponym>().Where(x => geoNameIds.Contains(x.GeoNameId)); reportBuilder.Report("Found {0} Pacific Ocean toponyms", pacifics.Count()); if (pacifics.Count() < 2) { reportBuilder.Report("Seeding Pacific Ocean toponyms."); _queryProcessor.Execute(new SingleGeoNamesToponym(8411083)); _queryProcessor.Execute(new SingleGeoNamesToponym(2363254)); reportBuilder.Report("There is/are now {0} Pacific Ocean toponyms.", pacifics.Count()); } } catch (Exception ex) { reportBuilder.Report(""); reportBuilder.Report("JOB FAILED!"); reportBuilder.Report(ex.GetType().Name); reportBuilder.Report(ex.Message); reportBuilder.Report(ex.StackTrace); _exceptionLogger.Log(ex); } finally { reportBuilder.Send(_mailSender); } }
public void Perform(FixDuplicateMexicos job) { var reportBuilder = new WorkReportBuilder("Fix Duplicate Mexicos"); try { // one is country, other is Estado de Mexico var mexicos = _entities.Query <Place>() .EagerLoad(_entities, new Expression <Func <Place, object> >[] { x => x.Ancestors.Select(y => y.Ancestor), x => x.Offspring.Select(y => y.Offspring), x => x.GeoPlanetPlace, x => x.GeoNamesToponym, }) .Where(x => x.OfficialName.Equals("Mexico", StringComparison.OrdinalIgnoreCase)).ToArray(); var mexico1 = mexicos[0]; var mexico2 = mexicos[1]; } catch (Exception ex) { reportBuilder.Report(""); reportBuilder.Report("JOB FAILED!"); reportBuilder.Report(ex.GetType().Name); reportBuilder.Report(ex.Message); reportBuilder.Report(ex.StackTrace); _exceptionLogger.Log(ex); } finally { reportBuilder.Send(_mailSender); } }
public void Perform(CanonilizeOceans job) { var reportBuilder = new WorkReportBuilder("Canonilize Oceans"); try { var atlantic = _entities.Query <Place>().Single(x => x.OfficialName == AtlanticText); var subAtlantics = _entities.Query <Place>() .Where(x => x.OfficialName == SouthAtlanticText || x.OfficialName == NorthAtlanticText) .Where(x => x.ParentId != atlantic.RevisionId); reportBuilder.Report("There is/are {0} sub-atlantic oceans that do not have atlantic for a parent.", subAtlantics.Count()); if (subAtlantics.Any()) { reportBuilder.Report("Canonilizing sub-atlantics."); var subAtlanticsArray = subAtlantics.ToArray(); foreach (var subAtlantic in subAtlanticsArray) { _updatePlace.Handle(new UpdatePlace(subAtlantic.RevisionId, atlantic.RevisionId)); } reportBuilder.Report("There is/are now {0} sub-atlantic oceans that do not have atlantic for a parent.", subAtlantics.Count()); reportBuilder.Report(""); } var pacific = _entities.Query <Place>().Single(x => x.OfficialName == PacificText); var subPacifics = _entities.Query <Place>() .Where(x => x.OfficialName == SouthPacificText || x.OfficialName == NorthPacificText) .Where(x => x.ParentId != pacific.RevisionId); reportBuilder.Report("There is/are {0} sub-pacific oceans that do not have pacific for a parent.", subPacifics.Count()); if (subPacifics.Any()) { reportBuilder.Report("Canonilizing sub-pacifics."); var subPacificsArray = subPacifics.ToArray(); foreach (var subPacific in subPacificsArray) { _updatePlace.Handle(new UpdatePlace(subPacific.RevisionId, pacific.RevisionId)); } reportBuilder.Report("There is/are now {0} sub-pacific oceans that do not have pacific for a parent.", subPacifics.Count()); } } catch (Exception ex) { reportBuilder.Report(""); reportBuilder.Report("JOB FAILED!"); reportBuilder.Report(ex.GetType().Name); reportBuilder.Report(ex.Message); reportBuilder.Report(ex.StackTrace); _exceptionLogger.Log(ex); } finally { reportBuilder.Send(_mailSender); } }
public void Perform(RepairPlaceHierarchies job) { lock (Lock) { var stopwatch = new Stopwatch(); stopwatch.Start(); var reportBuilder = new WorkReportBuilder("Repair Place Hierarchies"); reportBuilder.Report("{0}ms: Checking for Places with invalid ancestral hierarchies.", stopwatch.ElapsedMilliseconds); try { var brokenPlaces = _entities.Query <Place>() .Where(x => x.Parent != null) .Count(x => x.Ancestors.Count <= x.Parent.Ancestors.Count || // place should always have more ancestors than its parent !x.Ancestors.Select(y => y.AncestorId).Contains(x.ParentId.Value) // place ancestors should always contain the parent // place should have 1 more ancestor than its closest ancestor does || x.Ancestors.Count != x.Ancestors.OrderBy(y => y.Separation).FirstOrDefault().Ancestor.Ancestors.Count + 1) ; if (brokenPlaces < 1) { reportBuilder.Report("{0}ms: No Places appear to have invalid ancestral hierarchies.", stopwatch.ElapsedMilliseconds); } else { reportBuilder.Report("{0}ms: A total of {1} Places appear to have invalid hierarchies.", stopwatch.ElapsedMilliseconds, brokenPlaces); } reportBuilder.Report(""); var command = new EnsurePlaceHierarchies(); _placeNodes.Handle(command); reportBuilder.Report("{0}ms: Place ancestral hierarchy repair command ran.", stopwatch.ElapsedMilliseconds); reportBuilder.Report("At total of {0} Places have had their ancestral hierarchies repaired.", command.EnsuredPlaceNames.Count); foreach (var ensured in command.EnsuredPlaceNames) { reportBuilder.Report("{0} (PlaceId {1})", ensured.Value, ensured.Key); } reportBuilder.Report(""); reportBuilder.Report("Job completed in {0} minutes.", stopwatch.Elapsed.TotalMinutes); } catch (Exception ex) { reportBuilder.Report(""); reportBuilder.Report("JOB FAILED!"); reportBuilder.Report(ex.GetType().Name); reportBuilder.Report(ex.Message); reportBuilder.Report(ex.StackTrace); _exceptionLogger.Log(ex); } finally { reportBuilder.Send(_mailSender); } } }
public void Perform(SeedAtlanticOcean job) { var reportBuilder = new WorkReportBuilder("Seed Atlantic Ocean"); try { var atlantics = _queryProcessor.Execute(new PlacesWithName { MaxResults = 5, Term = AtlanticOceanText, TermMatchStrategy = StringMatchStrategy.Equals, }); if (atlantics.Any()) { reportBuilder.Report("At least {0} Place(s) named '{1}' already exist(s).", atlantics.Count(), AtlanticOceanText); } else { reportBuilder.Report("There are no Places named '{0}'.", AtlanticOceanText); reportBuilder.Report("Seeding '{0}'.", AtlanticOceanText); var geoPlanetPlaces = _geoPlanet.Places(AtlanticOceanText); var geoPlanetToponyms = _geoNames.Search(new SearchOptions(SearchType.NameEquals, AtlanticOceanText)); var geoNamesToponym = geoPlanetToponyms.FirstOrDefault(x => x.FeatureClassCode == "H"); var geoPlanetPlace = geoPlanetPlaces.FirstOrDefault(x => x.Type.Code == 37 || x.Type.Code == 38); if (geoPlanetPlace != null && geoNamesToponym != null) { _queryProcessor.Execute(new PlaceByWoeId(geoPlanetPlace.WoeId, geoNamesToponym.GeoNameId)); } reportBuilder.Report("There is/are now {0} Place(s) named '{1}'.", atlantics.Count(), AtlanticOceanText); } } catch (Exception ex) { reportBuilder.Report(""); reportBuilder.Report("JOB FAILED!"); reportBuilder.Report(ex.GetType().Name); reportBuilder.Report(ex.Message); reportBuilder.Report(ex.StackTrace); _exceptionLogger.Log(ex); } finally { reportBuilder.Send(_mailSender); } }
public void Perform(MigrateUsfAgreementData job) { var reportBuilder = new WorkReportBuilder("Migrate USF Agreement Data"); try { // for USF, move from description into content // do not preserve any titles as names. const int usfEstablishmentId = 3306; var usfAgreements = _entities.Get <Agreement>() .Where(x => x.Participants.Any(y => y.IsOwner && ( y.EstablishmentId == usfEstablishmentId || y.Establishment.Ancestors.Any(z => z.AncestorId == usfEstablishmentId) ) )) ; foreach (var usfAgreement in usfAgreements) { var html = usfAgreement.Description.ToHtml(); usfAgreement.Name = null; usfAgreement.Content = html; } _entities.SaveChanges(); } catch (Exception ex) { reportBuilder.Report(""); reportBuilder.Report("JOB FAILED!"); reportBuilder.Report(ex.GetType().Name); reportBuilder.Report(ex.Message); reportBuilder.Report(ex.StackTrace); _exceptionLogger.Log(ex); } finally { reportBuilder.Send(_mailSender); } }
public void Perform(ProjectEmployeeSummaryViews job) { var reportBuilder = new WorkReportBuilder("Cook Activity Data"); try { reportBuilder.Report("Getting relevant tenants."); var establishmentIds = _placesBuilder.GetEstablishmentIdsWithData().ToArray(); reportBuilder.Report("Operating on {0} tenants.", establishmentIds.Length); foreach (var establishmentId in establishmentIds) { var placesViews = _placesBuilder.Build(establishmentId); var activityCountView = _activityCountsBuilder.Build(establishmentId); reportBuilder.Report("Places view has {0} records., projecting...", placesViews.Length); _placesProjector.Set(placesViews, establishmentId); reportBuilder.Report("Places projected into view manager for establishment #{0}.", establishmentId); _activityCountsProjector.Set(activityCountView, establishmentId); } reportBuilder.Report("Activity data cooked."); } catch (Exception ex) { reportBuilder.Report(""); reportBuilder.Report("JOB FAILED!"); reportBuilder.Report(ex.GetType().Name); reportBuilder.Report(ex.Message); reportBuilder.Report(ex.StackTrace); _exceptionLogger.Log(ex); if (!_mailSent) { reportBuilder.Send(_mailSender); } _mailSent = true; } //finally // do not want to receive emails indicating success every 10 minutes //{ // if (!_mailSent) // reportBuilder.Send(_mailSender); // _mailSent = true; //} }
public void Perform(ComposeRegions job) { var reportBuilder = new WorkReportBuilder("Compose Regions"); try { var regions = _entities.Get <Place>() .Where(x => x.IsRegion && !x.IsWater && !x.Components.Any()); reportBuilder.Report("There is/are {0} uncomposed region(s).", regions.Count()); if (regions.Any()) { var mutated = false; var regionsArray = regions.ToArray(); foreach (var region in regionsArray) { reportBuilder.Report(""); reportBuilder.Report("Composing '{0}'...", region.OfficialName); //if (!region.IsRegion) continue; var woeId = region.GeoPlanetPlace.WoeId; var components = _entities.Get <Place>() .Where(x => x.GeoPlanetPlace != null && x.GeoPlanetPlace.BelongTos.Select(y => y.BelongToWoeId).Contains(woeId)); foreach (var component in components) { if (!component.IsCountry && !component.IsWater) { continue; } if (component.IsRegion) { continue; } reportBuilder.Report(" Component: '{0}'", component.OfficialName); if (region.Components.All(x => x.RevisionId != component.RevisionId)) { region.Components.Add(component); if (!mutated) { mutated = true; } } } } if (mutated) { _entities.SaveChanges(); } } } catch (Exception ex) { reportBuilder.Report(""); reportBuilder.Report("JOB FAILED!"); reportBuilder.Report(ex.GetType().Name); reportBuilder.Report(ex.Message); reportBuilder.Report(ex.StackTrace); _exceptionLogger.Log(ex); } finally { reportBuilder.Send(_mailSender); } }
public override void Handle(UserCreated e) { // is this a usf user? var usf = _queryProcessor.Execute(new EstablishmentByUrl("www.usf.edu")); var tenant = _queryProcessor.Execute(new EstablishmentById(e.TenantId)); if (tenant == null || usf == null || !usf.Equals(tenant)) { return; } var reportBuilder = new WorkReportBuilder("Handle USF User Created Event"); var logging = UsfFacultyProfileAttribute.MailLog.ToString(); try { // get the service integration var usfFacultyProfile = UsfFacultyProfileAttribute.UsfFacultyProfile.ToString(); var integration = _entities.Get <ServiceIntegration>() .EagerLoad(_entities, new Expression <Func <ServiceIntegration, object> >[] { x => x.StringAttributes, }) .SingleOrDefault(x => x.TenantId == e.TenantId && x.Name.Equals(usfFacultyProfile)); if (integration == null) { throw new InvalidOperationException(string.Format( "Found no service integration for '{0}_{1}'.", usfFacultyProfile, e.TenantId)); } reportBuilder.Report("Wrapping integration data into USF Faculty Profile Service object."); var service = new UsfFacultyProfileService(integration); logging = service.Logging; reportBuilder.Report("Invoking command to import USF person data."); _commandHandler.Handle(new ImportUsfPerson(e.Principal, service, e.UserId) { ReportBuilder = reportBuilder, }); } catch (Exception ex) { reportBuilder.Report(""); reportBuilder.Report("JOB FAILED!"); reportBuilder.Report(ex.GetType().Name); reportBuilder.Report(ex.Message); reportBuilder.Report(ex.StackTrace); _exceptionLogger.Log(ex); } finally { _entities.DiscardChanges(); var usfFacultyProfile = UsfFacultyProfileAttribute.UsfFacultyProfile.ToString(); var integration = _entities.Get <ServiceIntegration>() .EagerLoad(_entities, new Expression <Func <ServiceIntegration, object> >[] { x => x.StringAttributes, }) .SingleOrDefault(x => x.TenantId == e.TenantId && x.Name.Equals(usfFacultyProfile)); if (integration == null) { reportBuilder.Report("Found no service integration for '{0}_{1}'.", usfFacultyProfile, e.TenantId); reportBuilder.Send(_mailSender); } else { if (!string.IsNullOrWhiteSpace(logging)) { integration.LogEntries.Add(new ServiceLogEntry { IntegrationName = integration.Name, TenantId = integration.TenantId, Subject = reportBuilder.Subject, Log = reportBuilder.Message.ToString(), }); _entities.SaveChanges(); } if (logging == UsfFacultyProfileAttribute.MailLog.ToString()) { reportBuilder.Send(_mailSender); } } } }