public override void Synchronize(SyncronizationContext sc) { foreach (var item in Nodes) { item.Synchronize(sc); } }
public override void Synchronize(SyncronizationContext sc) { foreach (var item in this.Descendants <BaseNode>().ToList()) { item.Synchronize(sc); } }
public override void Synchronize(SyncronizationContext sc) { ValueProvider.Synchronize(sc, "if[]"); if (Operation != null) { sc.SynchronizeValue(ValueProvider.Type, ref Value, Operation.Value.IsList()); } using (sc.NewScope()) { ValueProvider.Declare(sc.Variables); IfBlock.Synchronize(sc); } if (ElseBlock != null) { using (sc.NewScope()) { ValueProvider.Declare(sc.Variables); ElseBlock.Synchronize(sc); } } }
public override void Synchronize(SyncronizationContext sc) { this.ValueProvider.Synchronize(sc, "@any"); if (Operation != null) { sc.SynchronizeValue(this.ValueProvider.Type, ref Value, Operation.Value.IsList()); } using (sc.NewScope()) { this.ValueProvider.Declare(sc.Variables); AnyBlock.Synchronize(sc); } if (NotAnyBlock != null) { using (sc.NewScope()) { this.ValueProvider.Declare(sc.Variables); NotAnyBlock.Synchronize(sc); } } }
private static string Synchronize(string text, SyncronizationContext sc) { BlockNode node = new TemplateWalker(text, sc.QueryDescription, sc.ModelType).ParseSync(); node.Synchronize(sc); return(node.ToString()); }
public override void Synchronize(SyncronizationContext sc) { ValueProvider.Synchronize(sc, "@foreach"); using (sc.NewScope()) { ValueProvider.Declare(sc.Variables); this.ForeachBlock.Synchronize(sc); } }
public override void Synchronize(SyncronizationContext sc) { return; }
internal static SqlPreCommand SynchronizeWordTemplate(Replacements replacements, WordTemplateEntity template, StringDistance sd) { try { if (template.Template == null) return null; var queryName = QueryLogic.ToQueryName(template.Query.Key); QueryDescription qd = DynamicQueryManager.Current.QueryDescription(queryName); Console.Clear(); SafeConsole.WriteLineColor(ConsoleColor.White, "WordTemplate: " + template.Name); Console.WriteLine(" Query: " + template.Query.Key); var file = template.Template.Retrieve(); try { using (var memory = new MemoryStream()) { memory.WriteAllBytes(file.BinaryFile); using (WordprocessingDocument document = WordprocessingDocument.Open(memory, true)) { Dump(document, "0.Original.txt"); var parser = new WordTemplateParser(document, qd, template.SystemWordTemplate.ToType()); parser.ParseDocument(); Dump(document, "1.Match.txt"); parser.CreateNodes(); Dump(document, "2.BaseNode.txt"); parser.AssertClean(); SyncronizationContext sc = new SyncronizationContext { ModelType = template.SystemWordTemplate.ToType(), QueryDescription = qd, Replacements = replacements, StringDistance = sd, HasChanges = false, Variables = new ScopedDictionary<string, ValueProviderBase>(null), }; foreach (var root in document.RecursivePartsRootElements()) { foreach (var node in root.Descendants<BaseNode>().ToList()) { node.Synchronize(sc); } } if (!sc.HasChanges) return null; Dump(document, "3.Synchronized.txt"); var variables = new ScopedDictionary<string, ValueProviderBase>(null); foreach (var root in document.RecursivePartsRootElements()) { foreach (var node in root.Descendants<BaseNode>().ToList()) { node.RenderTemplate(variables); } } Dump(document, "4.Rendered.txt"); } file.AllowChange = true; file.BinaryFile = memory.ToArray(); using (replacements.WithReplacedDatabaseName()) return Schema.Current.Table<FileEntity>().UpdateSqlSync(file, comment: "WordTemplate: " + template.Name); } } catch (TemplateSyncException ex) { if (ex.Result == FixTokenResult.SkipEntity) return null; if (ex.Result == FixTokenResult.DeleteEntity) return SqlPreCommandConcat.Combine(Spacing.Simple, Schema.Current.Table<WordTemplateEntity>().DeleteSqlSync(template), Schema.Current.Table<FileEntity>().DeleteSqlSync(file)); if (ex.Result == FixTokenResult.ReGenerateEntity) return Regenerate(template, replacements); throw new InvalidOperationException("Unexcpected {0}".FormatWith(ex.Result)); } finally { Console.Clear(); } } catch (Exception e) { return new SqlPreCommandSimple("-- Exception in {0}: {1}".FormatWith(template.BaseToString(), e.Message)); } }
public override void Synchronize(SyncronizationContext sc) { foreach (var item in Nodes) item.Synchronize(sc); }
public override void Synchronize(SyncronizationContext sc) { ValueProvider.Synchronize(sc, "@any[]"); if (Operation != null) sc.SynchronizeValue(ValueProvider.Type, ref Value, Operation == FilterOperation.IsIn); using (sc.NewScope()) { ValueProvider.Declare(sc.Variables); AnyBlock.Synchronize(sc); } if (NotAnyBlock != null) { using (sc.NewScope()) { ValueProvider.Declare(sc.Variables); NotAnyBlock.Synchronize(sc); } } }
internal static SqlPreCommand SynchronizeWordTemplate(Replacements replacements, WordTemplateEntity template, StringDistance sd) { try { if (template.Template == null || !replacements.Interactive) { return(null); } var queryName = QueryLogic.ToQueryName(template.Query.Key); QueryDescription qd = DynamicQueryManager.Current.QueryDescription(queryName); Console.Clear(); SafeConsole.WriteLineColor(ConsoleColor.White, "WordTemplate: " + template.Name); Console.WriteLine(" Query: " + template.Query.Key); var file = template.Template.Retrieve(); try { SyncronizationContext sc = new SyncronizationContext { ModelType = template.SystemWordTemplate.ToType(), QueryDescription = qd, Replacements = replacements, StringDistance = sd, HasChanges = false, Variables = new ScopedDictionary <string, ValueProviderBase>(null), }; var bytes = template.ProcessOpenXmlPackage(document => { Dump(document, "0.Original.txt"); var parser = new TemplateParser(document, qd, template.SystemWordTemplate.ToType(), template); parser.ParseDocument(); Dump(document, "1.Match.txt"); parser.CreateNodes(); Dump(document, "2.BaseNode.txt"); parser.AssertClean(); foreach (var root in document.AllRootElements()) { foreach (var node in root.Descendants <BaseNode>().ToList()) { node.Synchronize(sc); } } if (sc.HasChanges) { Dump(document, "3.Synchronized.txt"); var variables = new ScopedDictionary <string, ValueProviderBase>(null); foreach (var root in document.AllRootElements()) { foreach (var node in root.Descendants <BaseNode>().ToList()) { node.RenderTemplate(variables); } } Dump(document, "4.Rendered.txt"); } }); if (!sc.HasChanges) { return(null); } file.AllowChange = true; file.BinaryFile = bytes; using (replacements.WithReplacedDatabaseName()) return(Schema.Current.Table <FileEntity>().UpdateSqlSync(file, comment: "WordTemplate: " + template.Name)); } catch (TemplateSyncException ex) { if (ex.Result == FixTokenResult.SkipEntity) { return(null); } if (ex.Result == FixTokenResult.DeleteEntity) { return(SqlPreCommandConcat.Combine(Spacing.Simple, Schema.Current.Table <WordTemplateEntity>().DeleteSqlSync(template), Schema.Current.Table <FileEntity>().DeleteSqlSync(file))); } if (ex.Result == FixTokenResult.ReGenerateEntity) { return(Regenerate(template, replacements)); } throw new InvalidOperationException("Unexcpected {0}".FormatWith(ex.Result)); } finally { Console.Clear(); } } catch (Exception e) { return(new SqlPreCommandSimple("-- Exception in {0}: \r\n{1}".FormatWith(template.BaseToString(), e.Message.Indent(2, '-')))); } }
public override void Synchronize(SyncronizationContext sc) { ValueProvider.Synchronize(sc, IsRaw ? "@raw[]" : "@[]"); }
internal static SqlPreCommand ProcessEmailTemplate( Replacements replacements, Table table, EmailTemplateEntity et, StringDistance sd) { try { var queryName = QueryLogic.ToQueryName(et.Query.Key); QueryDescription qd = DynamicQueryManager.Current.QueryDescription(queryName); Console.Clear(); SafeConsole.WriteLineColor(ConsoleColor.White, "EmailTemplate: " + et.Name); Console.WriteLine(" Query: " + et.Query.Key); if (et.From != null && et.From.Token != null) { QueryTokenEntity token = et.From.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement, " From", allowRemoveToken: false, allowReCreate: et.SystemEmail != null)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(et); case FixTokenResult.SkipEntity: return null; case FixTokenResult.Fix: et.From.Token = token; break; case FixTokenResult.ReGenerateEntity: return Regenerate(et, replacements, table); default: break; } } if (et.Recipients.Any(a=>a.Token != null)) { Console.WriteLine(" Recipients:"); foreach (var item in et.Recipients.Where(a => a.Token != null).ToList()) { QueryTokenEntity token = item.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement, " Recipient", allowRemoveToken: false, allowReCreate: et.SystemEmail != null)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return table.DeleteSqlSync(et); case FixTokenResult.RemoveToken: et.Recipients.Remove(item); break; case FixTokenResult.SkipEntity: return null; case FixTokenResult.Fix: item.Token = token; break; case FixTokenResult.ReGenerateEntity: return Regenerate(et, replacements, table); default: break; } } } try { foreach (var item in et.Messages) { SyncronizationContext sc = new SyncronizationContext { ModelType = et.SystemEmail.ToType(), QueryDescription = qd, Replacements = replacements, StringDistance = sd, Variables = new ScopedDictionary<string, ValueProviderBase>(null) }; item.Subject = Synchronize(item.Subject, sc); item.Text = Synchronize(item.Text, sc); } using (replacements.WithReplacedDatabaseName()) return table.UpdateSqlSync(et, includeCollections: true, comment: "EmailTemplate: " + et.Name); } catch (TemplateSyncException ex) { if (ex.Result == FixTokenResult.SkipEntity) return null; if (ex.Result == FixTokenResult.DeleteEntity) return table.DeleteSqlSync(et); if (ex.Result == FixTokenResult.ReGenerateEntity) return Regenerate(et, replacements, table); throw new InvalidOperationException("Unexcpected {0}".FormatWith(ex.Result)); } finally { Console.Clear(); } } catch (Exception e) { return new SqlPreCommandSimple("-- Exception in {0}: {1}".FormatWith(et.BaseToString(), e.Message)); } }
public override void Synchronize(SyncronizationContext sc) { foreach (var item in this.Descendants<BaseNode>().ToList()) { item.Synchronize(sc); } }
public override void Synchronize(SyncronizationContext sc) { this.ValueProvider.Synchronize(sc, "@if"); if (Operation != null) sc.SynchronizeValue(this.ValueProvider.Type, ref Value, Operation == FilterOperation.IsIn); using (sc.NewScope()) { this.ValueProvider.Declare(sc.Variables); IfBlock.Synchronize(sc); } if (ElseBlock != null) { using (sc.NewScope()) { this.ValueProvider.Declare(sc.Variables); ElseBlock.Synchronize(sc); } } }
public override void Synchronize(SyncronizationContext sc) { ValueProvider.Synchronize(sc, "@"); ValueProvider.Declare(sc.Variables); }
internal static SqlPreCommand ProcessEmailTemplate(Replacements replacements, Table table, EmailTemplateEntity et, StringDistance sd) { try { var queryName = QueryLogic.ToQueryName(et.Query.Key); QueryDescription qd = DynamicQueryManager.Current.QueryDescription(queryName); Console.Clear(); SafeConsole.WriteLineColor(ConsoleColor.White, "EmailTemplate: " + et.Name); Console.WriteLine(" Query: " + et.Query.Key); if (et.From != null && et.From.Token != null) { QueryTokenEmbedded token = et.From.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement, " From", allowRemoveToken: false, allowReCreate: et.SystemEmail != null)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(et)); case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: et.From.Token = token; break; case FixTokenResult.ReGenerateEntity: return(Regenerate(et, replacements, table)); default: break; } } if (et.Recipients.Any(a => a.Token != null)) { Console.WriteLine(" Recipients:"); foreach (var item in et.Recipients.Where(a => a.Token != null).ToList()) { QueryTokenEmbedded token = item.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement, " Recipient", allowRemoveToken: false, allowReCreate: et.SystemEmail != null)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(et)); case FixTokenResult.RemoveToken: et.Recipients.Remove(item); break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: item.Token = token; break; case FixTokenResult.ReGenerateEntity: return(Regenerate(et, replacements, table)); default: break; } } } try { foreach (var item in et.Messages) { SyncronizationContext sc = new SyncronizationContext { ModelType = et.SystemEmail.ToType(), QueryDescription = qd, Replacements = replacements, StringDistance = sd, Variables = new ScopedDictionary <string, ValueProviderBase>(null) }; item.Subject = Synchronize(item.Subject, sc); item.Text = Synchronize(item.Text, sc); } using (replacements.WithReplacedDatabaseName()) return(table.UpdateSqlSync(et, includeCollections: true, comment: "EmailTemplate: " + et.Name)); } catch (TemplateSyncException ex) { if (ex.Result == FixTokenResult.SkipEntity) { return(null); } if (ex.Result == FixTokenResult.DeleteEntity) { return(table.DeleteSqlSync(et)); } if (ex.Result == FixTokenResult.ReGenerateEntity) { return(Regenerate(et, replacements, table)); } throw new InvalidOperationException("Unexcpected {0}".FormatWith(ex.Result)); } finally { Console.Clear(); } } catch (Exception e) { return(new SqlPreCommandSimple("-- Exception on {0}. {1}\r\n{2}".FormatWith(et.BaseToString(), e.GetType().Name, e.Message.Indent(2, '-')))); } }
public override void Synchronize(SyncronizationContext sc) { ValueProvider.Synchronize(sc, "@declare"); }
public abstract void Synchronize(SyncronizationContext sc);
public override void Synchronize(SyncronizationContext sc) { ValueProvider.Synchronize(sc, "if[]"); if (Operation != null) sc.SynchronizeValue(ValueProvider.Type, ref Value, Operation.Value.IsList()); using (sc.NewScope()) { ValueProvider.Declare(sc.Variables); IfBlock.Synchronize(sc); } if (ElseBlock != null) { using (sc.NewScope()) { ValueProvider.Declare(sc.Variables); ElseBlock.Synchronize(sc); } } }
private static string Synchronize(string text, SyncronizationContext sc) { BlockNode node = new TemplateWalker(text, sc.QueryDescription, sc.ModelType).ParseSync(); node.Synchronize(sc); return node.ToString(); }