public void LoadTypes() { if (null == this._agent) { throw new InvalidOperationException("Agent not set"); } string key = ConfigurationManager.AppSettings["CONTROL_TYPES"]; if (string.IsNullOrEmpty(key)) { throw new ApplicationException("'CONTROL_TYPES' web.config key not set"); } XmlDocument doc = new XmlDocument(); try { doc.Load(this._agent.OpenStream(key)); } finally { this._agent.CloseStream(key); } XmlNode root = doc.SelectSingleNode("types"); if (null == root) { throw new InvalidOperationException("Control types file has no types node"); } foreach (XmlNode node in root.ChildNodes) { ControlFactory.ControlDescriptor descriptor = new ControlFactory.ControlDescriptor(node.Attributes["key"].Value, node.Attributes["name"].Value, (node.Attributes["readOnly"] == null) ? string.Empty : node.Attributes["readOnly"].Value, (node.Attributes["readOnlyValue"] == null) ? string.Empty : node.Attributes["readOnlyValue"].Value, (node.Attributes["watermark"] == null) ? string.Empty : node.Attributes["watermark"].Value); if (node.HasChildNodes) { foreach (XmlNode child in node.ChildNodes) { ControlFactory.PropertyDescriptor propertyDescriptor = new ControlFactory.PropertyDescriptor(child.Attributes["name"].Value, (child.Attributes["value"] == null) ? string.Empty : child.Attributes["value"].Value, (child.Attributes["options"] == null) ? string.Empty : child.Attributes["options"].Value, (child.Attributes["ValueType"] == null) ? string.Empty : child.Attributes["ValueType"].Value, child.Attributes["isList"] != null && bool.Parse(child.Attributes["isList"].Value)); descriptor.EditableProperties.Add(propertyDescriptor.Name, propertyDescriptor); } } this._knownTypes.Add(descriptor.Key, descriptor); } }
public Control CreateReadOnlyControl(string key, Control scope) { if (null == this._monitor) { throw new ApplicationException("Monitor not set"); } if (!this.KnownTypes.ContainsKey(key)) { throw new InvalidOperationException(string.Format("Unknown control type '{0}'", key)); } ControlFactory.ControlDescriptor descriptor = this.KnownTypes[key]; Control control = null; try { control = (ReflectionServices.CreateInstance(descriptor.AssemblyQualifiedName) as Control); } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance("create readonly control error", null, ex, EVENT_TYPE.Error)); } if (null != control) { if (!string.IsNullOrEmpty(descriptor.ReadOnlyProperty)) { try { ReflectionServices.SetValue(control, descriptor.ReadOnlyProperty, descriptor.ReadOnlyValue); } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance(string.Format("set readonly property error '{0}'.'{1}'='{2}'", key, descriptor.ReadOnlyProperty, descriptor.ReadOnlyValue), null, ex, EVENT_TYPE.Error)); } } } if (control is NumberTextBox) { ((NumberTextBox)control).AutoIncrementScope = scope; } return(control); }