Esempio n. 1
0
        /// <summary>
        /// Updates the inputs to setup the default parameters transmission.
        /// If there is no anything found, the default value will be used.
        /// </summary>
        /// <param name="items">The previous engine items.</param>
        public void UpdateImplictInputs(Dictionary<string, FlowItem> items)
        {
            foreach (KeyValuePair<string, PropertyInfo> pair in TypeInfo.Inputs)
            {
                string name = pair.Key;
                PropertyInfo pi = pair.Value;

                // If there is no explict definition, needs to find the implict transmission.
                if (!Config.Inputs.ContainsKey(name))
                {
                    // Finds the last one which has the same name and is assignable.
                    foreach (FlowItem item in items.Values.Reverse())
                    {
                        if (item.TypeInfo.Outputs.ContainsKey(name) &&
                            pi.PropertyType.IsAssignableFrom(item.TypeInfo.Outputs[name].PropertyType))
                        {
                            // Adds a input item.
                            ConfigurationInput input = new ConfigurationInput
                            {
                                Name = name,
                                Value = new ConfigurationReference(item.Name, name).ToString(),
                                IsCdataSection = false,
                            };

                            Config.Inputs.Add(input.Name, input);
                            break;
                        }
                    }
                }
            }

            foreach (KeyValuePair<string, PropertyInfo> pair in TypeInfo.Inputs)
            {
                string name = pair.Key;
                PropertyInfo pi = pair.Value;

                if (!Config.Inputs.ContainsKey(name))
                {
                    // Gets the default value of this instance.
                    object obj = pi.GetValue(Handler, null);

                    ConfigurationInput input = new ConfigurationInput
                    {
                        Name = name,
                        Value = (obj == null) ? string.Empty : obj.ToString(),
                        IsCdataSection = false,
                    };

                    Config.Inputs.Add(input.Name, input);
                }
            }

            foreach (KeyValuePair<string, MethodInfo> pair in TypeInfo.Parsers)
            {
                string name = pair.Key;

                if (!Config.Inputs.ContainsKey(name))
                {
                    ConfigurationInput input = new ConfigurationInput
                    {
                        Name = name,
                        Value = string.Empty,
                        IsCdataSection = true,
                    };

                    Config.Inputs.Add(input.Name, input);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Validates the name of the input from configuration.
        /// </summary>
        /// <param name="input">The configuration input.</param>
        private void ValidateInput(ConfigurationInput input)
        {
            // All name of input should be constant value.
            if (ConfigurationReference.IsReference(input.Name))
            {
                throw new ConfigurationException(
                    Helper.NeutralFormat(
                        "Module \"{0}\" has a reference input name \"{1}\", which is not allowed here", Name, input.Name));
            }

            if (input.IsCdataSection)
            {
                // The input should be found in type info parsers.
                if (!TypeInfo.Parsers.ContainsKey(input.Name))
                {
                    throw new ConfigurationException(
                        Helper.NeutralFormat("Parser name \"{0}\" not found in module \"{1}\", one of below expected - {2}",
                            input.Name, Name, string.Join(",", TypeInfo.Parsers.Keys.ToArray())));
                }
            }
            else
            {
                // The input should be found in the type info inputs.
                if (!TypeInfo.Inputs.ContainsKey(input.Name))
                {
                    throw new ConfigurationException(
                        Helper.NeutralFormat("Input name \"{0}\" not found in module \"{1}\", one of below expected - {2}",
                            input.Name, Name, string.Join(",", TypeInfo.Inputs.Keys.ToArray())));
                }
            }
        }
        /// <summary>
        /// Parses the included file.
        /// </summary>
        /// <param name="resolver">The resolver to resolve the include file.</param>
        /// <returns>The Dictionary of ConfigurationModule.</returns>
        public Dictionary<string, ConfigurationModule> ParsesInclude(Configuration.ConfigurationResolver resolver)
        {
            Configuration config = new Configuration();

            config.ConfigurationResolve += resolver;

            config.Load(Source);

            Dictionary<string, ConfigurationModule> modules = config.GetAllModules();

            // Overwrite the inputs in the included file according to the inputs.
            foreach (ConfigurationInput item in Inputs.Values)
            {
                if (!ConfigurationReference.IsReference(item.Name))
                {
                    throw new ConfigurationException(
                        Helper.NeutralFormat("Input \"{0}\" in include element isn't reference", item.Name));
                }

                ConfigurationReference reference = new ConfigurationReference();
                reference.Parse(item.Name);

                if (!modules.ContainsKey(reference.Module))
                {
                    throw new ConfigurationException(
                        Helper.NeutralFormat(
                            "No such module name \"{0}\" found in include file, one of below expected - {1}", reference.Module,
                            string.Join(",", modules.Keys.ToArray())));
                }

                if (reference.Name == ConfigurationModule.SkipAttribute)
                {
                    // Overwrite the skip attribute.
                    modules[reference.Module].Skip = bool.Parse(item.Value);
                }
                else if (reference.Name == ConfigurationModule.KeepIntermediateDataAttribute)
                {
                    // Overwrite the keep intermediate data attribute.
                    modules[reference.Module].KeepIntermediateData = bool.Parse(item.Value);
                }
                else
                {
                    if (modules[reference.Module].Inputs.ContainsKey(reference.Name))
                    {
                        // Overwrite the exist input.
                        modules[reference.Module].Inputs[reference.Name].Value = item.Value;
                    }
                    else
                    {
                        // Create a new input.
                        ConfigurationInput input = new ConfigurationInput
                        {
                            Name = reference.Name,
                            Value = item.Value
                        };

                        modules[reference.Module].Inputs.Add(input.Name, input);
                    }

                    modules[reference.Module].Inputs[reference.Name].IsCdataSection = item.IsCdataSection;
                }
            }

            return modules;
        }