예제 #1
0
        /// <summary>
        ///  Initialize uSync elements (run start up import etc).
        /// </summary>
        private void InituSync()
        {
            var sw = Stopwatch.StartNew();

            try
            {
                using (var reference = _umbracoContextFactory.EnsureUmbracoContext())
                {
                    if (IsExportAtStatupEnabled() || (IsExportOnSaveOn() && !_syncFileService.RootExists(_uSyncConfig.GetRootFolder())))
                    {
                        var options = new SyncHandlerOptions
                        {
                            Group = _uSyncConfig.Settings.ExportOnSave
                        };

                        _logger.LogInformation("uSync: Running export at startup");
                        _uSyncService.Export(_uSyncConfig.GetRootFolder(), options);
                    }

                    if (IsImportAtStatupEnabled())
                    {
                        _logger.LogInformation("uSync: Running Import at startup {group}", _uSyncConfig.Settings.ImportAtStartup);

                        if (!HasStopFile(_uSyncConfig.GetRootFolder()))
                        {
                            _uSyncService.Import(_uSyncConfig.GetRootFolder(), false, new SyncHandlerOptions
                            {
                                Group = _uSyncConfig.Settings.ImportAtStartup
                            });

                            ProcessOnceFile(_uSyncConfig.GetRootFolder());
                        }
                        else
                        {
                            _logger.LogInformation("Startup Import blocked by usync.stop file");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, "uSync: Error during startup {message}", ex.Message);
            }
            finally
            {
                sw.Stop();
                _logger.LogInformation("uSync: Startup Complete {elapsed}ms", sw.ElapsedMilliseconds);
            }
        }
예제 #2
0
        private void InitBackOffice()
        {
            if (globalSettings.ExportAtStartup || (globalSettings.ExportOnSave && !syncFileService.RootExists(globalSettings.RootFolder)))
            {
                uSyncService.Export(globalSettings.RootFolder);
            }

            if (globalSettings.ImportAtStartup)
            {
                uSyncService.Import(globalSettings.RootFolder, false);
            }

            if (globalSettings.ExportOnSave)
            {
                var handlers = syncHandlers.GetValidHandlers("Save", globalSettings);
                foreach (var syncHandler in handlers)
                {
                    logger.Debug <uSyncBackofficeComponent>($"Starting up Handler {syncHandler.Handler.Name}");
                    syncHandler.Handler.Initialize(syncHandler.Settings);
                }
            }
        }
예제 #3
0
        private void InitBackOffice()
        {
            var sw = Stopwatch.StartNew();

            try
            {
                using (var reference = umbracoContextFactory.EnsureUmbracoContext())
                {
                    if (uSyncSettings.ExportAtStartup || (uSyncSettings.ExportOnSave && !syncFileService.RootExists(uSyncSettings.RootFolder)))
                    {
                        logger.Info <uSyncBackofficeComponent>("uSync: Running Export at startup");
                        uSyncService.Export(uSyncSettings.RootFolder, default(SyncHandlerOptions));
                    }

                    if (uSyncSettings.ImportAtStartup)
                    {
                        logger.Info <uSyncBackofficeComponent>("uSync: Running Import at startup");

                        if (!HasStopFile(uSyncSettings.RootFolder))
                        {
                            uSyncService.Import(uSyncSettings.RootFolder, false, new SyncHandlerOptions
                            {
                                Group = uSyncSettings.ImportAtStartupGroup
                            });

                            ProcessOnceFile(uSyncSettings.RootFolder);
                        }
                        else
                        {
                            logger.Info <uSyncBackofficeComponent>("Startup Import blocked by usync.stop file");
                        }
                    }

                    if (uSyncSettings.ExportOnSave)
                    {
                        var handlers = handlerFactory
                                       .GetValidHandlers(new SyncHandlerOptions(handlerFactory.DefaultSet, HandlerActions.Save))
                                       .ToList();

                        logger.Info <uSyncBackofficeComponent>("uSync: Initializing events for {count} Handlers", handlers.Count);

                        foreach (var syncHandler in handlers)
                        {
                            logger.Debug <uSyncBackofficeComponent>($"  Initializing up Handler {syncHandler.Handler.Name}");
                            syncHandler.Handler.Initialize(syncHandler.Settings);
                        }
                    }
                }

                sw.Stop();
                logger.Info <uSyncBackofficeComponent>("uSync: Startup Processes Complete {ElapsedMilliseconds}ms", sw.ElapsedMilliseconds);
            }
            catch (Exception ex)
            {
                logger.Warn <uSyncBackofficeComponent>($"uSync: Error during at startup {ex.Message}");
            }
        }