Esempio n. 1
0
        public void SearchIndex()
        {
            try
            {
                Configuration configuration = ReadConfiguration();

                Assert.NotNull(configuration);
                string             path = "root/configuration/node_1/ELEMENT_LIST";
                AbstractConfigNode node = configuration.Find(path);
                Assert.NotNull(node);
                Assert.Equal(path, node.GetSearchPath());

                path = "ELEMENT_LIST[3]";
                AbstractConfigNode nnode = node.Find(path);
                Assert.NotNull(nnode);
                Assert.True(nnode.GetType() == typeof(ConfigPathNode));
                LogUtils.Debug(nnode.GetAbsolutePath());

                path = "ELEMENT_LIST[2]/string_2";
                node = node.Find(path);
                Assert.NotNull(node);
                Assert.True(node.GetType() == typeof(ConfigValueNode));
                LogUtils.Debug(node.GetAbsolutePath());
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex);
                throw ex;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Set the target instance values reading from the passed configuration node.
        /// </summary>
        /// <typeparam name="T">Target Instance type</typeparam>
        /// <param name="parent">Configuration node instance</param>
        /// <param name="target">Target Type instance</param>
        /// <returns>Updated Target Type instance</returns>
        public static T Process <T>(AbstractConfigNode parent)
        {
            Preconditions.CheckArgument(parent);

            Type type   = typeof(T);
            T    target = default(T);

            ConfigPath path = (ConfigPath)Attribute.GetCustomAttribute(type, typeof(ConfigPath));

            if (path != null)
            {
                AbstractConfigNode node = null;
                if (!String.IsNullOrWhiteSpace(path.Path))
                {
                    node = parent.Find(path.Path);
                }
                if ((!Conditions.NotNull(node) || node.GetType() != typeof(ConfigPathNode)) && path.Required)
                {
                    throw new AnnotationProcessorException(String.Format("Annotation not found: [path={0}][type={1}]", path.Path, type.FullName));
                }
                if (Conditions.NotNull(node) && node.GetType() == typeof(ConfigPathNode))
                {
                    target = CreateInstance <T>(type, (ConfigPathNode)node);
                }
            }
            return(target);
        }
Esempio n. 3
0
        /// <summary>
        /// Set the target instance values reading from the passed configuration node.
        /// </summary>
        /// <typeparam name="T">Target Instance type</typeparam>
        /// <param name="parent">Configuration node instance</param>
        /// <param name="target">Target Type instance</param>
        /// <param name="valuePaths">List of Value paths used</param>
        /// <returns>Updated Target Type instance</returns>
        public static T Process <T>(AbstractConfigNode parent, T target, out List <string> valuePaths)
        {
            Preconditions.CheckArgument(parent);
            Preconditions.CheckArgument(target);

            valuePaths = null;
            Type       type = target.GetType();
            ConfigPath path = (ConfigPath)Attribute.GetCustomAttribute(type, typeof(ConfigPath));

            if (path != null)
            {
                AbstractConfigNode node = null;
                if (!String.IsNullOrWhiteSpace(path.Path))
                {
                    node = parent.Find(path.Path);
                }
                if ((!Conditions.NotNull(node) || node.GetType() != typeof(ConfigPathNode)) && path.Required)
                {
                    throw new AnnotationProcessorException(String.Format("Annotation not found: [path={0}][type={1}]", path.Path, type.FullName));
                }
                if (node != null && node.GetType() == typeof(ConfigPathNode))
                {
                    valuePaths = new List <string>();
                    target     = ReadValues((ConfigPathNode)node, target, valuePaths);
                    CallMethodInvokes((ConfigPathNode)node, target);
                }
            }
            return(target);
        }
Esempio n. 4
0
        /// <summary>
        /// Find a specified node relative to the specified node based on the search Path.
        /// </summary>
        /// <param name="node">Config node to search under</param>
        /// <param name="path">Search path</param>
        /// <returns>Configuratio Node</returns>
        public AbstractConfigNode Find(AbstractConfigNode node, string path)
        {
            Preconditions.CheckArgument(node);
            Preconditions.CheckArgument(path);

            return(node.Find(path));
        }
Esempio n. 5
0
        public void SearchParameters()
        {
            try
            {
                Configuration configuration = ReadConfiguration();

                Assert.NotNull(configuration);
                String             path = "root/configuration/node_1#";
                AbstractConfigNode node = configuration.Find(path);
                Assert.NotNull(node);
                Assert.True(node.GetType() == typeof(ConfigParametersNode));

                path = "#PARAM_1";
                node = configuration.Find(node, path);
                Assert.True(node.GetType() == typeof(ConfigValueNode));
                String param = ((ConfigValueNode)node).GetValue();
                Assert.False(String.IsNullOrEmpty(param));
                LogUtils.Debug(
                    String.Format("[path={0}] parameter value = {1}", path, param));

                path = "/root/configuration/node_1/node_2#PARAM_1";
                node = node.Find(path);
                Assert.NotNull(node);
                Assert.True(node.GetType() == typeof(ConfigValueNode));
                LogUtils.Debug("NODE>>", node);
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex);
                throw ex;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Load defined pipelines from the configuration.
        /// </summary>
        /// <param name="config">Configuration Node</param>
        public void Load(AbstractConfigNode config)
        {
            Contract.Requires(config != null);
            AbstractConfigNode ps = null;

            if (config.Name == CONFIG_NODE_PIPELINES)
            {
                ps = config;
            }
            else
            {
                ps = config.Find(CONFIG_NODE_PIPELINES);
            }
            if (ps != null)
            {
                if (ps.GetType() == typeof(ConfigPathNode))
                {
                    ps = ps.Find(CONFIG_NODE_PIPELINE);
                    if (ps != null && ps.GetType() == typeof(ConfigPathNode))
                    {
                        LoadPipeline((ConfigPathNode)ps);
                    }
                    else
                    {
                        LogUtils.Warn(String.Format("No pipeline defined: [path={0}]", config.GetAbsolutePath()));
                    }
                }
                else if (ps.GetType() == typeof(ConfigElementListNode))
                {
                    ConfigElementListNode nodes = (ConfigElementListNode)ps;
                    foreach (ConfigElementNode elem in nodes.GetValues())
                    {
                        if (elem.GetType() == typeof(ConfigPathNode) && elem.Name == CONFIG_NODE_PIPELINE)
                        {
                            LoadPipeline((ConfigPathNode)elem);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        public void SearchParent()
        {
            try
            {
                Configuration configuration = ReadConfiguration();

                Assert.NotNull(configuration);
                string             path = "root/configuration/node_1/ELEMENT_LIST";
                AbstractConfigNode node = configuration.Find(path);
                Assert.NotNull(node);
                Assert.Equal(path, node.GetSearchPath());
                path = "../node_2/node_3/../#";
                node = node.Find(path);
                Assert.NotNull(node);
                Assert.True(node.GetType() == typeof(ConfigParametersNode));
                LogUtils.Debug(node.GetAbsolutePath());
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex);
                throw ex;
            }
        }
Esempio n. 8
0
        public void SearchRecursive()
        {
            try
            {
                Configuration configuration = ReadConfiguration();

                Assert.NotNull(configuration);
                String             path = "root/**/updatedBy";
                AbstractConfigNode node = configuration.Find(path);
                Assert.NotNull(node);
                Assert.True(node.GetType() == typeof(ConfigSearchResult));

                path = "/**/node_2/#PARAM_1";
                node = node.Find(path);
                Assert.NotNull(node);
                Assert.True(node.GetType() == typeof(ConfigValueNode));
                LogUtils.Debug("NODE>>", node);
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex);
                throw ex;
            }
        }
Esempio n. 9
0
        public void Search()
        {
            try
            {
                Configuration configuration = ReadConfiguration();

                Assert.NotNull(configuration);
                string             path = "root/configuration/node_1";
                AbstractConfigNode node = configuration.Find(path);
                Assert.NotNull(node);
                Assert.Equal(path, node.GetSearchPath());
                path = "VALUE_LIST";
                node = node.Find(path);
                Assert.True(node.GetType() == typeof(ConfigListValueNode));
                Assert.Equal(8, ((ConfigListValueNode)node).Count());
                Assert.Equal(path, node.Name);
                LogUtils.Debug(node.GetAbsolutePath());
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex);
                throw ex;
            }
        }