public static PropertyDescriptorCollection GetWebClientProperties(IWebClientComponent obj, StringCollection names, Attribute[] attributes) { PropertyDescriptorCollection ps = TypeDescriptor.GetProperties(obj, attributes, true); List <PropertyDescriptor> lst = new List <PropertyDescriptor>(); foreach (PropertyDescriptor p in ps) { if (names == null || names.Contains(p.Name)) { if (VPLUtil.IsCompiling) { lst.Add(p); } else { if (VPLUtil.HasAttribute(p, typeof(ReadOnlyInProgrammingAttribute))) { lst.Add(new ReadOnlyPropertyDesc(p)); } else { lst.Add(p); } } } } WebClientValueCollection.AddPropertyDescs(lst, obj.CustomValues); return(new PropertyDescriptorCollection(lst.ToArray())); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (context != null && context.Instance != null && provider != null) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { string name = context.Instance.GetType().Name; WebClientValueCollection svc = context.Instance as WebClientValueCollection; if (svc == null) { IWebClientComponent wa = context.Instance as IWebClientComponent; if (wa != null) { svc = wa.CustomValues; name = wa.GetType().Name; } else { IVplObjectPointer vop = context.Instance as IVplObjectPointer; if (vop != null) { wa = vop.ObjectInstance as IWebClientComponent; if (wa != null) { svc = wa.CustomValues; name = wa.GetType().Name; } } if (svc == null) { WebClientValueCollection.PropertyDescriptorNewClientVariable psdv = context.PropertyDescriptor as WebClientValueCollection.PropertyDescriptorNewClientVariable; if (psdv != null) { svc = psdv.Owner; } else { WebClientValueCollection.PropertyDescriptorClientVariable psdv0 = context.PropertyDescriptor as WebClientValueCollection.PropertyDescriptorClientVariable; if (psdv0 != null) { svc = psdv0.Owner; } } } } } if (svc != null) { DialogWebClientValues dlg = new DialogWebClientValues(); dlg.LoadData(svc, name); if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK) { IHtmlElement ihe = svc.Owner as IHtmlElement; if (ihe != null) { ihe.OnSetProperty(context.PropertyDescriptor.Name); } IDevClassReferencer dcr = svc.Owner as IDevClassReferencer; if (dcr != null) { IDevClass dc = dcr.GetDevClass(); if (dc != null) { dc.NotifyChange(dcr, context.PropertyDescriptor.Name); } } } } } } return(value); }
public static void CreateJavaScript(IProperty SetProperty, string v, StringCollection sb, StringCollection parameters) { if (SetProperty.RootPointer != null && typeof(WebPage).IsAssignableFrom(SetProperty.RootPointer.BaseClassType)) { ClassPointer pp = SetProperty.PropertyOwner as ClassPointer; if (pp != null) { if (pp.ClassId != SetProperty.RootPointer.ClassId) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setPropertyByPageId({0},'{1}',{2});\r\n", pp.ClassId, SetProperty.Name, v)); return; } } } if (typeof(ProjectResources).Equals(SetProperty.Owner.ObjectInstance)) { if (string.CompareOrdinal(SetProperty.Name, "ProjectCultureName") == 0) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SwitchCulture({0});\r\n", v)); return; } } IWebClientComponent wcc = SetProperty.Owner.ObjectInstance as IWebClientComponent; if (wcc == null && SetProperty.Owner.ObjectInstance == null) { if (SetProperty.Owner.ObjectType != null) { if (SetProperty.Owner.ObjectType.GetInterface("IWebClientComponent") != null) { try { wcc = Activator.CreateInstance(SetProperty.Owner.ObjectType) as IWebClientComponent; if (wcc != null) { wcc.SetCodeName(SetProperty.Owner.CodeName); } } catch { } } } } if (wcc != null) { v = wcc.MapJavaScriptVallue(SetProperty.Name, v); } IWebClientPropertyCustomSetter wpcs = SetProperty.Owner.ObjectInstance as IWebClientPropertyCustomSetter; if (wpcs == null && SetProperty.Owner.ObjectInstance == null) { wpcs = wcc as IWebClientPropertyCustomSetter; } if (wpcs != null) { string ownerCode = SetProperty.Owner.GetJavaScriptReferenceCode(sb); if (wpcs.CreateSetPropertyJavaScript(ownerCode, SetProperty.Name, v, sb)) { return; } } if (string.CompareOrdinal("Font", SetProperty.Name) == 0) { IWebClientControl webc = SetProperty.Owner.ObjectInstance as IWebClientControl; if (webc != null) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setFont({0},{1});\r\n", WebPageCompilerUtility.JsCodeRef(webc.CodeName), WebPageCompilerUtility.GetFontJavascriptValues(v))); return; } } if (typeof(SessionVariableCollection).Equals(SetProperty.Owner.ObjectType)) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setSessionVariable('{0}',{1});\r\n", SetProperty.Name, v)); return; } if (typeof(LimnorWebApp).IsAssignableFrom(SetProperty.Owner.ObjectType)) { if (string.CompareOrdinal(SetProperty.Name, "GlobalVariableTimeout") == 0) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setSessionTimeout({0});\r\n", v)); return; } } string code = null; IWebClientPropertyHolder wcph = SetProperty.Owner.ObjectInstance as IWebClientPropertyHolder; if (wcph != null) { code = wcph.CreateSetPropertyJavaScript(SetProperty.Owner.CodeName, SetProperty.Name, v); if (!string.IsNullOrEmpty(code)) { sb.Add(code); } } IWebClientPropertySetter wcps = SetProperty.Owner.ObjectInstance as IWebClientPropertySetter; if (string.IsNullOrEmpty(code)) { if (wcps == null || !wcps.UseCustomSetter(SetProperty.Name)) { string left = SetProperty.GetJavaScriptReferenceCode(sb); if (left.EndsWith(".innerText", StringComparison.Ordinal)) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SetInnerText({0},{1});\r\n", left.Substring(0, left.Length - 10), v); } else if (left.StartsWith("JsonDataBinding.GetInnerText(", StringComparison.Ordinal)) { string oc = SetProperty.Owner.GetJavaScriptReferenceCode(sb); code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SetInnerText({0},{1});\r\n", oc, v); } else if (left.EndsWith(".Opacity", StringComparison.Ordinal)) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setOpacity({0},{1});\r\n", left.Substring(0, left.Length - ".Opacity".Length), v); } else if (left.StartsWith("JsonDataBinding.getOpacity(", StringComparison.Ordinal)) { string oc = SetProperty.Owner.GetJavaScriptReferenceCode(sb); code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setOpacity({0},{1});\r\n", oc, v); } else if (left.EndsWith(".style.display", StringComparison.Ordinal)) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setVisible({0},{1});\r\n", left.Substring(0, left.Length - ".style.display".Length), v); } else { if (wcc != null && v != null) { if (string.CompareOrdinal(SetProperty.Name, "Top") == 0 || string.CompareOrdinal(SetProperty.Name, "Left") == 0 || string.CompareOrdinal(SetProperty.Name, "Height") == 0 || string.CompareOrdinal(SetProperty.Name, "Width") == 0) { if (!v.EndsWith("px", StringComparison.Ordinal)) { code = string.Format(CultureInfo.InvariantCulture, "{0}=({1})+'px';\r\n", left, v); } } } if (code == null && SetProperty.Holder != null) { if (typeof(HtmlListBox).Equals(SetProperty.Holder.ObjectType) || typeof(HtmlDropDown).Equals(SetProperty.Holder.ObjectType)) { if (string.CompareOrdinal(SetProperty.Name, "SelectedValue") == 0 || string.CompareOrdinal(SetProperty.Name, "selectedValue") == 0) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SetSelectedListValue({0},{1});\r\n", SetProperty.Holder.GetJavaScriptReferenceCode(sb), v); } else if (string.CompareOrdinal(SetProperty.Name, "SelectedItem") == 0 || string.CompareOrdinal(SetProperty.Name, "selectedItem") == 0) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SetSelectedListText({0},{1});\r\n", SetProperty.Holder.GetJavaScriptReferenceCode(sb), v); } } } if (code == null) { code = string.Format(CultureInfo.InvariantCulture, "{0}={1};\r\n", left, v); } } if (!string.IsNullOrEmpty(code)) { sb.Add(code); } } } bool isCustomValue = false; if (string.CompareOrdinal("tag", SetProperty.Name) == 0) { isCustomValue = true; } else if (wcc != null) { WebClientValueCollection cvc = wcc.CustomValues; if (cvc != null) { if (cvc.ContainsKey(SetProperty.Name)) { isCustomValue = true; } } } if (isCustomValue) { string ownerCode = SetProperty.Owner.GetJavaScriptReferenceCode(sb); sb.Add(string.Format(CultureInfo.InvariantCulture, "{0}JsonDataBinding.onSetCustomValue({1},'{2}');\r\n", Indentation.GetIndent(), ownerCode, SetProperty.Name)); } if (wcps != null) { wcps.OnSetProperty(SetProperty.Name, v, sb); } }
public WebClientValueCollection(IWebClientComponent owner) { _owner = owner; }