Esempio n. 1
0
        private static FieldControl CreateFieldControlByHint(string hint)
        {
            FieldControl control = null;

            var designator = hint.Split(new char[] { ':' });

            if (designator.Count() != 2)
            {
                Logger.WriteWarning(Logger.EventId.NotDefined, string.Concat("Malformed field control hint: ", hint, ", falling back to default."));
                return(null);
            }

            var namespaces = from TagPrefixInfo tag in TagPrefixInfos
                             where tag.TagPrefix.Equals(designator[0], StringComparison.InvariantCultureIgnoreCase)
                             select tag.Namespace;

            var types = namespaces.Select(ns => TypeHandler.GetType(string.Concat(ns, ".", designator[1]))).Where(t => t != null);

            if (types.Count() > 0)
            {
                control = (FieldControl)Activator.CreateInstance(types.First());
            }

            if (control == null)
            {
                Logger.WriteWarning(Logger.EventId.NotDefined, string.Concat("Failed to instantiate field control by hint: ", hint, ", falling back to default."));
            }

            return(control);
        }
Esempio n. 2
0
        private static FieldControl CreateDefaultDateTimeControl(DateTimeFieldSetting dateTimeFieldSetting)
        {
            Type         controlType = null;
            FieldControl control     = null;

            controlType = typeof(DatePicker);
            control     = (FieldControl)Activator.CreateInstance(controlType);

            return(control);
        }
Esempio n. 3
0
        public static FieldControl CreateDefaultFieldControl(Field field)
        {
            FieldControl control = null;

            var    choiceSetting        = field.FieldSetting as ChoiceFieldSetting;
            var    longTextSetting      = field.FieldSetting as LongTextFieldSetting;
            var    dateTimeFieldSetting = field.FieldSetting as DateTimeFieldSetting;
            string hint = field.FieldSetting.ControlHint;

            if (!string.IsNullOrEmpty(hint))
            {
                control = CreateFieldControlByHint(hint);
            }
            //choice field?
            else if (choiceSetting != null)
            {
                control = CreateDefaultChoiceControl(choiceSetting);
            }
            //longtext field?
            else if (longTextSetting != null)
            {
                control = CreateDefaultLongTextControl(longTextSetting);
            }
            //datetime field?
            else if (dateTimeFieldSetting != null)
            {
                control = CreateDefaultDateTimeControl(dateTimeFieldSetting);
            }

            //generic way, also a fallback logic if we don't have a field control by now
            if (control == null)
            {
                Type controlType = null;

                if (!ControlTable.TryGetValue(field.FieldSetting.ShortName, out controlType))
                {
                    throw new ApplicationException(String.Concat("Cannot resolve the generic field control by '", field.GetType().FullName, "'"));
                }

                control = (FieldControl)Activator.CreateInstance(controlType);
            }

            if (control == null)
            {
                throw new ApplicationException(string.Concat("Failed to instantiate a field control for field ", field.Name));
            }

            control.FieldName = field.Name;
            control.DoAutoConfigure(field.FieldSetting);

            return(control);
        }
Esempio n. 4
0
        private static FieldControl CreateDefaultLongTextControl(LongTextFieldSetting longTextSetting)
        {
            Type         controlType = null;
            FieldControl control     = null;

            if (longTextSetting != null)
            {
                if (longTextSetting.ControlHint == "control:ChoiceOptionEditor")
                {
                    controlType = typeof(ChoiceOptionEditor);
                }
                if (longTextSetting.ControlHint == "control:SurveyRuleEditor")
                {
                    controlType = typeof(SurveyRuleEditor);
                }
                else
                {
                    switch (longTextSetting.TextType)
                    {
                    case TextType.RichText:
                        controlType = typeof(RichText);
                        break;

                    case TextType.AdvancedRichText:
                        controlType = typeof(RichText);
                        break;

                    default:
                        controlType = typeof(LongText);
                        break;
                    }
                }

                control = (FieldControl)Activator.CreateInstance(controlType);
            }

            return(control);
        }