public void InitializeViewState()
 {
     foreach (IUiControl tab in this.UiControls)
     {
         IWebUiControl WebUiChild = tab as IWebUiControl;
         WebUiChild.InitializeViewState();
     }
 }
Beispiel #2
0
        /// <exclude />
        protected override void OnInit(System.EventArgs e)
        {
            base.OnInit(e);

            if (!this.IsPostBack)
            {
                _webUiControl.InitializeViewState();
                return;
            }
        }
        /// <exclude />
        public static FormTreeCompiler AttachAndCompileParameterWidgets(Control attachmentControl, IEnumerable <ParameterProfile> parameterProfiles, Dictionary <string, object> bindings, string uniqueName, string panelLabel, IFormChannelIdentifier channelIdentifier, bool reset)
        {
            FormTreeCompiler compiler     = FunctionUiHelper.BuildWidgetForParameters(parameterProfiles, bindings, uniqueName, panelLabel, channelIdentifier);
            IWebUiControl    webUiControl = (IWebUiControl)compiler.UiControl;
            Control          form         = webUiControl.BuildWebControl();

            attachmentControl.Controls.Add(form);

            if (reset)
            {
                webUiControl.InitializeViewState();
            }

            return(compiler);
        }
        public override void BindStateToControlProperties()
        {
            int childIndex = 0;

            foreach (IUiControl childControl in this.UiControls)
            {
                if (ControlIsActive(childIndex))
                {
                    childControl.BindStateToControlProperties();
                }
                else
                {
                    IWebUiControl childWebUIControl = (childControl as IWebUiControl);
                    Verify.IsNotNull(childWebUIControl, "Child control has to inherit '{0}' interface", typeof(IWebUiControl).FullName);

                    childWebUIControl.InitializeViewState();
                }

                childIndex++;
            }
        }
        public override void InitializeLazyBindedControls()
        {
            int childIndex = 0;

            foreach (IUiControl childControl in this.UiControls)
            {
                if (ControlIsActive(childIndex))
                {
                    if (childControl is TemplatedContainerUiControl)
                    {
                        (childControl as TemplatedContainerUiControl).InitializeLazyBindedControls();
                    }
                }
                else
                {
                    IWebUiControl childWebUIControl = (childControl as IWebUiControl);
                    Verify.IsNotNull(childWebUIControl, "Child control has to inherit '{0}' interface", typeof(IWebUiControl).FullName);

                    childWebUIControl.InitializeViewState();
                }

                childIndex++;
            }
        }
        public static void InsertForm(Control control, ParameterList parameters)
        {
            Page currentPageHandler = HttpContext.Current.Handler as Page;


            if (currentPageHandler == null)
            {
                throw new InvalidOperationException("The Current HttpContext Handler must be a System.Web.Ui.Page");
            }

            Type dataType = null;
            DataTypeDescriptor dataTypeDescriptor = null;

            string dataTypeName = parameters.GetParameter <string>("DataType");

            dataType           = TypeManager.GetType(dataTypeName);
            dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(dataType);

            IFormChannelIdentifier channelIdentifier = FormsRendererChannel.Identifier;

            formHelper = new DataTypeDescriptorFormsHelper(dataTypeDescriptor);

            newData = DataFacade.BuildNew(dataType);
            GeneratedTypesHelper.SetNewIdFieldValue(newData);

            //Hide not editable fields, fox example - PageId
            GeneratedTypesHelper generatedTypesHelper = new GeneratedTypesHelper(dataTypeDescriptor);

            formHelper.AddReadOnlyFields(generatedTypesHelper.NotEditableDataFieldDescriptorNames);


            //If is Page Datatype
            if (PageFolderFacade.GetAllFolderTypes().Contains(dataType))
            {
                IPage currentPage = PageRenderer.CurrentPage;

                if (currentPage.GetDefinedFolderTypes().Contains(dataType) == false)
                {
                    currentPage.AddFolderDefinition(dataType.GetImmutableTypeId());
                }
                PageFolderFacade.AssignFolderDataSpecificValues(newData, currentPage);
            }

            _compiler = new FormTreeCompiler();

            //bindings = formHelper.GetBindings(newData);
            bindings = new Dictionary <string, object>();
            formHelper.UpdateWithNewBindings(bindings);
            formHelper.ObjectToBindings(newData, bindings);


            using (XmlReader reader = XDocument.Parse(formHelper.GetForm()).CreateReader())
            {
                try
                {
                    _compiler.Compile(reader, channelIdentifier, bindings, formHelper.GetBindingsValidationRules(newData));

                    #region ClientValidationRules
                    clientValidationRules = new Dictionary <string, List <ClientValidationRule> >();
                    foreach (var item in _compiler.GetField <object>("_context").GetProperty <IEnumerable>("Rebindings"))
                    {
                        var SourceProducer = item.GetProperty <object>("SourceProducer");
                        var uiControl      = SourceProducer as IWebUiControl;
                        if (uiControl != null)
                        {
                            clientValidationRules[uiControl.UiControlID] = uiControl.ClientValidationRules;
                        }
                    }
                    #endregion
                }
                catch (ConfigurationErrorsException e)
                {
                    if (e.Message.Contains("Failed to load the configuration for IUiControlFactory"))
                    {
                        throw new ConfigurationErrorsException("Composite.Forms.Renderer does not support widget. " + e.Message);
                    }
                    else
                    {
                        throw new ConfigurationErrorsException(e.Message);
                    }
                }
            }
            webUiControl = (IWebUiControl)_compiler.UiControl;

            Control form = webUiControl.BuildWebControl();
            control.Controls.Add(form);

            /*if (currentPageHandler.IsPostBack)
             *  try
             *  {
             *      compiler.SaveControlProperties();
             *  }
             *  catch { }*/

            if (!currentPageHandler.IsPostBack)
            {
                webUiControl.InitializeViewState();
            }



            return;
        }
        public static bool SubmitForm(ParameterList parameters, string captchaText)
        {
            try
            {
                _compiler.SaveControlProperties();
            }
            catch (Exception)
            { }
            webUiControl.InitializeViewState();

            Dictionary <string, string> errorMessages = formHelper.BindingsToObject(bindings, newData);

            DataTypeDescriptor dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(newData.DataSourceId.InterfaceType);

            foreach (var property in newData.DataSourceId.InterfaceType.GetProperties())
            {
                if (property.PropertyType == typeof(string) && (string)property.GetValue(newData, null) == string.Empty)
                {
                    property.SetValue(newData, null, null);
                }
            }


            ValidationResults validationResults = ValidationFacade.Validate(newData.DataSourceId.InterfaceType, newData);

            var isValid    = true;
            var useCaptcha = parameters.GetParameter <bool>("UseCaptcha");

            if (useCaptcha)
            {
                var Session = HttpContext.Current.Session;
                if (Session["FormsRendererCaptcha"] == null || !Captcha.IsValid(captchaText, Session["FormsRendererCaptcha"].ToString()))
                {
                    ErrorSummary.AddError(StringResourceSystemFacade.GetString("Composite.Forms.Renderer", "Composite.Forms.Captcha.CaptchaText.error"));
                    isValid = false;
                }
            }

            if (validationResults.IsValid == false)
            {
                isValid = false;

                Dictionary <string, string> errorSummary = new Dictionary <string, string>();

                foreach (ValidationResult result in validationResults)
                {
                    var label = result.Key;
                    var help  = result.Message;

                    try
                    {
                        label = dataTypeDescriptor.Fields[result.Key].FormRenderingProfile.Label;

                        help = dataTypeDescriptor.Fields[result.Key].FormRenderingProfile.HelpText;

                        //if no HelpText specified - use standard C1 error
                        if (help == string.Empty)
                        {
                            help = result.Message;
                        }

                        string error = GetLocalized(label) + ": " + GetLocalized(help);

                        if (!errorSummary.ContainsValue(error))
                        {
                            errorSummary.Add(errorSummary.Count().ToString(), error);
                        }
                    }
                    catch { }
                }

                // add errors to ErrorSummary
                foreach (var dict in errorSummary)
                {
                    ErrorSummary.AddError(dict.Value);
                }
            }
            //TODO: Looks like rudimentary code related to old C1 errros with binding?
            if (errorMessages != null)
            {
                isValid = false;
                foreach (var kvp in errorMessages)
                {
                    var label = kvp.Key;
                    try
                    {
                        label = dataTypeDescriptor.Fields[kvp.Key].FormRenderingProfile.Label;
                    }
                    catch { }
                    ErrorSummary.AddError(GetLocalized(label) + ": " + GetLocalized(kvp.Value));
                }
            }

            if (isValid)
            {
                using (new DataScope(DataScopeIdentifier.Administrated))
                {
                    IPublishControlled publishControlled = newData as IPublishControlled;
                    if (publishControlled != null)
                    {
                        publishControlled.PublicationStatus = GenericPublishProcessController.Draft;
                    }
                    DataFacade.AddNew(newData);

                    using (var datascope = new FormsRendererDataScope(newData))
                    {
                        var formEmailHeaders = parameters.GetParameter("Email") as IEnumerable <FormEmail>;

                        if (formEmailHeaders != null)
                        {
                            foreach (var formEmail in formEmailHeaders)
                            {
                                ParameterFacade.ResolveProperties(formEmail);
                                var inputXml = GetXElement(newData);
                                var body     = new XhtmlDocument();

                                body.AppendDocument(formEmail.Body);

                                if (formEmail.AppendFormData)
                                {
                                    var formData     = new XDocument();
                                    var xslTransform = new XslCompiledTransform();

                                    xslTransform.LoadFromPath(FormsRendererLocalPath + "Xslt/MailBody.xslt");

                                    using (var writer = formData.CreateWriter())
                                    {
                                        xslTransform.Transform(inputXml.CreateReader(), writer);
                                    }

                                    body.AppendDocument(formData);
                                }

                                Reflection.CallStaticMethod <object>("Composite.Core.WebClient.Renderings.Page.PageRenderer", "NormalizeXhtmlDocument", body);

                                var mailMessage = new MailMessage();
                                try
                                {
                                    mailMessage.From = new MailAddress(formEmail.From);
                                }
                                catch (Exception e)
                                {
                                    LoggingService.LogError(string.Format("Mail sending(From: '{0}')", formEmail.From), e.Message);
                                    continue;
                                }
                                try
                                {
                                    mailMessage.To.Add(formEmail.To);
                                }
                                catch (Exception e)
                                {
                                    LoggingService.LogError(string.Format("Mail sending(To: '{0}')", formEmail.To), e.Message);
                                    continue;
                                }
                                if (!string.IsNullOrEmpty(formEmail.Cc))
                                {
                                    try
                                    {
                                        mailMessage.CC.Add(formEmail.Cc);
                                    }
                                    catch (Exception e)
                                    {
                                        LoggingService.LogError(string.Format("Mail sending(Cc: '{0}')", formEmail.Cc), e.Message);
                                    }
                                }

                                try
                                {
                                    mailMessage.Subject    = formEmail.Subject;
                                    mailMessage.IsBodyHtml = true;
                                    mailMessage.Body       = body.ToString();

                                    new SmtpClient().Send(mailMessage);
                                }
                                catch (Exception e)
                                {
                                    throw new InvalidOperationException("Unable to send mail. Please ensure that web.config has correct /configuration/system.net/mailSettings: " + e.Message);
                                }
                            }
                        }
                    }
                }
            }
            return(isValid);
        }
Beispiel #8
0
 public void InitializeViewState()
 {
     _form.InitializeViewState();
 }