// Create an empty initialized template public Template() { head = new node(); addedHead = new node(); addedTail = addedHead; firstSection = new section(); tpl = this; fields = new Object[MAX_FIELDS]; sections = new Object[MAX_FIELDS]; }
public override void execute() { Template target = new Template(AssetPathUtility.DataAccessorTemplatePath, false); target.Set("className", className); target.Set("namespace", ns); target.Set("getCases", CreateGetCases()); target.Set("setCases", CreateSetCases()); string folderPath = AssetPathUtility.DataAccessorGeneratePath; string generatePath = NamingRuleUtility.CreateDataAccessorGeneratePath(className); GenerateCode(folderPath, generatePath, target.ToString()); }
// Create using template file public Template(string data) { head = new node(); addedHead = new node(); addedTail = addedHead; firstSection = new section(); tpl = this; fields = new Object[MAX_FIELDS]; sections = new Object[MAX_FIELDS]; data = SECTIONTAG_HEAD + data + SECTIONTAG_TAIL; construct(data, SECTIONTAG_HEAD_LEN, data.Length-SECTIONTAG_TAIL_LEN); }
public override void execute() { Template target = new Template(AssetPathUtility.DataScriptTemplatePath, false); target.Set("className", className); target.Set ("superClass", superClassName); string variableCode = ""; foreach(KeyValuePair<string, string> pair in variables) { string line = " public " + pair.Value + " " + pair.Key + ";"; variableCode += line + System.Environment.NewLine; } target.Set("variables", variableCode); string folderPath = AssetPathUtility.DataScriptGeneratePath; string generatePath = NamingRuleUtility.CreateDataScriptGeneratePath(className); GenerateCode(folderPath, generatePath, target.ToString()); }
public override void execute() { Template target = new Template(AssetPathUtility.AccessorManagerTemplatePath, false); target.Set("className", className); string createCode = ""; foreach(string name in dataClassNames) { createCode += " obj = prefab.GetComponent<" + name + ">();"; createCode += System.Environment.NewLine; createCode += " if(obj != null) return new " + name + "DataAccessor(obj);"; createCode += System.Environment.NewLine; } target.Set("createCode", createCode); string folderPath = AssetPathUtility.AccessorManagerGeneratePath; string generatePath = NamingRuleUtility.CreateAccessorManagerGeneratePath(className); GenerateCode(folderPath, generatePath, target.ToString()); }
void ReceivedItems(DiscoManager manager, DiscoNode node, object state) { string jid = node.JID.ToString(); string nodeName = String.Empty; if (node.Node != null) nodeName = node.Node; string templateContent = Util.ReadResource("ServiceDiscovery.html"); Template template = new Template(templateContent); template.SetField("NAME", jid); template.SetField("HREF", String.Format("xmpp:{0}?disco", jid)); template.SetField("NODE", nodeName); template.SelectSection("FEATURES"); foreach (var feature in node.FeatureNames) { template.SetField("FEATURE_NAME", feature); template.AppendSection(); } template.DeselectSection(); template.SelectSection("ITEMS"); foreach (DiscoNode item in node.Children) { template.SetField("ITEM_NAME", item.Name); template.SetField("ITEM_URL", String.Format("xmpp:{0}?disco;node={1}", item.JID.ToString(), item.Node)); template.AppendSection(); } template.DeselectSection(); template.SelectSection("IDENTITIES"); foreach (var identity in node.GetIdentities()) { template.SetField("IDENTITY_NAME", identity.Name); template.SetField("IDENTITY_CATEGORY", identity.Category); template.SetField("IDENTITY_TYPE", identity.Type); template.AppendSection(); } template.DeselectSection(); QApplication.Invoke(delegate { Uri uri = new Uri(String.Format("xmpp:{0}?disco;node={1}", node.JID.ToString(), node.Node)); LoadContent(uri, template.getContent()); }); }
// Copy ctor public Template(Template srctpl) { tpl = this; fields = new Object[MAX_FIELDS]; sections = new Object[MAX_FIELDS]; head = new node(); addedHead = new node(); addedTail = addedHead; firstSection = new section(); node tail = head; node currNode = srctpl.head; section lastSection = firstSection; section currSection = srctpl.firstSection.nextSection; for (; currSection != null; currSection = currSection.nextSection) { // Copy part before section while (currNode != currSection.preceding) { currNode = currNode.next; tail.next = new node(); tail = tail.next; if (currNode.val.shared) tail.val = _produceField(((field)currNode.val).key); else tail.val = new cell(); tail.val.val = currNode.val.val; } // Create section entry lastSection.nextSection = _produceSection(currSection.key); lastSection = lastSection.nextSection; lastSection.preceding = tail; lastSection.tpl = new Template(currSection.tpl); lastSection.tpl.parent = this; // Copy added content if (currSection.tpl.addedHead.next != null) { int len = 0; for (node n=currSection.tpl.addedHead.next; n!=null; n=n.next) len += n.val.val.Length; lastSection.tpl.addedTail.next = new node(); lastSection.tpl.addedTail = lastSection.tpl.addedTail.next; lastSection.tpl.addedTail.val = new cell(); // Make content string StringBuilder sb = new StringBuilder(len); for (node n=currSection.tpl.addedHead.next; n!=null; n=n.next) sb.Append(n.val.val); lastSection.tpl.addedTail.val.val = sb.ToString(); } } // Copy rest while ((currNode = currNode.next) != null) { tail.next = new node(); tail = tail.next; if (currNode.val.shared) tail.val = _produceField(((field)currNode.val).key); else tail.val = new cell(); tail.val.val = currNode.val.val; } }
public void SelectSection(string key) { section s = tpl._getSection(key); if (s == null) throw new Exception("SelectSection: Cannot find section "+key); tpl.tpl = s.tpl; tpl = tpl.tpl; }
public void DeselectSection() { if (tpl == this) throw new Exception("DeselectSection: No section selected"); tpl = tpl.parent; }