static void Main(string[] args) { var ninjectKernel = NinjectWebKernel.CreateKernel(); var updateService = new Service(); updateService.TransferFromTempToActual(); }
public BaseController(IGenericRepository <T> repository, IGenericRepository <Person> personRepo) { _personRepo = personRepo; ValidationSettings.AllowedQueryOptions = AllowedQueryOptions.All; ValidationSettings.MaxExpansionDepth = 4; Repo = repository; _primaryKeyProp = Repo.GetPrimaryKeyProperty(); _logger = NinjectWebKernel.CreateKernel().Get <ILogger>(); }
static void Main(string[] args) { var ninjectKernel = NinjectWebKernel.CreateKernel(); var personalAddressesServices = new MigratePersonalAddressesService(ninjectKernel.Get <IGenericRepository <PersonalAddress> >(), ninjectKernel.Get <IGenericRepository <Person> >(), ninjectKernel.Get <IAddressCoordinates>()); //personalAddressesServices.MigratePersonalAddresses(args.ToList()); var reportService = new MigrateReportsService(ninjectKernel.Get <IGenericRepository <Employment> >(), new GenericRepository <DriveReport>(new TempContext())); reportService.MigrateReports(args.ToList()); }
public IHttpActionResult GetCachedAddresses(bool includeCleanAddresses = false) { if (CurrentUser.IsAdmin) { var repo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <CachedAddress> >(); if (!includeCleanAddresses) { var res = repo.AsQueryable().Where(x => x.IsDirty); return(Ok(res)); } return(Ok(repo.AsQueryable())); } return(StatusCode(HttpStatusCode.Forbidden)); }
public new IHttpActionResult Post(PersonalAddress personalAddress) { if (!CurrentUser.Id.Equals(personalAddress.PersonId)) { return(StatusCode(HttpStatusCode.Forbidden)); } var coordinates = NinjectWebKernel.CreateKernel().Get <IAddressCoordinates>(); var result = coordinates.GetAddressCoordinates(personalAddress); personalAddress.Latitude = result.Latitude; personalAddress.Longitude = result.Longitude; return(base.Post(personalAddress)); }
/// <summary> /// API endpoint for getting the starting address of the map in the frontend. /// </summary> /// <returns>Starting address of frontend map</returns> public Address GetMapStart() { if (MapStartAddress == null) { var coordinates = NinjectWebKernel.CreateKernel().Get <IAddressCoordinates>(); MapStartAddress = new Address { StreetName = ConfigurationManager.AppSettings["MapStartStreetName"], StreetNumber = ConfigurationManager.AppSettings["MapStartStreetNumber"], ZipCode = int.Parse(ConfigurationManager.AppSettings["MapStartZipCode"]), Town = ConfigurationManager.AppSettings["MapStartTown"], }; MapStartAddress = coordinates.GetAddressCoordinates(MapStartAddress); } return(MapStartAddress); }
public void TryReClean() { var tempRepo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <TempAddressHistory> >(); var coords = new AddressCoordinates(); var i = 0; var rows = tempRepo.AsQueryable().Where(x => x.HomeIsDirty || x.WorkIsDirty).ToList(); foreach (var history in rows) { i++; Console.WriteLine(i + " of " + rows.Count); history.WorkIsDirty = false; history.HomeIsDirty = false; try { coords.GetAddressCoordinates(new Address { StreetName = SplitAddressOnNumber(history.HjemmeAdresse)[0], StreetNumber = SplitAddressOnNumber(history.HjemmeAdresse)[1], ZipCode = history.HjemmePostNr, Town = history.HjemmeBy }); } catch (Exception e) { history.HomeIsDirty = true; } try { coords.GetAddressCoordinates(new Address { StreetName = SplitAddressOnNumber(history.ArbejdsAdresse)[0], StreetNumber = SplitAddressOnNumber(history.ArbejdsAdresse)[1], ZipCode = history.ArbejdsPostNr, Town = history.ArbejdsBy }); } catch (Exception e) { history.WorkIsDirty = true; } } tempRepo.Save(); }
public void TransferFromTempToActual() { var tempRepo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <TempAddressHistory> >(); var actualRepo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <AddressHistory> >(); var workAddressRepo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <WorkAddress> >(); var personalAddressRepo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <PersonalAddress> >(); var coords = new AddressCoordinates(); var emplRepo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <Employment> >(); var i = 0; var rows = tempRepo.AsQueryable().Where(x => !x.WorkIsDirty && !x.HomeIsDirty).ToList(); foreach (var tempHistory in rows) { i++; Console.WriteLine(i + " of " + rows.Count); var currentTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; var empls = emplRepo.AsQueryable().Where(x => x.EmploymentId == tempHistory.MaNr).ToList(); if (empls.Count == 0) { continue;; } var empl = new Employment(); if (empls.Count == 1) { // If only one empl with manr exists just use that empl = empls.First(); } else { // If more than one exists then select the active one. // If an active one does not exist then select the one that ended most recently empl = empls.FirstOrDefault(x => x.EndDateTimestamp == 0) ?? empls.OrderByDescending(x => x.EndDateTimestamp).First(); } var workTemp = coords.GetAddressCoordinates(new WorkAddress() { StreetName = SplitAddressOnNumber(tempHistory.ArbejdsAdresse)[0], StreetNumber = SplitAddressOnNumber(tempHistory.ArbejdsAdresse)[1], ZipCode = tempHistory.ArbejdsPostNr, Town = tempHistory.ArbejdsBy, }); var workAddress = new WorkAddress { StreetName = workTemp.StreetName, StreetNumber = workTemp.StreetNumber, ZipCode = workTemp.ZipCode, Town = workTemp.Town, Latitude = workTemp.Latitude, Longitude = workTemp.Longitude }; var homeTemp = coords.GetAddressCoordinates(new PersonalAddress { StreetName = SplitAddressOnNumber(tempHistory.HjemmeAdresse)[0], StreetNumber = SplitAddressOnNumber(tempHistory.HjemmeAdresse)[1], ZipCode = tempHistory.HjemmePostNr, Town = tempHistory.HjemmeBy, }); var homeAddress = new PersonalAddress() { StreetName = homeTemp.StreetName, StreetNumber = homeTemp.StreetNumber, ZipCode = homeTemp.ZipCode, Town = homeTemp.Town, Latitude = homeTemp.Latitude, Longitude = homeTemp.Longitude, PersonId = empl.PersonId, Type = PersonalAddressType.OldHome, }; workAddressRepo.Insert(workAddress); personalAddressRepo.Insert(homeAddress); workAddressRepo.Save(); personalAddressRepo.Save(); var addressHistory = new Core.DomainModel.AddressHistory { WorkAddressId = workAddress.Id, HomeAddressId = homeAddress.Id, StartTimestamp = tempHistory.AktivFra, EndTimestamp = tempHistory.AktivTil, EmploymentId = empl.Id, IsMigrated = true, }; actualRepo.Insert(addressHistory); } actualRepo.Save(); }
public HashSet <string> GetUncleanableAddresses() { var provider = new DataProvider(); var coords = new AddressCoordinates(); var repo = NinjectWebKernel.CreateKernel().Get <IGenericRepository <TempAddressHistory> >(); Console.WriteLine("Loading histories"); var histories = provider.GetAddressHistoriesAsQueryable(); var i = 0; var max = histories.Count(); foreach (var ah in histories) { i++; Console.WriteLine("Attempting clean of address " + i + " of " + max); var tempHistory = new TempAddressHistory { AktivFra = (Int32)(ah.AktivFra.Subtract(new DateTime(1970, 1, 1))).TotalSeconds, AktivTil = (Int32)(ah.AktivTil.Subtract(new DateTime(1970, 1, 1))).TotalSeconds, ArbejdsAdresse = ah.ArbejdsAdresse, ArbejdsBy = ah.ArbejdsBy, ArbejdsPostNr = ah.ArbejdsPostNr, HjemmeAdresse = ah.HjemmeAdresse, HjemmeBy = ah.HjemmeBy, HjemmeLand = ah.HjemmeLand, HjemmePostNr = ah.HjemmePostNr, MaNr = ah.MaNr, Navn = ah.Navn, HomeIsDirty = false, WorkIsDirty = false, }; var home = new Address(); try { home = new Address { StreetName = SplitAddressOnNumber(ah.HjemmeAdresse)[0], StreetNumber = SplitAddressOnNumber(ah.HjemmeAdresse)[1], ZipCode = ah.HjemmePostNr, Town = ah.HjemmeBy }; coords.GetAddressCoordinates(home); } catch (Exception e) { tempHistory.HomeIsDirty = true; } var work = new Address(); try { work = new Address { StreetName = SplitAddressOnNumber(ah.ArbejdsAdresse)[0], StreetNumber = SplitAddressOnNumber(ah.ArbejdsAdresse)[1], ZipCode = ah.ArbejdsPostNr, Town = ah.ArbejdsBy }; coords.GetAddressCoordinates(work); } catch (Exception e) { tempHistory.WorkIsDirty = true; } repo.Insert(tempHistory); } repo.Save(); return(null); }
static void Main(string[] args) { var logger = NinjectWebKernel.CreateKernel().Get <ILogger>(); // hacks because of error with Entity Framework. // This forces the dmzconnection to use MySql. new DataContext(); var personSync = new PersonSyncService(new GenericDmzRepository <Profile>(new DmzContext()), new GenericRepository <Person>(new DataContext()), new GenericDmzRepository <Core.DmzModel.Employment>(new DmzContext()), NinjectWebKernel.CreateKernel().Get <IPersonService>(), logger); var driveSync = new DriveReportSyncService(new GenericDmzRepository <DriveReport>(new DmzContext()), new GenericRepository <Core.DomainModel.DriveReport>(new DataContext()), new GenericRepository <Rate>(new DataContext()), new GenericRepository <LicensePlate>(new DataContext()), NinjectWebKernel.CreateKernel().Get <IDriveReportService>(), NinjectWebKernel.CreateKernel().Get <IRoute <RouteInformation> >(), NinjectWebKernel.CreateKernel().Get <IAddressCoordinates>(), NinjectWebKernel.CreateKernel().Get <IGenericRepository <Core.DomainModel.Employment> >(), logger); var rateSync = new RateSyncService(new GenericDmzRepository <Core.DmzModel.Rate>(new DmzContext()), new GenericRepository <Rate>(new DataContext()), logger); var orgUnitSync = new OrgUnitSyncService(new GenericDmzRepository <Core.DmzModel.OrgUnit>(new DmzContext()), new GenericRepository <Core.DomainModel.OrgUnit>(new DataContext()), logger); var userAuthSync = new UserAuthSyncService(new GenericRepository <Core.DomainModel.AppLogin>(new DataContext()), new GenericDmzRepository <Core.DmzModel.UserAuth>(new DmzContext()), logger); var auditlogSync = new AuditlogSyncService(new GenericDmzRepository <Core.DmzModel.Auditlog>(new DmzContext()), new GenericRepository <Core.DomainModel.Auditlog>(new DataContext()), logger); logger.Debug("-------- DMZSYNC STARTED --------"); try { logger.Debug("SyncFromDMZ started"); Console.WriteLine("DriveReportsSyncFromDmz"); driveSync.SyncFromDmz(); } catch (Exception ex) { logger.Error($"Error during drivereport synchronization from DMZ", ex); logger.LogForAdmin("Fejl under synkronisering af indberetninger fra DMZ. Mobilindberetninger er ikke synkroniserede."); throw; } try { logger.Debug("OrgUnitSyncToDmz started"); Console.WriteLine("OrgUnitSyncToDmz"); orgUnitSync.SyncToDmz(); } catch (Exception ex) { logger.Error($"Error during orgunit synchronization to DMZ", ex); logger.LogForAdmin("Fejl ved synkronisering af organisationsenheder til DMZ."); throw; } try { logger.Debug("PersonSyncToDmz started"); Console.WriteLine("PersonSyncToDmz"); personSync.SyncToDmz(); } catch (Exception ex) { logger.Error($"Error during people synchronization to DMZ", ex); logger.LogForAdmin("Fejl ved synkronisering af medarbejdere til DMZ."); throw; } try { logger.Debug("RateSyncToDmz started"); Console.WriteLine("RateSyncToDmz"); rateSync.SyncToDmz(); } catch (Exception ex) { logger.Error($"Error during rate synchronization from DMZ", ex); logger.LogForAdmin("Fejl ved synkronisering af takster til DMZ."); throw; } try { logger.Debug("UserAuthSyncToDmz started"); Console.WriteLine("UserAuthSyncToDmz"); userAuthSync.SyncToDmz(); } catch (Exception ex) { logger.Error($"Error during userauth synchronization from DMZ", ex); logger.LogForAdmin("Fejl ved synkronisering af app-logins til DMZ. Nogle brugere vil muligvis ikke kunne logge på app."); throw; } try { logger.Debug("AuditlogSyncFromDmz started"); Console.WriteLine("AuditlogSyncFromDmz"); auditlogSync.SyncFromDmz(); } catch (Exception ex) { logger.Error($"Error during auditlog synchronization from DMZ", ex); logger.LogForAdmin("Fejl ved synkronisering af auditlogs fra DMZ."); throw; } logger.Debug("-------- DMZSYNC FINISHED --------"); Console.WriteLine("Done"); }