public EsasSynchronizationService(IList <SyncStrategyBundle> syncStrategyBundles, IEsasDbContextFactory esasStagingDbContextFactory, EsasWebServiceHealthChecker esasWebServiceHealthChecker, ILogger logger, IEmailService emailService)
        {
            logger.LogInformation("Service initializing...");
            _syncStrategyBundles         = syncStrategyBundles;
            _esasStagingDbContextFactory = esasStagingDbContextFactory;
            _esasWebServiceHealthChecker = esasWebServiceHealthChecker;
            _logger                  = logger;
            _emailService            = emailService;
            _isSynchronizationActive = false;

            _minuteIntervalBetweenEsasWsHealthcheck = Convert.ToInt32(ConfigurationManager.AppSettings["MinuteIntervalBetweenEsasWsHealthcheck"]);
            _logger.LogInformation($"{System.Environment.MachineName} - Esas sync Service was initialized. Happy trails!");
        }
Пример #2
0
        public static void Main()
        {
            try
            {
                _logger       = InitializeLogger();
                _emailService = new DummyEmailService();
                _logger.LogInformation("Creating OData container connection.");

                Uri odataWs = new Uri(ConfigurationManager.AppSettings["EsasWsUri"]);

                EsasWsContextFactory esasWsContextFactory = new EsasWsContextFactory(_esasSecuritySettings, odataWs, _logger);

                EsasWebServiceHealthChecker esasWebServiceHealthChecker = new EsasWebServiceHealthChecker(ConfigurationManager.AppSettings["EsasWsUri"], _esasSecuritySettings, _logger);
                _logger.LogInformation("Establishing sync-strategies.");

                IEsasDbContextFactory esasStagingDbContextFactory = new EsasDbContextFactory();
                IEnumerable <IEsasStagingDbDestination> esasStagingDbSyncStrategies = CreateEsasStagingDbDestinations(_logger);

                IEsasSyncDestination    stagingDbDestination      = new EsasStagingDbSyncDestination(esasStagingDbContextFactory, esasStagingDbSyncStrategies);
                ISyncResultsDestination whereToSendTheSyncResults = new EsasStagingDbLoadResultDestination(esasStagingDbContextFactory);
                ILoadTimeStrategy       loadTimeStrategy          = new LatestSuccesfulLoadStrategy(esasStagingDbContextFactory);

                IList <SyncStrategyBundle> syncStrategyBundles = new List <SyncStrategyBundle>();

                IEnumerable <IEsasSyncStrategy> standardEntitiesSyncs = CreateStandardEntitiesSyncs(esasWsContextFactory, whereToSendTheSyncResults, loadTimeStrategy, _logger, stagingDbDestination);

                // Create strategy-bundles for N-minute intervals for A am thru B pm, fx. 6 to 22:
                for (int hour = 6; hour < 22; hour++)
                {
                    for (int minutes = 0; minutes < 60; minutes += 30)
                    {
                        TimeSpan           syncTimeSpan = new TimeSpan(hour, minutes, 0);
                        SyncStrategyBundle bundle       = new SyncStrategyBundle(syncTimeSpan, standardEntitiesSyncs, _logger);
                        syncStrategyBundles.Add(bundle);
                    }
                }

                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[]
                {
                    new EsasSynchronizationService(syncStrategyBundles, esasStagingDbContextFactory, esasWebServiceHealthChecker, _logger, _emailService)
                };
#if (!DEBUG)
                // windows service rock'n roll
                ServiceBase.Run(ServicesToRun);
#else
                #region devSync - for manuel syncs.


                List <string> positivListe = new List <string>();

                #region strategyList
                // ***Virksomheds - og person - oplysninger ***
                positivListe.Add("LandLoadStrategy");
                positivListe.Add("KommuneLoadStrategy");
                positivListe.Add("PostnummerLoadStrategy");
                positivListe.Add("BrancheLoadStrategy");
                positivListe.Add("InstitutionVirksomhedLoadStrategy");
                positivListe.Add("InstitutionsoplysningerLoadStrategy");
                positivListe.Add("AfdelingsniveauLoadStrategy");
                positivListe.Add("AfdelingLoadStrategy");
                positivListe.Add("PersonLoadStrategy");
                positivListe.Add("PersonoplysningLoadStrategy");

                // *** opsætningstabeller, som øvrige syncs er afhængige af. ***
                positivListe.Add("AnsoegningskortOpsaetningLoadStrategy");
                positivListe.Add("PubliceringLoadStrategy");
                positivListe.Add("AdgangskravLoadStrategy");
                positivListe.Add("FravaersaarsagLoadStrategy");

                ////////// *** Uddannelsesaktiviteter ***
                positivListe.Add("UddannelsesaktivitetLoadStrategy");
                positivListe.Add("UddannelsesstrukturLoadStrategy");
                positivListe.Add("StruktureltUddannelseselementLoadStrategy");
                positivListe.Add("AktivitetsudbudLoadStrategy");

                //// *** PUE//Hold ***
                positivListe.Add("PlanlaegningsUddannelseselementLoadStrategy");
                positivListe.Add("HoldLoadStrategy");
                positivListe.Add("SamlaesningLoadStrategy");

                //// *** Ansøgninger ***
                positivListe.Add("RekvirenttypeLoadStrategy");
                positivListe.Add("AnsoegerLoadStrategy");
                positivListe.Add("AnsoegningsopsaetningLoadStrategy");
                positivListe.Add("AnsoegningskortTekstLoadStrategy");
                positivListe.Add("AnsoegningskortLoadStrategy");
                positivListe.Add("EksamenstypeLoadStrategy");
                positivListe.Add("OmraadenummerLoadStrategy");
                positivListe.Add("OmraadenummeropsaetningLoadStrategy");
                positivListe.Add("OmraadespecialiseringLoadStrategy");
                positivListe.Add("SpecialiseringLoadStrategy");
                positivListe.Add("AfslagsbegrundelseLoadStrategy");
                positivListe.Add("AnsoegningLoadStrategy");
                positivListe.Add("AnsoegningshandlingLoadStrategy");
                positivListe.Add("AnsoegningPlanlaegningsUddannelseselementLoadStrategy");
                positivListe.Add("BilagLoadStrategy");
                positivListe.Add("NationalAfgangsaarsagLoadStrategy");
                positivListe.Add("EnkeltfagLoadStrategy");

                //***GUEer / Studieforløb * **
                positivListe.Add("IndskrivningsformLoadStrategy");
                positivListe.Add("StudieforloebLoadStrategy");
                positivListe.Add("BedoemmelsesrundeLoadStrategy");
                positivListe.Add("KarakterLoadStrategy");
                positivListe.Add("GennemfoerelsesUddannelseselementLoadStrategy");
                positivListe.Add("BedoemmelseLoadStrategy");
                positivListe.Add("StudieinaktivPeriodeLoadStrategy");
                positivListe.Add("MeritRegistreringLoadStrategy");
                positivListe.Add("PraktikomraadeLoadStrategy");
                positivListe.Add("PraktikopholdLoadStrategy");
                //positivListe.Add("BevisgrundlagLoadStrategy"); --meget stor og omfattende tabel, er ikke sikker på dens forretningsværdi.Udelader den, for now.

                ////// *** Øvrige ***
                positivListe.Add("OptionSetValueLoadStrategy");
                #endregion strategyList

                var debugSyncStrategy   = new LatestSuccesfulLoadStrategy(esasStagingDbContextFactory);
                var debugSyncStrategies = CreateStandardEntitiesSyncs(esasWsContextFactory, whereToSendTheSyncResults, debugSyncStrategy, _logger, stagingDbDestination);

                //// tilføj initial-optionsetvaluestring load
                IEsasSyncStrategy initialOptionSetValueBulkLoadStrategy = new EsasSyncStrategy(new SyncStrategySettings {
                    SyncPriorityNumber = 1000
                },
                                                                                               new OptionSetValueLoadStrategy(esasWsContextFactory, _logger), stagingDbDestination, whereToSendTheSyncResults, _logger);
                debugSyncStrategies.Add(initialOptionSetValueBulkLoadStrategy);

                var initielleStrategier = debugSyncStrategies.Where(strat =>
                                                                    positivListe.Contains(strat.EsasEntitiesLoaderStrategy.GetType().Name)
                                                                    ||
                                                                    strat.EsasEntitiesLoaderStrategy.GetType().Name == "OptionSetValueInitialBulkLoadStrategy"
                                                                    );
                SyncStrategyBundle initialSaveToFileSyncBundle = new SyncStrategyBundle(
                    syncTime: new TimeSpan(01, 00, 00), // let's go back just a day for this manuel debug sync
                    syncStrategies: initielleStrategier,
                    logger: _logger);

                EsasSynchronizationService service = new EsasSynchronizationService(new List <SyncStrategyBundle>()
                {
                    initialSaveToFileSyncBundle
                }, esasStagingDbContextFactory, esasWebServiceHealthChecker, _logger, _emailService);
                initialSaveToFileSyncBundle.ExecuteSync();

                #endregion
#endif
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
                _emailService.SendStatusMail("Error in start of ESAS sync service", ex.Message);
                throw;
            }
        }