Exemple #1
0
        internal async void ObtainWdtForCurrentServer()
        {
            if (obtainingWdt)
            {
                return;
            }
            obtainingWdt = true;
            // try to get server datetime, if server configured
            try
            {
                while (true)
                {
                    if (!String.IsNullOrEmpty(ServerName))
                    {
                        var server = wurmApi.Servers.GetByName(new ServerName(ServerName));
                        var result = await server.TryGetCurrentTimeAsync();

                        if (result != null)
                        {
                            cachedWDT = result.Value;
                            hasWdt    = true;
                            break;
                        }
                    }

                    await Task.Delay(TimeSpan.FromSeconds(5));
                }
            }
            catch (Exception exception)
            {
                logger.Error(exception, "Error for server name: " + (ServerName ?? "NULL"));
            }
            finally
            {
                obtainingWdt = false;
            }
        }
        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();
            }
        }