///<summary>
        /// Initializes a new instance of <see cref="XamlRegistrationModule" />.
        ///</summary>
        ///<param name="configurationStream">The stream containing the configuration file content.</param>
        public XamlRegistrationModule(Stream configurationStream)
        {
            if (configurationStream.Length == 0)
            {
                throw new ArgumentException(string.Format(Resources.BadStreamContent, configurationStream));
            }

            this._configuration = (LightCoreConfiguration)XamlReader.Load(configurationStream);
        }
Пример #2
0
        ///<summary>
        /// Initializes a new instance of <see cref="XamlRegistrationModule" />.
        ///</summary>
        ///<param name="configurationStream">The stream containing the configuration file content.</param>
        public XamlRegistrationModule(Stream configurationStream)
        {
            if (configurationStream.Length == 0)
            {
                throw new ArgumentException(string.Format(Resources.BadStreamContent, configurationStream));
            }

            _configuration = (LightCoreConfiguration)XamlReader.Load(configurationStream);
        }
        ///<summary>
        /// Initializes a new instance of <see cref="XamlRegistrationModule" />.
        ///</summary>
        ///<param name="configurationPath">The path to a xaml config file.</param>
        public XamlRegistrationModule(string configurationPath)
        {
            if (!File.Exists(configurationPath))
            {
                throw new FileNotFoundException(string.Format(Resources.ConfigurationFileNotFoundFormat, configurationPath));
            }

            using (var file = File.Open(configurationPath, FileMode.Open))
            {
                this._configuration = (LightCoreConfiguration)XamlReader.Load(file);
            }
        }
Пример #4
0
        ///<summary>
        /// Initializes a new instance of <see cref="XamlRegistrationModule" />.
        ///</summary>
        ///<param name="configurationPath">The path to a xaml config file.</param>
        public XamlRegistrationModule(string configurationPath)
        {
            if (!File.Exists(configurationPath))
            {
                throw new FileNotFoundException(string.Format(Resources.ConfigurationFileNotFoundFormat, configurationPath));
            }

            using (var file = File.Open(configurationPath, FileMode.Open))
            {
                _configuration = (LightCoreConfiguration)XamlReader.Load(file);
            }
        }
Пример #5
0
 public JsonRegistrationModule(string configFilePath = "LightCore.json")
 {
     if (!File.Exists(configFilePath))
     {
         throw new FileNotFoundException("Config File not Found", configFilePath);
     }
     using (var stream = new FileStream(configFilePath, FileMode.Open, FileAccess.Read))
     {
         using (var sr = new StreamReader(stream))
         {
             _configuration = JsonConvert.DeserializeObject <LightCoreConfiguration>(sr.ReadToEnd());
         }
     }
 }
Пример #6
0
        /// <summary>
        ///     Registers all candidates.
        /// </summary>
        /// <param name="containerBuilder">The containerbuilder.</param>
        /// <param name="configuration">The configuration</param>
        public void Register(IContainerBuilder containerBuilder, LightCoreConfiguration configuration)
        {
            _configuration    = configuration;
            _containerBuilder = containerBuilder;

            IEnumerable <RegistrationGroup> registrationGroups      = configuration.RegistrationGroups;
            IEnumerable <Registration>      registrationsToRegister = configuration.Registrations;

            if (configuration.ActiveRegistrationGroups == null)
            {
                registrationsToRegister =
                    registrationsToRegister.Union(registrationGroups.SelectMany(g => g.Registrations));
            }
            else
            {
                var activeGroups = configuration.ActiveRegistrationGroups.Split(new[] { ',' },
                                                                                StringSplitOptions.RemoveEmptyEntries);

                foreach (var group in activeGroups)
                {
                    if (!registrationGroups.Any(g => g.Name != null && g.Name.Trim() == group.Trim()))
                    {
                        throw new ActiveGroupNotFoundException(
                                  Resources.ActiveRegistrationGroupNotFoundFormat.FormatWith(group));
                    }
                }

                Func <RegistrationGroup, bool> groupNameIsEmpty    = group => string.IsNullOrEmpty(group.Name);
                Func <RegistrationGroup, bool> groupNameIsNotEmpty = group => !groupNameIsEmpty(group);
                Func <RegistrationGroup, bool> groupIsActive       =
                    group => activeGroups.Any(activeGroup => activeGroup.Trim() == group.Name.Trim());

                var validGroupRegistrations = registrationGroups
                                              .Where(group => groupNameIsEmpty(group) || groupNameIsNotEmpty(group) && groupIsActive(group))
                                              .SelectMany(group => group.Registrations);

                registrationsToRegister = registrationsToRegister.Union(validGroupRegistrations);
            }

            foreach (var registration in registrationsToRegister)
            {
                ProcessRegistration(registration);
            }
        }
Пример #7
0
        /// <summary>
        /// Registers all candidates.
        /// </summary>
        /// <param name="containerBuilder">The containerbuilder.</param>
        /// <param name="configuration">The configuration</param>
        public void Register(IContainerBuilder containerBuilder, LightCoreConfiguration configuration)
        {
            this._configuration = configuration;
            this._containerBuilder = containerBuilder;

            IEnumerable<RegistrationGroup> registrationGroups = configuration.RegistrationGroups;
            IEnumerable<Registration> registrationsToRegister = configuration.Registrations;

            if (configuration.ActiveRegistrationGroups == null)
            {
                registrationsToRegister = registrationsToRegister.Union(registrationGroups.SelectMany(g => g.Registrations));
            }
            else
            {
                var activeGroups = configuration.ActiveRegistrationGroups.Split(new[] { ',' },
                                                                                 StringSplitOptions.RemoveEmptyEntries);

                foreach (string group in activeGroups)
                {
                    if (!registrationGroups.Any(g => g.Name != null && g.Name.Trim() == group.Trim()))
                    {
                        throw new ActiveGroupNotFoundException(
                            Resources.ActiveRegistrationGroupNotFoundFormat.FormatWith(group));
                    }
                }

                Func<RegistrationGroup, bool> groupNameIsEmpty = group => string.IsNullOrEmpty(group.Name);
                Func<RegistrationGroup, bool> groupNameIsNotEmpty = group => !groupNameIsEmpty(group);
                Func<RegistrationGroup, bool> groupIsActive =
                    group => activeGroups.Any(activeGroup => activeGroup.Trim() == group.Name.Trim());

                var validGroupRegistrations = registrationGroups
                    .Where(group => groupNameIsEmpty(group) || groupNameIsNotEmpty(group) && groupIsActive(group))
                    .SelectMany(group => group.Registrations);

                registrationsToRegister = registrationsToRegister.Union(validGroupRegistrations);
            }

            foreach (Registration registration in registrationsToRegister)
            {
                ProcessRegistration(registration);
            }
        }
 ///<summary>
 /// Initializes a new instance of <see cref="XamlRegistrationModule" />.
 /// Uses the default app.config or web.config for loading the configuration.
 ///</summary>
 public XamlRegistrationModule()
 {
     this._configuration = LightCoreConfiguration.Instance;
 }
Пример #9
0
 ///<summary>
 /// Initializes a new instance of <see cref="XamlRegistrationModule" />.
 /// Uses the default app.config or web.config for loading the configuration.
 ///</summary>
 public XamlRegistrationModule()
 {
     _configuration = LightCoreConfiguration.Instance;
 }