public static void GenerateTraceFile(OperationController operation)
        {
            if (Properties.Settings.Default.SaveOutTrace)
            {
                var fInfo = new FileInfo(operation.InputFile);

                string fName = fInfo.Name.Split('.')[0];
                if (!fInfo.Exists)
                {
                    fInfo = new FileInfo(AppDomain.CurrentDomain.BaseDirectory);
                }

                DirectoryInfo saveDirectory = GetSaveDirectory(fInfo);

                string outputFile = Path.Combine(
                    saveDirectory.FullName,
                    $"{fName}.log"
                    );
                operation.GeneratedFiles.Add(outputFile);
                operation.OutLocation = saveDirectory.FullName;
                using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write))
                    using (var sw = new StreamWriter(fs))
                    {
                        operation.WriteLogMessages(sw);
                    }
            }
        }
Example #2
0
        public static void GenerateLogFile(OperationController operation)
        {
            var fInfo = new FileInfo(operation.Location);

            string fName = fInfo.Name.Split('.')[0];

            if (!fInfo.Exists)
            {
                fInfo = new FileInfo(AppDomain.CurrentDomain.BaseDirectory);
            }

            DirectoryInfo saveDirectory = GetSaveDirectory(fInfo);

            if (saveDirectory == null)
            {
                return;
            }

            string outputFile = Path.Combine(
                saveDirectory.FullName,
                $"{fName}.log"
                );

            using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write))
                using (var sw = new StreamWriter(fs))
                {
                    operation.WriteLogMessages(sw);
                }
        }
        public static void DoWork(OperationController operation)
        {
            System.Globalization.CultureInfo before = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture =
                new System.Globalization.CultureInfo("en-US");
            operation.Reset();
            var sw = new Stopwatch();

            try
            {
                sw.Start();
                var fInfo = new FileInfo(operation.InputFile);

                var parser = new EvtcParser(new EvtcParserSettings(Properties.Settings.Default.Anonymous,
                                                                   Properties.Settings.Default.SkipFailedTries,
                                                                   Properties.Settings.Default.ParsePhases,
                                                                   Properties.Settings.Default.ParseCombatReplay,
                                                                   Properties.Settings.Default.ComputeDamageModifiers,
                                                                   Properties.Settings.Default.CustomTooShort,
                                                                   Properties.Settings.Default.DetailledWvW),
                                            APIController);

                //Process evtc here
                ParsedEvtcLog log = parser.ParseLog(operation, fInfo, out GW2EIEvtcParser.ParserHelpers.ParsingFailureReason failureReason);
                if (failureReason != null)
                {
                    failureReason.Throw();
                }
                var      externalTraces = new List <string>();
                string[] uploadresult   = UploadOperation(externalTraces, fInfo);
                if (Properties.Settings.Default.SendEmbedToWebhook && Properties.Settings.Default.UploadToDPSReports)
                {
                    var webhookSettings = new WebhookSettings(Properties.Settings.Default.WebhookURL, !Properties.Settings.Default.SendSimpleMessageToWebhook ? BuildEmbed(log, uploadresult[0]) : null);
                    WebhookController.SendMessage(externalTraces, uploadresult[0], webhookSettings);
                }
                foreach (string trace in externalTraces)
                {
                    operation.UpdateProgress(trace);
                }
                if (uploadresult[0].Contains("https"))
                {
                    operation.DPSReportLink = uploadresult[0];
                }
                //Creating File
                GenerateFiles(log, operation, uploadresult, fInfo);
            }
            catch (Exception ex)
            {
                throw new ProgramException(ex);
            }
            finally
            {
                sw.Stop();
                GC.Collect();
                Thread.CurrentThread.CurrentCulture = before;
                operation.Elapsed = ("Elapsed " + sw.ElapsedMilliseconds + " ms");
            }
        }
Example #4
0
        public static void DoWork(OperationController operation)
        {
            System.Globalization.CultureInfo before = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture =
                new System.Globalization.CultureInfo("en-US");
            var fInfo = new FileInfo(operation.Location);

            try
            {
                if (!fInfo.Exists)
                {
                    throw new FileNotFoundException("File " + fInfo.FullName + " does not exist");
                }
                var control = new ParsingController(new ParserSettings());

                if (!HasFormat())
                {
                    throw new InvalidDataException("No output format has been selected");
                }

                if (IsSupportedFormat(fInfo.Name))
                {
                    //Process evtc here
                    ParsedLog log          = control.ParseLog(operation, fInfo.FullName);
                    string[]  uploadresult = UploadController.UploadOperation(operation, fInfo);
                    //Creating File
                    GenerateFiles(log, operation, uploadresult, fInfo);
                }
                else
                {
                    throw new InvalidDataException("Not EVTC");
                }
            }
            catch (Exception ex)
            {
                throw new ExceptionEncompass(ex);
            }
            finally
            {
                GC.Collect();
                Thread.CurrentThread.CurrentCulture = before;
            }
        }
        private static void CompressFile(string file, MemoryStream str, OperationController operation)
        {
            // Create the compressed file.
            byte[] data       = str.ToArray();
            string outputFile = file + ".gz";

            using (FileStream outFile =
                       File.Create(outputFile))
            {
                using (var Compress =
                           new GZipStream(outFile,
                                          CompressionMode.Compress))
                {
                    // Copy the source file into
                    // the compression stream.
                    Compress.Write(data, 0, data.Length);
                }
            }
            operation.GeneratedFiles.Add(outputFile);
        }
        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}");
        }
Example #7
0
        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}");
        }
Example #9
0
        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}");
        }