示例#1
0
        public string output()
        {
            if (result == null)
            {
                result = new REACToutput(true);
            }

            //ensure matches setHeader fields
            outputFields.Add(id);
            outputFields.Add(email);
            outputFields.Add(brand);
            outputFields.Add(result.finding);
            outputFields.Add(result.comment);
            outputFields.Add(result.comment_code);
            outputFields.Add(result.sugg_email);
            outputFields.Add(result.sugg_comment);
            outputFields.Add(domain);
            outputFields.Add(baseDomain);
            outputFields.Add(result.fai_reason);
            outputFields.Add(result.fai_suggestion_source);
            outputFields.Add(result.fai_mx_status);
            outputFields.Add(result.fai_java_mx_error_type);
            outputFields.Add(result.fai_rid);
            outputFields.Add(result.fai_vsn);
            outputFields.Add(result.uuid);
            outputFields.Add(result.fai_servertime);
            outputFields.Add(result.error);
            return(String.Join("\t", outputFields.ToArray()));
        }
示例#2
0
        //async method to parse URL
        public async Task <REACToutput> reactEmail(string e)
        {
            //randomize before calling
            randomizeURL();

            string emailNoEncode = e;   //for logging

            if (e.Trim() == "")
            {
                e = "%20%09";
            }
            else
            {
                e = HttpUtility.UrlEncode(e);
            }
            string URLwEmail = URL + "&email=" + e;


            // Create the HttpClientHandler which will handle cookies.
            var handler = new HttpClientHandler();

            // Set cookies on handler.

            // Await on an async call to fetch here, convert to a data
            // set and return.
            var client = new HttpClient(handler);

            client.Timeout = TimeSpan.FromMilliseconds(1000 * 20);

            //Console.WriteLine(url);

            //capture runtime
            DateTime rStart = DateTime.Now;
            DateTime rEnd   = DateTime.Now;

            //result
            REACToutput rOut = null;

            // Wait for the HttpResponseMessage.
            string content = null;

            try
            {
                //add wait if needed
                double msSinceLastRT = (DateTime.Now - lastRTsend).TotalMilliseconds;
                int    addedWait     = 0;
                int    threadSleep   = calculateSleepMS();
                if (msSinceLastRT < threadSleep)
                {
                    addedWait = threadSleep - (int)msSinceLastRT;
                    Thread.Sleep(addedWait);
                    //DEBUG: Console.WriteLine("Added: " + addedWait + " | sleep calc: " + threadSleep);
                }
                lastRTsend = DateTime.Now;

                rStart = DateTime.Now;
                HttpResponseMessage response = await client.GetAsync(new Uri(URLwEmail));

                // Get the content, await on the string content.
                content = await response.Content.ReadAsStringAsync();

                //capture react end time
                rEnd = DateTime.Now;

                //parse response
                rOut            = JsonConvert.DeserializeObject <REACToutput>(content);
                rOut.REACTend   = rEnd;
                rOut.REACTstart = rStart;
                rOut.runtime    = (rEnd - rStart).TotalMilliseconds;

                if (perfEnabled)
                {
                    //due to batching/async, runtime and end time not being captured correctly, to eventually figure out
                    //ApplicationLog.Log(rOut.fai_servertime + "\t" + rOut.runtime + "\t" + rStart.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\t" + rEnd.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\t" + emailNoEncode + "\t" + URLwEmail);

                    //log sunny server time, added wait for request, # of running threads, start time
                    perfLog.Log(rOut.fai_servertime + "\t" + addedWait + "\t" + runningThreads + "\t" + rStart.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\t" + emailNoEncode + "\t" + URLwEmail);
                }
            }
            catch {
                //log error
                perfLog.Log("Error getting/parsing JSON response from: " + URLwEmail);
                rEnd = DateTime.Now;
            }

            //sleep here if need to pace requests
            //Thread.Sleep(calculateSleepMS());
            //await Task.Delay(calculateSleepMS());

            // Process content variable here into a data set and return.
            return(rOut);
        }