Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var kernel = NinjectWebKernel.GetKernel();

            var x = kernel.GetBindings(typeof(DataContext)).FirstOrDefault();

            kernel.RemoveBinding(x);

            kernel.Bind <DataContext>().ToSelf().InSingletonScope(); // we need to use a single dbcontext

            var logger = kernel.Get <ILogger>();

            // hacks because of error with Entity Framework.
            // This forces the dmzconnection to use MySql.
            new DataContext();

            var gpsEncryptService = new GPSEncryptService(logger);

            logger.Debug("-------- DMZ GPS Encrypt STARTED --------");

            try
            {
                logger.Debug("DoGPSEncrypt started");
                Console.WriteLine("DoGPSEncrypt");
                gpsEncryptService.DoGPSEncrypt();
            }
            catch (Exception ex)
            {
                logger.Error($"Error during encrypting geocoordinates on DMZ", ex);
                logger.LogForAdmin("Fejl under kryptering af geo koodinater i DMZ.");
                throw;
            }

            logger.Debug("-------- DMZ GPS Encrypt ENDED --------");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var ninjectKernel = NinjectWebKernel.CreateKernel();
            var updateService = new Service();

            updateService.TransferFromTempToActual();
        }
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        public static IKernel CreateKernel(List <KeyValuePair <Type, Type> > injectedServices)
        {
            _injectedServices = injectedServices;
            var kernel = new StandardKernel();

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();

                NinjectWebKernel.RegisterServices(kernel);

                RegisterServices(kernel);

                // Install our Ninject-based IDependencyResolver into the Web API config
                GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);

                return(kernel);
            }
            catch
            {
                kernel.Dispose();
                throw;
            }
        }
Exemplo n.º 4
0
 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>();
 }
Exemplo n.º 5
0
        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());
        }
        static void Main(string[] args)
        {
            // Checks if any files need to be generated and transfered to the payroll system daily at kl 16:00
            ILogger _logger = NinjectWebKernel.GetKernel().Get <ILogger>();

            _logger.Debug($"-------- FILE GENERATIONS STARTED --------");
            var service = NinjectWebKernel.GetKernel().Get <FileGenerationService>();

            service.RunFileGenerationService();
            _logger.Debug($"-------- FILE GENERATION FINISHED --------");
        }
Exemplo n.º 7
0
 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));
 }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
        /// <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);
        }
Exemplo n.º 10
0
        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();
        }
Exemplo n.º 11
0
        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();
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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");
        }