public void GivenTheCSVStatecodefileDelimiterIncorrect_WhenAnalyse_ThrowcensusAnalyserException() { cSVBuilder = new CSVBuilder(stateCodePath, '.', "SrNo,State,Name,TIN,StateCode"); var delimiterIncorrect = Assert.Throws <CensusAnalyserException>(() => csvstatecensus()); Assert.AreEqual("incorrect delimiter", delimiterIncorrect.GetMessage); }
public string ExportStaging(int clientId) { var client = _clientService.Get(clientId); if (client == null) { return("Client not found"); } var fileConfig = _fileService.GetConfiguration(clientId); if (fileConfig == null) { return($"File configuration not found for client {clientId}"); } if (string.IsNullOrEmpty(fileConfig.OutputPath)) { return($"No output file configuration found for Client: {clientId}"); } var list = GetImported(clientId); var writeFunc = new Dictionary <FileType, Func <string> > { { FileType.CSV, () => CSVBuilder.WriteToCsv(list, fileConfig.OutputPath) }, { FileType.JSON, () => JsonBuilder.WriteToJson(list, fileConfig.OutputPath) } }; return(writeFunc[fileConfig.FileType].Invoke()); }
public void GivenTheCSVStatecodeFileTypeIncorrect_WhenAnalyse_ThrowCensusAnalyserException() { cSVBuilder = new CSVBuilder(stateCodePathFileTypeIncorrect, ',', "SrNo,State,Name,TIN,StateCode"); var typeIncorrect = Assert.Throws <CensusAnalyserException>(() => csvstatecensus()); Assert.AreEqual("file type incorrect", typeIncorrect.GetMessage); }
public void GivenTheStateCensusCsvFileTypeIncorrect_WhenAnalyse_ThrowCensusAnalyserException() { cSVBuilder = new CSVBuilder(fileTypeIncorrect, ',', "State,Population,AreaInSqKm,DensityPerSqKm"); var typeIncorrect = Assert.Throws <CensusAnalyserException>(() => csvstatecensus()); Assert.AreEqual("file type incorrect", typeIncorrect.GetMessage); }
public void GivenTheCSVStateCodeFileHeaderIncorrect_WhenAnalyse_ThrowCensusAnalyserException() { cSVBuilder = new CSVBuilder(stateCodePath, ',', "SrNo,,TIN,StateCode"); var headerIncorrect = Assert.Throws <CensusAnalyserException>(() => csvstatecensus()); Assert.AreEqual("incorrect header", headerIncorrect.GetMessage); }
public void GivenTheStateCensusCsvFileHeaderIncorrect_WhenAnalyse_ThrowCensusAnalyserException() { cSVBuilder = new CSVBuilder(stateCensusDatapath, ',', "State,Popula tyPerSqKm"); var headerIncorrect = Assert.Throws <CensusAnalyserException>(() => csvstatecensus()); Assert.AreEqual("incorrect header", headerIncorrect.GetMessage); }
public void GivenTheStateCesnusCsvFileDelimiterIncorrect_WhenAnalyse_ThrowcensusAnalyserException() { cSVBuilder = new CSVBuilder(stateCensusDatapath, '.', "State,Population,AreaInSqKm,DensityPerSqKm"); var delimiterIncorrect = Assert.Throws <CensusAnalyserException>(() => csvstatecensus()); Assert.AreEqual("incorrect delimiter", delimiterIncorrect.GetMessage); }
public string GetLine(int index, XElement item, CSVBuilder instance) { string buffer = ""; foreach (var key in keys) { try { AutoCSVKeys.KeyDelegate spcKey; if (AutoCSVKeys.specialKeys.TryGetValue(key, out spcKey)) { buffer += spcKey(index, key, item.Attribute(key) != null ? item.Attribute(key).Value : "0", item, instance); } else { buffer += (item.Attribute(key) != null ? item.Attribute(key).Value : "0") + ","; } } catch (Exception e) { Debug.LogError(string.Format("An Error Occured while getting values from mod.xml : {0}", key)); Debug.LogWarning(e); } } buffer = buffer.Substring(0, buffer.Length - 1); // f****r buffer += "\n"; return(buffer); }
static void Main(string[] args) { string inputLocation = ConfigurationSettings.AppSettings["InputLocation"]; string archive = ConfigurationSettings.AppSettings["ArchiveLocation"]; var fileSystem = new FileSystemWrapper(inputLocation, archive); var inputter = new FileSystemInput(fileSystem); string outputLocation = ConfigurationSettings.AppSettings["OutputLocation"]; var fileSystemOutput = new OutputFileSystemWrapper(outputLocation); var csvBuilder = new CSVBuilder(); var outputter = new CSVFileOutput(fileSystemOutput, csvBuilder); var orderProcessor = new OrderProcessor(outputter); inputter.ConfigureProcessor(orderProcessor); inputter.Scan(); var stop = false; var startTimeSpan = TimeSpan.Zero; var periodTimeSpan = TimeSpan.FromMinutes(5); while (!stop) { var timer = new System.Threading.Timer((e) => { inputter.Scan(); }, null, startTimeSpan, periodTimeSpan); } }
public void GiventheStatesCensusCSVfile_WhenAnalyse_ShouldRecordNumberOfRecordmatches() { cSVBuilder = new CSVBuilder(stateCensusDatapath, ',', "State,Population,AreaInSqKm,DensityPerSqKm"); int count1 = GetCountFromStateCensusAnalyser(stateCensusDatapath); int count2 = csvstatecensus(); Assert.AreEqual(count1, count2); }
public void GivenCSVStateCodeFile_WhenAnalyse_ReturnNumberOfRecordsMatch() { cSVBuilder = new CSVBuilder(stateCodePath, ',', "SrNo,State Name,TIN,StateCode"); int count1 = GetCountFromStateCensusAnalyser(stateCodePath); int count2 = csvstatecensus(); Assert.AreEqual(count1, count2); }
public static string CsvString(ParsedLog log) { var ms = new MemoryStream(); var sw = new StreamWriter(ms); var builder = new CSVBuilder(sw, ",", log, null); builder.CreateCSV(); sw.Close(); return(sw.ToString()); }
public static string CsvString(ParsedEvtcLog log) { var ms = new MemoryStream(); var sw = new StreamWriter(ms); var builder = new CSVBuilder(log, csvSettings); builder.CreateCSV(sw); sw.Close(); return(sw.ToString()); }
public FileResult DownloadEntry(string type, long keyReference) { using (var dataEditor = new RFDataEditorActivity(Context, Username)) { var entry = dataEditor.GetDocumentForDownload(type, keyReference); if (entry != null) { var shortType = System.IO.Path.GetExtension(type).TrimStart('.'); var content = entry.Content; if (content is IRFDataSet) { var namePart = entry.Key.FriendlyString(); Array.ForEach(Path.GetInvalidFileNameChars(), c => namePart = namePart.Replace(c.ToString(), String.Empty)); var date = (entry.Key.GraphInstance != null ? entry.Key.GraphInstance.ValueDate : null) ?? DateTime.Now; return(File(RIFF.Interfaces.Formats.XLSX.XLSXGenerator.ExportToXLSX(type, content as IRFDataSet), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", String.Format("{0}_{3}-{1}-{2}.xlsx", namePart, shortType, keyReference, date.ToString("yyyyMMdd")))); } else if (entry.Content is RFFile) { var file = entry.Content as RFFile; return(File(file.Data, ImplyContentType(file.ContentName), file.Attributes.FileName)); } else if (entry.Content is RFRawReport) { var report = entry.Content as RFRawReport; var csvBuilder = new StringBuilder(); foreach (var section in report.Sections) { try { csvBuilder.Append(CSVBuilder.FromDataTable(section.AsDataTable())); } catch (Exception ex) { Log.Warning(this, "Error exporting section {0} of report {1} to .csv: {2}", section.Name, report.ReportCode, ex.Message); } } return(File(Encoding.UTF8.GetBytes(csvBuilder.ToString()), "text/csv", String.Format("{0}_{1}.csv", report.ReportCode, report.ValueDate.ToString("yyyy-MM-dd")))); } else { var namePart = entry.Key.FriendlyString(); Array.ForEach(Path.GetInvalidFileNameChars(), c => namePart = namePart.Replace(c.ToString(), String.Empty)); var date = (entry.Key.GraphInstance != null ? entry.Key.GraphInstance.ValueDate : null) ?? DateTime.Now; var xml = RFXMLSerializer.PrettySerializeContract(content); return(File(Encoding.UTF8.GetBytes(xml), "text/xml", String.Format("{0}_{3}-{1}-{2}.xml", namePart, shortType, keyReference, date.ToString("yyyyMMdd")))); } } } return(null); }
public override RFProcessingResult Process() { var result = new RFProcessingResult(); if (!_config.Enabled) { return(result); } try { int numRows = 0; var sqlQuery = _config.QueryFunc(); var fileName = _config.FileNameFunc(); var path = System.IO.Path.Combine(_config.DestinationPath, fileName); using (var connection = new SqlConnection(_config.ConnectionString)) { connection.Open(); try { var knownColumns = new Dictionary <string, int>(); using (var queryCommand = new SqlCommand(sqlQuery, connection)) { using (var reader = queryCommand.ExecuteReader(System.Data.CommandBehavior.SingleResult)) { var dataTable = new DataTable(); dataTable.Load(reader); if (dataTable != null && dataTable.Rows != null) { System.IO.File.WriteAllText( path, CSVBuilder.FromDataTable(dataTable)); numRows = dataTable.Rows.Count; } } } } catch (Exception ex) { throw new RFSystemException(this, ex, "Error running SQL report for file {0}", fileName); } } Context.SystemLog.Info(this, "Saved {0} rows from an SQL query into {1}", numRows, fileName); } catch (Exception ex) { throw new RFSystemException(this, ex, "Error running SQL report for path {0}", _config.DestinationPath); } result.WorkDone = true; return(result); }
public string ImportStaging(int clientId) { var client = _clientService.Get(clientId); if (client == null) { return("Client not found"); } var fileConfig = _fileService.GetConfiguration(clientId); if (fileConfig == null) { return($"File configuration not found for client {clientId}"); } if (string.IsNullOrEmpty(fileConfig.OutputPath)) { return($"No output file configuration found for Client: {clientId}"); } var list = GetImported(clientId); var writeFunc = new Dictionary <FileType, Func <List <string> > > { { FileType.CSV, () => CSVBuilder.ReadFromCsvFile(fileConfig.InputPath) }, { FileType.JSON, () => JsonBuilder.ReadFromJsonFile(fileConfig.InputPath) } }; var data = writeFunc[fileConfig.FileType].Invoke(); if (data == null) { return("Import Failed"); } var dto = Mapper.Map <List <string>, List <ImportedContact> >(data); dto.ForEach(item => { item.Phone = ValidatePhoneNumber(item.Phone); var contact = Mapper.Map <ImportedContact, Contact>(item); contact.IsValid = true; contact.ClientId = clientId; _contactRepo.Add(contact); }); return($"Imported {dto.Count} contacts"); }
/// <summary> /// Numbers the of records. /// </summary> /// <returns>It returns number of lines.</returns> public string NumberOfRecords() { try { CSVBuilder csvBuilder = new CSVBuilder(this.path, this.delimiter, this.csvHeader); this.path = csvBuilder.FilePath; this.delimiter = csvBuilder.Delimiter; this.csvHeader = csvBuilder.Header; string[] records = csvBuilder.Records; return(records.Length.ToString()); } catch (CustomException exception) { return(exception.Message); } }
public override RFProcessingResult Process() { var result = new RFProcessingResult(); if (_config.Enabled && !string.IsNullOrWhiteSpace(_config.ArchivePath)) { var inputReport = Context.LoadDocumentContent <RFRawReport>(InstanceParams.Key); if (inputReport != null) { var csvBuilder = new StringBuilder(); foreach (var section in inputReport.Sections) { csvBuilder.Append(CSVBuilder.FromDataTable(section.AsDataTable())); } var outputDirectory = Path.Combine(_config.ArchivePath, inputReport.ValueDate.ToString("yyyy-MM-dd")); Directory.CreateDirectory(outputDirectory); var outputPath = Path.Combine(outputDirectory, String.Format("{0}_{1}.csv", inputReport.SourceUniqueKey, inputReport.UpdateTime.ToLocalTime().ToString("yyyyMMdd_HHmmss"))); File.WriteAllBytes(outputPath, Encoding.UTF8.GetBytes(csvBuilder.ToString())); } result.WorkDone = true; } return(result); }
private static string BoneText(int index, string key, string parameter, XElement item, CSVBuilder instance) { return(item.Value); }
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 string GetBundleFromAsset(int index, string key, string assetName, XElement item, CSVBuilder instance) { string bundleName = "0"; string[][] assetNames = instance.packData.assetNames; string[] bundleNames = instance.packData.assetBundleNames; // TODO: Improve asset auto assignment search algorithms // 1. reduce search string to essential parts such as filename or first part of directory. // 2. cache found filenames to avoid same filename traps. // 3. research about shitty case of search algorithms (similar names, fucky situations (like url parsing you f****r)) for (int i = 0; i < bundleNames.Length; i++) { foreach (string name in assetNames[i]) { string fuckingshit = name.Substring(name.LastIndexOf('/')); // yeah fuckoff you f*****g c**t if (fuckingshit.Contains(assetName)) { bundleName = bundleNames[i]; } } } //Debug.Log(string.Format("{0}: {1}", key, bundleName)); if (bundleName == "0") { try { int dashIndex = key.LastIndexOf('-') < 0 ? key.Length : key.LastIndexOf('-'); string bundleKey = key.Substring(0, dashIndex) + "-bundle"; bundleName = item.Attribute(bundleKey) != null?item.Attribute(bundleKey).Value : "0"; } catch (Exception e) { Debug.LogWarning("Could not catch shits."); } } return(string.Format("{0},{1},", bundleName, assetName)); }
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, "") { 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 { SettingsContainer settings = new SettingsContainer(Properties.Settings.Default); Parser control = new Parser(settings); if (fInfo.Extension.Equals(".evtc", StringComparison.OrdinalIgnoreCase) || fInfo.Name.EndsWith(".evtc.zip", StringComparison.OrdinalIgnoreCase)) { //Process evtc here ParsedLog log = control.ParseLog(row, fInfo.FullName); Console.Write("Log Parsed\n"); bool uploadAuthorized = !Properties.Settings.Default.SkipFailedTries || (Properties.Settings.Default.SkipFailedTries && log.LogData.Success); if (Properties.Settings.Default.UploadToDPSReports && uploadAuthorized) { 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 && uploadAuthorized) { 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 && uploadAuthorized) { 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"; } } if (Properties.Settings.Default.SkipFailedTries) { if (!log.LogData.Success) { throw new SkipException(); } } //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 = "fail"; if (log.LogData.Success) { result = "kill"; } StatisticsCalculator statisticsCalculator = new StatisticsCalculator(settings); StatisticsCalculator.Switches switches = new StatisticsCalculator.Switches(); if (Properties.Settings.Default.SaveOutHTML) { HTMLBuilder.UpdateStatisticSwitches(switches); } if (Properties.Settings.Default.SaveOutCSV) { CSVBuilder.UpdateStatisticSwitches(switches); } if (Properties.Settings.Default.SaveOutJSON) { JSONBuilder.UpdateStatisticSwitches(switches); } Statistics statistics = statisticsCalculator.CalculateStatistics(log, switches); Console.Write("Statistics Computed\n"); string fName = fInfo.Name.Split('.')[0]; if (Properties.Settings.Default.SaveOutHTML) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}_{log.FightData.Logic.Extension}_{result}.html" ); using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs)) { if (Properties.Settings.Default.NewHtmlMode) { var builder = new HTMLBuilderNew(log, settings, statistics); builder.CreateHTML(sw, saveDirectory.FullName); } else { var builder = new HTMLBuilder(log, settings, statistics, uploadresult); builder.CreateHTML(sw); } } } } if (Properties.Settings.Default.SaveOutCSV) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}_{log.FightData.Logic.Extension}_{result}.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, settings, statistics, uploadresult); builder.CreateCSV(); } } } if (Properties.Settings.Default.SaveOutJSON) { string outputFile = Path.Combine( saveDirectory.FullName, $"{fName}_{log.FightData.Logic.Extension}_{result}.json" ); using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) { var builder = new JSONBuilder(sw, log, settings, statistics, false, uploadresult); builder.CreateJSON(); } } } 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); } catch (Exception ex) when(!System.Diagnostics.Debugger.IsAttached) { Console.Error.Write(ex.Message); throw new CancellationException(row, ex); } finally { Thread.CurrentThread.CurrentCulture = before; } }
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 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; }
public ModPackInfo(XDocument documentInfo) { string currentDirectory = GetProjectPath().Replace("/", "\\"); if (documentInfo != null) { #region Build AssetBundle Target Array IEnumerable <XElement> bundleTargets = documentInfo.Root.Element("bundles").Elements("bundle"); assetBundleNames = new string[bundleTargets.Count()]; assetNames = new string[bundleTargets.Count()][]; int index = 0; // lmao foreach (var bundle in bundleTargets) { IEnumerable <XElement> assets = bundle.Elements("asset"); int assetIndex = 0; string[] assetArray = new string[assets.Count()]; foreach (var asset in assets) { assetArray[assetIndex] = Path.Combine(currentDirectory, asset.Attribute("path").Value).Replace("\\", "/"); assetIndex++; } assetBundleNames[index] = bundle.Attribute("path").Value; assetNames[index] = assetArray; index++; } #endregion #region Build Material Swap Script if (documentInfo.Root.Element("matswap") != null) { sbuScriptBuilder = new SBUScriptBuilder(documentInfo.Root.Element("matswap")); } #endregion #region Build Manifest Buffer fileName = documentInfo.Root.Element("build").Attribute("name").Value; manifestBuilder = new ManifestBuilder(documentInfo); #endregion #region Build CSV Buffer IEnumerable <XElement> buildLists = documentInfo.Root.Element("build").Elements("list"); csvBuilders = new CSVBuilder[buildLists.Count()]; int csvIndex = 0; foreach (var list in buildLists) { string type = list.Attribute("type").Value; if (CSVBuilder.listTypeInfo.ContainsKey(type)) { if (CSVBuilder.listTypeInfo[type].isStudioMod) { csvBuilders[csvIndex] = new CSVBuilder(type, list.Attribute("path").Value, this); } else { csvBuilders[csvIndex] = new CSVBuilder(type, this); } } else { Debug.LogError(string.Format("Type \"{0}\" is an invalid list category.", type)); } csvBuilders[csvIndex].Generate(list.Elements("item")); csvIndex++; } #endregion } else { Debug.LogError("Invalid XML Document."); } }
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 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; } }
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); }
/// <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; }
/// <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; } }