Пример #1
0
        public async Task <IList <LogEntry> > ScanAsync(LogSearchParameters logSearchParameters,
                                                        CancellationToken cancellationToken)
        {
            var result = await runner.Run(logSearchParameters, cancellationToken).ConfigureAwait(false);

            return(result.LogEntries);
        }
Пример #2
0
        public async Task DoAsync()
        {
            var c = wurmApi.Characters.All.ChooseRandom();

            var args = new LogSearchParameters()
            {
                CharacterName = chars.ChooseRandom(),
                MinDate       = new DateTime(2014, 1, 1),
                MaxDate       = new DateTime(2016, 1, 1),
                LogType       = wurmApi.LogDefinitions.AllLogTypes.ChooseRandom()
            };

            var t1 = wurmApi.LogsHistory.ScanAsync(args);

            var t2 = c.Logs.ScanLogsServerGroupRestrictedAsync(new DateTime(2014, 1, 1),
                                                               new DateTime(2016, 1, 1),
                                                               wurmApi.LogDefinitions.AllLogTypes.ChooseRandom(),
                                                               wurmApi.ServerGroups.AllKnown.ChooseRandom());

            var t3 = c.Skills.TryGetCurrentSkillLevelAsync(skills.ChooseRandom(),
                                                           wurmApi.ServerGroups.AllKnown.ChooseRandom(),
                                                           TimeSpan.FromDays(365));

            var r1 = await t1;
            var r2 = await t2;
            var r3 = await t3;

            textBox.Text += "Scan complete, result count: " + r1.Count + "\r\n";
            textBox.Text += "SG-Scan complete, result count: " + r2.Count + "\r\n";
            textBox.Text += "Skill-Scan complete, skill: " + r3?.NameNormalized + " result: " + r3?.Value + "\r\n";
        }
Пример #3
0
 public LogsScanner(
     [NotNull] LogSearchParameters logSearchParameters, 
     [NotNull] JobCancellationManager cancellationManager,
     [NotNull] IWurmLogFiles wurmLogFiles,
     [NotNull] MonthlyLogFilesHeuristics monthlyHeuristics,
     [NotNull] LogFileStreamReaderFactory streamReaderFactory,
     [NotNull] ILogger logger,
     [NotNull] LogFileParserFactory logFileParserFactory, 
     [NotNull] IWurmApiConfig wurmApiConfig)
 {
     if (logSearchParameters == null) throw new ArgumentNullException("logSearchParameters");
     if (cancellationManager == null) throw new ArgumentNullException("cancellationManager");
     if (wurmLogFiles == null) throw new ArgumentNullException("wurmLogFiles");
     if (monthlyHeuristics == null) throw new ArgumentNullException("monthlyHeuristics");
     if (streamReaderFactory == null) throw new ArgumentNullException("streamReaderFactory");
     if (logger == null) throw new ArgumentNullException("logger");
     if (logFileParserFactory == null) throw new ArgumentNullException("logFileParserFactory");
     if (wurmApiConfig == null) throw new ArgumentNullException("wurmApiConfig");
     this.logSearchParameters = logSearchParameters;
     this.cancellationManager = cancellationManager;
     this.wurmLogFiles = wurmLogFiles;
     this.monthlyHeuristics = monthlyHeuristics;
     this.streamReaderFactory = streamReaderFactory;
     this.logger = logger;
     this.logFileParserFactory = logFileParserFactory;
     this.wurmApiConfig = wurmApiConfig;
 }
Пример #4
0
        async Task <IEnumerable <LogEntry> > Search([NotNull] LogSearchParameters searchParams,
                                                    CancellationToken cancellationToken)
        {
            if (searchParams == null)
            {
                throw new ArgumentNullException("searchParams");
            }
            var result = await wurmApi.LogsHistory.ScanAsync(searchParams, cancellationToken);

            return(result);
        }
Пример #5
0
 /// <summary>
 /// Extracts all lines matching scan parameters.
 /// </summary>
 /// <returns></returns>
 public LogsScanner Create(LogSearchParameters logSearchParameters, JobCancellationManager cancellationManager)
 {
     return new LogsScanner(
         logSearchParameters,
         cancellationManager,
         wurmLogFiles,
         heuristics,
         streamReaderFactory,
         logger,
         logFileParserFactory,
         wurmApiConfig);
 }
Пример #6
0
 /// <summary>
 /// Extracts all lines matching scan parameters.
 /// </summary>
 /// <returns></returns>
 public LogsScanner Create(LogSearchParameters logSearchParameters, JobCancellationManager cancellationManager)
 {
     return(new LogsScanner(
                logSearchParameters,
                cancellationManager,
                wurmLogFiles,
                heuristics,
                streamReaderFactory,
                logger,
                logFileParserFactory,
                wurmApiConfig));
 }
Пример #7
0
 public LogsScanner(
     [NotNull] LogSearchParameters logSearchParameters,
     [NotNull] JobCancellationManager cancellationManager,
     [NotNull] IWurmLogFiles wurmLogFiles,
     [NotNull] MonthlyLogFilesHeuristics monthlyHeuristics,
     [NotNull] LogFileStreamReaderFactory streamReaderFactory,
     [NotNull] IWurmApiLogger logger,
     [NotNull] LogFileParserFactory logFileParserFactory,
     [NotNull] IWurmApiConfig wurmApiConfig)
 {
     if (logSearchParameters == null)
     {
         throw new ArgumentNullException(nameof(logSearchParameters));
     }
     if (cancellationManager == null)
     {
         throw new ArgumentNullException(nameof(cancellationManager));
     }
     if (wurmLogFiles == null)
     {
         throw new ArgumentNullException(nameof(wurmLogFiles));
     }
     if (monthlyHeuristics == null)
     {
         throw new ArgumentNullException(nameof(monthlyHeuristics));
     }
     if (streamReaderFactory == null)
     {
         throw new ArgumentNullException(nameof(streamReaderFactory));
     }
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     if (logFileParserFactory == null)
     {
         throw new ArgumentNullException(nameof(logFileParserFactory));
     }
     if (wurmApiConfig == null)
     {
         throw new ArgumentNullException(nameof(wurmApiConfig));
     }
     this.logSearchParameters = logSearchParameters;
     this.cancellationManager = cancellationManager;
     this.wurmLogFiles        = wurmLogFiles;
     this.monthlyHeuristics   = monthlyHeuristics;
     this.streamReaderFactory = streamReaderFactory;
     this.logger = logger;
     this.logFileParserFactory = logFileParserFactory;
     this.wurmApiConfig        = wurmApiConfig;
 }
Пример #8
0
 static IEnumerable <LogEntry> FilterResults(IEnumerable <LogEntry> result, LogSearchParameters searchParams)
 {
     if (searchParams.LogType == LogType.Pm)
     {
         if (!string.IsNullOrEmpty(searchParams.PmRecipientName))
         {
             result =
                 result.Where(
                     s =>
                     s.PmConversationRecipient.Normalized.Equals(
                         searchParams.PmRecipientName.ToUpperInvariant())).ToArray();
         }
     }
     return(result);
 }
        public LogSearchEventsParser(LogSearchParameters logSearchParameters, IWurmApi wurmApi, ILogger logger)
        {
            if (logSearchParameters == null)
            {
                throw new ArgumentNullException("logSearchParameters");
            }
            if (wurmApi == null)
            {
                throw new ArgumentNullException("wurmApi");
            }
            this.logSearchParameters = logSearchParameters;
            this.wurmApi             = wurmApi;

            CombatStatus = new CombatStatus(logSearchParameters.CharacterName);
            processor    = new CombatResultsProcessor(CombatStatus, logger, wurmApi);
        }
Пример #10
0
        public List <LogItem> GetLogs(LogSearchParameters lsp)
        {
            SetSqlFormat("select * from {0}", SynnDataProvider.TableNames.Log);
            ClearParameters();
            if (!string.IsNullOrEmpty(lsp.Text))
            {
                StartORGroup();
                AddORLikeField("Trace", lsp.Text, LikeSelectionStyle.CheckBoth);
                AddORLikeField("Message", lsp.Text, LikeSelectionStyle.CheckBoth);
                EndORGroup();
            }
            if (lsp.FromDate.HasValue)
            {
                AddSqlWhereField("Date", lsp.FromDate, ">=");
            }
            if (lsp.ToDate.HasValue)
            {
                AddSqlWhereField("Date", lsp.ToDate, "<");
            }
            var lst = new List <LogItem>();

            FillList(lst, typeof(LogItem));
            return(lst);
        }
Пример #11
0
 public IList<LogEntry> Scan(LogSearchParameters logSearchParameters, CancellationToken cancellationToken)
 {
     return TaskHelper.UnwrapSingularAggegateException(() => ScanAsync(logSearchParameters, cancellationToken).Result);
 }
Пример #12
0
 public async Task<IList<LogEntry>> ScanAsync(LogSearchParameters logSearchParameters,
     CancellationToken cancellationToken)
 {
     var result = await runner.Run(logSearchParameters, cancellationToken).ConfigureAwait(false);
     return result.LogEntries;
 }
Пример #13
0
 public IList <LogEntry> Scan(LogSearchParameters logSearchParameters, CancellationToken cancellationToken)
 {
     return(TaskHelper.UnwrapSingularAggegateException(() => ScanAsync(logSearchParameters, cancellationToken).Result));
 }
Пример #14
0
 string Convert(LogSearchParameters args)
 {
     return($"{args.CharacterName}, {args.LogType}");
 }
Пример #15
0
        async void PerformSearch()
        {
            LogSearchParameters searchParams = null;

            try
            {
                if (searching)
                {
                    throw new InvalidOperationException("Search already running");
                }
                searching = true;

                cancellationTokenSource = new CancellationTokenSource();

                buttonCancelSearch.Visible = true;

                richTextBoxAllLines.Clear();
                listBoxAllResults.Items.Clear();

                dateTimePickerTimeFrom.Value = new DateTime(
                    dateTimePickerTimeFrom.Value.Year,
                    dateTimePickerTimeFrom.Value.Month,
                    dateTimePickerTimeFrom.Value.Day,
                    0,
                    0,
                    0);
                dateTimePickerTimeTo.Value = new DateTime(
                    dateTimePickerTimeTo.Value.Year,
                    dateTimePickerTimeTo.Value.Month,
                    dateTimePickerTimeTo.Value.Day,
                    23,
                    59,
                    59);

                var pmCharacter = GetPmCharacter();

                searchParams = new LogSearchParameters()
                {
                    LogType         = GetLogType(),
                    CharacterName   = GetCharacter(),
                    MinDate         = dateTimePickerTimeFrom.Value,
                    MaxDate         = dateTimePickerTimeTo.Value,
                    PmRecipientName = pmCharacter
                };

                var searchType   = GetSearchType();
                var searchPhrase = GetPhrase();

                var result = await Search(searchParams, cancellationTokenSource.Token);

                ParseAndDisplay(result, searchType, searchPhrase, searchParams);
            }
            catch (OperationCanceledException exception)
            {
                // cancelled
                logger.Info(exception, "Search cancelled.");
            }
            catch (Exception exception)
            {
                logger.Error(exception, "Search error, params: " + (searchParams != null ? searchParams.ToString() : "NULL"));
                MessageBox.Show(exception.ToString());
            }
            finally
            {
                searching = false;
                labelWorking.Hide();
                buttonCancelSearch.Visible  = false;
                listBoxAllResults.Visible   = true;
                richTextBoxAllLines.Visible = true;
                buttonCommitSearch.Text     = "Search";
                richTextBoxAllLines.Select(0, 0);
                richTextBoxAllLines.ScrollToCaret();
            }
        }
Пример #16
0
        void ParseAndDisplay(IEnumerable <LogEntry> result, SearchTypeId searchTypeId, string searchPhrase, LogSearchParameters searchParams)
        {
            List <SingleSearchMatch> matches = new List <SingleSearchMatch>();

            result = FilterResults(result, searchParams);

            List <string> results = new List <string>();
            int           currentLineBeginIndex = 0;
            var           pattern = searchTypeId == SearchTypeId.RegexEscapedCaseIns
                ? ("(?i)" + Regex.Escape(searchPhrase))
                : searchPhrase;

            foreach (var logEntry in result)
            {
                // restoring entry as string, so legacy code can be used without major rewrite
                var line = RestoreLogEntry(logEntry);
                results.Add(line);

                if (!string.IsNullOrWhiteSpace(searchPhrase))
                {
                    MatchCollection matchcollection = Regex.Matches(line, pattern);
                    foreach (Match match in matchcollection)
                    {
                        long matchStart  = currentLineBeginIndex + match.Index;
                        long matchLength = match.Length;

                        matches.Add(new SingleSearchMatch(matchStart, matchLength, BuildDateForMatch(line)));
                    }
                }
                currentLineBeginIndex += line.Length + 1; // richtextbox seems to always add 1-length eol ??
            }

            lastMatches = matches;

            buttonCommitSearch.Text = "Loading results...";

            labelAllResults.Text = "All results: " + matches.Count;

            richTextBoxAllLines.Visible = false;
            listBoxAllResults.Visible   = false;
            labelWorking.Show();
            this.Refresh();

            richTextBoxAllLines.Clear();
            listBoxAllResults.Items.Clear();
            richTextBoxAllLines.Lines = results.ToArray();
            if (matches.Any())
            {
                bool tooManyToProcess   = false;
                bool tooManyToHighlight = false;
                if (matches.Count > 20000)
                {
                    tooManyToProcess = true;
                }
                if (matches.Count > 5000)
                {
                    tooManyToHighlight = true;
                }
                if (!tooManyToProcess)
                {
                    foreach (var searchmatch in matches)
                    {
                        string matchDesc = "";
                        matchDesc += searchmatch.MatchDate;
                        if (!tooManyToHighlight)
                        {
                            richTextBoxAllLines.Select((int)searchmatch.BeginCharPos, (int)searchmatch.LenghtChars);
                            richTextBoxAllLines.SelectionBackColor = Color.LightBlue;
                        }
                        listBoxAllResults.Items.Add(matchDesc);
                        Application.DoEvents();
                    }
                }
                else
                {
                    listBoxAllResults.Items.Add("too many matches");
                    listBoxAllResults.Items.Add("narrow the search");
                }
            }
        }