Example #1
0
 private void addMessageIfNotNull(Control control, string s)
 {
     if (s != null)
     {
         control.AddControlsReturnThis("The value posted from this box was '{0}'".FormatWith(s).GetLiteralControl());
     }
 }
Example #2
0
        // Web Forms compatibility. Remove when EnduraCode goal 790 is complete.
        private static IReadOnlyCollection <Control> addEtherealControls(Control parent, EtherealComponentOrElement component)
        {
            var element = component as ElementNode;

            if (element != null)
            {
                EwfPage.Instance.AddEtherealControl(parent, element);
                return(((EtherealControl)element).Control.ToCollection());
            }

            var etherealComponent = component as EtherealComponent;

            if (etherealComponent != null)
            {
                return(etherealComponent.GetChildren().AddEtherealControls(parent));
            }

            var     identifiedComponent = (IdentifiedEtherealComponent)component;
            var     componentData       = identifiedComponent.ComponentDataGetter();
            Control ph = null;

            ph = new PlaceholderControl(
                () => {
                foreach (var linker in componentData.UpdateRegionLinkers)
                {
                    EwfPage.Instance.AddUpdateRegionLinker(
                        new LegacyUpdateRegionLinker(
                            ph,
                            linker.KeySuffix,
                            linker.PreModificationRegions.Select(
                                region =>
                                new LegacyPreModificationUpdateRegion(
                                    region.Sets,
                                    () => region.ComponentGetter().SelectMany(i => EwfPage.Instance.ControlsByComponent[i]),
                                    region.ArgumentGetter)),
                            arg => linker.PostModificationRegionGetter(arg).SelectMany(i => EwfPage.Instance.ControlsByComponent[i])));
                }

                var validationIndex = 0;
                var errorDictionary = new Dictionary <EwfValidation, IReadOnlyCollection <string> >();
                foreach (var i in componentData.Validations)
                {
                    errorDictionary.Add(i, EwfPage.Instance.AddModificationErrorDisplayAndGetErrors(ph, validationIndex.ToString(), i).ToImmutableArray());
                    validationIndex += 1;
                }

                var children = componentData.ChildGetter(new ModificationErrorDictionary(errorDictionary.ToImmutableDictionary()));
                if (componentData.Id == null)
                {
                    children.AddEtherealControls(ph);
                    return(ImmutableArray <Control> .Empty);
                }
                var np = new NamingPlaceholder(ImmutableArray <Control> .Empty);
                if (componentData.Id.Any())
                {
                    np.ID = componentData.Id + "np";
                }
                children.AddEtherealControls(np);
                return(np.ToCollection());
            });
            if (!string.IsNullOrEmpty(componentData.Id))
            {
                ph.ID = componentData.Id;
            }
            parent.AddControlsReturnThis(ph);
            return(ph.ToCollection());
        }
        // Web Forms compatibility. Remove when EnduraCode goal 790 is complete.
        private static IReadOnlyCollection <Control> addEtherealControls(Control parent, EtherealComponentOrElement component)
        {
            if (component is ElementNode element)
            {
                EwfPage.Instance.AddEtherealControl(parent, element);
                return(((EtherealControl)element).Control.ToCollection());
            }

            if (component is EtherealComponent etherealComponent)
            {
                var controls = etherealComponent.GetChildren().AddEtherealControls(parent);
                if (component is EtherealAutofocusRegion autofocusRegion)
                {
                    foreach (var i in controls)
                    {
                        if (!EwfPage.Instance.AutofocusConditionsByControl.TryGetValue(i, out var conditions))
                        {
                            conditions = new List <AutofocusCondition>();
                            EwfPage.Instance.AutofocusConditionsByControl.Add(i, conditions);
                        }
                        conditions.Add(autofocusRegion.Condition);
                    }
                }
                return(controls);
            }

            var     identifiedComponent = (IdentifiedEtherealComponent)component;
            var     componentData       = identifiedComponent.ComponentDataGetter();
            Control ph = null;

            ph = new PlaceholderControl(
                () => {
                foreach (var linker in componentData.UpdateRegionLinkers)
                {
                    EwfPage.Instance.AddUpdateRegionLinker(
                        new LegacyUpdateRegionLinker(
                            ph,
                            linker.KeySuffix,
                            linker.PreModificationRegions.Select(
                                region => new LegacyPreModificationUpdateRegion(
                                    region.Sets,
                                    () => region.ComponentGetter().SelectMany(i => EwfPage.Instance.ControlsByComponent[i]),
                                    region.ArgumentGetter)),
                            arg => linker.PostModificationRegionGetter(arg).SelectMany(i => EwfPage.Instance.ControlsByComponent[i])));
                }

                var validationIndex = 0;
                var errorDictionary = new Dictionary <EwfValidation, IReadOnlyCollection <string> >();
                foreach (var i in componentData.ErrorSources.Validations)
                {
                    var errors = EwfPage.Instance.AddModificationErrorDisplayAndGetErrors(ph, validationIndex.ToString(), i).ToImmutableArray();
                    errorDictionary.Add(i, errors);
                    if (errors.Any())
                    {
                        EwfPage.Instance.ValidationsWithErrors.Add(i);
                    }
                    validationIndex += 1;
                }

                var children = componentData.ChildGetter(
                    new ModificationErrorDictionary(
                        errorDictionary.ToImmutableDictionary(),
                        componentData.ErrorSources.IncludeGeneralErrors
                                                                ? AppRequestState.Instance.EwfPageRequestState.GeneralModificationErrors
                                                                : ImmutableArray <TrustedHtmlString> .Empty));
                if (componentData.Id == null)
                {
                    children.AddEtherealControls(ph);
                    return(ImmutableArray <Control> .Empty);
                }
                var np = new NamingPlaceholder(ImmutableArray <Control> .Empty);
                if (componentData.Id.Any())
                {
                    np.ID = componentData.Id + "np";
                }
                children.AddEtherealControls(np);
                return(np.ToCollection());
            });
            if (!string.IsNullOrEmpty(componentData.Id))
            {
                ph.ID = componentData.Id;
            }
            parent.AddControlsReturnThis(ph);
            return(ph.ToCollection());
        }