/// <summary> /// Method used to add def to def dictionary /// </summary> /// <param name="key">Key to use</param> /// <param name="def">Def object to add</param> internal void AddDef(string key, def def, KScriptObject parent = null) { if (parent != null) { def.SetBaseScriptObject(parent); def.SetContainer(this); } defs.Add(key, def); }
private void Iterate(XmlNode node, Document.KScriptDocument doc, KScriptContainer container, KScriptDocumentCollectionNode docNode) { foreach (XmlNode item in node.ChildNodes) { if (!(item.NodeType != XmlNodeType.Comment || item.NodeType == XmlNodeType.Text)) { continue; } KScriptObject obj = GetScriptObject(item, container); if (obj == null) { continue; } if (!PrepareProperties(obj, item, container)) { continue; } IParserHandler parserHandler = GetParserInterface(obj); if (parserHandler != null) { KScriptDocumentNode collection = new KScriptDocumentNode(parserHandler.GenerateKScriptObject(obj, item)); docNode.Nodes.Add(collection); continue; } if (item.HasChildNodes) { KScriptDocumentCollectionNode withoutParserCollection = new KScriptDocumentCollectionNode(obj); Iterate(item, doc, container, withoutParserCollection); docNode.Nodes.Add(withoutParserCollection); continue; } docNode.Nodes.Add(new KScriptDocumentNode(obj)); continue; } }
/// <summary> /// Prepares properties for KScript objects. /// </summary> /// <param name="obj"></param> /// <param name="item"></param> /// <param name="container"></param> /// <returns></returns> public bool PrepareProperties(KScriptObject obj, XmlNode item, KScriptContainer container) { if (obj["Contents"] != null) { obj["Contents"] = item.InnerText; } foreach (XmlAttribute at in item.Attributes) { if (at.Name != "Contents") { if (at.Name.StartsWith("__")) { container.GetConstantProperties().Add(at.Name.Substring(2), at.Value); } else { obj[at.Name.ToLower()] = at.Value; } } } if (typeof(def).IsAssignableFrom(obj.GetType())) { obj.SetContainer(container); if (item.ChildNodes.OfType <XmlCDataSection>().Count() > 0) { obj["Contents"] = item.ChildNodes.OfType <XmlCDataSection>().ToArray()[0].Data; } else { obj["Contents"] = item.InnerXml; } container[((def)obj).id] = obj as def; } if (typeof(defm).IsAssignableFrom(obj.GetType())) { defm _obj = (defm)obj; string[] ids = _obj.ids.Split(','); foreach (string id in ids) { container[id] = new def(_obj.Contents); } } obj.Init(container); if (typeof(KScriptIDObject).IsAssignableFrom(obj.GetType())) { ((KScriptIDObject)obj).RegisterObject(); } if (obj.GetValidationType() != KScriptObject.ValidationTypes.DURING_PARSING) { try { obj.Validate(); } catch (KScriptValidationException ex) { if (typeof(KScriptInvalidScriptType).IsAssignableFrom(ex.GetType())) { return(false); } } } if (obj.RunImmediately) { try { obj.Run(); } catch (Exception ex) { container.HandleException(obj, ex); } } return(true); }
public OperatorHandler GetOperatorInterface(KScriptObject obj) { var objX = KScriptContainer.LoadedOperatorHandlers.Values.FirstOrDefault(i => GetOperatorHandler(i).CanRun(obj)) ?? null; return(GetOperatorHandler(objX)); }
public IParserHandler GetParserInterface(KScriptObject obj) => GetParserHandler(KScriptContainer.LoadedParserHandlers.Values.FirstOrDefault(i => GetParserHandler(i).IsAcceptedObject(obj)) ?? null);
public KScriptCommand(KScriptContainer container, KScriptObject parent) : base(container) { }