// Web Forms compatibility. Remove when EnduraCode goal 790 is complete.
        private static IReadOnlyCollection <Control> getControls(FlowComponentOrNode component)
        {
            if (component is Control control)
            {
                return(control.ToCollection());
            }

            if (component is FlowComponent flowComponent)
            {
                var controls = flowComponent.GetChildren().GetControls().ToImmutableArray();
                if (component is FlowAutofocusRegion 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 = (IdentifiedFlowComponent)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))
                               .GetControls();
                if (componentData.Id == null)
                {
                    return(children);
                }
                return(new NamingPlaceholder(children)
                {
                    ID = "{0}np".FormatWith(ph.UniqueID.Separate("$", false).Last())
                }.ToCollection());
            });
            if (!string.IsNullOrEmpty(componentData.Id))
            {
                ph.ID = componentData.Id;
            }
            return(ph.ToCollection());
        }
Ejemplo n.º 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());
        }