public Enquiry(HttpContext Context)
        {
            TraceProcessor.Verbose("---------------------------------------------");
            TraceProcessor.Verbose(string.Format("enquiry_type = \"{0}\"", Context.Request["enquiry_type"]));
            enquiry_type = Context.Request["enquiry_type"];

            TraceProcessor.Verbose(string.Format("firstname = \"{0}\"", Context.Request["firstname"]));
            firstname = Context.Request["firstname"];

            TraceProcessor.Verbose(string.Format("lastname = \"{0}\"", Context.Request["lastname"]));
            lastname = Context.Request["lastname"];

            TraceProcessor.Verbose(string.Format("email = \"{0}\"", Context.Request["email"]));
            email = Context.Request["email"];

            TraceProcessor.Verbose(string.Format("visitkey = \"{0}\"", Context.Request["visitkey"]));
            visitkey = Context.Request["visitkey"];

            TraceProcessor.Verbose(string.Format("return_url = \"{0}\"", Context.Request["return_url"]));
            return_url = Context.Request["return_url"];

            TraceProcessor.Verbose(string.Format("hp = \"{0}\"", Context.Request["hp"]));
            hp = Context.Request["hp"];
            TraceProcessor.Verbose("---------------------------------------------");
        }
 /// <summary>
 /// Write out the Trace Level of the application.
 /// </summary>
 private void WriteTraceHeader()
 {
     TraceProcessor.Error(String.Format("========================== START {0} ==========================", DateTime.Now.ToString()));
     TraceProcessor.Error("-------------------------- TraceLevelSwitch - Error Tracing Enabled");
     TraceProcessor.Warning("-------------------------- TraceLevelSwitch - Warning Tracing Enabled");
     TraceProcessor.Information("-------------------------- TraceLevelSwitch - Info Tracing Enabled");
     TraceProcessor.Verbose("-------------------------- TraceLevelSwitch - Verbose Tracing Enabled", true);
 }
        /// <summary>
        /// Post form to Click Dimensions
        /// </summary>
        private string AddClick(Enquiry FormEnquiry)
        {
            if (!FormEnquiry.hp.Equals(String.Empty))
            {
                throw new ApplicationException("Robot check failed.  hp field was not empty.");
            }

            #region Build Form Data Request

            string formCaptureUrl = null;
            string visitorKey     = FormEnquiry.visitkey;
            string postData       = null;

            switch (FormEnquiry.enquiry_type)
            {
            case "CustomForm Form":
                //Form Capture String Generated
                formCaptureUrl = Properties.Settings.Default.CustomForm_FormCaptureURL;
                postData       = String.Format($"{FormEnquiry.ToPostDataString()}");
                break;

            default:
                throw new ApplicationException("Unexpected Enquiry Type.");
            }


            TraceProcessor.Verbose(string.Format("formCaptureUrl = \"{0}\"", formCaptureUrl));
            TraceProcessor.Verbose(string.Format("postData = \"{0}\"", postData));

            #endregion Build Form Data Request

            // Post data to Click Dimensions Server
            string serverResponse = this.PostToServer(formCaptureUrl, postData);

            return(serverResponse);
        }
        public void ProcessRequest(HttpContext context)
        {
            string url = String.Empty;

            this.WriteTraceHeader();

            Enquiry enquiry        = new Enquiry(context);
            string  responsefromfc = String.Empty;

            TraceProcessor.Verbose(string.Format("hp = \"{0}\"", enquiry.hp));

            if (enquiry.hp.Equals(String.Empty))
            {
                try
                {
                    // Post form to Click Dimensions
                    responsefromfc = AddClick(enquiry);
                }
                #region Error Trapping
                catch (ApplicationException ex)
                {
                    //Non fatal error, ignore.
                    TraceProcessor.Warning(string.Format("WARNING: {0}", ex.Message));
                }
                catch (Exception ex)
                {
                    TraceProcessor.Error(string.Format("EXCEPTION: {0}", ex.ToString()));
                    responsefromfc = string.Format("EXCEPTION: {0}", ex.Message);
                }
                #endregion Error Trapping

                TraceProcessor.Information(string.Format("responsefromfc = \"{0}\"", responsefromfc));

                #region Compose redirect URL

                if (responsefromfc.Equals("success") && enquiry.enquiry_type.Equals("CustomForm Form"))
                {
                    url = string.Format("{0}?success=1", enquiry.return_url);
                }
                else if (responsefromfc.Equals("error") && enquiry.enquiry_type.Equals("CustomForm Form"))
                {
                    url = string.Format("{0}?success=0", enquiry.return_url);
                }

                // Default case
                else
                {
                    url = string.Format("{0}?success=0", enquiry.return_url);
                }

                #endregion Compose redirect URL
            }
            else
            {
                // Copmpose redirect URL
                url = string.Format("{0}?success=spam", enquiry.return_url);
            }

            // Redirect.
            TraceProcessor.Information(string.Format("Redirect: {0}", url), true);
            context.Response.Redirect(url);
        }