Ejemplo n.º 1
0
        public static ParsedLog ParseLog(string location)
        {
            var parser = new ParsingController(new TestParserSettings());

            var row = new GridRow(location as string, "Ready to parse")
            {
                BgWorker = new System.ComponentModel.BackgroundWorker()
                {
                    WorkerReportsProgress = true
                }
            };


            var fInfo = new FileInfo(row.Location);

            if (!fInfo.Exists)
            {
                throw new FileNotFoundException("Error Encountered: File does not exist", fInfo.FullName);
            }
            if (!ProgramHelper.IsSupportedFormat(fInfo.Name))
            {
                throw new InvalidDataException("Error Encountered: Not EVTC");
            }

            return(parser.ParseLog(row, fInfo.FullName));
        }
        /// <summary>
        /// Starts the process
        /// </summary>
        /// <returns></returns>
        public static void Start()
        {
            var stringinput = "";

            while (true)
            {
                try
                {
                    Console.WriteLine("Enter the url");
                    stringinput = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(stringinput) && string.IsNullOrEmpty(stringinput))
                    {
                        throw new ArgumentException("input string is null or empty");
                    }
                    break;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Console.ReadLine();
                    Console.Clear();
                }
            }
            ParsingController.Start(stringinput);
        }
        public static ParsedLog ParseLog(string location)
        {
            ParsingController parser = new ParsingController();

            GridRow row = new GridRow(location 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));
            }
            if (!GeneralHelper.IsSupportedFormat(fInfo.Name))
            {
                throw new CancellationException(row, new InvalidDataException("Not EVTC"));
            }

            return(parser.ParseLog(row, fInfo.FullName));
        }
        public BlackboardStageWidget(MainRecognizerWindow parent)
            : base(parent)
        {
            Glade.XML gladeXml = new XML("mathtextrecognizer.glade",
                                         "unassistedStageWidgetBase");

            gladeXml.Autoconnect(this);

            gladeXml = new XML("mathtextrecognizer.glade",
                               "blackboardMenu");

            gladeXml.Autoconnect(this);

            this.Add(unassistedStageWidgetBase);

            ocrController = new OCRController();
            ocrController.MessageLogSent +=
                new MessageLogSentHandler(OnControllerMessageLogSent);

            ocrController.ProcessFinished +=
                new EventHandler(OnOCRControllerProcessFinished);
            ocrController.NodeBeingProcessed +=
                new NodeBeingProcessedHandler(OnControllerStepDone);

            tokenizingController = new TokenizingController();
            tokenizingController.MessageLogSent +=
                new MessageLogSentHandler(OnControllerMessageLogSent);
            tokenizingController.ProcessFinished +=
                new EventHandler(OnTokenizingControllerProcessFinished);
            tokenizingController.NodeBeingProcessed +=
                new NodeBeingProcessedHandler(OnControllerStepDone);

            parsingController = new ParsingController();
            parsingController.MessageLogSent +=
                new MessageLogSentHandler(OnControllerMessageLogSent);
            parsingController.Matching +=
                new MatchingHandler(OnControllerStepDone);

            parsingController.ProcessFinished +=
                new EventHandler(OnParsingControllerProcessFinished);

            InitializeWidgets();

            tokenizingFinished = false;

            this.ShowAll();
        }
Ejemplo n.º 5
0
        public static void DoWork(GridRow row)
        {
            System.Globalization.CultureInfo before = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture =
                new System.Globalization.CultureInfo("en-US");
            UploadController up_controller = new UploadController();
            FileInfo         fInfo         = new FileInfo(row.Location);

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

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

                if (IsSupportedFormat(fInfo.Name))
                {
                    //Process evtc here
                    ParsedLog log          = control.ParseLog(row, fInfo.FullName);
                    string[]  uploadresult = up_controller.UploadOperation(row, fInfo);
                    //Creating File
                    GenerateFiles(log, row, uploadresult, fInfo);
                }
                else
                {
                    row.BgWorker.UpdateProgress(row, "Not EVTC", 100);
                    throw new InvalidDataException("Not EVTC");
                }
            }
            catch (Exception ex)
            {
                throw new CancellationException(row, ex);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = before;
            }
        }
        public static ParsedLog ParseLog(string location)
        {
            var parser = new ParsingController(new TestParserSettings());

            var operation = new ConsoleOperationController(location as string, "Ready to parse");

            var fInfo = new FileInfo(operation.Location);

            if (!fInfo.Exists)
            {
                throw new FileNotFoundException("File does not exist", fInfo.FullName);
            }
            if (!ProgramHelper.IsSupportedFormat(fInfo.Name))
            {
                throw new InvalidDataException("Not EVTC");
            }

            return(parser.ParseLog(operation, fInfo.FullName));
        }
        /// <summary>
        /// <see cref="ParsingStageWidget"/>'s constructor.
        /// </summary>
        /// <param name="window">
        /// The <see cref="MainRecognizerWindow"/> that contains the widget.
        /// </param>
        public ParsingStageWidget(MainRecognizerWindow window) : base(window)
        {
            Glade.XML gladeXml = new XML("mathtextrecognizer.glade",
                                         "parsingStageBaseWidget");

            gladeXml.Autoconnect(this);

            this.Add(parsingStageBaseWidget);



            InitializeWidgets();

            controller = new ParsingController();
            controller.MessageLogSent +=
                new MessageLogSentHandler(OnControllerMessageLogSent);

            controller.ProcessFinished += OnControllerProcessFinishedHandler;

            controller.Matching +=
                new MatchingHandler(OnControllerMatching);

            controller.MatchingFinished +=
                new MatchingFinishedHandler(OnControllerMatchingFinished);

            controller.StepDone +=
                new EventHandler(OnControllerStepDone);

            controller.TokenMatching +=
                new TokenMatchingHandler(OnControllerTokenMatching);

            controller.TokenMatchingFinished +=
                new TokenMatchingFinishedHandler(OnControllerTokenMatchingFinished);

            controller.RuleSequenceRestored +=
                new SequenceSetHandler(OnControllerSequenceRestored);

            controller.RelatedSequenceSet +=
                new SequenceSetHandler(OnControllerRelatedSequenceSet);


            this.ShowAll();
        }
Ejemplo n.º 8
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;
            }
        }
Ejemplo n.º 9
0
        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;
            }
        }
Ejemplo n.º 10
0
        /// <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;
            }
        }