/// <summary> /// Get the page path /// </summary> internal string GetPath() { PropertyTemplate ptm = NonParameterizedTemplate.Spawn(GetPropertyTemplate(pagePathTemplate), Parent, this.Context) as PropertyTemplate; if (ptm == null) { return(pagePathTemplate); } else { return(ptm.FillTemplate()); } }
/// <summary> /// Get the abstract of the article /// </summary> /// <returns></returns> internal string GetAbstract() { PropertyTemplate ptm = NonParameterizedTemplate.Spawn(GetPropertyTemplate(pageAbstractProperty), Parent, this.Context) as PropertyTemplate; if (ptm == null) { return(base.GetContextPropertyValue(pageAbstractProperty).ToString()); } else { return(ptm.FillTemplate()); } }
/// <summary> /// Generate the TOC /// </summary> private void PrepareTOC(Article.Article artc) { // Create a TOC Article Article.Article tocArticle = artc; FeatureTemplate tocTemplate = NonParameterizedTemplate.Spawn(FindTemplate(tocArticle.GetType().FullName, tocArticle), this, tocArticle) as FeatureTemplate; tocArticle.Title = tocArticle.Title ?? tocTemplate.GetTitle(); // Populate Toc Article tocArticle.Content = globalTemplate.FillTemplate(tocTemplate); // Create child TOC if they are empty if (tocArticle.Children != null) { for (int i = 0; i < tocArticle.Children.Count; i++) { PrepareTOC(tocArticle.Children.Data[i]); } } }
/// <summary> /// Fill in template details /// </summary> public override string FillTemplate() { // Get the value of this item object value = ExecuteMethod(this.Context); if (value == null) { return(""); } FeatureTemplate ftpl = NonParameterizedTemplate.Spawn(Parent.FindTemplate(value.GetType().FullName, value) as NonParameterizedTemplate, Parent, value) as FeatureTemplate; // Current template fields string[][] templateFields = new string[][] { new string[] { "$feature$", ftpl == null ? "" : ftpl.FillTemplate() }, new string[] { "$date$", DateTime.Now.ToString("yyyy-MM-dd") }, new string[] { "$time$", DateTime.Now.ToString("HH:mm:ss") }, new string[] { "$user$", SystemInformation.UserName }, new string[] { "$value$", this.Escaped ? value.ToString().Replace(">", ">").Replace("<", "<").Replace("$", "$").Replace("@", "@").Replace("^", "^") : value.ToString().Replace("$", "$").Replace("@", "@").Replace("^", "^").Replace("\\", "\\\\") }, // Clean Template parameters from TOSTRING() new string[] { "$$", "$" }, new string[] { "@@", "@" }, new string[] { "^^", "^" }, new string[] { "$version$", Assembly.GetEntryAssembly().GetName().Version.ToString() }, new string[] { "$typeName$", Context == null ? "" : Context.GetType().Name } }; // Output string output = Content.Clone() as string; foreach (string[] kv in templateFields) { output = output.Replace(kv[0], kv[1]); } return(output); }
public override string FillTemplate() { //// Current template fields string[][] templateFields = new string[][] { new string[] { "$feature$", "Invalid Operation" }, new string[] { "01-09-2009", DateTime.Now.ToString("yyyy-MM-dd") }, new string[] { "$date$", DateTime.Now.ToString("yyyy-MM-dd") }, new string[] { "$time$", DateTime.Now.ToString("HH:mm:ss") }, new string[] { "$user$", SystemInformation.UserName }, new string[] { "$value$", Context.ToString().Replace("<", "<").Replace(">", ">").Replace("$", "$").Replace("@", "@").Replace("^", "^") }, new string[] { "$$", "$" }, new string[] { "@@", "@" }, new string[] { "^^", "^;" }, new string[] { "$version$", Assembly.GetEntryAssembly().GetName().Version.ToString() }, new string[] { "$typeName$", Context == null ? "" : Context.GetType().Name }, new string[] { "$guid$", Guid.NewGuid().ToString() }, new string[] { "$guid2$", Guid.NewGuid().ToString() } }; if (this.Context is Feature && (this.Context as Feature).Annotations.Exists(o => o is SuppressBrowseAnnotation)) { System.Diagnostics.Trace.WriteLine(String.Format("Feature '{0}' won't be published as a SuppressBrowse annotation was found", (this.Context as Feature).Name), "warn"); return(""); } string output = Content; foreach (string[] kv in templateFields) { output = output.Replace(kv[0], kv[1]); } // Process output for literals #region Literals while (output.Contains("$")) { int litPos = output.IndexOf('$'); int ePos = output.IndexOf('$', litPos + 1); System.Diagnostics.Debug.Assert(ePos >= litPos, String.Format("Unfinished template variable in HTML template '{0}'", output)); string parmName = ""; if (ePos > litPos) { parmName = output.Substring(litPos + 1, ePos - litPos - 1); } PropertyTemplate pt = NonParameterizedTemplate.Spawn(GetPropertyTemplate(parmName) as NonParameterizedTemplate, Parent, GetContextPropertyValue(parmName)) as PropertyTemplate; var ctxPropertyValue = GetContextPropertyValue(parmName); if (pt == null && !string.IsNullOrEmpty(parmName)) // None found ... use value { output = output.Replace(string.Format("${0}$", parmName), string.Format("{0}", ctxPropertyValue).Replace("$", "$").Replace("@", "@").Replace("^", "^")); } else if (pt.Property == null) { System.Diagnostics.Trace.WriteLine(String.Format("Invalid property name for parameter '{0}' propertyTemplate name '{1}'", parmName, pt.Name), "error"); output = output.Replace(String.Format("${0}$", parmName), "<span style=\"color:red\">Invalid property name</span>"); } else if (!string.IsNullOrEmpty(parmName))// Found, so use { pt.Context = GetContextPropertyValue(pt.Property); output = output.Replace(string.Format("${0}$", parmName), pt.FillTemplate().Replace("$", "$").Replace("@", "@").Replace("^", "^")); } } #endregion #region Arrays while (output.Contains("@")) { int litPos = output.IndexOf('@'); int ePos = output.IndexOf('@', litPos + 1); string parmName = output.Substring(litPos + 1, ePos - litPos - 1); object[] value = null; PropertyTemplate pt = NonParameterizedTemplate.Spawn(GetPropertyTemplate(parmName) as NonParameterizedTemplate, Parent, null) as PropertyTemplate; if (parmName == "this") { value = ConvertToObjectArray(this.Context); } else { value = ConvertToObjectArray(GetContextPropertyValue(pt != null ? pt.Property : parmName)); } // First, we'll look for a property template that has the specific name //value = ConvertToObjectArray(GetContextPropertyValue(pt != null ? pt.Property : parmName)); if (value != null && pt == null) { foreach (object o in value) { output = output.Replace(string.Format("@{0}@", parmName), string.Format("{0}@{1}@", o, parmName)); } output = output.Replace(string.Format("@{0}@", parmName), ""); } else if (value != null && pt != null) // Apply template { foreach (object o in value) { PropertyTemplate cpt = NonParameterizedTemplate.Spawn(pt, Parent, o) as PropertyTemplate; output = output.Replace(string.Format("@{0}@", parmName), string.Format("{0}@{1}@", cpt.FillTemplate().Replace("$", "$").Replace("@", "@").Replace("^", "^"), parmName)); } output = output.Replace(string.Format("@{0}@", parmName), ""); } else { output = output.Replace(string.Format("@{0}@", parmName), ""); } } #endregion #region Functoids while (output.Contains("^")) { int litPos = output.IndexOf('^'); int ePos = output.IndexOf('^', litPos + 1); System.Diagnostics.Debug.Assert(ePos != -1, String.Format("Template field not closed at '{0}'", this.Name)); string funcName = output.Substring(litPos + 1, ePos - litPos - 1); // First, we'll look for a property template that has the specific name var funcTemplate = NonParameterizedTemplate.Spawn(this.SubTemplates.Find(o => o.Name == funcName && o is FunctoidTemplate), this.Parent, this.Context) as FunctoidTemplate; object content = null; if (funcTemplate == null) { content = String.Format("<span style=\"color:red\">Could not find function template '{0}'</span>", funcName); } else { content = funcTemplate.FillTemplate(); } if (content is IEnumerable && !(content is String)) { foreach (object o in content as IEnumerable) { string ovalue = o == null ? "" : o.ToString().Replace("$", "$").Replace("@", "@").Replace("^", "^"); output = output.Replace(string.Format("^{0}^", funcName), string.Format("{0}^{1}^", ovalue, funcName)); } output = output.Replace(string.Format("^{0}^", funcName), ""); } else { output = output.Replace(string.Format("^{0}^", funcName), string.Format("{0}", content.ToString().Replace("$", "$").Replace("@", "@").Replace("^", "^"))); } } #endregion // Apply XmlElement Templates output = ApplyXmlElementTemplates(output); return(output); }
public override string FillTemplate() { // First... see if there is a feature that could process this item if (Context == null) { return(""); } FeatureTemplate ftpl = Content.Contains("$feature$") ? NonParameterizedTemplate.Spawn(Parent.FindTemplate(Context.GetType().FullName, Context) as NonParameterizedTemplate, Parent, Context) as FeatureTemplate : null; // Current template fields string[][] templateFields = new string[][] { new string[] { "$feature$", ftpl == null ? "" : ftpl.FillTemplate() }, new string[] { "$date$", DateTime.Now.ToString("yyyy-MM-dd") }, new string[] { "$time$", DateTime.Now.ToString("HH:mm:ss") }, new string[] { "$user$", SystemInformation.UserName }, new string[] { "$guid$", Guid.NewGuid().ToString() }, new string[] { "$value$", escaped ? Context.ToString().Replace(">", ">").Replace("<", "<").Replace("$", "$").Replace("@", "@").Replace("^", "^") : Context.ToString().Replace("$", "$").Replace("@", "@").Replace("^", "^").Replace("\\", "\\\\") }, // Clean Template parameters from TOSTRING() new string[] { "$$", "$" }, new string[] { "@@", "@" }, new string[] { "^^", "^" }, new string[] { "$version$", Assembly.GetEntryAssembly().GetName().Version.ToString() }, new string[] { "$typeName$", Context == null ? "" : Context.GetType().Name } }; if (this.Context is Feature && (this.Context as Feature).Annotations.Exists(o => o is SuppressBrowseAnnotation)) { System.Diagnostics.Trace.WriteLine(String.Format("Feature '{0}' won't be published as a SuppressBrowse annotation was found", (this.Context as Feature).Name), "warn"); return(""); } string output = Content.Clone() as string; foreach (string[] kv in templateFields) { output = output.Replace(kv[0], kv[1]); } // Process output for literals #region Literals while (output.Contains("$")) { int litPos = output.IndexOf('$'); int ePos = output.IndexOf('$', litPos + 1); System.Diagnostics.Debug.Assert(ePos != -1, String.Format("Template field not closed at '{0}'", this.Name)); string parmName = output.Substring(litPos + 1, ePos - litPos - 1); // First, we'll look for a property template that has the specific name object content = GetContextPropertyValue(parmName); string value = content == null ? "" : content.ToString().Replace("$", "$").Replace("@", "@").Replace("^", "^"); output = output.Replace(string.Format("${0}$", parmName), string.Format("{0}", value)); } #endregion #region Arrays while (output.Contains("@")) { int litPos = output.IndexOf('@'); int ePos = output.IndexOf('@', litPos + 1); string parmName = output.Substring(litPos + 1, ePos - litPos - 1); // First, we'll look for a property template that has the specific name object[] value = ConvertToObjectArray(GetContextPropertyValue(parmName)); if (value != null) { foreach (object o in value) { string ovalue = o == null ? "" : o.ToString().Replace("$", "$").Replace("@", "@").Replace("^", "^"); output = output.Replace(string.Format("@{0}@", parmName), string.Format("{0}@{1}@", ovalue, parmName)); } output = output.Replace(string.Format("@{0}@", parmName), ""); } else { output = output.Replace(string.Format("@{0}@", parmName), ""); } } #endregion return(output); }
public ArticleCollection Process(ClassRepository rep) { ArticleCollection artc = new ArticleCollection(); List <Feature> features = new List <Feature>(); foreach (KeyValuePair <string, Feature> kv in rep) { features.Add(kv.Value); } // Sort so classes are processed first features.Sort(delegate(Feature a, Feature b) { if ((a is SubSystem) && !(b is SubSystem)) { return(-1); } else if ((b is SubSystem) && !(a is SubSystem)) { return(1); } else if ((a is Class) && !(b is Class)) { return(1); } else if ((b is Class) && !(a is Class)) { return(-1); } else { return(a.GetType().Name.CompareTo(b.GetType().Name)); } }); //var vocabArticle = new MohawkCollege.EHR.gpmr.Pipeline.Renderer.Deki.Article.Article() //{ // Title = "Vocabulary", // Children = new ArticleCollection() //}; //vocabArticle.Children.Add(new Article.Article() { Title = "Code Systems" }); //vocabArticle.Children.Add(new Article.Article() { Title = "Concept Domains" }); //vocabArticle.Children.Add(new Article.Article() { Title = "Value Sets" }); //artc.Add(vocabArticle); WaitThreadPool wtp = new WaitThreadPool(); // A thread that does the doohickey thing Thread doohickeyThread = new Thread((ThreadStart) delegate() { string[] hickeythings = { "|", "/", "-", "\\" }; int hickeyThingCount = 0; try { while (true) { int cPosX = Console.CursorLeft, cPosY = Console.CursorTop; Console.SetCursorPosition(1, cPosY); Console.Write(hickeythings[hickeyThingCount++ % hickeythings.Length]); Console.SetCursorPosition(cPosX, cPosY); Thread.Sleep(1000); } } catch { } }); doohickeyThread.Start(); // Loop through each feature foreach (Feature f in features) { // Find the feature template FeatureTemplate ftpl = NonParameterizedTemplate.Spawn(FindTemplate(f.GetType().FullName, f) as NonParameterizedTemplate, this, f) as FeatureTemplate; if (ftpl == null) { System.Diagnostics.Trace.WriteLine(string.Format("Feature '{0}' won't be published as no feature template could be located", f.Name), "warn"); } else if (f.Annotations.Find(o => o is SuppressBrowseAnnotation) != null) { System.Diagnostics.Trace.WriteLine(String.Format("Feature '{0}' won't be published as a SuppressBrowse annotation was found", f.Name), "warn"); } else if (ftpl.NewPage) { System.Diagnostics.Trace.WriteLine(string.Format("Queueing ({1}) '{0}'...", f.Name, f.GetType().Name), "debug"); // Create a new worker Worker w = new Worker(); w.ArticleCollection = artc; w.FeatureTemplate = ftpl; w.OnComplete += delegate(object sender, EventArgs e) { Worker wrkr = sender as Worker; System.Diagnostics.Trace.WriteLine(String.Format("Rendered ({1}) '{0}'...", (wrkr.FeatureTemplate.Context as Feature).Name, wrkr.FeatureTemplate.Context.GetType().Name), "debug"); }; wtp.QueueUserWorkItem(w.Start); } } System.Diagnostics.Trace.WriteLine("Waiting for work items to complete...", "debug"); wtp.WaitOne(); doohickeyThread.Abort(); ArticleCollection retVal = new ArticleCollection(); Article.Article MasterTOC = new MohawkCollege.EHR.gpmr.Pipeline.Renderer.Deki.Article.Article(); MasterTOC.Children = artc; System.Diagnostics.Trace.WriteLine("Creating Table of Contents...", "information"); PrepareTOC(MasterTOC); MasterTOC.Children = null; artc.Add(MasterTOC); return(artc); }