Exemplo n.º 1
0
        public static ObjectProperty GetCustProps(Object obj, PropertyInfo prop)
        {
            ObjectProperty objprop = new ObjectProperty {
                Name                     = prop.Name,
                DefValue                 = obj.GetType().GetProperty(prop.Name).GetValue(obj, null),
                PropertyType             = prop.PropertyType,
                CanRead                  = prop.CanRead,
                CanWrite                 = prop.CanWrite,
                Props                    = prop,
                CompanionSourceFieldName = String.Empty,
                FieldMode                = (prop.PropertyType == typeof(bool)) ?
                                           WidgetAttribute.FieldMode.CheckBox : WidgetAttribute.FieldMode.TextBox
            };

            try {
                foreach (Attribute attr in objprop.Props.GetCustomAttributes(true))
                {
                    if (attr is WidgetAttribute)
                    {
                        var widgetAttrib = attr as WidgetAttribute;
                        if (null != widgetAttrib)
                        {
                            try { objprop.CompanionSourceFieldName = widgetAttrib.SelectFieldSource; } catch { objprop.CompanionSourceFieldName = ""; }
                            try { objprop.FieldMode = widgetAttrib.Mode; } catch { objprop.FieldMode = WidgetAttribute.FieldMode.Unknown; }
                        }
                    }
                }
            } catch (Exception ex) { }

            objprop.FieldDescription = ReflectionUtilities.GetDescriptionAttribute(obj.GetType(), objprop.Name);

            return(objprop);
        }
Exemplo n.º 2
0
		public static ObjectProperty GetCustProps(Object obj, PropertyInfo prop) {
			ObjectProperty objprop = new ObjectProperty {
				Name = prop.Name,
				DefValue = obj.GetType().GetProperty(prop.Name).GetValue(obj, null),
				PropertyType = prop.PropertyType,
				CanRead = prop.CanRead,
				CanWrite = prop.CanWrite,
				Props = prop,
				CompanionSourceFieldName = String.Empty,
				FieldMode = (prop.PropertyType == typeof(bool)) ?
						WidgetAttribute.FieldMode.CheckBox : WidgetAttribute.FieldMode.TextBox
			};
			try {
				foreach (Attribute attr in objprop.Props.GetCustomAttributes(true)) {
					if (attr is WidgetAttribute) {
						var widgetAttrib = attr as WidgetAttribute;
						if (null != widgetAttrib) {
							try { objprop.CompanionSourceFieldName = widgetAttrib.SelectFieldSource; } catch { objprop.CompanionSourceFieldName = ""; }
							try { objprop.FieldMode = widgetAttrib.Mode; } catch { objprop.FieldMode = WidgetAttribute.FieldMode.Unknown; }
						}
					}
				}
			} catch (Exception ex) { }

			objprop.FieldDescription = ReflectionUtilities.GetDescriptionAttribute(obj.GetType(), objprop.Name);

			return objprop;
		}
Exemplo n.º 3
0
 public override bool Equals(Object obj)
 {
     //Check for null and compare run-time types.
     if (obj == null || this.GetType() != obj.GetType())
     {
         return(false);
     }
     if (obj is ObjectProperty)
     {
         ObjectProperty p = (ObjectProperty)obj;
         return((this.Name == p.Name) && (this.PropertyType == p.PropertyType));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
        public static ObjectProperty GetCustProps(Object obj, PropertyInfo prop)
        {
            ObjectProperty objprop = new ObjectProperty(obj, prop);

            try {
                foreach (Attribute attr in objprop.Props.GetCustomAttributes(true))
                {
                    if (attr is WidgetAttribute)
                    {
                        var widgetAttrib = attr as WidgetAttribute;
                        if (null != widgetAttrib)
                        {
                            try { objprop.CompanionSourceFieldName = widgetAttrib.SelectFieldSource; } catch { objprop.CompanionSourceFieldName = ""; }
                            try { objprop.FieldMode = widgetAttrib.Mode; } catch { objprop.FieldMode = WidgetAttribute.FieldMode.Unknown; }
                        }
                    }
                }
            } catch (Exception ex) { }

            objprop.FieldDescription = ReflectionUtilities.GetDescriptionAttribute(obj.GetType(), objprop.Name);

            return(objprop);
        }
		protected void rpProps_Bind(object sender, RepeaterItemEventArgs e) {
			if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) {
				HiddenField hdnName = (HiddenField)e.Item.FindControl("hdnName");
				TextBox txtValue = (TextBox)e.Item.FindControl("txtValue");
				DropDownList ddlValue = (DropDownList)e.Item.FindControl("ddlValue");
				CheckBox chkValue = (CheckBox)e.Item.FindControl("chkValue");
				CheckBoxList chkValues = (CheckBoxList)e.Item.FindControl("chkValues");

				txtValue.Visible = true;
				string sName = hdnName.Value;

				ObjectProperty ListSourceProperty = new ObjectProperty();

				string sListSourcePropertyName = (from p in lstDefProps
												  where p.Name.ToLower() == sName.ToLower()
														&& !String.IsNullOrEmpty(p.CompanionSourceFieldName)
												  select p.CompanionSourceFieldName).FirstOrDefault();

				if (String.IsNullOrEmpty(sListSourcePropertyName)) {
					sListSourcePropertyName = String.Empty;
				}

				ListSourceProperty = (from p in lstDefProps
									  where p.CanRead == true
									  && p.CanWrite == false
									  && p.Name.ToLower() == sListSourcePropertyName.ToLower()
									  select p).FirstOrDefault();

				var dp = (from p in lstDefProps
						  where p.Name.ToLower() == sName.ToLower()
						  select p).FirstOrDefault();

				if (ListSourceProperty != null) {
					if (ListSourceProperty.DefValue is Dictionary<string, string>) {
						txtValue.Visible = false;

						//work with a drop down list, only allow one item in the drop down.
						if (dp.FieldMode == WidgetAttribute.FieldMode.DropDownList) {
							ddlValue.Visible = true;

							ddlValue.DataTextField = "Value";
							ddlValue.DataValueField = "Key";

							GeneralUtilities.BindListDefaultText(ddlValue, ListSourceProperty.DefValue, null, "Select Value", "");

							if (!String.IsNullOrEmpty(txtValue.Text)) {
								try {
									GeneralUtilities.SelectListValue(ddlValue, txtValue.Text);
								} catch { }
							}
						}

						// work with a checkbox list, allow more than one value
						if (dp.FieldMode == WidgetAttribute.FieldMode.CheckBoxList) {
							chkValues.Visible = true;

							chkValues.DataTextField = "Value";
							chkValues.DataValueField = "Key";

							GeneralUtilities.BindList(chkValues, ListSourceProperty.DefValue);

							// since this is a multi selected capable field, look for anything that starts with the
							// field name and has the delimeter trailing
							var pp = (from p in lstProps
									  where p.KeyName.ToLower().StartsWith(sName.ToLower() + "|")
									  select p).ToList();

							if (pp.Any()) {
								foreach (ListItem v in chkValues.Items) {
									v.Selected = (from p in pp
												  where p.KeyValue == v.Value
												  select p.KeyValue).Count() < 1 ? false : true;
								}
							}
						}
					}
				}

				if (dp.FieldMode == WidgetAttribute.FieldMode.RichHTMLTextBox
						|| dp.FieldMode == WidgetAttribute.FieldMode.MultiLineTextBox) {
					txtValue.Visible = true;
					txtValue.TextMode = TextBoxMode.MultiLine;
					txtValue.Columns = 60;
					txtValue.Rows = 5;
					if (dp.FieldMode == WidgetAttribute.FieldMode.RichHTMLTextBox) {
						txtValue.CssClass = "mceEditor";
					}
				}

				if (dp.PropertyType == typeof(bool) || dp.FieldMode == WidgetAttribute.FieldMode.CheckBox) {
					txtValue.Visible = false;
					chkValue.Visible = true;

					chkValue.Checked = Convert.ToBoolean(txtValue.Text);
				}
			}
		}
Exemplo n.º 6
0
        //============================
        public static List<ObjectProperty> GetWidgetProperties(Widget w, Guid guidContentID)
        {
            Object widget = new Object();

            List<WidgetProps> lstProps = w.ParseDefaultControlProperties();

            if (w.ControlPath.Contains(":")) {
                if (w.ControlPath.ToUpper().StartsWith("CLASS:")) {
                    try {
                        string className = w.ControlPath.Replace("CLASS:", "");
                        Type t = Type.GetType(className);
                        widget = Activator.CreateInstance(t);
                    } catch (Exception ex) { }
                } else {
                    try {
                        string[] path = w.ControlPath.Split(':');
                        string objectPrefix = path[0];
                        string objectClass = path[1];

                        Type t = Type.GetType(objectClass);
                        Object obj = Activator.CreateInstance(t);

                        Object attrib = ReflectionUtilities.GetAttribute<WidgetActionSettingModelAttribute>(t, objectPrefix);

                        if (attrib != null) {
                            Type s = Type.GetType(((WidgetActionSettingModelAttribute)attrib).ClassName);
                            widget = Activator.CreateInstance(s);
                        }
                    } catch (Exception ex) { }
                }
            }

            if (widget is IAdminModule) {
                var w1 = (IAdminModule)widget;
                w1.SiteID = SiteData.CurrentSiteID;
            }

            if (widget is IWidget) {
                var w1 = (IWidget)widget;
                w1.SiteID = SiteData.CurrentSiteID;
                w1.RootContentID = w.Root_ContentID;
                w1.PageWidgetID = w.Root_WidgetID;
                w1.IsDynamicInserted = true;
            }

            if (widget is IWidgetRawData) {
                var w1 = (IWidgetRawData)widget;
                w1.RawWidgetData = w.ControlProperties;
            }

            List<ObjectProperty> lstDefProps = ObjectProperty.GetObjectProperties(widget);

            //require that widget be attributed to be on the list
            List<string> limitedPropertyList = (from ww in widget.GetType().GetProperties()
                                                where Attribute.IsDefined(ww, typeof(WidgetAttribute))
                                                select ww.Name.ToLower()).ToList();

            List<ObjectProperty> lstPropsToEdit = (from p in lstDefProps
                                                   join l in limitedPropertyList on p.Name.ToLower() equals l.ToLower()
                                                   where p.CanRead == true
                                                       && p.CanWrite == true
                                                   select p).ToList();

            foreach (var dp in lstPropsToEdit) {
                string sName = dp.Name.ToLower();
                List<WidgetProps> lstItmVals = lstProps.Where(x => x.KeyName.ToLower().StartsWith(sName + "|") || x.KeyName.ToLower() == sName).ToList();

                ObjectProperty ListSourceProperty = new ObjectProperty();

                string sListSourcePropertyName = (from p in lstDefProps
                                                  where p.Name.ToLower() == sName.ToLower()
                                                        && !String.IsNullOrEmpty(p.CompanionSourceFieldName)
                                                  select p.CompanionSourceFieldName).FirstOrDefault();

                if (String.IsNullOrEmpty(sListSourcePropertyName)) {
                    sListSourcePropertyName = String.Empty;
                }

                ListSourceProperty = (from p in lstDefProps
                                      where p.CanRead == true
                                         && p.CanWrite == false
                                         && p.Name.ToLower() == sListSourcePropertyName.ToLower()
                                      select p).FirstOrDefault();

                if (lstItmVals != null && lstItmVals.Any() && dp.FieldMode != WidgetAttribute.FieldMode.CheckBoxList) {
                    dp.TextValue = lstItmVals != null ? lstItmVals.FirstOrDefault().KeyValue : String.Empty;
                    dp.DefValue = dp.TextValue;
                }

                Type pt = dp.PropertyType;

                if (ListSourceProperty != null) {
                    if (ListSourceProperty.DefValue is Dictionary<string, string>) {
                        dp.Options = OptionSelections.GetOptionsFromDictionary((Dictionary<string, string>)ListSourceProperty.DefValue);

                        // work with a checkbox list, allow more than one value
                        if (dp.FieldMode == WidgetAttribute.FieldMode.CheckBoxList) {
                            // since this is a multi selected capable field, look for anything that starts with the
                            // field name and has the delimeter trailing

                            if (lstItmVals.Count > 0) {
                                foreach (var v in dp.Options) {
                                    v.Selected = (from p in lstItmVals
                                                  where p.KeyValue == v.Value
                                                  select p.KeyValue).Any();
                                }
                            }
                        }
                    }
                }

                if ((pt == typeof(bool)) || dp.FieldMode == WidgetAttribute.FieldMode.CheckBox) {
                    dp.FieldMode = WidgetAttribute.FieldMode.CheckBox;
                    dp.CheckBoxState = Convert.ToBoolean(dp.DefValue);
                }
            }

            return lstPropsToEdit;
        }
Exemplo n.º 7
0
        //============================

        public static List <ObjectProperty> GetWidgetProperties(Widget w, Guid guidContentID)
        {
            Object widget = new Object();

            List <WidgetProps> lstProps = w.ParseDefaultControlProperties();

            if (w.ControlPath.Contains(":"))
            {
                if (w.ControlPath.ToUpperInvariant().StartsWith("CLASS:"))
                {
                    try {
                        string className = w.ControlPath.Replace("CLASS:", "");
                        Type   t         = ReflectionUtilities.GetTypeFromString(className);
                        widget = Activator.CreateInstance(t);
                    } catch (Exception ex) { }
                }
                else
                {
                    try {
                        string[] path         = w.ControlPath.Split(':');
                        string   objectPrefix = path[0];
                        string   objectClass  = path[1];

                        Type t = ReflectionUtilities.GetTypeFromString(objectClass);

                        Object obj    = Activator.CreateInstance(t);
                        Object attrib = ReflectionUtilities.GetAttribute <WidgetActionSettingModelAttribute>(t, objectPrefix);

                        if (attrib != null && attrib is WidgetActionSettingModelAttribute)
                        {
                            string attrClass = (attrib as WidgetActionSettingModelAttribute).ClassName;
                            Type   s         = ReflectionUtilities.GetTypeFromString(attrClass);

                            widget = Activator.CreateInstance(s);
                        }
                    } catch (Exception ex) { }
                }
            }
            else
            {
                if (w.ControlPath.Contains("|"))
                {
                    try {
                        string[] path       = w.ControlPath.Split('|');
                        string   viewPath   = path[0];
                        string   modelClass = String.Empty;
                        if (path.Length > 1)
                        {
                            modelClass = path[1];
                            Type objType = ReflectionUtilities.GetTypeFromString(modelClass);

                            widget = Activator.CreateInstance(objType);
                        }
                    } catch (Exception ex) { }
                }
            }

            if (widget is IAdminModule)
            {
                var w1 = (IAdminModule)widget;
                w1.SiteID = SiteData.CurrentSiteID;
            }

            if (widget is IWidget)
            {
                var w1 = (IWidget)widget;
                w1.SiteID            = SiteData.CurrentSiteID;
                w1.RootContentID     = w.Root_ContentID;
                w1.PageWidgetID      = w.Root_WidgetID;
                w1.IsDynamicInserted = true;
            }

            if (widget is IWidgetRawData)
            {
                var w1 = (IWidgetRawData)widget;
                w1.RawWidgetData = w.ControlProperties;
            }

            List <ObjectProperty> lstDefProps = ObjectProperty.GetObjectProperties(widget);

            //require that widget be attributed to be on the list
            List <string> limitedPropertyList = (from ww in widget.GetType().GetProperties()
                                                 where Attribute.IsDefined(ww, typeof(WidgetAttribute))
                                                 select ww.Name.ToLowerInvariant()).ToList();

            List <ObjectProperty> lstPropsToEdit = (from p in lstDefProps
                                                    join l in limitedPropertyList on p.Name.ToLowerInvariant() equals l.ToLowerInvariant()
                                                    where p.CanRead == true &&
                                                    p.CanWrite == true
                                                    select p).ToList();

            foreach (var dp in lstPropsToEdit)
            {
                string             sName      = dp.Name.ToLowerInvariant();
                List <WidgetProps> lstItmVals = lstProps.Where(x => x.KeyName.ToLowerInvariant().StartsWith(sName + "|") || x.KeyName.ToLowerInvariant() == sName).ToList();

                ObjectProperty sourceProperty = new ObjectProperty();

                string sListSourcePropertyName = (from p in lstDefProps
                                                  where p.Name.ToLowerInvariant() == sName.ToLowerInvariant() &&
                                                  !String.IsNullOrEmpty(p.CompanionSourceFieldName)
                                                  select p.CompanionSourceFieldName).FirstOrDefault();

                if (String.IsNullOrEmpty(sListSourcePropertyName))
                {
                    sListSourcePropertyName = String.Empty;
                }

                sourceProperty = (from p in lstDefProps
                                  where p.CanRead == true &&
                                  p.CanWrite == false &&
                                  p.Name.ToLowerInvariant() == sListSourcePropertyName.ToLowerInvariant()
                                  select p).FirstOrDefault();

                if (dp.FieldMode != WidgetAttribute.FieldMode.CheckBoxList)
                {
                    string sDefTxt = String.Empty;

                    if (lstItmVals != null && lstItmVals.Any())
                    {
                        dp.TextValue = lstItmVals != null?lstItmVals.FirstOrDefault().KeyValue : String.Empty;

                        dp.DefValue = dp.TextValue;
                    }
                    else
                    {
                        if (dp.DefValue != null)
                        {
                            sDefTxt = dp.DefValue.ToString();

                            if (dp.PropertyType == typeof(Boolean))
                            {
                                bool vB = Convert.ToBoolean(dp.DefValue.ToString());
                                sDefTxt = vB.ToString();
                            }
                            if (dp.PropertyType == typeof(System.Drawing.Color))
                            {
                                System.Drawing.Color vC = (System.Drawing.Color)dp.DefValue;
                                sDefTxt = System.Drawing.ColorTranslator.ToHtml(vC);
                            }
                        }

                        dp.TextValue = sDefTxt;
                    }
                }

                Type pt = dp.PropertyType;

                if (sourceProperty != null)
                {
                    if (sourceProperty.DefValue is Dictionary <string, string> )
                    {
                        dp.Options = OptionSelections.GetOptionsFromDictionary((Dictionary <string, string>)sourceProperty.DefValue);

                        // work with a checkbox list, allow more than one value
                        if (dp.FieldMode == WidgetAttribute.FieldMode.CheckBoxList)
                        {
                            // since this is a multi selected capable field, look for anything that starts with the
                            // field name and has the delimiter trailing

                            if (lstItmVals.Any() && dp.Options.Any())
                            {
                                foreach (var v in dp.Options)
                                {
                                    v.Selected = (from p in lstItmVals
                                                  where p.KeyValue == v.Key
                                                  select p.KeyValue).Any();
                                }
                            }
                        }
                    }
                }

                if (dp.FieldMode == WidgetAttribute.FieldMode.Unknown)
                {
                    if (pt == typeof(String) || pt == typeof(DateTime) ||
                        pt == typeof(Int16) || pt == typeof(Int32) || pt == typeof(Int64) ||
                        pt == typeof(float) || pt == typeof(Decimal) ||
                        pt == typeof(Guid) || pt == typeof(System.Drawing.Color))
                    {
                        dp.FieldMode = WidgetAttribute.FieldMode.TextBox;
                    }
                }

                if ((pt == typeof(Boolean)) || dp.FieldMode == WidgetAttribute.FieldMode.CheckBox)
                {
                    dp.FieldMode     = WidgetAttribute.FieldMode.CheckBox;
                    dp.CheckBoxState = Convert.ToBoolean(dp.TextValue);
                }
            }

            return(lstPropsToEdit);
        }
Exemplo n.º 8
0
        public static ObjectProperty GetCustProps(Object obj, PropertyInfo prop)
        {
            ObjectProperty objprop = new ObjectProperty(obj, prop);

            try {
                foreach (Attribute attr in objprop.Props.GetCustomAttributes(true)) {
                    if (attr is WidgetAttribute) {
                        var widgetAttrib = attr as WidgetAttribute;
                        if (null != widgetAttrib) {
                            try { objprop.CompanionSourceFieldName = widgetAttrib.SelectFieldSource; } catch { objprop.CompanionSourceFieldName = ""; }
                            try { objprop.FieldMode = widgetAttrib.Mode; } catch { objprop.FieldMode = WidgetAttribute.FieldMode.Unknown; }
                        }
                    }
                }
            } catch (Exception ex) { }

            objprop.FieldDescription = ReflectionUtilities.GetDescriptionAttribute(obj.GetType(), objprop.Name);

            return objprop;
        }