コード例 #1
0
        async Task Initialize()
        {
            try
            {
                LogSearchData lgs = new LogSearchData();
                lgs.SetSearchCriteria(
                    PlayerName,
                    GameLogTypes.Event,
                    DateTime.Now - TimeSpan.FromDays(5),
                    DateTime.Now,
                    "",
                    SearchTypes.RegexEscapedCaseIns);

                lgs = await WurmLogSearcherAPI.SearchWurmLogsAsync(lgs);

                foreach (string line in lgs.AllLines)
                {
                    ProcessLogLine(line, false);
                }
 
                ServerGroupEstablished = true;
            }
            catch (Exception _e)
            {
                Logger.LogError("Something went wrong when trying to establish server group for player: " + PlayerName, this, _e);
            }
        }
コード例 #2
0
ファイル: Searcher_Test.cs プロジェクト: webba/WurmAssistant2
 async Task GetSearchResults()
 {
     LogSearchData searchdata = new LogSearchData();
     searchdata.SetSearchCriteria(
         "Aldur",
         GameLogTypes.Alliance,
         DateTime.Now - TimeSpan.FromDays(2),
         DateTime.Now,
         "",
         SearchTypes.RegexEscapedCaseIns);
     LogSearchData results = await WurmLogSearcherAPI.SearchWurmLogsAsync(searchdata);
     textBox2.Lines = results.AllLines.ToArray();
 }
コード例 #3
0
        private async Task PerformAsyncInits(DateTime lastCheckup)
        {
            try
            {
                TimeSpan timeToCheck = DateTime.Now - lastCheckup;
                if (timeToCheck > TimeSpan.FromDays(120)) timeToCheck = TimeSpan.FromDays(120);
                if (timeToCheck < TimeSpan.FromDays(7)) timeToCheck = TimeSpan.FromDays(7);

                LogSearchData lgs = new LogSearchData();
                lgs.SetSearchCriteria(
                    Player,
                    GameLogTypes.Event,
                    DateTime.Now - timeToCheck,
                    DateTime.Now,
                    "",
                    SearchTypes.RegexEscapedCaseIns);

                lgs = await WurmLogSearcherAPI.SearchWurmLogsAsync(lgs);

                ServerInfo.ServerGroup mostRecentGroup = ServerInfo.ServerGroup.Unknown;
                string mostRecentServerName = null;

                foreach (string line in lgs.AllLines)
                {
                    if (line.Contains("You are on"))
                    {
                        string serverName;
                        ServerInfo.ServerGroup group = WurmLogSearcherAPI.GetServerGroupFromLine(line, out serverName);
                        if (group != ServerInfo.ServerGroup.Unknown)
                        {
                            if (!String.IsNullOrEmpty(serverName)) Settings.Value.GroupToServerMap[group] = serverName;
                            mostRecentServerName = serverName;
                            mostRecentGroup = group;
                        }
                    }
                }

                if (mostRecentGroup != ServerInfo.ServerGroup.Unknown && !currentServerGroupFound)
                {
                    CurrentServerGroup = mostRecentGroup;
                    if (mostRecentServerName != null) Settings.Value.CurrentServerName = mostRecentServerName;
                    currentServerGroupFound = true;
                    Settings.Value.LastServerGroupCheckup = DateTime.Now;
                }

                //init timers here!
                InitTimers(Settings.Value.ActiveTimers);

                LayoutControl.EnableAddingTimers();
                Settings.DelayedSave();
            }
            catch (Exception _e)
            {
                Logger.LogError("problem updating current server group", this, _e);
            }
        }
コード例 #4
0
            private void SearchLogs()
            {
                DateTime searchFrom = LastLogSearch;
                if (DateTime.Now - searchFrom > TimeSpan.FromDays(60))
                {
                    searchFrom = DateTime.Now - TimeSpan.FromDays(60);
                }
                else if (DateTime.Now - searchFrom < TimeSpan.FromDays(2))
                {
                    searchFrom = DateTime.Now - TimeSpan.FromDays(2);
                }

                var lgs = new LogSearchData
                {
                    SearchCriteria = new LogSearchData.SearchData(
                        _playerName,
                        GameLogTypes.Event,
                        searchFrom,
                        DateTime.Now,
                        "",
                        SearchTypes.RegexEscapedCaseIns)
                };

                var task = WurmLogSearcherAPI.SearchWurmLogsAsync(lgs);
                task.Wait();
                lgs = task.Result;

                //parse results
                string lastServerName = null;
                foreach (var line in lgs.AllLines)
                {
                    var result = PlayerServerTracker.MatchServerFromLogLine(line);
                    if (result != null)
                    {
                        lastServerName = result;

                        string useless;
                        var sg = WurmLogSearcherAPI.GetServerGroupFromLine(line, out useless);
                        if (sg != WurmServer.ServerInfo.ServerGroup.Unknown)
                        {
                            DateTime thisLineStamp;
                            if (WurmLogSearcherAPI.TryParseDateTimeFromSearchResultLine(line, out thisLineStamp))
                            {
                                ServerGroupsManager.Update(sg, thisLineStamp, result);
                            }
                            else Logger.LogError("Could not process timestamp from line? "+thisLineStamp);
                        }
                        else Logger.LogError("Unknown server? "+line, this);
                    }
                }

                // checking if real-time log events didn't set this field already
                if (!ServerEstablished)
                {
                    if (lastServerName != null) _serverName = lastServerName;
                    ServerEstablished = true;
                }

                LastLogSearch = DateTime.Now;

                NeedSaving = true;

                LogSearchFinished = true;
                ServerEstablished = true;
            }
コード例 #5
0
        /// <summary>
        /// Performs search through Wurm logs with the supplied search data.
        /// Returns null if search fails, reason is logged.
        /// </summary>
        /// <param name="logsearchdata">requires search criteria, 
        /// sending object without it will result in exception</param>
        /// <exception cref="ArgumentNullException">supplied LogSearchData had no search criteria</exception>
        /// <exception cref="InvalidOperationException">LogSearcher was not initialized</exception>
        /// <returns></returns>
        public static async Task<LogSearchData> SearchWurmLogsAsync(LogSearchData logsearchdata)
        {
            if (!isInitialized) ThrowInitException();

            Logger.LogDebug("Enqueuing custom search", THIS);
            return await LogSearchMan.PerformSearchAsync(logsearchdata);
        }
コード例 #6
0
        /// <summary>
        /// Create a lookup table, that knows which server group player was on at given time point.
        /// </summary>
        /// <param name="playerName"></param>
        /// <param name="daysToLookBack">from DateTime.Now</param>
        /// <returns></returns>
        private static async Task<ServerGroupTimeTable> CreateSGTimeTable(string playerName, int daysToLookBack)
        {
            LogSearchData logsearchdata = new LogSearchData();
            logsearchdata.SearchCriteria = new LogSearchData.SearchData(
                playerName,
                GameLogTypes.Event,
                DateTime.Now - TimeSpan.FromDays(daysToLookBack),
                DateTime.Now,
                "",
                SearchTypes.RegexEscapedCaseIns);
            logsearchdata = await SearchWurmLogsAsync(logsearchdata);

            DateTime startDT = DateTime.Now - TimeSpan.FromDays(daysToLookBack);
            startDT = new DateTime(startDT.Year, startDT.Month, startDT.Day, 0, 0, 0);

            ServerGroupTimeTable timetable = new ServerGroupTimeTable(ServerInfo.ServerGroup.Unknown, startDT);

            foreach (var line in logsearchdata.AllLines)
            {
                if (line.Contains("You are on"))
                {
                    string server;
                    ServerInfo.ServerGroup group = GetServerGroupFromLine(line, out server);
                    if (group != ServerInfo.ServerGroup.Unknown)
                        timetable.Register(group, LogSearchManager.BuildDateForMatch(line));
                }
            }
            return timetable;
        }
コード例 #7
0
 static string FormatSearchParams(LogSearchData logsearchdata2)
 {
     if (logsearchdata2.SearchCriteria == null)
     {
         return "No search criteria";
     }
     return string.Format("Player: {2}, Log: {0}, Key: {1}, From: {3}, To: {4}",
         logsearchdata2.SearchCriteria.GameLogType, logsearchdata2.SearchCriteria.SearchKey,
         logsearchdata2.SearchCriteria.Player, logsearchdata2.SearchCriteria.TimeFrom,
         logsearchdata2.SearchCriteria.TimeTo);
 }
コード例 #8
0
        //could not use async lambda in Task<T> for some reason
        private static async Task<Dictionary<ServerInfo.ServerGroup, float>> GetSkillsForPlayer_LambdaBugWorkaround(
            string playerName, int daysToLookBack, string skillName)
        {
            try
            {
                // build time table to identify, to which server group each skill gain belongs
                // TODO move this to method

                ServerGroupTimeTable timetable = await CreateSGTimeTable(playerName, daysToLookBack);

                // get most recent skill for each server group

                LogSearchData logsearchdata2 = new LogSearchData();
                logsearchdata2.SearchCriteria = new LogSearchData.SearchData(
                    playerName,
                    GameLogTypes.Skills,
                    DateTime.Now - TimeSpan.FromDays(daysToLookBack),
                    DateTime.Now,
                    "",
                    SearchTypes.RegexEscapedCaseIns);
                logsearchdata2 = await SearchWurmLogsAsync(logsearchdata2);

                Dictionary<ServerInfo.ServerGroup, float> results = new Dictionary<ServerInfo.ServerGroup, float>();

                string SKILL_INCREASED = skillName + " increased";
                string SKILL_DECREASED = skillName + " decreased";

                Guid searchId = Guid.NewGuid();

                // disabled, due to crashing WA on occasion, cause unknown
                //Logger.LogInfo(string.Format("Starting parsing results for {2} skill search: {0} Logging Handle: {1}",
                //    FormatSearchParams(logsearchdata2), searchId, skillName));

                foreach (var line in logsearchdata2.AllLines)
                {
                    if (line.Contains(SKILL_INCREASED) || line.Contains(SKILL_DECREASED))
                    {
                        float skill = WurmHelper.ExtractSkillLEVELFromLine(line);
                        ServerInfo.ServerGroup group = timetable.GetGroupForDate(LogSearchManager.BuildDateForMatch(line));

                        // disabled, due to crashing WA on occasion, cause unknown
                        //Logger.LogInfo(string.Format("Logging handle: [{0}]; Matched line: [{1}] to server group: [{2}]", searchId, line, group));
                        
                        if (skill > 0)
                        {
                            results[group] = skill;
                        }
                        else
                        {
                            Logger.LogError("extracted " + skillName + " skill was 0", THIS);
                        }
                    }
                }

                return results;
            }
            catch (Exception _e)
            {
                Logger.LogCritical("problem with GetSkillsForPlayer::implementation", THIS, _e);
                return null;
            }
        }
コード例 #9
0
        /// <summary>
        /// Performs search through Wurm logs with the supplied search data. 
        /// Results are filtered by server group and log entries from other groups are discarded.
        /// Returns null if search fails, reason is logged.
        /// </summary>
        /// <param name="logsearchdata">requires search criteria, 
        /// sending object without it will result in exception</param>
        /// <exception cref="ArgumentNullException">supplied LogSearchData had no search criteria</exception>
        /// <exception cref="InvalidOperationException">LogSearcher was not initialized</exception>
        /// <param name="group">Server group type</param>
        /// <returns></returns>
        public static async Task<LogSearchData> SearchWurmLogsFilteredByServerGroupAsync(LogSearchData logsearchdata, ServerInfo.ServerGroup group)
        {
            // for other logs than event, there is no "You are on", 
            // this needs a secondary mirror search through events,
            // build cache of contraits to verify if line should be discarded
            // FIXED


            // TODO create proper cache?

            ServerGroupTimeTable timetable = null;
            if (logsearchdata.SearchCriteria.GameLogType != GameLogTypes.Event)
            {
                string playername = logsearchdata.SearchCriteria.Player;
                int daysToLookBack = (int)(DateTime.Now - logsearchdata.SearchCriteria.TimeFrom).TotalDays + 1;
                timetable = await CreateSGTimeTable(playername, daysToLookBack);
            }

            logsearchdata = await SearchWurmLogsAsync(logsearchdata);

            object[] args = new object[2] { logsearchdata, timetable };

            Task<LogSearchData> task = new Task<LogSearchData>(x =>
                {
                    try
                    {
                        var lgs = (LogSearchData)args[0];
                        var ttable = args[1] == null ? null : (ServerGroupTimeTable)args[1];
                        List<string> newResults = new List<string>();
                        bool validServerGroup = false;
                        foreach (string line in lgs.AllLines)
                        {
                            //check if valid server group
                            if (lgs.SearchCriteria.GameLogType == GameLogTypes.Event && line.Contains("You are on"))
                            {
                                string server;
                                ServerInfo.ServerGroup extractedGroup = GetServerGroupFromLine(line, out server);
                                if (extractedGroup == group) validServerGroup = true;
                                else validServerGroup = false;
                            }
                            else if (lgs.SearchCriteria.GameLogType != GameLogTypes.Event)
                            {
                                ServerInfo.ServerGroup extractedGroup = ttable.GetGroupForDate(LogSearchManager.BuildDateForMatch(line));
                                if (extractedGroup == group) validServerGroup = true;
                                else validServerGroup = false;
                            }
                            if (validServerGroup)
                            {
                                newResults.Add(line);
                            }
                        }
                        lgs.AllLines = newResults;
                        return lgs;
                    }
                    catch (Exception _e)
                    {
                        Logger.LogCritical("problem while performing group-filtered log search", THIS, _e);
                        return null;
                    }
                }, args);
            task.Start();

            return await task;
        }
コード例 #10
0
ファイル: WurmTimer.cs プロジェクト: webba/WurmAssistant2
        /// <summary>
        /// returns null on error, filters out other server groups,
        /// min/max search date is unbound using this overload
        /// </summary>
        /// <param name="logType"></param>
        /// <param name="since">amount of time to look back, will accept any value</param>
        /// <returns></returns>
        protected async Task<List<string>> GetLogLinesFromLogHistoryAsync(GameLogTypes logType, TimeSpan since)
        {
            LogSearchData lgs = new LogSearchData();
            lgs.SetSearchCriteria(
                Player,
                logType,
                DateTime.Now - since,
                DateTime.Now,
                "",
                SearchTypes.RegexEscapedCaseIns);

            lgs = await WurmLogSearcherAPI.SearchWurmLogsFilteredByServerGroupAsync(lgs, TargetServerGroup);

            return lgs.AllLines;
        }
コード例 #11
0
        internal Task<LogSearchData> PerformSearchAsync(LogSearchData logSearchData)
        {
            if (logSearchData.SearchCriteria == null)
            {
                throw new ArgumentNullException("SearchCriteria", "Search task cannot run without search criteria");
            }

            Task<LogSearchData> searchTask = new Task<LogSearchData>(x =>
                {
                    Logger.LogDebug("Search started", THIS);
                    try
                    {
                        // unbox the container
                        LogSearchData work_logSearchData = (LogSearchData)x;
                        // get the correct log searcher based on player
                        LogFileSearcherV2 logsearcher;
                        if (SearchersDict.TryGetValue(work_logSearchData.SearchCriteria.Player, out logsearcher))
                        {
                            //get the searcher to provide a string list of all required entries
                            //send the container to get results, then retrieve the container
                            work_logSearchData = logsearcher.GetFilteredSearchList(
                                work_logSearchData.SearchCriteria.GameLogType,
                                work_logSearchData.SearchCriteria.TimeFrom,
                                work_logSearchData.SearchCriteria.TimeTo,
                                work_logSearchData);
                        }
                        //callback and return search results in a thread safe way
                        if (work_logSearchData.CallerControl != null)
                        {
                            if (work_logSearchData.CallerControl.GetType() == typeof(FormLogSearcher))
                            {
                                FormLogSearcher ui = (FormLogSearcher)work_logSearchData.CallerControl;
                                work_logSearchData.AllLinesArray = work_logSearchData.AllLines.ToArray();
                                try
                                {
                                    Logger.LogDebug("Dispatching search results to Searcher UI", THIS);
                                    ui.BeginInvoke(new FormLogSearcher.DisplaySearchResultsCallback(ui.DisplaySearchResults), new object[] { logSearchData });
                                }
                                catch (Exception _e)
                                {
                                    Logger.LogError("!!! LogSearcher: error while trying to invoke FormLogSearcher, TrdStart_PerformSearch", THIS, _e);
                                }
                                Logger.LogDebug("Search completed", THIS);
                                return work_logSearchData;
                            }
                            else
                            {
                                Logger.LogDebug("Search completed", THIS);
                                return work_logSearchData;
                            }
                        }
                        else
                        {
                            Logger.LogDebug("Search completed", THIS);
                            return work_logSearchData;
                        }
                    }
                    catch (Exception _e)
                    {
                        Logger.LogDebug("Search completed", THIS);
                        Logger.LogCritical("!!! LogSearcher: Unexpected exception at TrdStart_PerformSearch", THIS, _e);
                        LogSearchData work_logSearchData = (LogSearchData)x;
                        if (work_logSearchData.CallerControl != null)
                        {
                            if (work_logSearchData.CallerControl.GetType() == typeof(FormLogSearcher))
                            {
                                try
                                {
                                    FormLogSearcher ui = (FormLogSearcher)work_logSearchData.CallerControl;
                                    work_logSearchData.AllLinesArray = work_logSearchData.AllLines.ToArray();
                                    Logger.LogDebug("Dispatching empty search results to Searcher UI", THIS);
                                    ui.BeginInvoke(new FormLogSearcher.DisplaySearchResultsCallback(ui.DisplaySearchResults), new object[] { logSearchData });
                                }
                                catch (Exception _ee)
                                {
                                    Logger.LogError("!!! LogSearcher: error while trying to invoke FormLogSearcher, TrdStart_PerformSearch", THIS, _ee);
                                }
                            }
                        }
                        return null;
                    }
                }, (object)logSearchData);
            EnqueueNewSearchTask(searchTask);
            return searchTask;
        }
コード例 #12
0
 internal void DoSearch(LogSearchData logsearchdata)
 {
     LogSearchMan.PerformSearchAsync(logsearchdata);
     ScheduledLogSearchData = logsearchdata;
     UpdateUIAboutScheduledSearch(SearchStatus.Searching);
     isSearchScheduled = false;
 }
コード例 #13
0
        internal void DisplaySearchResults(LogSearchData logSearchData)
        {
            buttonCommitSearch.Text = "Loading results...";
            this.Refresh();
            if (!logSearchData.StopSearching)
            {
                labelAllResults.Text = "All results: " + logSearchData.SearchResults.Count;

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

                richTextBoxAllLines.Clear();
                listBoxAllResults.Items.Clear();
                richTextBoxAllLines.Lines = logSearchData.AllLinesArray;
                bool tooManyToProcess = false;
                bool tooManyToHighlight = false;
                if (logSearchData.SearchResults.Count > 20000) tooManyToProcess = true;
                if (logSearchData.SearchResults.Count > 5000) tooManyToHighlight = true;
                if (!tooManyToProcess)
                {
                    foreach (LogSearchData.SingleSearchMatch searchmatch in logSearchData.SearchResults)
                    {
                        if (!logSearchData.StopSearching) //&& !ParentModule.isAppClosing) //avoid app exit exceptions due to Application.DoEvents
                        {
                            string matchDesc = "";
                            matchDesc += searchmatch.MatchDate;
                            if (!tooManyToHighlight)
                            {
                                richTextBoxAllLines.Select((int)searchmatch.Begin, (int)searchmatch.Length);
                                richTextBoxAllLines.SelectionBackColor = Color.LightBlue;
                            }
                            listBoxAllResults.Items.Add(matchDesc);
                            try { Application.DoEvents(); } //improve interface responsiveness and allow cancelling
                            catch { Debug.WriteLine("ERROR in appclosing workaround"); }
                        }
                    }
                }
                else
                {
                    listBoxAllResults.Items.Add("too many matches");
                    listBoxAllResults.Items.Add("narrow the search");
                }

                //if (!ParentModule.isAppClosing) //avoid app exit exceptions due to Application.DoEvents
                {
                    try
                    {
                        labelWorking.Hide();
                        buttonCancelSearch.Visible = false;
                        listBoxAllResults.Visible = true;
                        richTextBoxAllLines.Visible = true;
                        richTextBoxAllLines.Select(0, 0);
                        richTextBoxAllLines.ScrollToCaret();
                    }
                    catch { Debug.WriteLine("ERROR in appclosing workaround"); }
                }
            }
            //if (!ParentModule.isAppClosing) //avoid app exit exceptions due to Application.DoEvents
            {
                try
                {
                    buttonCommitSearch.Text = "Search";
                    buttonCommitSearch.Enabled = true;
                }
                catch { Debug.WriteLine("ERROR in appclosing workaround"); }
            }
        }
コード例 #14
0
 void PerformSearch()
 {
     try
     {
         // create new search data container
         LogSearchData logSearchData = new LogSearchData();
         HandleToCurrentLogSearchData = logSearchData;
         // enable cancel button
         buttonCancelSearch.Visible = true;
         // clear old results
         richTextBoxAllLines.Clear();
         listBoxAllResults.Items.Clear();
         // write container with return address
         logSearchData.CallerControl = this;
         // adjust timeto if necessary (monitor)
         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);
         Debug.WriteLine("Search begin");
         Debug.WriteLine("from " + dateTimePickerTimeFrom.Value + " to " + dateTimePickerTimeTo.Value);
         // drop all search criteria into the container
         logSearchData.SetSearchCriteria(
             comboBoxPlayerName.Text,
             GameLogTypesEX.GetLogTypeForName(comboBoxLogType.Text),
             dateTimePickerTimeFrom.Value,
             dateTimePickerTimeTo.Value,
             textBoxSearchKey.Text,
             SearchTypesEX.GetSearchTypeForName(comboBoxSearchType.Text)
             );
         // add pm player if applies
         if (comboBoxLogType.Text == GameLogTypesEX.GetNameForLogType(GameLogTypes.PM))
         {
             logSearchData.SetPM_Player(textBoxPM.Text);
         }
         // pass the container further
         DoSearch(logSearchData);
     }
     catch (Exception _e)
     {
         MessageBox.Show("Error while starting search, this is a bug please report!");
         Logger.LogError("LogSearcher: Error while performing search", this, _e);
     }
 }