private void ParseLog(object logFile) { UploadController up_controller = null; System.Globalization.CultureInfo before = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); GridRow row = new GridRow(logFile as string, "Ready to parse") { 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)); } //Upload Process Task <string> DREITask = null; Task <string> DRRHTask = null; Task <string> RaidarTask = null; string[] uploadresult = new string[3] { "", "", "" }; try { ParsingController control = new ParsingController(); if (!GeneralHelper.HasFormat()) { throw new CancellationException(row, new Exception("No output format has been selected")); } if (GeneralHelper.IsSupportedFormat(fInfo.Name)) { //Process evtc here ParsedLog log = control.ParseLog(row, fInfo.FullName); Console.Write("Log Parsed\n"); if (Properties.Settings.Default.UploadToDPSReports) { Console.Write("Uploading to DPSReports using EI\n"); if (up_controller == null) { up_controller = new UploadController(); } DREITask = Task.Factory.StartNew(() => up_controller.UploadDPSReportsEI(fInfo)); if (DREITask != null) { while (!DREITask.IsCompleted) { System.Threading.Thread.Sleep(100); } uploadresult[0] = DREITask.Result; } else { uploadresult[0] = "Failed to Define Upload Task"; } } if (Properties.Settings.Default.UploadToDPSReportsRH) { Console.Write("Uploading to DPSReports using RH\n"); if (up_controller == null) { up_controller = new UploadController(); } DRRHTask = Task.Factory.StartNew(() => up_controller.UploadDPSReportsRH(fInfo)); if (DRRHTask != null) { while (!DRRHTask.IsCompleted) { System.Threading.Thread.Sleep(100); } uploadresult[1] = DRRHTask.Result; } else { uploadresult[1] = "Failed to Define Upload Task"; } } if (Properties.Settings.Default.UploadToRaidar) { Console.Write("Uploading to Raidar\n"); if (up_controller == null) { up_controller = new UploadController(); } RaidarTask = Task.Factory.StartNew(() => up_controller.UploadRaidar(fInfo)); if (RaidarTask != null) { while (!RaidarTask.IsCompleted) { System.Threading.Thread.Sleep(100); } uploadresult[2] = RaidarTask.Result; } else { uploadresult[2] = "Failed to Define Upload Task"; } } //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); } if (saveDirectory == null) { throw new CancellationException(row, new InvalidDataException("Save Directory not found")); } string result = log.FightData.Success ? "kill" : "fail"; string encounterLengthTerm = Properties.Settings.Default.AddDuration ? "_" + (log.FightData.FightDuration / 1000).ToString() + "s" : ""; string PoVClassTerm = Properties.Settings.Default.AddPoVProf ? "_" + log.PlayerList.Find(x => x.AgentItem.Name.Split(':')[0] == log.LogData.PoV.Split(':')[0]).Prof.ToLower() : ""; Console.Write("Statistics Computed\n"); string fName = fInfo.Name.Split('.')[0]; fName = $"{fName}{PoVClassTerm}_{log.FightData.Logic.Extension}{encounterLengthTerm}_{result}"; if (Properties.Settings.Default.SaveOutHTML) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.html" ); using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs)) { var builder = new HTMLBuilder(log, uploadresult); builder.CreateHTML(sw, saveDirectory.FullName); } } } if (Properties.Settings.Default.SaveOutCSV) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.csv" ); using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding(1252))) { var builder = new CSVBuilder(sw, ",", log, uploadresult); builder.CreateCSV(); } } } if (Properties.Settings.Default.SaveOutJSON) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.json" ); using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) { var builder = new RawFormatBuilder(sw, log, uploadresult); builder.CreateJSON(); } } } if (Properties.Settings.Default.SaveOutXML) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.xml" ); using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) { var builder = new RawFormatBuilder(sw, log, uploadresult); builder.CreateXML(); } } } Console.Write("Generation Done\n"); } else { Console.Error.Write("Not EVTC"); throw new CancellationException(row, new InvalidDataException("Not EVTC")); } } catch (SkipException s) { Console.Error.Write(s.Message); throw new CancellationException(row, s); } catch (TooShortException t) { Console.Error.Write(t.Message); throw new CancellationException(row, t); } catch (Exception ex) when(!System.Diagnostics.Debugger.IsAttached) { Console.Error.Write(ex.Message); throw new CancellationException(row, ex); } finally { Thread.CurrentThread.CurrentCulture = before; } }
/// <summary> /// Invoked when a BackgroundWorker begins working. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BgWorkerDoWork(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; UploadController up_controller = null; e.Result = rowData; _runningCount++; _anyRunning = true; bg.ThrowIfCanceled(rowData); try { FileInfo fInfo = new FileInfo(rowData.Location); if (fInfo == null || !fInfo.Exists) { bg.UpdateProgress(rowData, "File does not exist", 100); e.Cancel = true; throw new CancellationException(rowData); } //Upload Process Task <string> DREITask = null; Task <string> DRRHTask = null; Task <string> RaidarTask = null; string[] uploadresult = new string[3] { "", "", "" }; bg.UpdateProgress(rowData, " Working...", 0); ParsingController parser = new ParsingController(); if (!GeneralHelper.HasFormat()) { throw new CancellationException(rowData, new Exception("No output format has been selected")); } if (GeneralHelper.IsSupportedFormat(fInfo.Name)) { //Process evtc here bg.UpdateProgress(rowData, "10% - Reading Binary...", 10); ParsedLog log = parser.ParseLog(rowData, fInfo.FullName); bg.ThrowIfCanceled(rowData); bg.UpdateProgress(rowData, "35% - Data parsed", 35); if (Properties.Settings.Default.UploadToDPSReports) { bg.UpdateProgress(rowData, " 40% - Uploading to DPSReports using EI...", 40); if (up_controller == null) { up_controller = new UploadController(); } DREITask = Task.Factory.StartNew(() => up_controller.UploadDPSReportsEI(fInfo)); if (DREITask != null) { while (!DREITask.IsCompleted) { System.Threading.Thread.Sleep(100); } uploadresult[0] = DREITask.Result; } else { uploadresult[0] = "Failed to Define Upload Task"; } } bg.ThrowIfCanceled(rowData); if (Properties.Settings.Default.UploadToDPSReportsRH) { bg.UpdateProgress(rowData, " 40% - Uploading to DPSReports using RH...", 40); if (up_controller == null) { up_controller = new UploadController(); } DRRHTask = Task.Factory.StartNew(() => up_controller.UploadDPSReportsRH(fInfo)); if (DRRHTask != null) { while (!DRRHTask.IsCompleted) { System.Threading.Thread.Sleep(100); } uploadresult[1] = DRRHTask.Result; } else { uploadresult[1] = "Failed to Define Upload Task"; } } bg.ThrowIfCanceled(rowData); if (Properties.Settings.Default.UploadToRaidar) { bg.UpdateProgress(rowData, " 40% - Uploading to Raidar...", 40); if (up_controller == null) { up_controller = new UploadController(); } RaidarTask = Task.Factory.StartNew(() => up_controller.UploadRaidar(fInfo)); if (RaidarTask != null) { while (!RaidarTask.IsCompleted) { System.Threading.Thread.Sleep(100); } uploadresult[2] = RaidarTask.Result; } else { uploadresult[2] = "Failed to Define Upload Task"; } } bg.ThrowIfCanceled(rowData); //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); } if (saveDirectory == null) { throw new CancellationException(rowData, new Exception("Invalid save directory")); } string result = log.FightData.Success ? "kill" : "fail"; string encounterLengthTerm = Properties.Settings.Default.AddDuration ? "_" + (log.FightData.FightDuration / 1000).ToString() + "s" : ""; string PoVClassTerm = Properties.Settings.Default.AddPoVProf ? "_" + log.PlayerList.Find(x => x.AgentItem.Name.Split(':')[0] == log.LogData.PoV.Split(':')[0]).Prof.ToLower() : ""; bg.ThrowIfCanceled(rowData); bg.UpdateProgress(rowData, "85% - Statistics computed", 85); bg.ThrowIfCanceled(rowData); string fName = fInfo.Name.Split('.')[0]; fName = $"{fName}{PoVClassTerm}_{log.FightData.Logic.Extension}{encounterLengthTerm}_{result}"; bg.UpdateProgress(rowData, "90% - Creating File...", 90); bg.ThrowIfCanceled(rowData); if (Properties.Settings.Default.SaveOutHTML) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.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, uploadresult); builder.CreateHTML(sw, saveDirectory.FullName); } } if (Properties.Settings.Default.SaveOutCSV) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.csv" ); string splitString = ""; if (rowData.LogLocation != null) { splitString = ","; } rowData.LogLocation += splitString + outputFile; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs, Encoding.GetEncoding(1252))) { var builder = new CSVBuilder(sw, ",", log, uploadresult); builder.CreateCSV(); } } if (Properties.Settings.Default.SaveOutJSON) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.json" ); string splitString = ""; if (rowData.LogLocation != null) { splitString = ","; } rowData.LogLocation += splitString + saveDirectory.FullName; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs, Encoding.UTF8)) { var builder = new RawFormatBuilder(sw, log, uploadresult); builder.CreateJSON(); } } if (Properties.Settings.Default.SaveOutXML) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.xml" ); string splitString = ""; if (rowData.LogLocation != null) { splitString = ","; } rowData.LogLocation += splitString + saveDirectory.FullName; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs, Encoding.UTF8)) { var builder = new RawFormatBuilder(sw, log, uploadresult); builder.CreateXML(); } } bg.UpdateProgress(rowData, $"100% - Complete_{log.FightData.Logic.Extension}_{result}", 100); } else { bg.UpdateProgress(rowData, "Not EVTC", 100); e.Cancel = true; Console.Error.Write("Not EVTC"); throw new CancellationException(rowData); } } catch (SkipException s) { Console.Write(s.Message); throw new CancellationException(rowData, s); } catch (TooShortException t) { Console.Write(t.Message); throw new CancellationException(rowData, t); } catch (Exception ex) when(!System.Diagnostics.Debugger.IsAttached) { Console.Error.Write(ex.Message); throw new CancellationException(rowData, ex); } finally { System.Threading.Thread.CurrentThread.CurrentCulture = before; } }
private static void GenerateFiles(ParsedLog log, GridRow rowData, string[] uploadresult, FileInfo fInfo) { rowData.BgWorker.ThrowIfCanceled(rowData); rowData.BgWorker.UpdateProgress(rowData, "50% - Creating File(s)...", 50); //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); } if (saveDirectory == null) { throw new InvalidDataException("Save Directory not found"); } string result = log.FightData.Success ? "kill" : "fail"; string encounterLengthTerm = Properties.Settings.Default.AddDuration ? "_" + (log.FightData.FightDuration / 1000).ToString() + "s" : ""; string PoVClassTerm = Properties.Settings.Default.AddPoVProf ? "_" + log.LogData.PoV.Prof.ToLower() : ""; string fName = fInfo.Name.Split('.')[0]; fName = $"{fName}{PoVClassTerm}_{log.FightData.Logic.Extension}{encounterLengthTerm}_{result}"; rowData.BgWorker.ThrowIfCanceled(rowData); if (Properties.Settings.Default.SaveOutHTML) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.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, uploadresult); builder.CreateHTML(sw, saveDirectory.FullName); } } rowData.BgWorker.ThrowIfCanceled(rowData); if (Properties.Settings.Default.SaveOutCSV) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.csv" ); string splitString = ""; if (rowData.LogLocation != null) { splitString = ","; } rowData.LogLocation += splitString + outputFile; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs, Encoding.GetEncoding(1252))) { var builder = new CSVBuilder(sw, ",", log, uploadresult); builder.CreateCSV(); } } rowData.BgWorker.ThrowIfCanceled(rowData); if (Properties.Settings.Default.SaveOutJSON) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.json" ); string splitString = ""; if (rowData.LogLocation != null) { splitString = ","; } rowData.LogLocation += splitString + saveDirectory.FullName; Stream str; if (Properties.Settings.Default.CompressRaw) { str = new MemoryStream(); } else { str = new FileStream(outputFile, FileMode.Create, FileAccess.Write); } using (var sw = new StreamWriter(str, GeneralHelper.NoBOMEncodingUTF8)) { var builder = new RawFormatBuilder(log, uploadresult); builder.CreateJSON(sw); } if (str is MemoryStream msr) { CompressFile(outputFile, msr); } } rowData.BgWorker.ThrowIfCanceled(rowData); if (Properties.Settings.Default.SaveOutXML) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.xml" ); string splitString = ""; if (rowData.LogLocation != null) { splitString = ","; } rowData.LogLocation += splitString + saveDirectory.FullName; Stream str; if (Properties.Settings.Default.CompressRaw) { str = new MemoryStream(); } else { str = new FileStream(outputFile, FileMode.Create, FileAccess.Write); } using (var sw = new StreamWriter(str, GeneralHelper.NoBOMEncodingUTF8)) { var builder = new RawFormatBuilder(log, uploadresult); builder.CreateXML(sw); } if (str is MemoryStream msr) { CompressFile(outputFile, msr); } } rowData.BgWorker.ThrowIfCanceled(rowData); rowData.BgWorker.UpdateProgress(rowData, $"100% - Complete_{log.FightData.Logic.Extension}_{result}", 100); }
private static void GenerateFiles(ParsedEvtcLog log, OperationController operation, string[] uploadStrings, FileInfo fInfo) { operation.UpdateProgressWithCancellationCheck("Creating File(s)"); DirectoryInfo saveDirectory = GetSaveDirectory(fInfo); string result = log.FightData.Success ? "kill" : "fail"; string encounterLengthTerm = Properties.Settings.Default.AddDuration ? "_" + (log.FightData.FightDuration / 1000).ToString() + "s" : ""; string PoVClassTerm = Properties.Settings.Default.AddPoVProf ? "_" + log.LogData.PoV.Spec.ToString().ToLower() : ""; string fName = fInfo.Name.Split('.')[0]; fName = $"{fName}{PoVClassTerm}_{log.FightData.Logic.Extension}{encounterLengthTerm}_{result}"; var uploadResults = new UploadResults(uploadStrings[0], uploadStrings[1]); if (Properties.Settings.Default.SaveOutHTML) { operation.UpdateProgressWithCancellationCheck("Creating HTML"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.html" ); operation.GeneratedFiles.Add(outputFile); operation.OpenableFiles.Add(outputFile); operation.OutLocation = saveDirectory.FullName; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs)) { var builder = new HTMLBuilder(log, new HTMLSettings( Properties.Settings.Default.LightTheme, Properties.Settings.Default.HtmlExternalScripts, Properties.Settings.Default.HtmlExternalScriptsPath, Properties.Settings.Default.HtmlExternalScriptsCdn, Properties.Settings.Default.HtmlCompressJson ), htmlAssets, ParserVersion, uploadResults); builder.CreateHTML(sw, saveDirectory.FullName); } operation.UpdateProgressWithCancellationCheck("HTML created"); } if (Properties.Settings.Default.SaveOutCSV) { operation.UpdateProgressWithCancellationCheck("Creating CSV"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.csv" ); operation.GeneratedFiles.Add(outputFile); operation.OpenableFiles.Add(outputFile); operation.OutLocation = saveDirectory.FullName; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs, Encoding.GetEncoding(1252))) { var builder = new CSVBuilder(log, new CSVSettings(","), ParserVersion, uploadResults); builder.CreateCSV(sw); } operation.UpdateProgressWithCancellationCheck("CSV created"); } if (Properties.Settings.Default.SaveOutJSON || Properties.Settings.Default.SaveOutXML) { var builder = new RawFormatBuilder(log, new RawFormatSettings(Properties.Settings.Default.RawTimelineArrays), ParserVersion, uploadResults); if (Properties.Settings.Default.SaveOutJSON) { operation.UpdateProgressWithCancellationCheck("Creating JSON"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.json" ); operation.OutLocation = saveDirectory.FullName; Stream str; if (Properties.Settings.Default.CompressRaw) { str = new MemoryStream(); } else { str = new FileStream(outputFile, FileMode.Create, FileAccess.Write); } using (var sw = new StreamWriter(str, NoBOMEncodingUTF8)) { builder.CreateJSON(sw, Properties.Settings.Default.IndentJSON); } if (str is MemoryStream msr) { CompressFile(outputFile, msr, operation); operation.UpdateProgressWithCancellationCheck("JSON compressed"); } else { operation.GeneratedFiles.Add(outputFile); } operation.UpdateProgressWithCancellationCheck("JSON created"); } if (Properties.Settings.Default.SaveOutXML) { operation.UpdateProgressWithCancellationCheck("Creating XML"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.xml" ); operation.OutLocation = saveDirectory.FullName; Stream str; if (Properties.Settings.Default.CompressRaw) { str = new MemoryStream(); } else { str = new FileStream(outputFile, FileMode.Create, FileAccess.Write); } using (var sw = new StreamWriter(str, NoBOMEncodingUTF8)) { builder.CreateXML(sw, Properties.Settings.Default.IndentXML); } if (str is MemoryStream msr) { CompressFile(outputFile, msr, operation); operation.UpdateProgressWithCancellationCheck("XML compressed"); } else { operation.GeneratedFiles.Add(outputFile); } operation.UpdateProgressWithCancellationCheck("XML created"); } } operation.UpdateProgressWithCancellationCheck($"Completed parsing for {result}ed {log.FightData.Logic.Extension}"); }
private static void GenerateFiles(ParsedEvtcLog log, OperationController operation, string[] uploadresult, FileInfo fInfo) { operation.UpdateProgressWithCancellationCheck("Creating File(s)"); DirectoryInfo saveDirectory = GetSaveDirectory(fInfo); string result = log.FightData.Success ? "kill" : "fail"; string encounterLengthTerm = Properties.Settings.Default.AddDuration ? "_" + (log.FightData.FightEnd / 1000).ToString() + "s" : ""; string PoVClassTerm = Properties.Settings.Default.AddPoVProf ? "_" + log.LogData.PoV.Prof.ToLower() : ""; string fName = fInfo.Name.Split('.')[0]; fName = $"{fName}{PoVClassTerm}_{log.FightData.Logic.Extension}{encounterLengthTerm}_{result}"; // parallel stuff if (Properties.Settings.Default.MultiThreaded) { log.FightData.GetPhases(log); operation.UpdateProgressWithCancellationCheck("Multi threading"); var playersAndTargets = new List <AbstractSingleActor>(log.PlayerList); playersAndTargets.AddRange(log.FightData.Logic.Targets); foreach (AbstractSingleActor actor in playersAndTargets) { // that part can't be // actor.ComputeBuffMap(log); } if (log.CanCombatReplay) { var playersAndTargetsAndMobs = new List <AbstractSingleActor>(log.FightData.Logic.TrashMobs); playersAndTargetsAndMobs.AddRange(playersAndTargets); // init all positions Parallel.ForEach(playersAndTargetsAndMobs, actor => actor.GetCombatReplayPolledPositions(log)); } else if (log.CombatData.HasMovementData) { Parallel.ForEach(log.PlayerList, player => player.GetCombatReplayPolledPositions(log)); } Parallel.ForEach(playersAndTargets, actor => actor.GetBuffGraphs(log)); // Parallel.ForEach(log.PlayerList, player => player.GetDamageModifierStats(log, null)); // once simulation is done, computing buff stats is thread safe Parallel.ForEach(log.PlayerList, player => player.GetBuffs(log, BuffEnum.Self)); Parallel.ForEach(log.FightData.Logic.Targets, target => target.GetBuffs(log)); } if (Properties.Settings.Default.SaveOutHTML) { operation.UpdateProgressWithCancellationCheck("Creating HTML"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.html" ); operation.GeneratedFiles.Add(outputFile); operation.OpenableFiles.Add(outputFile); operation.OutLocation = saveDirectory.FullName; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs)) { var builder = new HTMLBuilder(log, new HTMLSettings(Properties.Settings.Default.LightTheme, Properties.Settings.Default.HtmlExternalScripts), htmlAssets, uploadresult); builder.CreateHTML(sw, saveDirectory.FullName); } operation.UpdateProgressWithCancellationCheck("HTML created"); } if (Properties.Settings.Default.SaveOutCSV) { operation.UpdateProgressWithCancellationCheck("Creating CSV"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.csv" ); operation.GeneratedFiles.Add(outputFile); operation.OpenableFiles.Add(outputFile); operation.OutLocation = saveDirectory.FullName; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs, Encoding.GetEncoding(1252))) { var builder = new CSVBuilder(log, new CSVSettings(","), uploadresult); builder.CreateCSV(sw); } operation.UpdateProgressWithCancellationCheck("CSV created"); } if (Properties.Settings.Default.SaveOutJSON || Properties.Settings.Default.SaveOutXML) { var builder = new RawFormatBuilder(log, new RawFormatSettings(Properties.Settings.Default.RawTimelineArrays), uploadresult); if (Properties.Settings.Default.SaveOutJSON) { operation.UpdateProgressWithCancellationCheck("Creating JSON"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.json" ); operation.OutLocation = saveDirectory.FullName; Stream str; if (Properties.Settings.Default.CompressRaw) { str = new MemoryStream(); } else { str = new FileStream(outputFile, FileMode.Create, FileAccess.Write); } using (var sw = new StreamWriter(str, NoBOMEncodingUTF8)) { builder.CreateJSON(sw, Properties.Settings.Default.IndentJSON); } if (str is MemoryStream msr) { CompressFile(outputFile, msr, operation); operation.UpdateProgressWithCancellationCheck("JSON compressed"); } else { operation.GeneratedFiles.Add(outputFile); } operation.UpdateProgressWithCancellationCheck("JSON created"); } if (Properties.Settings.Default.SaveOutXML) { operation.UpdateProgressWithCancellationCheck("Creating XML"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.xml" ); operation.OutLocation = saveDirectory.FullName; Stream str; if (Properties.Settings.Default.CompressRaw) { str = new MemoryStream(); } else { str = new FileStream(outputFile, FileMode.Create, FileAccess.Write); } using (var sw = new StreamWriter(str, NoBOMEncodingUTF8)) { builder.CreateXML(sw, Properties.Settings.Default.IndentXML); } if (str is MemoryStream msr) { CompressFile(outputFile, msr, operation); operation.UpdateProgressWithCancellationCheck("XML compressed"); } else { operation.GeneratedFiles.Add(outputFile); } operation.UpdateProgressWithCancellationCheck("XML created"); } } operation.UpdateProgress($"Completed parsing for {result}ed {log.FightData.Logic.Extension}"); }
private static void GenerateFiles(ParsedEvtcLog log, OperationController operation, string[] uploadStrings, FileInfo fInfo) { operation.UpdateProgressWithCancellationCheck("Creating File(s)"); DirectoryInfo saveDirectory = GetSaveDirectory(fInfo); string result = log.FightData.Success ? "kill" : "fail"; string encounterLengthTerm = Properties.Settings.Default.AddDuration ? "_" + (log.FightData.FightDuration / 1000).ToString() + "s" : ""; string PoVClassTerm = Properties.Settings.Default.AddPoVProf ? "_" + log.LogData.PoV.Spec.ToString().ToLower() : ""; string fName = fInfo.Name.Split('.')[0]; fName = $"{fName}{PoVClassTerm}_{log.FightData.Logic.Extension}{encounterLengthTerm}_{result}"; // parallel stuff if (Properties.Settings.Default.MultiThreaded && HasFormat()) { IReadOnlyList <PhaseData> phases = log.FightData.GetPhases(log); operation.UpdateProgressWithCancellationCheck("Multi threading"); var friendliesAndTargets = new List <AbstractSingleActor>(log.Friendlies); friendliesAndTargets.AddRange(log.FightData.Logic.Targets); var friendliesAndTargetsAndMobs = new List <AbstractSingleActor>(log.FightData.Logic.TrashMobs); friendliesAndTargetsAndMobs.AddRange(friendliesAndTargets); foreach (AbstractSingleActor actor in friendliesAndTargetsAndMobs) { // that part can't be // due to buff extensions actor.GetTrackedBuffs(log); actor.GetMinions(log); } Parallel.ForEach(friendliesAndTargets, actor => actor.GetStatus(log)); /*if (log.CombatData.HasMovementData) * { * // init all positions * Parallel.ForEach(friendliesAndTargetsAndMobs, actor => actor.GetCombatReplayPolledPositions(log)); * }*/ Parallel.ForEach(friendliesAndTargetsAndMobs, actor => actor.GetBuffGraphs(log)); Parallel.ForEach(friendliesAndTargets, actor => { foreach (PhaseData phase in phases) { actor.GetBuffDistribution(log, phase.Start, phase.End); } }); Parallel.ForEach(friendliesAndTargets, actor => { foreach (PhaseData phase in phases) { actor.GetBuffPresence(log, phase.Start, phase.End); } }); // //Parallel.ForEach(log.PlayerList, player => player.GetDamageModifierStats(log, null)); Parallel.ForEach(log.Friendlies, actor => { foreach (PhaseData phase in phases) { actor.GetBuffs(BuffEnum.Self, log, phase.Start, phase.End); } }); Parallel.ForEach(log.PlayerList, actor => { foreach (PhaseData phase in phases) { actor.GetBuffs(BuffEnum.Group, log, phase.Start, phase.End); } }); Parallel.ForEach(log.PlayerList, actor => { foreach (PhaseData phase in phases) { actor.GetBuffs(BuffEnum.OffGroup, log, phase.Start, phase.End); } }); Parallel.ForEach(log.PlayerList, actor => { foreach (PhaseData phase in phases) { actor.GetBuffs(BuffEnum.Squad, log, phase.Start, phase.End); } }); Parallel.ForEach(log.FightData.Logic.Targets, actor => { foreach (PhaseData phase in phases) { actor.GetBuffs(BuffEnum.Self, log, phase.Start, phase.End); } }); } var uploadResults = new UploadResults(uploadStrings[0], uploadStrings[1]); if (Properties.Settings.Default.SaveOutHTML) { operation.UpdateProgressWithCancellationCheck("Creating HTML"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.html" ); operation.GeneratedFiles.Add(outputFile); operation.OpenableFiles.Add(outputFile); operation.OutLocation = saveDirectory.FullName; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs)) { var builder = new HTMLBuilder(log, new HTMLSettings( Properties.Settings.Default.LightTheme, Properties.Settings.Default.HtmlExternalScripts, Properties.Settings.Default.HtmlExternalScriptsPath, Properties.Settings.Default.HtmlExternalScriptsCdn, Properties.Settings.Default.HtmlCompressJson ), htmlAssets, ParserVersion, uploadResults); builder.CreateHTML(sw, saveDirectory.FullName); } operation.UpdateProgressWithCancellationCheck("HTML created"); } if (Properties.Settings.Default.SaveOutCSV) { operation.UpdateProgressWithCancellationCheck("Creating CSV"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.csv" ); operation.GeneratedFiles.Add(outputFile); operation.OpenableFiles.Add(outputFile); operation.OutLocation = saveDirectory.FullName; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs, Encoding.GetEncoding(1252))) { var builder = new CSVBuilder(log, new CSVSettings(","), ParserVersion, uploadResults); builder.CreateCSV(sw); } operation.UpdateProgressWithCancellationCheck("CSV created"); } if (Properties.Settings.Default.SaveOutJSON || Properties.Settings.Default.SaveOutXML) { var builder = new RawFormatBuilder(log, new RawFormatSettings(Properties.Settings.Default.RawTimelineArrays), ParserVersion, uploadResults); if (Properties.Settings.Default.SaveOutJSON) { operation.UpdateProgressWithCancellationCheck("Creating JSON"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.json" ); operation.OutLocation = saveDirectory.FullName; Stream str; if (Properties.Settings.Default.CompressRaw) { str = new MemoryStream(); } else { str = new FileStream(outputFile, FileMode.Create, FileAccess.Write); } using (var sw = new StreamWriter(str, NoBOMEncodingUTF8)) { builder.CreateJSON(sw, Properties.Settings.Default.IndentJSON); } if (str is MemoryStream msr) { CompressFile(outputFile, msr, operation); operation.UpdateProgressWithCancellationCheck("JSON compressed"); } else { operation.GeneratedFiles.Add(outputFile); } operation.UpdateProgressWithCancellationCheck("JSON created"); } if (Properties.Settings.Default.SaveOutXML) { operation.UpdateProgressWithCancellationCheck("Creating XML"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.xml" ); operation.OutLocation = saveDirectory.FullName; Stream str; if (Properties.Settings.Default.CompressRaw) { str = new MemoryStream(); } else { str = new FileStream(outputFile, FileMode.Create, FileAccess.Write); } using (var sw = new StreamWriter(str, NoBOMEncodingUTF8)) { builder.CreateXML(sw, Properties.Settings.Default.IndentXML); } if (str is MemoryStream msr) { CompressFile(outputFile, msr, operation); operation.UpdateProgressWithCancellationCheck("XML compressed"); } else { operation.GeneratedFiles.Add(outputFile); } operation.UpdateProgressWithCancellationCheck("XML created"); } } operation.UpdateProgressWithCancellationCheck($"Completed parsing for {result}ed {log.FightData.Logic.Extension}"); }
private static void GenerateFiles(ParsedLog log, OperationController operation, string[] uploadresult, FileInfo fInfo) { operation.ThrowIfCanceled(); operation.UpdateProgress("Creating File(s)"); DirectoryInfo saveDirectory = GetSaveDirectory(fInfo); if (saveDirectory == null) { throw new InvalidDataException("Save Directory not found"); } string result = log.FightData.Success ? "kill" : "fail"; string encounterLengthTerm = Properties.Settings.Default.AddDuration ? "_" + (log.FightData.FightEnd / 1000).ToString() + "s" : ""; string PoVClassTerm = Properties.Settings.Default.AddPoVProf ? "_" + log.LogData.PoV.Prof.ToLower() : ""; string fName = fInfo.Name.Split('.')[0]; fName = $"{fName}{PoVClassTerm}_{log.FightData.Logic.Extension}{encounterLengthTerm}_{result}"; operation.ThrowIfCanceled(); // parallel stuff if (log.ParserSettings.MultiTasks) { operation.UpdateProgress("Multi threading buff and damage mod computations"); log.FightData.GetPhases(log); foreach (Player p in log.PlayerList) { // that part can't be // p.ComputeBuffMap(log); } foreach (NPC npc in log.FightData.Logic.Targets) { // that part can't be // npc.ComputeBuffMap(log); } var actors = new List <AbstractSingleActor>(log.PlayerList); actors.AddRange(log.FightData.Logic.Targets); Parallel.ForEach(actors, actor => actor.GetBuffGraphs(log)); // Parallel.ForEach(log.PlayerList, player => player.GetDamageModifierStats(log, null)); Parallel.ForEach(log.PlayerList, player => player.GetBuffs(log, BuffEnum.Self)); } if (Properties.Settings.Default.SaveOutHTML) { operation.UpdateProgress("Creating HTML"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.html" ); operation.LogLocation = outputFile; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs)) { var builder = new HTMLBuilder(log, uploadresult, Properties.Settings.Default.LightTheme, Properties.Settings.Default.HtmlExternalScripts); builder.CreateHTML(sw, saveDirectory.FullName, operation); } operation.UpdateProgress("HTML created"); } operation.ThrowIfCanceled(); if (Properties.Settings.Default.SaveOutCSV) { operation.UpdateProgress("Creating CSV"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.csv" ); string splitString = ""; if (operation.LogLocation != null) { splitString = ","; } operation.LogLocation += splitString + outputFile; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs, Encoding.GetEncoding(1252))) { var builder = new CSVBuilder(sw, ",", log, uploadresult); builder.CreateCSV(operation); } operation.UpdateProgress("CSV created"); } operation.ThrowIfCanceled(); if (Properties.Settings.Default.SaveOutJSON || Properties.Settings.Default.SaveOutXML) { var builder = new RawFormatBuilder(log, uploadresult, operation); if (Properties.Settings.Default.SaveOutJSON) { operation.UpdateProgress("Creating JSON"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.json" ); string splitString = ""; if (operation.LogLocation != null) { splitString = ","; } operation.LogLocation += splitString + saveDirectory.FullName; Stream str; if (Properties.Settings.Default.CompressRaw) { str = new MemoryStream(); } else { str = new FileStream(outputFile, FileMode.Create, FileAccess.Write); } using (var sw = new StreamWriter(str, GeneralHelper.NoBOMEncodingUTF8)) { builder.CreateJSON(sw, Properties.Settings.Default.IndentJSON); } if (str is MemoryStream msr) { CompressFile(outputFile, msr); operation.UpdateProgress("JSON compressed"); } operation.UpdateProgress("JSON created"); } operation.ThrowIfCanceled(); if (Properties.Settings.Default.SaveOutXML) { operation.UpdateProgress("Creating XML"); string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.xml" ); string splitString = ""; if (operation.LogLocation != null) { splitString = ","; } operation.LogLocation += splitString + saveDirectory.FullName; Stream str; if (Properties.Settings.Default.CompressRaw) { str = new MemoryStream(); } else { str = new FileStream(outputFile, FileMode.Create, FileAccess.Write); } using (var sw = new StreamWriter(str, GeneralHelper.NoBOMEncodingUTF8)) { builder.CreateXML(sw, Properties.Settings.Default.IndentXML); } if (str is MemoryStream msr) { CompressFile(outputFile, msr); operation.UpdateProgress("XML compressed"); } operation.UpdateProgress("XML created"); } operation.ThrowIfCanceled(); } operation.UpdateProgress($"Completed parsing for {result}ed {log.FightData.Logic.Extension}"); }
private static void GenerateFiles(ParsedLog log, GridRow rowData, string[] uploadresult, FileInfo fInfo) { rowData.BgWorker.ThrowIfCanceled(rowData); rowData.BgWorker.UpdateProgress(rowData, "50% - Creating File(s)...", 50); //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); } if (saveDirectory == null) { throw new InvalidDataException("Error Encountered: Save Directory not found"); } string result = log.FightData.Success ? "kill" : "fail"; string encounterLengthTerm = Properties.Settings.Default.AddDuration ? "_" + (log.FightData.FightEnd / 1000).ToString() + "s" : ""; string PoVClassTerm = Properties.Settings.Default.AddPoVProf ? "_" + log.LogData.PoV.Prof.ToLower() : ""; string fName = fInfo.Name.Split('.')[0]; fName = $"{fName}{PoVClassTerm}_{log.FightData.Logic.Extension}{encounterLengthTerm}_{result}"; rowData.BgWorker.ThrowIfCanceled(rowData); // parallel stuff if (log.ParserSettings.MultiTasks) { log.FightData.GetPhases(log); foreach (Player p in log.PlayerList) { // that part can't be // p.ComputeBuffMap(log); } foreach (NPC npc in log.FightData.Logic.Targets) { // that part can't be // npc.ComputeBuffMap(log); } var actors = new List <AbstractSingleActor>(log.PlayerList); actors.AddRange(log.FightData.Logic.Targets); Parallel.ForEach(actors, actor => actor.GetBuffGraphs(log)); // Parallel.ForEach(log.PlayerList, player => player.GetDamageModifierStats(log, null)); Parallel.ForEach(log.PlayerList, player => player.GetBuffs(log, BuffEnum.Self)); } if (Properties.Settings.Default.SaveOutHTML) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.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, uploadresult, Properties.Settings.Default.LightTheme, Properties.Settings.Default.HtmlExternalScripts); builder.CreateHTML(sw, saveDirectory.FullName); } } rowData.BgWorker.ThrowIfCanceled(rowData); if (Properties.Settings.Default.SaveOutCSV) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.csv" ); string splitString = ""; if (rowData.LogLocation != null) { splitString = ","; } rowData.LogLocation += splitString + outputFile; using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) using (var sw = new StreamWriter(fs, Encoding.GetEncoding(1252))) { var builder = new CSVBuilder(sw, ",", log, uploadresult); builder.CreateCSV(); } } rowData.BgWorker.ThrowIfCanceled(rowData); if (Properties.Settings.Default.SaveOutJSON || Properties.Settings.Default.SaveOutXML) { var builder = new RawFormatBuilder(log, uploadresult); if (Properties.Settings.Default.SaveOutJSON) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.json" ); string splitString = ""; if (rowData.LogLocation != null) { splitString = ","; } rowData.LogLocation += splitString + saveDirectory.FullName; Stream str; if (Properties.Settings.Default.CompressRaw) { str = new MemoryStream(); } else { str = new FileStream(outputFile, FileMode.Create, FileAccess.Write); } using (var sw = new StreamWriter(str, GeneralHelper.NoBOMEncodingUTF8)) { builder.CreateJSON(sw, Properties.Settings.Default.IndentJSON); } if (str is MemoryStream msr) { CompressFile(outputFile, msr); } } rowData.BgWorker.ThrowIfCanceled(rowData); if (Properties.Settings.Default.SaveOutXML) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}.xml" ); string splitString = ""; if (rowData.LogLocation != null) { splitString = ","; } rowData.LogLocation += splitString + saveDirectory.FullName; Stream str; if (Properties.Settings.Default.CompressRaw) { str = new MemoryStream(); } else { str = new FileStream(outputFile, FileMode.Create, FileAccess.Write); } using (var sw = new StreamWriter(str, GeneralHelper.NoBOMEncodingUTF8)) { builder.CreateXML(sw, Properties.Settings.Default.IndentXML); } if (str is MemoryStream msr) { CompressFile(outputFile, msr); } } rowData.BgWorker.ThrowIfCanceled(rowData); } rowData.BgWorker.UpdateProgress(rowData, $"100% - Complete_{log.FightData.Logic.Extension}_{result}", 100); }