public override void Make(IConfigurationType config, IExpressionsManager manager) { if (null == manager) { throw new ArgumentNullException("manager"); } if (null == config) { throw new ArgumentNullException("config"); } IConfigurationElement element = config as IConfigurationElement; if (null == element) { throw new ArgumentException("config must be an IConfigurationElement"); } if (element.Elements.ContainsKey("operands")) { foreach (IConfigurationElement operandElement in element.GetElementReference("operands").Elements.Values) { string type = operandElement.GetAttributeReference("type").Value.ToString(); IToken token = manager.Token(type); if (null == token) { throw new InvalidOperationException(string.Format("Cannot make the type '{0}'", type)); } token.Make(operandElement, manager); this.Operands.Add(token); } } }
public EncryptedConfigurationElement( [NotNull] IConfigurationElement <string> configurationElement, [NotNull] string passwordName, [NotNull] IDataProtection dataProtection) { _ConfigurationElement = configurationElement ?? throw new ArgumentNullException(nameof(configurationElement)); _PasswordName = passwordName ?? throw new ArgumentNullException(nameof(passwordName)); _DataProtection = dataProtection ?? throw new ArgumentNullException(nameof(dataProtection)); }
public override void Make(IConfigurationType config, IExpressionsManager manager) { if (null == config) { throw new ArgumentNullException("config"); } if (null == manager) { throw new ArgumentNullException("manager"); } IConfigurationElement tokenElement = config as IConfigurationElement; if (null == tokenElement) { throw new ArgumentException("config is not an IConfigurationElement"); } if (!tokenElement.Elements.ContainsKey("source")) { throw new ConfigurationException("Bad views field token configuration: 'source' element not found"); } IConfigurationElement sourceElement = tokenElement.GetElementReference("source"); Make(sourceElement, manager); }
private void AddElementToCache(IConfigurationElement element) { var rootElement = element as IRootConfigurationElement; if (rootElement != null && !CachedElements.ContainsKey(rootElement.Id)) CachedElements.Add(rootElement.Id, rootElement); }
public override void Make(IConfigurationType config, IExpressionsManager manager) { if (null == config) { throw new ArgumentNullException("config"); } if (null == manager) { throw new ArgumentNullException("manager"); } IConfigurationElement tokenElement = config as IConfigurationElement; if (null == tokenElement) { throw new ArgumentException("config is not an IConfigurationElement"); } if (!tokenElement.Elements.ContainsKey("source")) { throw new ConfigurationException("Bad views token configuration: 'source' element not found"); } IConfigurationElement sourceElement = tokenElement.GetElementReference("source"); if (!sourceElement.Attributes.ContainsKey("parameter")) { throw new ConfigurationException("Bad views token configuration: 'source' element has no 'parameter' attribute"); } this.ParameterName = sourceElement.GetAttributeReference("parameter").Value.ToString(); }
public override void ToConfiguration(IConfigurationElement config) { if (null == config) throw new ArgumentNullException("config"); IConfigurationElement sourceElement = config.AddElement("source"); WriteConfiguration(sourceElement); }
public JsonNetConfigurationSection(IConfiguration root, IConfigurationElement parent, JToken node, string key, SectionType type) : base(root, parent, node, type) { GuardPath(key); Key = key; }
/// <summary> /// Returns an instance of <see cref="ICustomMenuConfigurer"/> if any has been registered /// using the associated extension point. If no type has been contributed, NULL is returned. /// </summary> /// <returns>An instance of <see cref="ICustomMenuConfigurer"/> or NULL</returns> private static ICustomMenuConfigurer GetCustomMenuConfigurer() { IConfigurationElement[] customMenuConfigurerElements = ExtensionService.Instance.GetConfigurationElements(ExtensionPointIdCustomMenuConfigurer); if (customMenuConfigurerElements == null || customMenuConfigurerElements.Length == 0) { return(null); } IConfigurationElement customMenuConfigurationElement = customMenuConfigurerElements[0]; string id = customMenuConfigurationElement["id"]; string clsName = customMenuConfigurationElement["class"]; if (string.IsNullOrEmpty(clsName)) { return(null); } IBundle providingBundle = ExtensionService.Instance.GetProvidingBundle(customMenuConfigurationElement); try { Type instanceType = TypeLoader.TypeForName(providingBundle, clsName); return(instanceType.NewInstance <ICustomMenuConfigurer>()); } catch (Exception ex) { ILog logWriter = LogManager.GetLog(typeof(MenuItemProvider)); logWriter.Error( "Error on creating instance of custom menu configurer. " + $"Id is '{id}'. Providing bundle is '{providingBundle}'", ex); return(null); } }
public Preference([NotNull] string name, [NotNull] IConfigurationElement <T> defaultPreference, [NotNull] IPreferencesStore preferencesStore) { Name = name ?? throw new ArgumentNullException(nameof(name)); _DefaultPreference = defaultPreference ?? throw new ArgumentNullException(nameof(defaultPreference)); _PreferencesStore = preferencesStore ?? throw new ArgumentNullException(nameof(preferencesStore)); Reload(); }
protected override void WriteConfiguration(IConfigurationElement sourceElement) { if (null == sourceElement) throw new ArgumentNullException("sourceElement"); sourceElement.AddAttribute("table").Value = this.TableName; base.WriteConfiguration(sourceElement); }
protected virtual void Make(IConfigurationElement sourceElement, IExpressionsManager manager) { if (null == sourceElement) throw new ArgumentNullException("sourceElement"); if (null == manager) throw new ArgumentNullException("manager"); if (!sourceElement.Attributes.ContainsKey("field")) throw new ConfigurationException("Bad views field token configuration: 'source' element has no 'field' attribute"); this.FieldName = sourceElement.GetAttributeReference("field").Value.ToString(); }
protected JsonNetConfigurationElement(IConfiguration root, IConfigurationElement parent, JToken node, SectionType type) { Root = root; Parent = parent; Node = node ?? throw new ArgumentNullException(nameof(node)); Type = type; }
public override void Copy(IConfigurationElement element) { base.Copy(element); var rootElement = element as IRootConfigurationElement; if (rootElement != null) this.Id = rootElement.Id; }
protected virtual void WriteConfiguration(IConfigurationElement sourceElement) { if (null == sourceElement) { throw new ArgumentNullException("sourceElement"); } sourceElement.AddAttribute("field").Value = this.FieldName; }
/// <inheritdoc /> protected override void OnInitialize() { IConfigurationElement[] configurationElements = ExtensionService.Instance.GetConfigurationElements(DataViewExtensionPointId); if (configurationElements.Length == 0) { _log.Warning("No data view has been contributed by any extension point!"); return; } _log.Debug($"{configurationElements.Length} data view contributions has been found"); for (int i = -1; ++i != configurationElements.Length;) { IConfigurationElement configurationElement = configurationElements[i]; string id = configurationElement["id"]; string cls = configurationElement["class"]; string label = configurationElement["label"]; if (string.IsNullOrEmpty(label)) { label = id; } _log.Debug($"Registering contribution {{id: '{id}', cls: '{cls}', label: '{label}'}}"); if (string.IsNullOrWhiteSpace(id)) { _log.Error("Id attribute of data view extension contribution is null or empty!"); continue; } if (string.IsNullOrWhiteSpace(cls)) { _log.Error($"Class attribute of data view extension contribution is null or empty!. Contribution id: '{id}'"); continue; } IBundle providingBundle = ExtensionService.Instance.GetProvidingBundle(configurationElement); try { Type dataViewType = TypeLoader.TypeForName(providingBundle, cls); // NLS support label = NLS.Localize(label, dataViewType); DataViewContribution dataViewContribution = new DataViewContribution { DataViewId = id, DataViewType = dataViewType, DataViewLabel = label }; iRegisteredDataViews.Add(dataViewContribution); _log.Info($"Data view contribution '{id}' registered."); } catch (Exception ex) { _log.Error($"Error loading type '{cls}'.", ex); } } }
/// <summary> /// Creates a new instance. /// </summary> public NewWizardTreeContentProvider() { IConfigurationElement[] configurationElements = ExtensionService.Instance .GetConfigurationElements(ExtensionPointId); IConfigurationElement[] categories = configurationElements.Where(x => x.Prefix == "category").ToArray(); IConfigurationElement[] wizards = configurationElements.Where(x => x.Prefix == "wizard").ToArray(); IDictionary <string, CategoryContribution> idToCategoryMap = new Dictionary <string, CategoryContribution>(categories.Length); // Processing categories for (int i = -1; ++i < categories.Length;) { IConfigurationElement category = categories[i]; string id = category["id"]; string label = category["label"]; CategoryContribution contribution = new CategoryContribution { Id = id, Label = label }; idToCategoryMap.Add(id, contribution); iContributions.Add(contribution); } // Processing wizards for (int i = -1; ++i < wizards.Length;) { IConfigurationElement wizard = wizards[i]; string id = wizard["id"]; string category = wizard["category"]; string label = wizard["label"]; string className = wizard["class"]; if (string.IsNullOrEmpty(className)) { continue; } IBundle providingBundle = ExtensionService.Instance.GetProvidingBundle(wizard); Type wizardType = TypeLoader.TypeForName(providingBundle, className); IWizard wizardImpl = Activator.CreateInstance(wizardType) as IWizard; WizardContribution contribution = new WizardContribution { Id = id, Label = label, Category = category, Wizard = wizardImpl }; // Is it a categorized item? if (!string.IsNullOrEmpty(category)) { CategoryContribution categoryContr; if (idToCategoryMap.TryGetValue(category, out categoryContr)) { categoryContr.Wizards.Add(contribution); continue; } } iContributions.Add(contribution); } }
private SqlCommand BuildCommand(IConfigurationElement commandElement, IBinder binder, WebPartManager manager) { SqlCommand command = new SqlCommand(); foreach (IConfigurationElementAttribute attribute in commandElement.Attributes.Values) { ReflectionServices.SetValue(command, attribute.ConfigKey, attribute.Value); } IBindingItemsCollection bindingParams = binder.NewBindingItemCollectionInstance(); binder.BindingSet.Add(commandElement.ConfigKey, bindingParams); foreach (IConfigurationElement parameterElement in commandElement.Elements.Values) { SqlParameter parameter = new SqlParameter(); foreach (IConfigurationElementAttribute parameterAttribute in parameterElement.Attributes.Values) { if ("bind" == parameterAttribute.ConfigKey) { string bindstring = parameterAttribute.Value.ToString(); bool isOutput = parameterElement.Attributes.ContainsKey("Direction") && ("Output" == parameterElement.GetAttributeReference("Direction").Value.ToString() || "InputOutput" == parameterElement.GetAttributeReference("Direction").Value.ToString()); if (bindstring.Contains(".")) { string sourcestring = bindstring.Substring(0, bindstring.IndexOf(".")); IBindingItem bindingItem = binder.NewBindingItemInstance(); if (!isOutput) { bindingItem.Source = manager.FindControl(sourcestring); bindingItem.SourceProperty = bindstring.Substring(sourcestring.Length + 1); bindingItem.Target = parameter; bindingItem.TargetProperty = "Value"; } else { bindingItem.Target = manager.FindControl(sourcestring); bindingItem.TargetProperty = bindstring.Substring(sourcestring.Length + 1); bindingItem.Source = parameter; bindingItem.SourceProperty = "Value"; } bindingParams.Add(bindingItem); } } else { ReflectionServices.SetValue(parameter, parameterAttribute.ConfigKey, parameterAttribute.Value); } } if (null == parameter.Value) { parameter.Value = DBNull.Value; } command.Parameters.Add(parameter); } return(command); }
public IConfigurationElementAttributesCollection Clone(IConfigurationElement parent) { ConfigurationElementAttributesCollection clone = new ConfigurationElementAttributesCollection(parent); foreach (IConfigurationElementAttribute attribute in this.Values) { clone.Add(attribute.ConfigKey, attribute.Clone()); } return(clone); }
protected virtual void SaveCellProperties(TableCell cell, IConfigurationElement configCell) { if (ControlFactory.Instance.KnownTypes.ContainsKey("TableCell")) { ControlFactory.ControlDescriptor descriptor = ControlFactory.Instance.KnownTypes["TableCell"]; foreach (string name in descriptor.EditableProperties.Keys) { configCell.AddAttribute(name).Value = ReflectionServices.ToString(ReflectionServices.ExtractValue(cell, name)); } } }
private SqlCommand BuildCommand(IConfigurationElement commandElement, IBinder binder, WebPartManager manager) { SqlCommand command = new SqlCommand(); foreach (IConfigurationElementAttribute attribute in commandElement.Attributes.Values) { ReflectionServices.SetValue(command, attribute.ConfigKey, attribute.Value); } IBindingItemsCollection bindingParams = binder.NewBindingItemCollectionInstance(); binder.BindingSet.Add(commandElement.ConfigKey, bindingParams); foreach (IConfigurationElement parameterElement in commandElement.Elements.Values) { SqlParameter parameter = new SqlParameter(); foreach (IConfigurationElementAttribute parameterAttribute in parameterElement.Attributes.Values) { if ("bind" == parameterAttribute.ConfigKey) { string bindstring = parameterAttribute.Value.ToString(); bool isOutput = parameterElement.Attributes.ContainsKey("Direction") && ("Output" == parameterElement.GetAttributeReference("Direction").Value.ToString() || "InputOutput" == parameterElement.GetAttributeReference("Direction").Value.ToString()); if (bindstring.Contains(".")) { string sourcestring = bindstring.Substring(0, bindstring.IndexOf(".")); IBindingItem bindingItem = binder.NewBindingItemInstance(); if (!isOutput) { bindingItem.Source = manager.FindControl(sourcestring); bindingItem.SourceProperty = bindstring.Substring(sourcestring.Length + 1); bindingItem.Target = parameter; bindingItem.TargetProperty = "Value"; } else { bindingItem.Target = manager.FindControl(sourcestring); bindingItem.TargetProperty = bindstring.Substring(sourcestring.Length + 1); bindingItem.Source = parameter; bindingItem.SourceProperty = "Value"; } bindingParams.Add(bindingItem); } } else { ReflectionServices.SetValue(parameter, parameterAttribute.ConfigKey, parameterAttribute.Value); } } if (null == parameter.Value) { parameter.Value = DBNull.Value; } command.Parameters.Add(parameter); } return command; }
public override void ToConfiguration(IConfigurationElement config) { if (null == config) { throw new ArgumentNullException("config"); } IConfigurationElement sourceElement = config.AddElement("source"); sourceElement.AddAttribute("parameter").Value = this.ParameterName; }
protected override void WriteConfiguration(IConfigurationElement sourceElement) { if (null == sourceElement) { throw new ArgumentNullException("sourceElement"); } sourceElement.AddAttribute("view").Value = this.ViewName; base.WriteConfiguration(sourceElement); }
public override void ToConfiguration(IConfigurationElement config) { if (null == config) { throw new ArgumentNullException("config"); } IConfigurationElement sourceElement = config.AddElement("source"); WriteConfiguration(sourceElement); }
public virtual void Copy(IConfigurationElement element) { if (element == null) throw new ArgumentNullException("element"); this.Name = element.Name; this.Attributes.Clear(); element.Attributes.ForEach(x => this.Attributes.Add(x)); this.Children.Clear(); element.Children.ForEach(x => this.Children.Add(x)); }
private bool DeleteConfigSection(IPermissionActor target) { IConfigurationElement config = target is IPermissionGroup ? GroupsConfig["Groups"] : PlayersConfig[((IUser)target).UserType]; List <PermissionSection> values = config.Get <PermissionSection[]>().ToList(); int i = values.RemoveAll(c => c.Id.Equals(target.Id, StringComparison.OrdinalIgnoreCase)); config.Set(values); return(i > 0); }
private void ParseProperties(BoundField target, IConfigurationElement propertiesConfig) { foreach (IConfigurationElement element in propertiesConfig.Elements.Values) { try { ReflectionServices.SetValue(target, element.GetAttributeReference("member").Value.ToString(), element.GetAttributeReference("value").Value, true); } catch { } } }
private void ConfigureConfigurationElement <T>(T instance, IExtension extension) { IConfigurationElement configElement = instance as IConfigurationElement; if (configElement != null) { configElement.Configure(extension); } else { //TODO: adfasdf } }
private void BuildCommand(IConfigurationElement parametersSection, ParameterCollection parameters) { parameters.Clear(); foreach (IConfigurationElement parameterElement in parametersSection.Elements.Values) { Parameter commandParameter = new Parameter(); foreach (IConfigurationElement propertyElement in parameterElement.Elements.Values) { ReflectionServices.SetValue(commandParameter, propertyElement.GetAttributeReference("name").Value.ToString(), propertyElement.GetAttributeReference("value").Value); } parameters.Add(commandParameter); } }
/// <summary> Starts the Extension Service. </summary> public void Start() { if (_started) { return; } iLogger.Debug("Starting extension service"); IList <IPluginInfo> providedPlugins = PluginService.Instance.ProvidedPlugins; for (int i = -1; ++i != providedPlugins.Count;) { IPluginInfo plugin = providedPlugins[i]; Stream stream = plugin.Bundle.GetResourceAsStream(ExtensionFileName); if (stream == null) { continue; } // Create a parser and parse the stream ExtensionFileParser parser = ExtensionFileParser.GetInstance(stream); ExtensionPointMap map = parser.Parse(); // Map bundle to Configuration Elements IList <IConfigurationElement> cfgElements = new List <IConfigurationElement>(map.Count); using (IEnumerator <KeyValuePair <string, IList <IConfigurationElement> > > itr = map.GetEnumerator()) { while (itr.MoveNext()) { KeyValuePair <string, IList <IConfigurationElement> > entry = itr.Current; IList <IConfigurationElement> cfgElementSet = entry.Value; for (int j = -1; ++j != cfgElementSet.Count;) { IConfigurationElement cfgEl = cfgElementSet[j]; cfgElements.Add(cfgEl); } } } _bundleToConfigurationElementMap.Add(plugin.Bundle, cfgElements); // Merge the new elements to the existing ones _extensionPointMap.Merge(map); } _started = true; iLogger.Debug("Extension service started"); }
public IConfigurationElementAttribute GetAttributeReference(string element, string attribute) { if (string.IsNullOrEmpty(element)) { throw new ArgumentNullException(element); } if (string.IsNullOrEmpty(attribute)) { throw new ArgumentNullException(attribute); } IConfigurationElement elementRef = this.GetElementReference(element); return(elementRef.GetAttributeReference(attribute)); }
protected virtual void LoadCellProperties(TableCell cell, IConfigurationElement configCell) { if (ControlFactory.Instance.KnownTypes.ContainsKey("TableCell")) { ControlFactory.ControlDescriptor descriptor = ControlFactory.Instance.KnownTypes["TableCell"]; foreach (string name in descriptor.EditableProperties.Keys) { if (configCell.Attributes.ContainsKey(name)) { ReflectionServices.SetValue(cell, name, configCell.GetAttributeReference(name).Value); } } } }
public static IExpression Expression(this IExpressionsManager manager, XElement element) { Configuration config = new Configuration(); IConfigurationElement configElement = config.AddSection("expression extensions").AddElement("expression"); configElement.ReadXml(element.CreateReader()); IExpression expression = manager.Token(configElement.GetAttributeReference("type").Value.ToString()) as IExpression; if (null != expression) { expression.Make(configElement, manager); } return(expression); }
/// <summary> /// Creates an instance of <see cref="IPreferenceStoreManager"/>. First, it is looked up if a custom implementation /// is provided by an extension point. If not, a default implementation is returned. Otherwise the contribution with /// the highest priority is taken. There is always just one implementation of <see cref="IPreferenceStoreManager"/>. /// </summary> /// <returns> /// An instance of <see cref="IPreferenceStoreManager"/> either provided by an extension point or the /// default implementation. /// </returns> private static IPreferenceStoreManager CreatePreferenceStoreManager() { ILog logWriter = LogManager.GetLog(typeof(PreferenceStoreManager)); IConfigurationElement[] configurationElements = ExtensionService.Instance.GetConfigurationElements(PreferenceStoreManagerExtensionPointId); // Default if (configurationElements == null || configurationElements.Length == 0) { logWriter.Info("No preference store manager contributed. Using default implementation."); return(GetDefaultPreferenceStoreManager()); } // Max priority IConfigurationElement maxPriorityElement = configurationElements.OrderByDescending(element => { string priorityValue = element["priority"]; if (!int.TryParse(priorityValue, out int priority)) { return(0); } return(priority); }).First(); // Grab the bundle IBundle providingBundle = ExtensionService.Instance.GetProvidingBundle(maxPriorityElement); logWriter.Debug($"Plug-in '{providingBundle}' provides a custom preference store manager implementation with highest priority."); // Grab the type string className = maxPriorityElement["class"]; if (string.IsNullOrEmpty(className)) { logWriter.Error($"Plug-in '{providingBundle}' provides a custom preference store manager implementation with an empty " + "class attribute. Using default implementation."); return(GetDefaultPreferenceStoreManager()); } // Allocate try { Type instanceType = TypeLoader.TypeForName(providingBundle, className); IPreferenceStoreManager preferenceStoreManager = instanceType.NewInstance <IPreferenceStoreManager>(); logWriter.Info($"Preference store manager of type '{preferenceStoreManager.GetType()}' successfully installed"); return(preferenceStoreManager); } catch (Exception ex) { logWriter.Error($"Error on installing preference store manager from plug-in '{providingBundle}' (Class '{className}').", ex); return(GetDefaultPreferenceStoreManager()); } }
private void CopyConfigElement(IConfigurationElement fromSection, IConfigurationElement toSection) { foreach (IConfigurationSection fromChild in fromSection.GetChildren()) { IConfigurationSection toChild = toSection.CreateSection(fromChild.Key, fromChild.Type); if (fromChild.Type != SectionType.Object) { toChild.Set(fromChild.Get()); } else { CopyConfigElement(fromChild, toChild); } } }
/// <inheritdoc /> protected override void OnInitialize() { IConfigurationElement[] configurationElements = ExtensionService.Instance.GetConfigurationElements(ExtensionPointId); for (int i = -1; ++i != configurationElements.Length;) { IConfigurationElement element = configurationElements[i]; IBundle bundle = ExtensionService.Instance.GetProvidingBundle(element); string id = element.Id; string providerType = element["provider"]; string resourcePath = element["resourcePath"]; if (string.IsNullOrEmpty(id)) { _log.Error($"Bundle '{bundle}' declares a localization contribution with no id"); continue; } if (string.IsNullOrEmpty(providerType)) { _log.Error($"Bundle '{bundle}' declares the localization contribution '{id}' with no provider type"); continue; } if (string.IsNullOrEmpty(resourcePath)) { _log.Error($"Bundle '{bundle}' declares the localization contribution '{id}' with an empty resource path"); continue; } if (!_registry.TryGetValue(id, out LocalizationContribution localizationContribution)) { Type provider; try { provider = TypeLoader.TypeForName(bundle, providerType); } catch (Exception ex) { _log.Error($"Error on resolving type of '{providerType}' provided by bundle '{bundle}' for localization contribution '{id}'", ex); continue; } localizationContribution = new LocalizationContribution(id, provider); _registry.Add(id, localizationContribution); } ResourcePathReference resourcePathReference = new ResourcePathReference(localizationContribution.ProviderType.Assembly, resourcePath); localizationContribution.Sources.Add(resourcePathReference); } }
public static void ToConfiguration(this IToken token, IConfigurationElement config) { if (!config.Attributes.ContainsKey("type")) config.AddAttribute("type").Value = token.Key; else if ((string)config.GetAttributeReference("type").Value != token.Key) config.GetAttributeReference("type").Value = token.Key; IExpression expression = token as IExpression; if (null != expression) { IConfigurationElement operandsElement = config.AddElement("operands"); int index = 0; foreach (IToken operand in expression.Operands.Where(o => null != o)) { IConfigurationElement operandElement = operandsElement.AddElement(index.ToString()); operand.ToConfiguration(operandElement); index++; } } else { IBasicToken basicToken = token as IBasicToken; if (null != basicToken) { IConfigurationElement sourceElement = config.AddElement("source"); if (null != basicToken.Source) { if (basicToken.Source is Control) sourceElement.AddAttribute("id").Value = ((Control)basicToken.Source).ID; else sourceElement.AddAttribute("id").Value = basicToken.Source; if (!String.IsNullOrEmpty(basicToken.Member)) sourceElement.AddAttribute("member").Value = basicToken.Member; } else if (null != basicToken.Value) sourceElement.AddAttribute("value").Value = basicToken.Source; } else { System.Reflection.MethodInfo concreteMethod = token.GetType().GetMethod("ToConfiguration", new Type[] { typeof(IConfigurationElement) }); if (null != concreteMethod) concreteMethod.Invoke(token, new object[] { config }); } } }
protected virtual void Make(IConfigurationElement sourceElement, IExpressionsManager manager) { if (null == sourceElement) { throw new ArgumentNullException("sourceElement"); } if (null == manager) { throw new ArgumentNullException("manager"); } if (!sourceElement.Attributes.ContainsKey("field")) { throw new ConfigurationException("Bad views field token configuration: 'source' element has no 'field' attribute"); } this.FieldName = sourceElement.GetAttributeReference("field").Value.ToString(); }
public static void ToXml(this IExpression expression, XmlTextWriter writer) { if (null == expression) { throw new ArgumentNullException("expression"); } if (null == writer) { throw new ArgumentNullException("writer"); } Configuration config = new Configuration(); IConfigurationElement configElement = config.AddSection("expression extensions").AddElement("expression"); expression.ToConfiguration(configElement); configElement.WriteXml(writer); }
public virtual void DisplayItem(Table table, IConfigurationElement element, string index, IBinder binder, ITemplatingItem item, TableItemStyle style, TableItemStyle invalidStyle, WebPartManager manager) { this.DisplayItem(table, element, index, binder, item, style, invalidStyle, null, manager); }
protected virtual void WriteConfiguration(IConfigurationElement sourceElement) { if (null == sourceElement) throw new ArgumentNullException("sourceElement"); sourceElement.AddAttribute("field").Value = this.FieldName; }
public override void ToConfiguration(IConfigurationElement config) { if (null == config) throw new ArgumentNullException("config"); IConfigurationElement sourceElement = config.AddElement("source"); sourceElement.AddAttribute("parameter").Value = this.ParameterName; }
public virtual void DisplayItem(Table table, IConfigurationElement element, string index, IBinder binder, ITemplatingItem item, TableItemStyle style, TableItemStyle invalidStyle, Dictionary<string, Control> registry, WebPartManager manager) { string[] span = null; if (element.Attributes.ContainsKey("span") && null != element.GetAttributeReference("span").Value) span = element.GetAttributeReference("span").Value.ToString().Split(new char[] { ',' }); string[] rowspan = null; if (element.Attributes.ContainsKey("rowspan") && null != element.GetAttributeReference("rowspan").Value) rowspan = element.GetAttributeReference("rowspan").Value.ToString().Split(new char[] { ',' }); TableRow tr = new TableRow(); tr.ID = string.Concat(new string[] { table.ID, "-", element.ConfigKey, "-", index }); tr.Attributes["key"] = element.ConfigKey; tr.ApplyStyle(style); foreach (IConfigurationElementAttribute attribute in element.Attributes.Values) { if ("span" != attribute.ConfigKey && "rowspan" != attribute.ConfigKey) { tr.Style.Add(attribute.ConfigKey, attribute.Value.ToString()); } } table.Rows.Add(tr); int count = 0; foreach (IConfigurationElement controlElement in element.Elements.Values) { TableCell tc = new TableCell(); tc.ID = tr.ID + "-" + controlElement.ConfigKey; tc.Attributes["key"] = controlElement.ConfigKey; if (span != null && span.Length > count) { int columnSpan = 1; int.TryParse(span[count], out columnSpan); tc.ColumnSpan = columnSpan; if (rowspan != null && rowspan.Length > count) { int rowSpan = 1; int.TryParse(rowspan[count], out rowSpan); tc.RowSpan = rowSpan; } count++; } tr.Cells.Add(tc); string pullpush = null; foreach (IConfigurationElement propertyElement in controlElement.Elements.Values) { if (propertyElement.Attributes.ContainsKey("for") && "cell" == propertyElement.GetAttributeReference("for").Value.ToString() && propertyElement.Attributes.ContainsKey("member") && propertyElement.Attributes.ContainsKey("value")) { try { ReflectionServices.SetValue(tc, propertyElement.GetAttributeReference("member").Value.ToString(), propertyElement.GetAttributeReference("value").Value); } catch (Exception ex) { ControlFactory.Instance.Monitor.Register(ControlFactory.Instance, ControlFactory.Instance.Monitor.NewEventInstance("set cell attributes error", null, ex, EVENT_TYPE.Error)); } } if (propertyElement.Attributes.ContainsKey("pull")) { pullpush = propertyElement.GetAttributeReference("pull").Value.ToString(); } else { if (propertyElement.Attributes.ContainsKey("push")) { pullpush = propertyElement.GetAttributeReference("push").Value.ToString(); } } } Control cellControl = ControlFactory.Instance.CreateControl(controlElement, index, binder, item, tc, invalidStyle, registry, manager); if (null != cellControl) { cellControl.ID = string.Concat(new string[] { table.ID, "-", element.ConfigKey, "-", index, "-", controlElement.ConfigKey, "-ctrl" }); tc.Controls.Add(cellControl); if (cellControl is BaseDataBoundControl && !string.IsNullOrEmpty(pullpush)) { if (!item.BoundControls.ContainsKey(pullpush)) { item.BoundControls.Add(pullpush, new List<BaseDataBoundControl>()); } item.BoundControls[pullpush].Add((BaseDataBoundControl)cellControl); } } } }
private void AssertAreEqual(IConfigurationElement expected, IConfigurationElement actual) { Assert.AreEqual(expected.Name, actual.Name); Assert.AreEqual(expected.Attributes.Count, actual.Attributes.Count); Assert.AreEqual(expected.Attributes.Keys.Count, actual.Attributes.Keys.Intersect(expected.Attributes.Keys).Count()); expected.Attributes.Keys.ForEach(x => Assert.AreEqual(expected.Attributes[x], actual.Attributes[x])); }
private TransitPoint CreateTransitPoint(WebPartManager manager, IConfigurationElement element, IExpressionsManager expressionsManager) { bool valid = false; TransitPoint transitPoint = new TransitPoint(); if (element.Attributes.ContainsKey("id")) { valid = true; transitPoint.Chronicler = (ReflectionServices.FindControlEx(element.GetAttributeReference("id").Value.ToString(), manager) as IChronicler); } if (element.Attributes.ContainsKey("member")) { transitPoint.Member = element.GetAttributeReference("member").Value.ToString(); } if (element.Attributes.ContainsKey("value")) { valid = true; transitPoint.Value = element.GetAttributeReference("value").Value; } if (element.Elements.ContainsKey("expression")) { valid = true; IConfigurationElement expressionElement = element.GetElementReference("expression"); IExpression expression = expressionsManager.Token(expressionElement.GetAttributeReference("type").Value.ToString()) as IExpression; if (null == expression) throw new InvalidOperationException("Token is not an IExpression"); expression.Make(expressionElement, expressionsManager); transitPoint.Expression = expression; } if (!valid) transitPoint = null; return transitPoint; }
public void TestSetup() { _id = 8; _name = "Test Config"; _configurationMock = MockRepository.GenerateMock<IRootConfigurationElement>(); _configurationMock.Stub(x => x.Name).Return(_name); _configurationMock.Id = _id; _configurationChildMock = MockRepository.GenerateMock<IConfigurationElement>(); _configurationChildMock.Stub(x => x.Name).Return("Child"); _configurationMock.Stub(x => x.Children).Return(new List<IConfigurationElement>(new [] { _configurationChildMock })); _configurationMock.Stub(x => x.Attributes).Return(new Dictionary<string, string>() { { "Attribute One", "Value One" }, { "Attribute Two", "Value Two" } }); _locatorMock = MockRepository.GenerateMock<IConfigurationResourceLocator>(); _locatorMock.Stub(x => x.Locate(Arg<string>.Is.NotEqual(_name))).Return(new IConfigurationElement[] { }); _locatorMock.Stub(x => x.Locate(Arg<string>.Is.Equal(_name))).Return(new IConfigurationElement[] { _configurationMock }); _watcherMock = MockRepository.GenerateMock<IConfigurationResourceWatcher>(); _repository = new WatchingConfigurationRepository(_locatorMock, _watcherMock); _locatorMock.Stub(x => x.Locate(Arg<string>.Is.Equal(_name))).Return(new[] { _configurationMock }); }
public Control CreateControl(IConfigurationElement controlElement, string index, IBinder binder, ITemplatingItem item, WebControl container, TableItemStyle invalidStyle, Dictionary<string, Control> registry, WebPartManager manager) { if (null == this._monitor) { throw new ApplicationException("Monitor not set"); } Control result; if (!controlElement.Attributes.ContainsKey("proxy") && !controlElement.Attributes.ContainsKey("type")) { result = null; } else { Control cellControl = null; string cellControlName = null; if (controlElement.Attributes.ContainsKey("proxy")) { object proxyIDValue = controlElement.GetAttributeReference("proxy").Value; string proxyID = null; if (null != proxyIDValue) { proxyID = proxyIDValue.ToString(); } if (string.IsNullOrEmpty(proxyID)) { result = null; return result; } Control proxy = ReflectionServices.FindControlEx(proxyID, manager); if (null == proxy) { this._monitor.Register(this, this._monitor.NewEventInstance("create proxy error", null, new ApplicationException("can't find proxy " + proxyID), EVENT_TYPE.Error)); } string proxyMember = null; if (!controlElement.Attributes.ContainsKey("proxyMember")) { this._monitor.Register(this, this._monitor.NewEventInstance("create proxy error", null, new ApplicationException("proxyMember not found for proxy " + proxyID), EVENT_TYPE.Error)); } else { proxyMember = controlElement.GetAttributeReference("proxyMember").Value.ToString(); } try { cellControl = (ReflectionServices.ExtractValue(proxy, proxyMember) as Control); cellControlName = proxy + "." + proxyMember; } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance("create proxy error", null, ex, EVENT_TYPE.Error)); } if (cellControl == null && null != proxy) { this._monitor.Register(this, this._monitor.NewEventInstance("create proxy error", null, new ApplicationException(string.Format("member {0} of proxy type {1} is not a Control", proxyMember, proxy.GetType().FullName)), EVENT_TYPE.Error)); } } else { Control scope = container; if (container is TableCell) { scope = container.Parent.Parent; } try { cellControl = this.CreateControl(controlElement.GetAttributeReference("type").Value.ToString(), new bool?(item == null || item.IsReadOnly), scope); cellControlName = controlElement.GetAttributeReference("type").Value.ToString(); } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance("create control error", null, ex, EVENT_TYPE.Error)); } } if (null == cellControl) { result = null; } else { string type = null; if (controlElement.Attributes.ContainsKey("type")) { type = controlElement.GetAttributeReference("type").Value.ToString(); if (cellControl is IButtonControl) { IButtonControl btn = cellControl as IButtonControl; if (("Commander" == type || "LinkCommander" == type) && !controlElement.Attributes.ContainsKey("command")) { this._monitor.Register(this, this._monitor.NewEventInstance(string.Format("create {0} error", type), null, new ApplicationException("command not found"), EVENT_TYPE.Error)); } else { if (controlElement.Attributes.ContainsKey("command")) { btn.CommandName = controlElement.GetAttributeReference("command").Value.ToString(); } } btn.CommandArgument = index; } if (cellControl is StatelessDropDownList) ((StatelessDropDownList)cellControl).CommandArgument = index; } if (null != registry) { registry.Add(controlElement.ConfigKey, cellControl); } var properties = controlElement.Elements.Values; foreach (IConfigurationElement controlPropertyElement in properties) { if (!controlPropertyElement.Attributes.ContainsKey("for") || !("cell" == controlPropertyElement.GetAttributeReference("for").Value.ToString())) { string propertyName = null; if (!controlPropertyElement.Attributes.ContainsKey("member")) { this._monitor.Register(this, this._monitor.NewEventInstance(string.Format("'{0}' property set error", cellControlName), null, new ApplicationException(string.Format("member not found for '{0}'", controlPropertyElement.ConfigKey)), EVENT_TYPE.Error)); } else { propertyName = controlPropertyElement.GetAttributeReference("member").Value.ToString(); } IExpression expression = null; LWAS.Extensible.Interfaces.IResult expressionResult = null; if (controlPropertyElement.Elements.ContainsKey("expression")) { IConfigurationElement expressionElement = controlPropertyElement.GetElementReference("expression"); Manager sysmanager = manager as Manager; if (null != sysmanager && null != sysmanager.ExpressionsManager && expressionElement.Attributes.ContainsKey("type")) { expression = sysmanager.ExpressionsManager.Token(expressionElement.GetAttributeReference("type").Value.ToString()) as IExpression; if (null != expression) { try { expression.Make(expressionElement, sysmanager.ExpressionsManager); expressionResult = expression.Evaluate(); } catch (ArgumentException ax) { } } } } object defaultValue = null; if (!string.IsNullOrEmpty(propertyName) && controlPropertyElement.Attributes.ContainsKey("value")) { defaultValue = controlPropertyElement.GetAttributeReference("value").Value; if (null == expression || null == binder) { try { if (string.IsNullOrEmpty(cellControlName) || propertyName != this.KnownTypes[cellControlName].ReadOnlyProperty || (propertyName == this.KnownTypes[cellControlName].ReadOnlyProperty && defaultValue != null && !string.IsNullOrEmpty(defaultValue.ToString()))) { if (propertyName == "Watermark") { if (null != defaultValue && !String.IsNullOrEmpty(defaultValue.ToString())) ReflectionServices.SetValue(cellControl, propertyName, defaultValue); } else ReflectionServices.SetValue(cellControl, propertyName, defaultValue); } } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance(string.Format("'{0}'.'{1}'='{2}' error", cellControlName, propertyName, controlPropertyElement.GetAttributeReference("value").Value), null, ex, EVENT_TYPE.Error)); } } else { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = new Dictionary<string, object>() { { "0", defaultValue} }; bindingItem.SourceProperty = "0"; bindingItem.Target = cellControl; bindingItem.TargetProperty = propertyName; bindingItem.Expression = expression; bindingItem.ExpressionEvaluationResult = expressionResult; binder.BindingItems.Add(bindingItem); } } if (controlPropertyElement.Attributes.ContainsKey("isList") && (bool)controlPropertyElement.GetAttributeReference("isList").Value) { object list = null; try { list = ReflectionServices.ExtractValue(cellControl, propertyName); if (null == list) throw new InvalidOperationException(string.Format("Member '{0}' is empty", propertyName)); if (!(list is ListItemCollection) && !(list is IDictionary<string, object>)) throw new InvalidOperationException(String.Format("Unsupported list type '{0}'", list.GetType().Name)); } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance("failed to retrive the list", null, ex, EVENT_TYPE.Error)); } if (null != list) { if (controlPropertyElement.Attributes.ContainsKey("hasEmpty") && (bool)controlPropertyElement.GetAttributeReference("hasEmpty").Value) { if (list is ListItemCollection) ((ListItemCollection)list).Add(""); else if (list is Dictionary<string, object>) ((Dictionary<string, object>)list).Add("", ""); } foreach (IConfigurationElement listItemElement in controlPropertyElement.Elements.Values) { string value = null; string text = null; string pull = null; if (listItemElement.Attributes.ContainsKey("value") && null != listItemElement.GetAttributeReference("value").Value) value = listItemElement.GetAttributeReference("value").Value.ToString(); if (listItemElement.Attributes.ContainsKey("text") && null != listItemElement.GetAttributeReference("text").Value) text = listItemElement.GetAttributeReference("text").Value.ToString(); if (listItemElement.Attributes.ContainsKey("pull") && null != listItemElement.GetAttributeReference("pull").Value) pull = listItemElement.GetAttributeReference("pull").Value.ToString(); if (list is ListItemCollection) { ListItem li = new ListItem(text, value); ((ListItemCollection)list).Add(li); if (null != binder && !String.IsNullOrEmpty(pull)) { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = item.Data; bindingItem.SourceProperty = pull; bindingItem.Target = li; bindingItem.TargetProperty = "Text"; bindingItem.Expression = expression; binder.BindingItems.Add(bindingItem); } } else if (list is Dictionary<string, object>) { ((Dictionary<string, object>)list).Add(value, text); if (null != binder && !String.IsNullOrEmpty(pull)) { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = item.Data; bindingItem.SourceProperty = pull; bindingItem.Target = list; bindingItem.TargetProperty = value; bindingItem.Expression = expression; binder.BindingItems.Add(bindingItem); } } } } } if (controlPropertyElement.Attributes.ContainsKey("property")) { if (container.Page != null && null != binder) { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = WebPartManager.GetCurrentWebPartManager(container.Page); bindingItem.SourceProperty = "WebParts." + controlPropertyElement.GetAttributeReference("property").Value.ToString(); bindingItem.Target = cellControl; bindingItem.TargetProperty = propertyName; if (string.IsNullOrEmpty(cellControlName) || propertyName != this.KnownTypes[cellControlName].ReadOnlyProperty) bindingItem.DefaultValue = defaultValue; bindingItem.Expression = expression; binder.BindingItems.Add(bindingItem); } } if (controlPropertyElement.Attributes.ContainsKey("pull")) { string pull = controlPropertyElement.GetAttributeReference("pull").Value.ToString(); if (binder != null && null != item) { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = item.Data; bindingItem.SourceProperty = pull; bindingItem.Target = cellControl; bindingItem.TargetProperty = propertyName; if (string.IsNullOrEmpty(cellControlName) || propertyName != this.KnownTypes[cellControlName].ReadOnlyProperty) bindingItem.DefaultValue = defaultValue; bindingItem.Expression = expression; binder.BindingItems.Add(bindingItem); if (item.InvalidMember == bindingItem.SourceProperty) container.ApplyStyle(invalidStyle); } if (this.IsDesignEnabled && propertyName == this.KnownTypes[cellControlName].WatermarkProperty) { // StyleTextBox has its own Watermark feature if (typeof(StyledTextBox).IsInstanceOfType(cellControl)) { ReflectionServices.SetValue(cellControl, "Watermark", pull); } else container.Attributes.Add("watermark", pull); } } } } result = cellControl; } } return result; }
protected override void Make(IConfigurationElement sourceElement, IExpressionsManager manager) { if (null == sourceElement) throw new ArgumentNullException("sourceElement"); if (null == manager) throw new ArgumentNullException("manager"); if (!sourceElement.Attributes.ContainsKey("view")) throw new ConfigurationException("Bad view as token configuration: 'source' element has no 'view' attribute"); this.ViewName = sourceElement.GetAttributeReference("view").Value.ToString(); base.Make(sourceElement, manager); }
public void Initialize() { ConfigureFromCanConfigurables(); InitializeCulture(); var initializers = new IConfigurationElement[] { Serialization, Commands, Events, Tasks, Views, Sagas, Frontend, CallContext, ExecutionContext, Security, DefaultStorage, }; Parallel.ForEach(initializers, i => i.Initialize(Container)); ConfigurationDone(); }
private BoundField GetField(IConfigurationElement element) { if (element.Attributes.ContainsKey("type")) { string type = element.Attributes["type"].Value.ToString(); BoundField field; switch (type) { case "Text": { field = new BoundField(); break; } case "Label": { field = new BoundField(); field.ReadOnly = true; break; } case "Date": { field = new DateBoundField(); break; } case "Number": { field = new NumberBoundField(); break; } case "DropDownList": { field = new DropDownListField(); break; } case "CheckBox": case "Check": { field = new CheckBoxField(); break; } case "Hidden": { field = new BoundField(); field.ItemStyle.CssClass = "hidden"; break; } default: { throw new ArgumentException("Unknown grid view field type '" + element.Attributes["type"].Value.ToString() + "'"); } } if (!(field is CheckBoxField)) { field.HtmlEncode = false; } if (element.Attributes.ContainsKey("DataMember")) field.DataField = element.Attributes["DataMember"].Value.ToString(); ; if (element.Attributes.ContainsKey("HeaderText")) field.HeaderText = element.Attributes["HeaderText"].Value.ToString(); ; if (element.Attributes.ContainsKey("FormatString")) { try { field.DataFormatString = element.Attributes["FormatString"].Value.ToString(); } catch { } } if (field is DropDownListField) { if (element.Attributes.ContainsKey("DataTextField")) { ((DropDownListField)field).DataTextField = element.GetAttributeReference("DataTextField").Value.ToString(); } if (element.Attributes.ContainsKey("DataValueField")) { ((DropDownListField)field).DataValueField = element.GetAttributeReference("DataValueField").Value.ToString(); } } return field; } return null; }
private void AddAttributes(IConfigurationElement commandElement) { commandElement.AddAttribute("text").Value = ""; commandElement.AddAttribute("type").Value = SqlDataSourceCommandType.Text; }
public abstract void ToConfiguration(IConfigurationElement config);