//public const string InfoPrefix = "### "; //public const string ReportPrefix = "### MDRDESK REPORT: "; //public const string SeparatorPrefix = "### SEPARATOR: "; //public const string CountPrefix = "### COUNT: "; //public const string ColumnPrefix = "### COLUMNS: "; //public const string TitlePrefix = "### TITLE: "; //public const string DescrPrefix = "#### "; //public const string ItemSeparator = Constants.HeavyAsteriskPadded; public static bool WriteReport(string path, string report, string title, ColumnInfo[] cols, string[] notes, listing <string>[] lines, out string error) { error = null; StreamWriter sr = null; StringBuilder sb = null; try { sr = new StreamWriter(path); sr.WriteLine(ReportPrefix + report ?? string.Empty); sr.WriteLine(TitlePrefix + title ?? string.Empty); sr.WriteLine(SeparatorPrefix + Constants.ReportSeparator); sr.WriteLine(CountPrefix + Utils.LargeNumberString(lines.Length)); sr.WriteLine(ColumnPrefix + ColumnInfo.ToString(cols)); for (int i = 0, icnt = notes.Length; i < icnt; ++i) { sr.WriteLine(DescrPrefix + notes[i]); } Debug.Assert(lines != null && lines.Length > 0); sb = StringBuilderCache.Acquire(StringBuilderCache.MaxCapacity); var itemCount = lines[0].Count; var lastItemNdx = itemCount - 1; for (int i = 0, icnt = lines.Length; i < icnt; ++i) { sb.Clear(); var ln = lines[i]; for (int j = 0; j < itemCount; ++j) { sb.Append(ln.GetItem(j)); if (j < lastItemNdx) { sb.Append(Constants.ReportSeparator); } } sr.WriteLine(sb.ToString()); } return(true); } catch (Exception ex) { error = Utils.GetExceptionErrorString(ex); return(false); } finally { if (sb != null) { StringBuilderCache.Release(sb); } sr?.Close(); } }
public static ListingInfo ReadReportFile(string path, out string title, out string error) { error = null; title = String.Empty; StreamReader sr = null; StringBuilder sbDescr = StringBuilderCache.Acquire(); try { int itemCnt = 0; string colSpecs = string.Empty; string[] separators = new string[] { Constants.HeavyAsteriskPadded }; string report = null; sr = new StreamReader(path); string ln = sr.ReadLine(); if (!ln.StartsWith(ReportFile.ReportPrefix)) { error = "This is not a mdrdesk report file"; return(null); } report = ln.Substring(ReportPrefix.Length); if (!string.IsNullOrWhiteSpace(report)) { sbDescr.Append("Report: ").Append(report).AppendLine(); } while (ln.StartsWith(InfoPrefix)) { if (ln.StartsWith(CountPrefix)) { var pos = Utils.SkipWhites(ln, CountPrefix.Length); itemCnt = Int32.Parse(ln.Substring(pos, ln.Length - pos), NumberStyles.AllowThousands); ln = sr.ReadLine(); } else if (ln.StartsWith(ColumnPrefix)) { var pos = Utils.SkipWhites(ln, ColumnPrefix.Length); colSpecs = ln.Substring(pos); ln = sr.ReadLine(); } else if (ln.StartsWith(TitlePrefix)) { title = ln.Substring(TitlePrefix.Length); ln = sr.ReadLine(); } else if (ln.StartsWith(SeparatorPrefix)) { var sep = ln.Substring(SeparatorPrefix.Length); separators = new[] { sep }; ln = sr.ReadLine(); } else { ln = sr.ReadLine(); } } while (ln.StartsWith(DescrPrefix)) { sbDescr.Append(ln.Substring(DescrPrefix.Length)).AppendLine(); ln = sr.ReadLine(); } ColumnType[] colTypes; ValueTuple <string, ColumnType, int>[] columns = GetColumnInfo(colSpecs, separators, out colTypes); var itemLst = new List <string>(itemCnt * columns.Length); while (ln != null) { if (ln.Length == 0 || ln[0] != '#') { ParseReportLine(ln, separators, colTypes, itemLst); } else { if (ln.StartsWith(DescrPrefix)) { sbDescr.Append(ln.Substring(DescrPrefix.Length)).AppendLine(); } else if (ln.StartsWith(CountPrefix)) { var pos = Utils.SkipWhites(ln, CountPrefix.Length); itemCnt = Int32.Parse(ln.Substring(pos, ln.Length - pos), NumberStyles.AllowThousands); } } ln = sr.ReadLine(); } int colCnt = columns.Length; Debug.Assert((itemLst.Count % colCnt) == 0); var dataAry = itemLst.ToArray(); var itemAry = new listing <string> [dataAry.Length / colCnt]; var dataNdx = 0; for (int i = 0, icnt = dataAry.Length; i < icnt; i += colCnt) { itemAry[dataNdx++] = new listing <string>(dataAry, i, colCnt); } var colInfos = new ColumnInfo[columns.Length]; for (int i = 0, icnt = colInfos.Length; i < icnt; ++i) { colInfos[i] = new ColumnInfo(columns[i].Item1, columns[i].Item2, columns[i].Item3, i + 1, true); } //if (IsColumnTypeString(colInfos[0].ColumnType)) //{ // Array.Sort(itemAry, new ListingStrCmpAsc(0)); //} //else //{ // Array.Sort(itemAry, new ListingNumCmpAsc(0)); //} var result = new ListingInfo(null, itemAry, colInfos, sbDescr.ToString(), title); return(result); } catch (Exception ex) { error = Utils.GetExceptionErrorString(ex); return(null); } finally { StringBuilderCache.Release(sbDescr); sr?.Close(); } }
public static bool GetConfigSettings(out string error) { error = null; DacFolder = string.Empty; DumpsFolder = string.Empty; ProcDumpFolder = string.Empty; RecentIndexList = new List <string>(); RecentAdhocList = new List <string>(); StringBuilder errors = StringBuilderCache.Acquire(256); try { #if DEBUG //string myfolder = @"D:\Jerzy\WinDbgStuff\MDRDesk\"; string myfolder = @"C:\WinDbgStuff\MDRDesk\"; #else string myfolder = DumpFileMoniker.MyFolder; #endif string installFolder = DumpFileMoniker.GetParentFolder(myfolder); var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var appSettings = (AppSettingsSection)config.GetSection("appSettings"); if (appSettings.Settings.Count != 0) { foreach (string key in appSettings.Settings.AllKeys) { var ky = key.ToLower(); if (Utils.SameStrings(ky, "dacfolder")) { var folder = appSettings.Settings[key].Value.Trim(); if (Directory.Exists(folder)) { DacFolder = folder; } string path = installFolder + @"mscordacwks"; if (Directory.Exists(path)) { DacFolder = path; } else { errors.AppendLine("Dac folder does not exist: " + folder); } } else if (Utils.SameStrings(ky, "mapfolder")) { var folder = appSettings.Settings[key].Value.Trim(); if (Directory.Exists(folder)) { DumpsFolder = folder; } else { // if dumps folder exists, add it to config string path = installFolder + @"dumps"; if (Directory.Exists(path)) { DumpsFolder = path; } else { errors.AppendLine("Dumps folder does not exist: " + folder); } } } else if (Utils.SameStrings(ky, "procdumpfolder")) { var folder = appSettings.Settings[key].Value.Trim(); if (Directory.Exists(folder)) { ProcDumpFolder = folder; } else { ProcDumpFolder = ""; } // else errors.AppendLine("procdum.exe folder does not exist: " + folder); } else if (Utils.SameStrings(ky, "helpfolder")) { var folder = appSettings.Settings[key].Value.Trim(); if (Directory.Exists(folder)) { HelpFolder = folder; } else { string path = myfolder + @"Documentation"; if (Directory.Exists(path)) { HelpFolder = myfolder; } else { errors.AppendLine("Documentation folder does not exist: " + folder); } } } else if (Utils.SameStrings(ky, "refbuilder")) { var val = appSettings.Settings[key].Value.Trim(); CppRefBuilder = string.Compare(val, "c++", StringComparison.OrdinalIgnoreCase) == 0; } else if (Utils.SameStrings(ky, "refreader")) { var val = appSettings.Settings[key].Value.Trim(); MapRefReader = string.Compare(val, "map", StringComparison.OrdinalIgnoreCase) == 0; } else if (Utils.SameStrings(ky, "wnddbgfolder")) { var folder = appSettings.Settings[key].Value.Trim(); if (Directory.Exists(folder)) { WndDbgFolder = folder; } //else errors.AppendLine("help folder does not exist: " + folder); } else if (Utils.SameStrings(ky, "graphproxy")) { GraphDbJar = appSettings.Settings[key].Value.Trim(); } else if (Utils.SameStrings(ky, "graphport")) { GraphPort = Int32.Parse(appSettings.Settings[key].Value.Trim()); } else if (Utils.SameStrings(ky, "recentindices")) { GetSemicolonDelimitedFolderPaths(RecentIndexList, appSettings.Settings[key].Value); } else if (Utils.SameStrings(ky, "recentadhocs")) { GetSemicolonDelimitedFilePaths(RecentAdhocList, appSettings.Settings[key].Value); } else if (Utils.SameStrings(ky, "typedisplaymode")) { TypesDisplayMode = appSettings.Settings[key].Value.Trim(); } } } else { error = "The appSettings section is empty."; } if (errors.Length > 0) { return(false); } return(true); } catch (Exception ex) { error = Utils.GetExceptionErrorString(ex); return(false); } finally { if (errors.Length > 0) { error = "Initialization Failed" + Constants.HeavyGreekCrossPadded + "Setup.GetConfigSettings()" + Constants.HeavyGreekCrossPadded + "MDRDesk application config file is invalid." + Environment.NewLine + "See details." + Constants.HeavyGreekCrossPadded + StringBuilderCache.GetStringAndRelease(errors); } else { StringBuilderCache.Release(errors); } } }