Inheritance: System.EventArgs
Esempio n. 1
0
 public void PushMessage(IntelEventArgs message)
 {
     if (messages.Count > maxMessages) {
         messages.Dequeue();
     }
     messages.Enqueue(new MessageData {
         Message = message
     });
     this.Invalidate();
 }
Esempio n. 2
0
 /// <summary>
 ///     Sent by <see cref="IntelReporter"/> every time it parses a
 ///     new log entry.
 /// </summary>
 private void intelReporter_IntelReported(object sender, IntelEventArgs e)
 {
     messageView.PushMessage(e);
     if (e.Message.IndexOf("Dabigredboat", StringComparison.OrdinalIgnoreCase) != -1) {
         ++this.noveltyCount;
         this.UpdateStatus();
     }
 }
Esempio n. 3
0
 /// <summary>
 ///     Event handler for <see cref="IntelChannelContainer.IntelReported"/>.
 /// </summary>
 private void channels_IntelReported(object sender, IntelEventArgs e)
 {
     Contract.Requires(e != null);
     this.OnIntelReported(e);
 }
Esempio n. 4
0
 /// <summary>
 ///     Raises the <see cref="IntelReported"/> event.
 /// </summary>
 protected internal virtual void OnIntelReported(IntelEventArgs e)
 {
     Contract.Requires<ArgumentNullException>(e != null, "e");
     // Raise the event (as appropriate)
     this.lastIntel = DateTime.UtcNow;
     var handler = this.IntelReported;
     if (handler != null) {
         var sync = this.synchronizingObject;
         WaitCallback callback = (state) => handler(this, e);
         if ((sync != null) && sync.InvokeRequired) {
             sync.BeginInvoke(callback, new object[] { null });
         } else {
             ThreadPool.QueueUserWorkItem(callback);
         }
     }
     // Report the intel
     try {
         lock (this.syncRoot) {
             // Race condition avoidance
             if (!this.IsRunning) {
                 return;
             }
             // Report as necessary
             var session = this.GetSession(true);
             if (session.Report(e)) {
                 this.Status = IntelStatus.Active;
                 ++this.IntelSent;
                 this.OnPropertyChanged("IntelSent");
             } else {
                 ++this.IntelDropped;
                 this.OnPropertyChanged("IntelDropped");
             }
         }
     } catch (WebException) {
         this.Status = IntelStatus.NetworkError;
         ++this.IntelDropped;
         this.OnPropertyChanged("IntelDropped");
     } catch (AuthenticationException) {
         this.Status = IntelStatus.AuthenticationError;
         ++this.IntelDropped;
         this.OnPropertyChanged("IntelDropped");
     }
 }
Esempio n. 5
0
 /// <summary>Sends a log entry to the intel reporting server.</summary>
 /// <param name="e">An instance of <see cref="IntelEventArgs" />
 /// containing the information to report.</param>
 /// <returns>
 /// <see langword="true" /> if our session is still valid;
 /// otherwise, <see langword="false" />.
 /// </returns>
 public bool Report(IntelEventArgs e)
 {
     Contract.Requires<ArgumentNullException>(e != null, "e");
     return this.Report(e.Channel, e.Timestamp, e.Message);
 }
        /// <summary>Raises the <see cref="IntelReported" /> event.</summary>
        /// <param name="e">Arguments of the event being raised.</param>
        /// <remarks>
        /// <see cref="OnIntelReported" /> makes no changes to the internal
        /// object state and can be safely called at any time.  If the
        /// logic within <see cref="CreateChannel" /> is replaced, the
        /// <see cref="IntelChannel.IntelReported" /> event needs to be
        /// forwarded to <see cref="OnIntelReported" />.
        /// </remarks>
        protected virtual void OnIntelReported(IntelEventArgs e)
        {
            Contract.Requires<ArgumentNullException>(e != null, "e");

            Interlocked.Increment(ref this.uploadCount);
            this.OnPropertyChanged("IntelCount");

            var handler = this.IntelReported;
            if (handler != null) {
                handler(this, e);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Called every couple of seconds to sweep the log file for
        /// new entries.
        /// </summary>
        /// <remarks>
        /// <see cref="OnTick" /> will be called from within a synchronized
        /// context so derived classes should not attempt to perform any
        /// additional synchronization themselves.
        /// </remarks>
        protected virtual void OnTick()
        {
            if (this.watcher == null) {
                // Try (again) to create the watcher object
                try {
                    this.watcher = this.CreateFileSystemWatcher();
                    this.Status = IntelStatus.Waiting;
                    this.ScanFiles();
                } catch (ArgumentException) {
                    // Still doesn't seem to exist
                }
            }

            if (this.reader != null) {
                // Read new log entries from the current log
                try {
                    string line;
                    while ((line = reader.ReadLine()) != null) {
                        Trace.WriteLine("R " + line, IntelExtensions.WebTraceCategory);
                        var match = Parser.Match(line);
                        if (match.Success && !match.Groups[7].Value.StartsWith(MotdPrefix)) {
                            var e = new IntelEventArgs(
                                this.Name,
                                new DateTime(
                                    match.Groups[1].ToInt32(),
                                    match.Groups[2].ToInt32(),
                                    match.Groups[3].ToInt32(),
                                    match.Groups[4].ToInt32(),
                                    match.Groups[5].ToInt32(),
                                    match.Groups[6].ToInt32(),
                                    DateTimeKind.Utc),
                                match.Groups[7].Value);
                            this.OnIntelReported(e);
                        }
                    }
                } catch (IOException) {
                    this.CloseFile();
                }

                // Close the log if it has been idle for too long
                if (this.lastEntry + this.expireLog < DateTime.UtcNow) {
                    this.CloseFile();
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Raises the <see cref="IntelReported" /> event.
        /// </summary>
        /// <param name="e">Arguments for the event being raised.</param>
        /// <remarks>
        /// <see cref="OnIntelReported" /> will be called from within
        /// a synchronized context so derived classes should not attempt to
        /// perform any additional synchronization themselves.
        /// </remarks>
        protected internal void OnIntelReported(IntelEventArgs e)
        {
            Contract.Requires<ArgumentNullException>(e != null, "e");

            ThreadPool.QueueUserWorkItem(delegate(object state) {
                Contract.Requires(state is IntelEventArgs);
                var handler = this.IntelReported;
                if (handler != null) {
                    handler(this, (IntelEventArgs)state);
                }
            }, e);

            this.lastEntry = DateTime.UtcNow;
            ++this.IntelCount;
            this.OnPropertyChanged("IntelCount");
        }