Esempio n. 1
0
 public CsvExport(
     ILogger <CsvExport> logger
     , IMonitoredPostRepository repo
     , IOptions <CsvExportConfiguration> config
     , IMapper mapper
     )
 {
     _logger = logger;
     _repo   = repo;
     _config = config.Value;
     _mapper = mapper;
 }
Esempio n. 2
0
        private void Load()
        {
            var path = HostingEnvironment.MapPath(@"/config/formEditor.config");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            var configFile = new FileInfo(path);

            if (configFile.Exists == false)
            {
                return;
            }
            XDocument configXml;

            try
            {
                configXml = XDocument.Load(configFile.FullName);
                if (configXml.Root == null)
                {
                    throw new ConfigurationErrorsException("Missing root node in configuration file.");
                }
            }
            catch (Exception ex)
            {
                // bad config XML
                Log.Error(ex, "Could not parse the configuration file.");
                return;
            }

            var jobs      = configXml.Root.Element("Jobs");
            var authToken = jobs?.Attribute("authToken")?.Value;

            Jobs = string.IsNullOrEmpty(authToken) ? null : new JobsConfiguration(authToken);

            var customFields = configXml.Root.Element("CustomFields");

            if (customFields != null)
            {
                CustomFields.AddRange(
                    customFields.Elements("Field").Where(e => e.Attribute("type") != null).Select(e =>
                                                                                                  new CustomField
                {
                    Name        = e.Attribute("name")?.Value ?? "No name",
                    Type        = e.Attribute("type").Value,
                    FixedValues = e.Attribute("fixedValues")?.Value == "true"
                }
                                                                                                  )
                    );
            }

            var customConditions = configXml.Root.Element("CustomConditions");

            if (customConditions != null)
            {
                CustomConditions.AddRange(
                    customConditions.Elements("Condition").Where(e => e.Attribute("type") != null).Select(e =>
                                                                                                          new CustomCondition
                {
                    Name = e.Attribute("name")?.Value ?? "No name",
                    Type = e.Attribute("type").Value
                }
                                                                                                          )
                    );
            }

            var index = configXml.Root.Element("Storage")?.Element("Index");

            if (index != null)
            {
                var type = ParseType(index, typeof(IIndex),
                                     t => t.GetConstructors().Any(c =>
                {
                    var parameters = c.GetParameters();
                    return(parameters.Length == 1 && parameters.First().ParameterType == typeof(int));
                })
                                                ? null
                                                : $"Custom Index type \"{t}\" does not contain a constructor that takes an integer (content ID) as it's only parameter"
                                     );
                if (type != null)
                {
                    IndexType = type;
                }
            }

            var maxSubmissionsForCurrentUserHandler = configXml.Root.Element("Limitations")?.Element("MaxSubmissionsForCurrentUserHandler");

            if (maxSubmissionsForCurrentUserHandler != null)
            {
                var type = ParseType(maxSubmissionsForCurrentUserHandler, typeof(IMaxSubmissionsForCurrentUserHandler),
                                     t => t.GetConstructors().Any(c => c.GetParameters().Any() == false)
                                                ? null
                                                : $"Custom MaxSubmissionsForCurrentUserHandler type \"{t}\" does not contain a parameterless constructor"
                                     );

                if (type != null)
                {
                    MaxSubmissionsForCurrentUserHandlerType = type;
                }
            }

            var delimiter = configXml.Root.Element("CsvExport")?.Attribute("delimiter")?.Value ?? ";";

            CsvExport = new CsvExportConfiguration(delimiter);
        }