public static object printf(ITextMetalContext templatingContext, string[] parameters) { const int CNT_P = 2; // token, format object value; if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } if ((object)parameters == null) { throw new ArgumentNullException(nameof(parameters)); } if (parameters.Length != CNT_P) { throw new InvalidOperationException(string.Format("printf expects '{1}' parameter(s) but received '{0}' parameter(s).", parameters.Length, CNT_P)); } var x = templatingContext.GetWildcardReplacer(); if (!x.GetByToken(parameters[0], out value)) { return(null); } return(string.Format(value?.ToString() ?? string.Empty, parameters[1])); //return value.SafeToString(parameters[1]); }
protected override async ValueTask CoreExpandTemplateAsync(ITextMetalContext templatingContext) { templatingContext.GetWildcardReplacer().GetByToken("yo", out object value); await templatingContext.CurrentOutput.TextWriter.WriteLineAsync(string.Format("test: yo={0}", value)); await templatingContext.CurrentOutput.EnterScopeAsync("", false, Encoding.Default); }
protected override void CoreExpandTemplate(ITextMetalContext templatingContext) { //templatingContext.RequestDebugger(); templatingContext.GetWildcardReplacer().GetByToken("yo", out object value); templatingContext.CurrentOutput.TextWriter.WriteLine("test: yo={0}", value); templatingContext.CurrentOutput.EnterScope("", false, Encoding.Default); }
/// <summary> /// Expands the template tree into the templating context current output. /// </summary> /// <param name="templatingContext"> The templating context. </param> public void ExpandTemplate(ITextMetalContext templatingContext) { if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } templatingContext.DebugBreak(); }
/// <summary> /// Evaluates at run-time, an expression tree yielding an object value result. /// </summary> /// <param name="templatingContext"> The templating context. </param> /// <returns> An expression return value or null. </returns> public object EvaluateExpression(ITextMetalContext templatingContext) { if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } templatingContext.DebugBreak(); return(null); }
/// <summary> /// Gets the value of the current associative object instance. /// </summary> /// <param name="templatingContext"> The templating context. </param> /// <returns> A value or null. </returns> public object GetAssociativeObjectValue(ITextMetalContext templatingContext) { if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } templatingContext.DebugBreak(); return(this); }
/// <summary> /// Gets the dictionary enumerator for the current associative object instance. /// </summary> /// <param name="templatingContext"> The templating context. </param> /// <returns> An instance of IDictionaryEnumerator or null. </returns> public IDictionaryEnumerator GetAssociativeObjectEnumeratorDict(ITextMetalContext templatingContext) { if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } templatingContext.DebugBreak(); return(null); }
/// <summary> /// Re-orders an enumerable of values, yielding a re-ordered enumerable. /// </summary> /// <param name="templatingContext"> The templating context. </param> /// <param name="values"> </param> /// <returns> </returns> public IEnumerable EvaluateSort(ITextMetalContext templatingContext, IEnumerable values) { if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } templatingContext.DebugBreak(); return(values); }
protected override async ValueTask CoreExpandTemplateAsync(ITextMetalContext templatingContext) { string text; DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy; if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } dynamicWildcardTokenReplacementStrategy = templatingContext.GetWildcardReplacer(); text = templatingContext.Tokenizer.ExpandTokens(this.Value, dynamicWildcardTokenReplacementStrategy); await templatingContext.CurrentOutput.TextWriter.WriteAsync(text); }
public async ValueTask HostAsync() { ITextMetalTemplate textMetalTemplate; __ITextMetalModel textMetalModel; ITextMetalOutput textMetalOutput; Dictionary <string, object> properties; properties = new Dictionary <string, object>(); await using (ITextMetalTemplateFactory textMetalTemplateFactory = new StubTemplateFactory()) { //textMetalTemplateFactory.Configuration = ... await textMetalTemplateFactory.CreateAsync(); textMetalTemplate = await textMetalTemplateFactory.GetTemplateObjectAsync(new Uri("urn:null"), properties); await using (ITextMetalModelFactory textMetalModelFactory = new StubModelFactory()) { //textMetalModelFactory.Configuration = ... await textMetalModelFactory.CreateAsync(); textMetalModel = await textMetalModelFactory.GetModelObjectAsync(properties); await using (ITextMetalOutputFactory textMetalOutputFactory = new StubTextMetalOutputFactory()) { //textMetalOutputFactory.Configuration = ... await textMetalOutputFactory.CreateAsync(); textMetalOutput = await textMetalOutputFactory.GetOutputObjectAsync(new Uri("urn:null"), properties); //textMetalOutput.TextWriter.WriteLine("xxx"); await using (ITextMetalContext textMetalContext = this.CreateContext()) { textMetalContext.IteratorModels.Push(textMetalModel); await textMetalTemplate.ExpandTemplateAsync(textMetalContext); textMetalContext.IteratorModels.Pop(); } } } } }
public async ValueTask ExpandTemplateAsync(ITextMetalContext templatingContext) { DynamicWildcardTokenReplacementStrategy dynamicWildcardTokenReplacementStrategy; if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } dynamicWildcardTokenReplacementStrategy = templatingContext.GetWildcardReplacer(); if (this.IsScopeBlock) { templatingContext.VariableTables.Push(new Dictionary <string, object>()); } await this.CoreExpandTemplateAsync(templatingContext); if (this.IsScopeBlock) { templatingContext.VariableTables.Pop(); } }
protected abstract ValueTask CoreExpandTemplateAsync(ITextMetalContext templatingContext);
public async ValueTask <EmailMessage> HostAsync(bool strictMatching, EmailPrototype emailPrototype, object textMetalModel) { ITextMetalTemplateObject textMetalTemplate; EmailMessage emailMessage; INativeXmlSerializationStrategy nativeXmlSerializationStrategy; IXyzlSerializer xyzlSerializer; XmlTextReader templateXmlTextReader; if ((object)emailPrototype == null) { throw new ArgumentNullException(nameof(emailPrototype)); } emailMessage = new EmailMessage(); xyzlSerializer = new XyzlSerializer(SolderFascadeAccessor.DataTypeFascade, SolderFascadeAccessor.ReflectionFascade); xyzlSerializer.RegisterKnownObject <EmailTemplateEchoFragment>(new XyzlName() { LocalName = "From", NamespaceUri = "http://textmetal.wellengineered.us/stdlib/v6.0.0" }); xyzlSerializer.RegisterKnownObject <EmailTemplateEchoFragment>(new XyzlName() { LocalName = "To", NamespaceUri = "http://textmetal.wellengineered.us/stdlib/v6.0.0" }); xyzlSerializer.RegisterKnownObject <EmailTemplateEchoFragment>(new XyzlName() { LocalName = "ReplyTo", NamespaceUri = "http://textmetal.wellengineered.us/stdlib/v6.0.0" }); xyzlSerializer.RegisterKnownObject <EmailTemplateEchoFragment>(new XyzlName() { LocalName = "Sender", NamespaceUri = "http://textmetal.wellengineered.us/stdlib/v6.0.0" }); xyzlSerializer.RegisterKnownObject <EmailTemplateEchoFragment>(new XyzlName() { LocalName = "CarbonCopy", NamespaceUri = "http://textmetal.wellengineered.us/stdlib/v6.0.0" }); xyzlSerializer.RegisterKnownObject <EmailTemplateEchoFragment>(new XyzlName() { LocalName = "BlindCarbonCopy", NamespaceUri = "http://textmetal.wellengineered.us/stdlib/v6.0.0" }); xyzlSerializer.RegisterKnownObject <EmailTemplateEchoFragment>(new XyzlName() { LocalName = "Subject", NamespaceUri = "http://textmetal.wellengineered.us/stdlib/v6.0.0" }); xyzlSerializer.RegisterKnownObject <EmailTemplateEchoFragment>(new XyzlName() { LocalName = "Body", NamespaceUri = "http://textmetal.wellengineered.us/stdlib/v6.0.0" }); //xyzlSerializer.RegisterKnownValueObject<TextMetalTemplateTextObject>(); nativeXmlSerializationStrategy = new NativeXyzlSerializationStrategy(xyzlSerializer); await using (ITextMetalContext textMetalContext = this.CreateContext()) { textMetalContext.IteratorModels.Push(textMetalModel); // FROM if ((object)emailPrototype.FromXml != null) { using (templateXmlTextReader = new XmlTextReader(new StringReader(emailPrototype.FromXml.OuterXml))) textMetalTemplate = await nativeXmlSerializationStrategy.DeserializeObjectFromNativeAsync <ITextMetalTemplateObject>(templateXmlTextReader); await textMetalTemplate.ExpandTemplateAsync(textMetalContext); emailMessage.From = this.StringWriter.ToString(); this.StringWriter.GetStringBuilder().Clear(); } // SENDER if ((object)emailPrototype.SenderXml != null) { using (templateXmlTextReader = new XmlTextReader(new StringReader(emailPrototype.SenderXml.OuterXml))) textMetalTemplate = await nativeXmlSerializationStrategy.DeserializeObjectFromNativeAsync <ITextMetalTemplateObject>(templateXmlTextReader); await textMetalTemplate.ExpandTemplateAsync(textMetalContext); emailMessage.Sender = this.StringWriter.ToString(); this.StringWriter.GetStringBuilder().Clear(); } // REPLY_TO if ((object)emailPrototype.ReplyToXml != null) { using (templateXmlTextReader = new XmlTextReader(new StringReader(emailPrototype.ReplyToXml.OuterXml))) textMetalTemplate = await nativeXmlSerializationStrategy.DeserializeObjectFromNativeAsync <ITextMetalTemplateObject>(templateXmlTextReader); await textMetalTemplate.ExpandTemplateAsync(textMetalContext); emailMessage.ReplyTo = this.StringWriter.ToString(); this.StringWriter.GetStringBuilder().Clear(); } // TO if ((object)emailPrototype.ToXml != null) { using (templateXmlTextReader = new XmlTextReader(new StringReader(emailPrototype.ToXml.OuterXml))) textMetalTemplate = await nativeXmlSerializationStrategy.DeserializeObjectFromNativeAsync <ITextMetalTemplateObject>(templateXmlTextReader); await textMetalTemplate.ExpandTemplateAsync(textMetalContext); emailMessage.To = this.StringWriter.ToString(); this.StringWriter.GetStringBuilder().Clear(); } // CC if ((object)emailPrototype.CarbonCopyXml != null) { using (templateXmlTextReader = new XmlTextReader(new StringReader(emailPrototype.CarbonCopyXml.OuterXml))) textMetalTemplate = await nativeXmlSerializationStrategy.DeserializeObjectFromNativeAsync <ITextMetalTemplateObject>(templateXmlTextReader); await textMetalTemplate.ExpandTemplateAsync(textMetalContext); emailMessage.CarbonCopy = this.StringWriter.ToString(); this.StringWriter.GetStringBuilder().Clear(); } // BCC if ((object)emailPrototype.BlindCarbonCopyXml != null) { using (templateXmlTextReader = new XmlTextReader(new StringReader(emailPrototype.BlindCarbonCopyXml.OuterXml))) textMetalTemplate = await nativeXmlSerializationStrategy.DeserializeObjectFromNativeAsync <ITextMetalTemplateObject>(templateXmlTextReader); await textMetalTemplate.ExpandTemplateAsync(textMetalContext); emailMessage.BlindCarbonCopy = this.StringWriter.ToString(); this.StringWriter.GetStringBuilder().Clear(); } // SUBJECT if ((object)emailPrototype.SubjectXml != null) { using (templateXmlTextReader = new XmlTextReader(new StringReader(emailPrototype.SubjectXml.OuterXml))) textMetalTemplate = await nativeXmlSerializationStrategy.DeserializeObjectFromNativeAsync <ITextMetalTemplateObject>(templateXmlTextReader); await textMetalTemplate.ExpandTemplateAsync(textMetalContext); emailMessage.Subject = this.StringWriter.ToString(); this.StringWriter.GetStringBuilder().Clear(); } // IS_BODY_HTML emailMessage.IsBodyHtml = emailPrototype.IsBodyHtml; // BODY if ((object)emailPrototype.BodyXml != null) { using (templateXmlTextReader = new XmlTextReader(new StringReader(emailPrototype.BodyXml.OuterXml))) textMetalTemplate = await nativeXmlSerializationStrategy.DeserializeObjectFromNativeAsync <ITextMetalTemplateObject>(templateXmlTextReader); await textMetalTemplate.ExpandTemplateAsync(textMetalContext); emailMessage.Body = this.StringWriter.ToString(); this.StringWriter.GetStringBuilder().Clear(); } textMetalContext.IteratorModels.Pop(); } return(emailMessage); }
protected abstract void CoreExpandTemplate(ITextMetalContext templatingContext);
/// <summary> /// Gets the enumerator (tick one) for the current associative object instance. /// </summary> /// <param name="templatingContext"> The templating context. </param> /// <returns> An instance of IEnumerator`1 or null. </returns> public IEnumerator <KeyValuePair <string, object> > GetAssociativeObjectEnumeratorTickOne(ITextMetalContext templatingContext) { if ((object)templatingContext == null) { throw new ArgumentNullException(nameof(templatingContext)); } templatingContext.DebugBreak(); return(null); }
protected async override ValueTask CoreExpandTemplateAsync(ITextMetalContext templatingContext) { await templatingContext.CurrentOutput.TextWriter.WriteAsync(string.Format("hello:{0:O}", DateTime.Now)); }
protected override void CoreExpandTemplate(ITextMetalContext templatingContext) { templatingContext.CurrentOutput.TextWriter.Write(string.Format("hello:{0:O}", DateTime.Now)); }
public void Host(IDictionary <string, IList <object> > arguments, IDictionary <string, IList <object> > properties) { DateTime startUtc, endUtc; ITextMetalTemplate textMetalTemplate; __ITextMetalModel textMetalModel; ITextMetalOutput textMetalOutput; Dictionary <string, object> arguments_; Dictionary <string, object> properties_; Dictionary <string, object> globalVariableTable; IAssemblyInformationFascade assemblyInformationFascade; if ((object)arguments == null) { throw new ArgumentNullException(nameof(arguments)); } if ((object)properties == null) { throw new ArgumentNullException(nameof(properties)); } startUtc = DateTime.UtcNow; arguments_ = arguments.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Count == 1 ? kvp.Value[0] : kvp.Value.ToArray()); properties_ = properties.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Count == 1 ? kvp.Value[0] : kvp.Value.ToArray()); assemblyInformationFascade = new AssemblyInformationFascade(this.ReflectionFascade, typeof(TextMetalToolHost).GetTypeInfo().Assembly); Lazy <object> lazyGuid = new Lazy <object>(() => Guid.NewGuid()); Func <object> getDate = () => DateTime.UtcNow; var environment = new { Arguments = Environment.GetCommandLineArgs(), Variables = Environment.GetEnvironmentVariables(), NewLine = Environment.NewLine, Version = Environment.Version, MachineName = Environment.MachineName, UserName = Environment.UserName, OSVersion = Environment.OSVersion, UserDomainName = Environment.UserDomainName, Is64BitOperatingSystem = Environment.Is64BitOperatingSystem, Is64BitProcess = Environment.Is64BitProcess, ProcessorCount = Environment.ProcessorCount, GetDate = getDate, LazyGuid = lazyGuid }; var tooling = new { AssemblyVersion = assemblyInformationFascade.AssemblyVersion, InformationalVersion = assemblyInformationFascade.InformationalVersion, NativeFileVersion = assemblyInformationFascade.NativeFileVersion, ModuleName = assemblyInformationFascade.ModuleName, Company = assemblyInformationFascade.Company, Configuration = assemblyInformationFascade.Configuration, Copyright = assemblyInformationFascade.Copyright, Description = assemblyInformationFascade.Description, Product = assemblyInformationFascade.Product, Title = assemblyInformationFascade.Title, Trademark = assemblyInformationFascade.Trademark, StartedWhenUtc = startUtc }; // globals (GVT) globalVariableTable = new Dictionary <string, object>(); globalVariableTable.Add("Tooling", tooling); globalVariableTable.Add("Environment", environment); globalVariableTable.Add("Properties", properties_); globalVariableTable.Add("Arguments", arguments_); // add arguments to GVT /*foreach (KeyValuePair<string, IList<object>> argument in arguments) * { * if (argument.Value.Count == 0) * continue; * * globalVariableTable.Add(argument.Key, * argument.Value.Count == 1 ? argument.Value[0] : argument.Value); * }*/ // add properties to GVT /*foreach (KeyValuePair<string, IList<object>> property in properties) * { * if (property.Value.Count == 0) * continue; * * globalVariableTable.Add(property.Key, * property.Value.Count == 1 ? property.Value[0] : property.Value); * }*/ // do the deal... using (ITextMetalTemplateFactory textMetalTemplateFactory = NewObjectFromType <ITextMetalTemplateFactory>(this.Configuration.GetTemplateFactoryType())) { //textMetalTemplateFactory.Configuration = ... textMetalTemplateFactory.Create(); textMetalTemplate = textMetalTemplateFactory.GetTemplateObject(new Uri("urn:null"), properties_); using (ITextMetalModelFactory textMetalModelFactory = NewObjectFromType <ITextMetalModelFactory>(this.Configuration.GetModelFactoryType())) { //textMetalModelFactory.Configuration = ... textMetalModelFactory.Create(); textMetalModel = textMetalModelFactory.GetModelObject(properties_); using (ITextMetalOutputFactory textMetalOutputFactory = NewObjectFromType <ITextMetalOutputFactory>(this.Configuration.GetOutputFactoryType())) { //textMetalOutputFactory.Configuration = ... textMetalOutputFactory.Create(); textMetalOutput = textMetalOutputFactory.GetOutputObject(new Uri("urn:null"), properties_); //textMetalOutput.TextWriter.WriteLine("xxx"); using (ITextMetalContext textMetalContext = this.CreateContext()) { //textMetalContext.Configuration = ... textMetalContext.Create(); //textMetalContext.DiagnosticOutput.WriteObject(textMetalTemplate, "#template.xml"); //textMetalContext.DiagnosticOutput.WriteObject(textMetalModel, "#model.xml"); textMetalContext.DiagnosticOutput.TextWriter.WriteLine("['{0:O}' (UTC)]\tText templating started.", tooling.StartedWhenUtc); textMetalContext.VariableTables.Push(globalVariableTable); textMetalContext.IteratorModels.Push(textMetalModel); textMetalTemplate.ExpandTemplate(textMetalContext); textMetalContext.IteratorModels.Pop(); textMetalContext.VariableTables.Pop(); endUtc = DateTime.UtcNow; textMetalContext.DiagnosticOutput.TextWriter.WriteLine("['{0:O}' (UTC)]\tText templating completed with duration: '{1}'.", endUtc, (endUtc - startUtc)); } } } } }