private JankyNodeContext ResolveContext(XmlDocument xmlDoc, object dc, IDictionary <string, object> resources) { var ctx = new JankyNodeContext(dc); JankyUIManager.Register(ctx); ctx.RootNode = NodeHelper <Node> .Instance.Activate(ctx); var settings = xmlDoc.SelectSingleNode("/*[local-name() = 'JankyUI']/*[local-name() = 'Resources']"); if (settings != null) { foreach (XmlNode setting in settings.ChildNodes) { var key = setting.Attributes["key"].Value; var value = setting.Attributes["value"].Value; if (ctx.Resources.ContainsKey(key)) { ctx.Resources[key] = ctx.Resources[key] + "|" + value; } else { ctx.Resources[key] = value; } } if (resources != null) { // Replace with Overrides foreach (var kvp in resources) { if (ctx.Resources.ContainsKey(kvp.Key)) { ctx.Resources.Remove(kvp.Key); } } foreach (var kvp in resources) { var key = kvp.Key; var value = kvp.Value; if (ctx.Resources.ContainsKey(key) && ctx.Resources[key] is string && value is string) { ctx.Resources[key] = ctx.Resources[key] + "|" + value; } else { ctx.Resources[key] = value; } } } } var window = xmlDoc.SelectSingleNode("/*[local-name() = 'JankyUI']/*[local-name() = 'Window']"); var node = ResolveNodeRecursive(ctx, window); ctx.RootNode.Children.Add(node); return(ctx); }
private Node ResolveNodeRecursive(JankyNodeContext context, XmlNode xmlNode) { var nodeName = xmlNode.LocalName; var nodeInfo = _nodes[nodeName]; var props = xmlNode.Attributes .OfType <XmlAttribute>() .ToDictionary(x => x.LocalName, x => x.Value); var node = nodeInfo.Activate(context, props); foreach (XmlNode childNode in xmlNode.ChildNodes) { if (childNode.NodeType == XmlNodeType.Comment) { continue; } var child = ResolveNodeRecursive(context, childNode); node.Children.Add(child); } return(node); }
internal static void Register(JankyNodeContext ctx) { ctx.WindowID = WindowIDCounter++; Windows[ctx.WindowID] = ctx; }