public SynchronizationData ReadConfiguration()
        {
            var syncData = new SynchronizationData();

            if (_configuration == null)
            {
                return(syncData);
            }

            try
            {
                syncData.RunAsInitializationModule           = _configuration.RunAsInitializationModule;
                syncData.RunInitializationModuleEveryStartup = _configuration.RunInitializationModuleEveryStartup;

                if (_configuration.SiteDefinitions != null && _configuration.SiteDefinitions.Count > 0)
                {
                    syncData.SiteDefinitions = new List <SiteDefinition>();
                    foreach (var options in _configuration.SiteDefinitions)
                    {
                        var siteDefinition = new SiteDefinition()
                        {
                            Id      = string.IsNullOrEmpty(options.Id) ? Guid.Empty : new Guid(options.Id),
                            Name    = string.IsNullOrEmpty(options.Name) ? string.Empty : options.Name,
                            SiteUrl = string.IsNullOrEmpty(options.SiteUrl) ? null : new Uri(options.SiteUrl),
                            Hosts   = ToHostDefinitions(options.Hosts)
                        };
                        if (!string.IsNullOrEmpty(siteDefinition.Name) && siteDefinition.SiteUrl != null)
                        {
                            syncData.SiteDefinitions.Add(siteDefinition);
                        }
                    }
                }
                else
                {
                    Logger.Information($"Found no site definitions to handle.");
                }

                if (_configuration.ScheduledJobs != null && _configuration.ScheduledJobs.Count > 0)
                {
                    syncData.ScheduledJobs = new List <ScheduledJobDefinition>();
                    foreach (var options in _configuration.ScheduledJobs)
                    {
                        var job = new ScheduledJobDefinition
                        {
                            Id        = options.Id,
                            Name      = options.Name,
                            IsEnabled = options.IsEnabled,
                            AutoRun   = options.AutoRun
                        };
                        syncData.ScheduledJobs.Add(job);
                    }
                }
                else
                {
                    Logger.Information($"Found no schedule jobs to handle.");
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"No configuration found in the web.config. Missing env.synchronizer section.", ex);
            }

            return(syncData);
        }
Exemplo n.º 2
0
        public SynchronizationData ReadConfiguration()
        {
            var config   = new SynchronizerConfiguration();
            var syncData = new SynchronizationData();

            if (config.Settings == null)
            {
                return(syncData);
            }

            try
            {
                syncData.RunAsInitializationModule           = config.Settings.RunAsInitializationModule;
                syncData.RunInitializationModuleEveryStartup = config.Settings.RunInitializationModuleEveryStartup;

                if (config.Settings.SiteDefinitions != null && config.Settings.SiteDefinitions.Count > 0)
                {
                    syncData.SiteDefinitions = new List <SiteDefinition>();
                    foreach (SiteDefinitionElement element in config.Settings.SiteDefinitions)
                    {
                        var siteDefinition = new SiteDefinition()
                        {
                            Id      = string.IsNullOrEmpty(element.Id) ? Guid.Empty : new Guid(element.Id),
                            Name    = string.IsNullOrEmpty(element.Name) ? string.Empty : element.Name,
                            SiteUrl = string.IsNullOrEmpty(element.SiteUrl) ? null : new Uri(element.SiteUrl),
                            Hosts   = element.Hosts.ToHostDefinitions()
                        };
                        if (!string.IsNullOrEmpty(siteDefinition.Name) && siteDefinition.SiteUrl != null)
                        {
                            syncData.SiteDefinitions.Add(siteDefinition);
                        }
                    }
                }
                else
                {
                    Logger.Information($"Found no site definitions to handle.");
                }

                if (config.Settings.ScheduleJobs != null && config.Settings.ScheduleJobs.Count > 0)
                {
                    syncData.ScheduledJobs = new List <ScheduledJobDefinition>();
                    foreach (ScheduledJobElement element in config.Settings.ScheduleJobs)
                    {
                        var job = new ScheduledJobDefinition
                        {
                            Id        = element.Id,
                            Name      = element.Name,
                            IsEnabled = element.IsEnabled
                        };
                        syncData.ScheduledJobs.Add(job);
                    }
                }
                else
                {
                    Logger.Information($"Found no schedule jobs to handle.");
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"No configuration found in the web.config. Missing env.synchronizer section.", ex);
            }

            return(syncData);
        }