public void Reset() { RootNamespaces.Clear(); Namespaces.Clear(); Symbols.Clear(); LastError = string.Empty; FileName = null; }
protected void GenerateTexts() { cw.Indented("namespace "); var ns = RootNamespaces.FirstOrDefault(x => x != "Serenity") ?? "App"; sb.Append(ns + ".Texts"); cw.InBrace(delegate { Regex filter = null; if (LocalTextFilters.Count > 0) { var fb = new StringBuilder("^("); bool append = false; foreach (string item in LocalTextFilters) { if (append) { fb.Append('|'); } if (!string.IsNullOrEmpty(item)) { if (item[0] == '^' && item[item.Length - 1] == '$') { fb.Append(item.Substring(1, item.Length - 2)); } else { fb.Append(item.Replace(".", "\\.", StringComparison.Ordinal) + ".*"); } append = true; } } fb.Append(")$"); filter = new Regex(fb.ToString(), RegexOptions.Compiled | RegexOptions.IgnoreCase); } var list = localTextKeys.Where(x => !string.IsNullOrWhiteSpace(x) && (filter == null || filter.IsMatch(x)) && x.Split('.').All(p => SqlSyntax.IsValidIdentifier(p))) .ToList(); list.Sort((i1, i2) => string.CompareOrdinal(i1, i2)); var jwBuilder = new StringBuilder(); var jw = new JsonTextWriter(new StringWriter(jwBuilder)); jw.QuoteName = false; jw.WriteStartObject(); List <string> stack = new List <string>(); int stackCount = 0; for (int i = 0; i < list.Count; i++) { var key = list[i]; var parts = key.Split('.'); int same = 0; if (stackCount > 0) { while (same < stackCount && same < parts.Length && stack[same] == parts[same]) { same++; } for (int level = same; level < stackCount; level++) { jw.WriteEndObject(); cw.EndBrace(); } stackCount = same; } for (int level = same; level < parts.Length - 1; level++) { string part = parts[level]; if (stack.Count > level) { stack[level] = part; } else { stack.Add(part); } jw.WritePropertyName(part); jw.WriteStartObject(); sb.AppendLine(); if (level == 0) { cw.Indented("declare namespace "); } else { cw.Indented("namespace "); } sb.Append(part); cw.StartBrace(); } stackCount = parts.Length - 1; if (same != parts.Length) { string part = parts[parts.Length - 1]; bool nextStartsWithThis = false; if (i + 1 < list.Count) { var next = list[i + 1]; if (next.StartsWith(key, StringComparison.Ordinal) && next.Length > key.Length && next[key.Length] == '.') { nextStartsWithThis = true; } } if (nextStartsWithThis) { stackCount = parts.Length; if (stack.Count > stackCount - 1) { stack[stackCount - 1] = part; } else { stack.Add(part); } jw.WritePropertyName(part); jw.WriteStartObject(); cw.Indented("namespace "); sb.Append(part); cw.StartBrace(); jw.WritePropertyName("export const __"); jw.WriteValue(1); cw.IndentedLine("__: string;"); } else { jw.WritePropertyName(part); jw.WriteValue(1); cw.Indented("export const "); sb.Append(part); sb.AppendLine(": string;"); } } } for (int i = 0; i < stackCount; i++) { jw.WriteEndObject(); cw.EndBrace(); sb.AppendLine(); } jw.WriteEndObject(); cw.Indented(ns); sb.Append(@"['Texts'] = Q.proxyTexts(Texts, '', "); jw.Flush(); sb.Append(jwBuilder.ToString()); sb.AppendLine(");"); }); AddFile("Texts.ts"); }
private bool LoadSymbols(IDiaSession session, object sender, LoadPDBTask task) { var worker = sender as BackgroundWorker; worker?.ReportProgress(0, "Finding symbols"); IDiaEnumSymbols allSymbols; if (task.Filter.Length > 0) { uint compareFlags = 0; if (!task.WholeExpression || task.UseRegularExpression) { compareFlags |= 0x8; } if (!task.MatchCase) { compareFlags |= 0x2; } else { compareFlags |= 0x2; } if (task.UseRegularExpression) { session.findChildren(session.globalScope, SymTagEnum.SymTagUDT, @task.Filter, compareFlags, out allSymbols); } else if (task.WholeExpression) { session.findChildren(session.globalScope, SymTagEnum.SymTagUDT, task.Filter, compareFlags, out allSymbols); } else { string filter = '*' + task.Filter + '*'; session.findChildren(session.globalScope, SymTagEnum.SymTagUDT, @filter, compareFlags, out allSymbols); } } else { session.findChildren(session.globalScope, SymTagEnum.SymTagUDT, null, 0, out allSymbols); } if (allSymbols == null) { return(false); } worker?.ReportProgress(0, "Counting symbols"); var allSymbolsCount = worker != null ? allSymbols.count : 0; var i = 0; worker?.ReportProgress(0, "Adding symbols"); foreach (IDiaSymbol sym in allSymbols) { if (worker != null && worker.CancellationPending) { return(false); } if (task.SecondPDB) { SymbolInfo info = FindSymbolInfo(sym.name); if (info != null) { info.NewSize = sym.length; } } else { if (sym.length > 0 && !HasSymbolInfo(sym.name)) { var symbolInfo = new SymbolInfo(sym.name, sym.GetType().Name, sym.length); symbolInfo.ProcessChildren(sym); Symbols.Add(symbolInfo.Name, symbolInfo); if (symbolInfo.Name.Contains("::") && !symbolInfo.Name.Contains("<")) { RootNamespaces.Add(symbolInfo.Name.Substring(0, symbolInfo.Name.IndexOf("::"))); Namespaces.Add(symbolInfo.Name.Substring(0, symbolInfo.Name.LastIndexOf("::"))); } } } var percentProgress = (int)Math.Round((double)(100 * i++) / allSymbolsCount); percentProgress = Math.Max(Math.Min(percentProgress, 99), 1); worker?.ReportProgress(percentProgress, String.Format("Adding symbol {0} on {1}", i, allSymbolsCount)); } worker?.ReportProgress(100, String.Format("{0} symbols added", allSymbolsCount)); return(true); }