/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing } else { string absoluteUrl = ResolveUrl(FeedURL); if (EnableAutodiscovery && (ContentType.ToLowerCSafe() != "application/xml")) { // Add link to page header string link = HTMLHelper.GetLink(absoluteUrl, ContentType, "alternate", null, FeedTitle); LiteralControl ltlMetadata = new LiteralControl(link); ltlMetadata.EnableViewState = false; Page.Header.Controls.Add(ltlMetadata); } Controls.Clear(); if (!string.IsNullOrEmpty(LinkIcon)) { HyperLink lnkFeedImg = new HyperLink(); lnkFeedImg.ID = "lnkFeedImg"; lnkFeedImg.NavigateUrl = absoluteUrl; lnkFeedImg.EnableViewState = false; lnkFeedImg.CssClass = "FeedLink"; Image imgFeed = new Image(); imgFeed.ID = "imgFeed"; imgFeed.ImageUrl = UIHelper.GetImageUrl(this.Page, LinkIcon); imgFeed.AlternateText = FeedTitle; imgFeed.EnableViewState = false; imgFeed.CssClass = "FeedIcon"; lnkFeedImg.Controls.Add(imgFeed); Controls.Add(lnkFeedImg); } if (!string.IsNullOrEmpty(LinkText)) { HyperLink lnkFeedText = new HyperLink(); lnkFeedText.ID = "lnkFeedText"; lnkFeedText.NavigateUrl = absoluteUrl; lnkFeedText.EnableViewState = false; lnkFeedText.CssClass = "FeedLink"; Label ltlFeed = new Label(); ltlFeed.ID = "ltlFeed"; ltlFeed.EnableViewState = false; ltlFeed.Text = HTMLHelper.HTMLEncode(LinkText); ltlFeed.CssClass = "FeedCaption"; lnkFeedText.Controls.Add(ltlFeed); Controls.Add(lnkFeedText); } } }
/// <summary> /// Invoked when a BackgroundWorker begins working. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BgWorker_DoWork(object sender, DoWorkEventArgs e) { System.Globalization.CultureInfo before = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); BackgroundWorker bg = sender as BackgroundWorker; GridRow rowData = e.Argument as GridRow; e.Result = rowData; bg.ThrowIfCanceled(rowData); FileInfo fInfo = new FileInfo(rowData.Location); if (!fInfo.Exists) { bg.UpdateProgress(rowData, "File does not exist", 100); e.Cancel = true; throw new CancellationException(rowData); } bg.UpdateProgress(rowData, " Working...", 0); Parser parser = new Parser(); if (fInfo.Extension.Equals(".evtc", StringComparison.OrdinalIgnoreCase) || fInfo.Name.EndsWith(".evtc.zip", StringComparison.OrdinalIgnoreCase)) { //Process evtc here bg.UpdateProgress(rowData, "10% - Reading Binary...", 10); parser.ParseLog(rowData, fInfo.FullName); ParsedLog log = parser.GetParsedLog(); log.validateLogData(); bg.ThrowIfCanceled(rowData); bg.UpdateProgress(rowData, "35% - Data parsed", 35); //Creating File //save location DirectoryInfo saveDirectory; if (Properties.Settings.Default.SaveAtOut || Properties.Settings.Default.OutLocation == null) { //Default save directory saveDirectory = fInfo.Directory; } else { //Customised save directory saveDirectory = new DirectoryInfo(Properties.Settings.Default.OutLocation); } string bossid = parser.getBossData().getID().ToString(); string result = parser.getLogData().getBosskill() ? "kill" : "fail"; SettingsContainer settings = new SettingsContainer(Properties.Settings.Default); Statistics statistics; StatisticsCalculator statisticsCalculator = new StatisticsCalculator(settings); if (Properties.Settings.Default.SaveOutHTML) { statistics = statisticsCalculator.calculateStatistics(log, HTMLBuilder.GetStatisticSwitches()); } else { statistics = statisticsCalculator.calculateStatistics(log, CSVBuilder.GetStatisticSwitches()); } bg.UpdateProgress(rowData, "85% - Statistics computed", 85); string fName = fInfo.Name.Split('.')[0]; bg.UpdateProgress(rowData, "90% - Creating File...", 90); if (Properties.Settings.Default.SaveOutHTML) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}_{HTMLHelper.GetLink(bossid + "-ext")}_{result}.html" ); rowData.LogLocation = outputFile; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs)) { var builder = new HTMLBuilder(log, settings, statistics); builder.CreateHTML(sw); } } if (Properties.Settings.Default.SaveOutCSV) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}_{HTMLHelper.GetLink(bossid + "-ext")}_{result}.csv" ); rowData.LogLocation = outputFile; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs)) { var builder = new CSVBuilder(log, settings, statistics); builder.CreateCSV(sw, ","); } } bg.UpdateProgress(rowData, $"100% - Complete_{HTMLHelper.GetLink(bossid + "-ext")}_{result}", 100); } else { bg.UpdateProgress(rowData, "Not EVTC", 100); e.Cancel = true; throw new CancellationException(rowData); } System.Threading.Thread.CurrentThread.CurrentCulture = before; }
private void ParseLog(object logFile) { System.Globalization.CultureInfo before = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); GridRow row = new GridRow(logFile as string, "") { BgWorker = new System.ComponentModel.BackgroundWorker() { WorkerReportsProgress = true } }; row.Metadata.FromConsole = true; FileInfo fInfo = new FileInfo(row.Location); if (!fInfo.Exists) { throw new CancellationException(row, new FileNotFoundException("File does not exist", fInfo.FullName)); } Parser control = new Parser(); if (fInfo.Extension.Equals(".evtc", StringComparison.OrdinalIgnoreCase) || fInfo.Name.EndsWith(".evtc.zip", StringComparison.OrdinalIgnoreCase)) { //Process evtc here control.ParseLog(row, fInfo.FullName); ParsedLog log = control.GetParsedLog(); log.validateLogData(); Console.Write("Log Parsed"); //Creating File //save location DirectoryInfo saveDirectory; if (Properties.Settings.Default.SaveAtOut || Properties.Settings.Default.OutLocation == null) { //Default save directory saveDirectory = fInfo.Directory; } else { //Customised save directory saveDirectory = new DirectoryInfo(Properties.Settings.Default.OutLocation); } string bossid = control.getBossData().getID().ToString(); string result = "fail"; if (control.getLogData().getBosskill()) { result = "kill"; } SettingsContainer settings = new SettingsContainer(Properties.Settings.Default); Statistics statistics; StatisticsCalculator statisticsCalculator = new StatisticsCalculator(settings); if (Properties.Settings.Default.SaveOutHTML) { statistics = statisticsCalculator.calculateStatistics(log, HTMLBuilder.GetStatisticSwitches()); } else { statistics = statisticsCalculator.calculateStatistics(log, CSVBuilder.GetStatisticSwitches()); } Console.Write("Statistics Computed"); string fName = fInfo.Name.Split('.')[0]; if (Properties.Settings.Default.SaveOutHTML) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}_{HTMLHelper.GetLink(bossid + "-ext")}_{result}.html" ); using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs)) { HTMLBuilder builder = new HTMLBuilder(log, settings, statistics); builder.CreateHTML(sw); } } } if (Properties.Settings.Default.SaveOutCSV) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}_{HTMLHelper.GetLink(bossid + "-ext")}_{result}.csv" ); using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs)) { CSVBuilder builder = new CSVBuilder(log, settings, statistics); builder.CreateCSV(sw, ","); } } } Console.Write("Generation Done"); } else { throw new CancellationException(row, new InvalidDataException("Not EVTC")); } System.Threading.Thread.CurrentThread.CurrentCulture = before; }