예제 #1
0
        /// <summary>
        /// This method invokes a check on a thread from the thread pool.
        /// </summary>
        /// <param name="threadContext">State object specified by the caller to QueueUserWorkItem.</param>
        private void ThreadPoolCallback(Object threadContext)
        {
            try
            {
                // Ensure the thread state is of the correct type
                if (!(threadContext is WatcherCheckState))
                {
                    Trace.TraceError("Error: State passed to Watcher check is not of the proper type.");
                    return;
                }

                WatcherCheckState threadState = (WatcherCheckState)threadContext;

                // Invoke the check
                //Stopwatch sw = new Stopwatch();
                //sw.Start();
                //threadState.parser.Open(threadState.session);
                threadState.check.Check(threadState.session);
                // Must close the parser when done.
                // Stop the stopwatch and print the elapsed time for the check to complete (and the threads to be handled).
                //sw.Stop(); if (sw.ElapsedMilliseconds > 0)
                //{
                //    Debug.Print("[*] Timing:{0}:{1}:{2}", threadState.check.GetShortName(), sw.ElapsedMilliseconds, threadState.session.url);
                //}
            }

            catch (Exception e)
            {
                Trace.TraceWarning("Warning: Watcher check threw an unhandled exception: {0}", e.Message);
                ExceptionLogger.HandleException(e);
            }
        }
예제 #2
0
        /// <summary>
        /// This method invokes all enabled checks against the given session.
        /// </summary>
        /// <param name="oSession">Instance of the Fiddler session to examine.</param>
        public void RunEnabledChecks(Session oSession)
        {
            // Ignore proxy requests
            if ((oSession.oRequest.headers.HTTPMethod.Equals("CONNECT")))
            {
                Trace.TraceInformation("Ignoring proxy request on session ID {0}.", oSession.id);
                return;
            }

            Trace.TraceInformation("Running checks on session ID {0}.", oSession.id);
            lock (_lock)
            {
                WatcherCheckState state = new WatcherCheckState();
                state.session = oSession;
                //state.parser = new UtilityHtmlParser();

                // Enumerate the available checks
                foreach (WatcherCheck check in Checks)
                {
                    // Skip disabled checks
                    if (check.Enabled == false)
                    {
                        Trace.TraceInformation("Skipping disabled check \"{0}\".", check.GetName());
                        continue;
                    }

                    // ... and run the enabled ones
                    state.check = check;
                    ThreadPool.QueueUserWorkItem(ThreadPoolCallback, state);
                }
            }
        }