Example #1
0
        /// <summary>
        /// Parses all log files found, reporting progress to the user.
        /// </summary>
        /// <param name="sender">
        /// the thread used for parsing the logs
        /// </param>
        /// <param name="e">
        /// information on the thread used for parsing the logs
        /// </param>
        private void BackgroundProcessLogs(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = (BackgroundWorker)sender;
            Stream stream;

            try
            {
                foreach (string logFileName in logFiles)
                {
                    // open file stream
                    stream = new FileStream(logFileName, FileMode.Open, FileAccess.Read);

                    if (stream != null)
                    {
                        // parse log
                        List<HostileWorldsLog> hwlogs;

                        try
                        {
                            hwlogs = logParser.ParseLogFromStream(stream);
                        }
                        catch (ArgumentException)
                        {
                            // adding a key (e.g. a player name) to a dictionary twice throws an ArgumentException
                            LogParserError parseError = new LogParserError();

                            parseError.logFileName = logFileName;
                            parseError.errorDescription = "This tool does not support matches with two or more players having the same player name.";

                            // remember the log containing the error...
                            parseErrors.Add(parseError);

                            // ... and parse the next log
                            continue;
                        }

                        matchLogs.AddRange(hwlogs);

                        // count matches
                        foreach (HostileWorldsLog log in hwlogs)
                        {
                            serverMatches++;

                            if (!log.MatchFinished)
                            {
                                unfinishedMatches++;
                            }
                        }

                        // update status progress bar
                        logFilesProcessed++;

                        worker.ReportProgress(logFilesProcessed * 100 / logFiles.Count, logFileName);
                    }
                    else
                    {
                        AppendResult("Unable to open log file " + logFileName + ".");
                    }
                }
            }
            catch (Exception ex)
            {
                ShowErrorDialog(ex.Message);
            }
        }
Example #2
0
        /// <summary>
        /// Parses all log files found, reporting progress to the user.
        /// </summary>
        /// <param name="sender">
        /// the thread used for parsing the logs
        /// </param>
        /// <param name="e">
        /// information on the thread used for parsing the logs
        /// </param>
        private void BackgroundProcessLogs(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = (BackgroundWorker)sender;
            Stream           stream;

            try
            {
                foreach (string logFileName in logFiles)
                {
                    // open file stream
                    stream = new FileStream(logFileName, FileMode.Open, FileAccess.Read);

                    if (stream != null)
                    {
                        // parse log
                        List <HostileWorldsLog> hwlogs;

                        try
                        {
                            hwlogs = logParser.ParseLogFromStream(stream);
                        }
                        catch (ArgumentException)
                        {
                            // adding a key (e.g. a player name) to a dictionary twice throws an ArgumentException
                            LogParserError parseError = new LogParserError();

                            parseError.logFileName      = logFileName;
                            parseError.errorDescription = "This tool does not support matches with two or more players having the same player name.";

                            // remember the log containing the error...
                            parseErrors.Add(parseError);

                            // ... and parse the next log
                            continue;
                        }

                        matchLogs.AddRange(hwlogs);

                        // count matches
                        foreach (HostileWorldsLog log in hwlogs)
                        {
                            serverMatches++;

                            if (!log.MatchFinished)
                            {
                                unfinishedMatches++;
                            }
                        }

                        // update status progress bar
                        logFilesProcessed++;

                        worker.ReportProgress(logFilesProcessed * 100 / logFiles.Count, logFileName);
                    }
                    else
                    {
                        AppendResult("Unable to open log file " + logFileName + ".");
                    }
                }
            }
            catch (Exception ex)
            {
                ShowErrorDialog(ex.Message);
            }
        }