Example #1
0
        // Private methods.
        /// <summary>
        /// An event handler called when the calendar range has changed.
        /// </summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">The event arguments.</param>
        private void OnCalendarDateChanged(object sender, DateRangeEventArgs e)
        {
            // Show a waiting message.
            this.ShowMessage(Resources.LogClock_48, "Log", "Reading log files...", true);
            this.listView.Enabled = false;
            this.toolStrip.Enabled = false;
            this.listView.Items.Clear();
            this.controlLogEvent.Event = null;

            // Clear the list of events.
            this.events = null;

            // Create a new update state.
            ControlLogUpdateState state = new ControlLogUpdateState(e);

            // If a current update is in progress, cancel the update state.
            if (null != this.state)
                this.state.Cancel();

            // Update the global state.
            this.state = state;

            // Update the log information asynchronously on a system thread pool.
            ThreadPool.QueueUserWorkItem(new WaitCallback(this.BeginUpdateLog), state);
        }
Example #2
0
        /// <summary>
        /// Completes an asynchronous request to update the log. The request is completed
        /// on the UI thread.
        /// </summary>
        /// <param name="argument">The update state.</param>
        private void EndUpdateLog(object argument)
        {
            // Execute the code on the UI thread.
            this.Invoke(() =>
                {
                    ControlLogUpdateState state = argument as ControlLogUpdateState;

                    // If the state is not canceled.
                    if (!state.IsCanceled)
                    {
                        // Complete the update.
                        state.Complete();
                        // Set the global state to null.
                        this.state = null;
                        // Hide the waiting message.
                        this.HideMessage();
                        this.listView.Enabled = true;
                        this.toolStrip.Enabled = true;

                        // Set the list of events.
                        this.events = state.Events;

                        // Update the log list.
                        if (this.events != null)
                        {
                            // Add the events.
                            foreach (LogEvent evt in this.events)
                            {
                                // Create a list view item for each event.
                                ListViewItem item = new ListViewItem(
                                    new string[] { evt.Timestamp.ToString(), evt.Source, evt.Message },
                                    (int)evt.Type
                                    );
                                item.Tag = evt;
                                item.IndentCount = evt.Indent;
                                evt.Tag = item;

                                // Check whether this item should be in the log.
                                if ((this.listTypes[(int)evt.Type].State != CheckState.Checked) ||
                                    (this.listLevels[(int)evt.Level].State != CheckState.Checked))
                                    continue;

                                // Add the event item to the list.
                                this.listView.Items.Add(item);
                            }
                        }
                    }
                });
        }