Exemple #1
0
        private int Apply(ref object owner, NodeVisitor visitor)
        {
            int count = 0;

            FARLogger.TraceFormat("Applying visitor to config node {0}[{1}]", Id, Name ?? "{null}");
            foreach (ValueReflection value in Values)
            {
                FARLogger.TraceFormat("Visiting value {0}[{1}].{2}", Id, Name, value.Name);
                try
                {
                    visitor.VisitValue(owner, value);
                }
                catch (Exception e)
                {
                    FARLogger.ExceptionFormat(e, "Exception loading value {0} in {1}", value.Name, value.DeclaringType);
                    count++;
                }
            }

            foreach (ListValueReflection reflection in ListValues)
            {
                if (reflection.IsNodeValue)
                {
                    NodeReflection nodeReflection = GetReflection(reflection.ValueType);

                    FARLogger.TraceFormat("Visiting list nodes {0}[{1}].{2}[{3}]",
                                          Id,
                                          Name ?? "{null}",
                                          reflection.NodeId,
                                          reflection.Name ?? "{null}");
                    try
                    {
                        visitor.VisitNodeList(owner, reflection, nodeReflection);
                    }
                    catch (Exception e)
                    {
                        FARLogger.ExceptionFormat(e,
                                                  "Exception loading node ({2}) list {0} in {1}",
                                                  reflection.Name,
                                                  reflection.DeclaringType,
                                                  reflection.NodeId);
                        count++;
                    }
                }
                else
                {
                    FARLogger.TraceFormat("Visiting list values {0}[{1}].{2}", Id, Name ?? "{null}", reflection.Name);
                    try
                    {
                        visitor.VisitValueList(owner, reflection);
                    }
                    catch (Exception e)
                    {
                        FARLogger.ExceptionFormat(e,
                                                  "Exception loading value list {0} in {1}",
                                                  reflection.Name,
                                                  reflection.DeclaringType);
                        count++;
                    }
                }
            }

            foreach (NodeReflection node in Nodes)
            {
                FARLogger.TraceFormat("Visiting subnode {0}[{1}].{2}[{3}]",
                                      Id,
                                      Name ?? "{null}",
                                      node.Id,
                                      node.Name ?? "{null}");
                try
                {
                    visitor.VisitNode(owner, node);
                }
                catch (Exception e)
                {
                    FARLogger.ExceptionFormat(e,
                                              "Exception loading node {2}[{0}] in {1}",
                                              node.Name,
                                              node.DeclaringType,
                                              node.Id);
                    count++;
                }
            }

            return(count);
        }