예제 #1
0
        private static string BuildFormBodyText(BaseController controller, WebForm webForm, Page page, bool fieldDataOnly)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            if (webForm == null)
            {
                throw new ArgumentNullException("webForm");
            }
            if (!fieldDataOnly && !controller.ModelState.IsValid)
            {
                throw new ApplicationException("Model State is invalid. Be sure model state is valid before calling BuildFormBodyText");
            }

            StringBuilder textBody = new StringBuilder();

            if (!fieldDataOnly)
            {
                textBody.AppendLine(BuildFormSubject(controller, webForm, page));
            }
            textBody.AppendLine();

            List <WebFormField> fields = webForm.WebFormFields.AsQueryable().WhereIsActive().ApplySortDefault().ToList();

            foreach (WebFormField field in fields)
            {
                string value1 = controller.Request.GetFormFieldValue1String(field);
                string value2 = controller.Request.GetFormFieldValue2String(field);

                if (string.IsNullOrEmpty(value1))
                {
                    value1 = "(blank)";
                }
                else if (field.DataType == GStoreValueDataType.ValueListItemDropdown || field.DataType == GStoreValueDataType.ValueListItemRadio)
                {
                    value1 = field.GetValueListItemName(value1);
                }
                else if (field.DataType == GStoreValueDataType.ValueListItemMultiCheckbox)
                {
                    value1 = field.GetValueListItemNameList(value1);
                }


                textBody.AppendLine(field.Name + " = " + value1 + (string.IsNullOrEmpty(value2) ? string.Empty : ", " + value2) + "\n");
            }
            if (!fieldDataOnly)
            {
                UserProfile             userProfile             = controller.CurrentUserProfileOrNull;
                StoreFrontConfiguration storeFrontConfiguration = controller.CurrentStoreFrontConfigOrThrow;

                textBody.AppendLine();
                textBody.AppendLine("- - - - - - - -");
                //header info
                textBody.AppendLine("User: "******"(anonymous)" : "'" + userProfile.FullName + "' <" + userProfile.Email + ">"));
                textBody.AppendLine("Url: " + controller.Request.Url.ToString());
                textBody.AppendLine("Store Front: " + storeFrontConfiguration.Name + " [" + storeFrontConfiguration.StoreFrontId + "] Url: " + storeFrontConfiguration.PublicUrl);
                textBody.AppendLine("Client: " + storeFrontConfiguration.Client.Name + " [" + storeFrontConfiguration.ClientId + "]");
                textBody.AppendLine("Host: " + controller.Request.Url.Host);
                textBody.AppendLine("Raw Url: " + controller.Request.RawUrl);
                textBody.AppendLine("IP Address: " + controller.Request.UserHostAddress);
                textBody.AppendLine("User Agent: " + controller.Request.UserAgent);
                textBody.AppendLine();

                HttpSessionStateBase session = controller.Session;
                textBody.AppendLine("Session Start Date Time: " + (session.EntryDateTime().HasValue ? session.EntryDateTime().ToString() : "(unknown)"));
                textBody.AppendLine("Session Entry Raw Url: " + (session.EntryRawUrl() ?? "(unknown)"));
                textBody.AppendLine("Session Entry Url: " + (session.EntryUrl() ?? "(unknown)"));
                textBody.AppendLine("Session Referrer: " + (session.EntryReferrer() ?? "(unknown)"));
                textBody.AppendLine();
            }

            return(textBody.ToString());
        }