public virtual bool SetConfigProperties() { bool result = true; if (Instance != null) { Type type = Instance.GetType(); IEnumerator enumerator = Properties.GetEnumerator(); while (enumerator.MoveNext()) { ConfigurationProperty configProperty = enumerator.Current as ConfigurationProperty; PropertyInfo property = type.GetProperty(configProperty.Name); if (property != null) { ConfigureAttribute configAttribute = property.GetCustomAttribute(typeof(ConfigureAttribute)) as ConfigureAttribute; if (configAttribute != null) { if (property.PropertyType != typeof(string) && (string.IsNullOrWhiteSpace(this[configProperty] as string))) { continue; } object configValue = Convert.ChangeType(this[configProperty.Name], property.PropertyType); if (!(configAttribute.DefaultValue.Equals(configValue))) { property.SetValue(Instance, configValue); } } } } } return(result); }
protected virtual bool InitializeProperty(PropertyInfo property) { bool result = false; if (property != null) { Type propertyType = property.PropertyType; ConfigureAttribute configure = property.GetCustomAttribute(typeof(ConfigureAttribute)) as ConfigureAttribute; MethodInfo getMethod = property.GetGetMethod(); object value = null; if ((getMethod != null) && (getMethod.GetParameters().Count() == 0)) { value = property.GetValue(this); } if ((configure == null) && (value != null)) { if ((value as IInitiator) != null) { (value as IInitiator).Initialize(); } } else if ((configure != null) && (value == null)) { if (configure.AutoInit()) { if (configure.InitTypeTemplateCnt > 0) { InitializeTemplateTypes(configure, property); } else { property.SetValue(this, Activator.CreateInstance(configure.InitType)); } } else { property.SetValue(this, configure.DefaultValue); } value = property.GetValue(this); } if ((value as IInitiator) != null) { ((IInitiator)value).Initialize(); } result = true; } return(result); }
/// <summary> /// Gets the service bus details from t. /// </summary> /// <param name="domainType">Type of the domain.</param> /// <returns></returns> static ServiceBusDetails GetServiceBusDetailsFromT(Type domainType) { ServiceBusDetails serviceBusDetails = new ServiceBusDetails(); ConfigureAttribute customAttribute = (ConfigureAttribute)Attribute.GetCustomAttribute(domainType, typeof(ConfigureAttribute)); if (customAttribute != null && !string.IsNullOrEmpty(customAttribute.Connection)) { if (_eventBusConfiguration != null) { _eventBusConfiguration.TryGet(customAttribute.Connection, out string serviceBusConnection); if (!string.IsNullOrEmpty(serviceBusConnection)) { serviceBusDetails.Connection = serviceBusConnection; serviceBusDetails.TopicName = customAttribute.TopicName; serviceBusDetails.EventId = customAttribute.EventId; //serviceBusDetails.ProducerId = (Int16)_domainManager.ServiceType; //serviceBusDetails.ProducerApplicationId = (Int16)_domainManager.ApplicationType; Dictionary <string, string> dict = serviceBusConnection.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) .Select(part => part.Split(new[] { '=' }, 2)) .ToDictionary(split => split[0], split => split[1]); serviceBusDetails.ServiceBusNamespace = dict["Endpoint"].Split("//")[1].Split('.')[0]; serviceBusDetails.SharedAccessKeyName = dict["SharedAccessKeyName"]; serviceBusDetails.SharedAccessKey = dict["SharedAccessKey"]; serviceBusDetails.Endpoint = dict["Endpoint"].Split("//")[1].Split('/')[0]; //// version wise event bus: if EventTypeVersion == 0 then consider version = 1 else set subscription name based on version defined in ConfigureAttribute serviceBusDetails.EventTypeVersion = customAttribute.EventTypeVersion; if (serviceBusDetails.EventTypeVersion == 0) { serviceBusDetails.EventTypeVersion = 1; } //serviceBusDetails.Subscription = $"{_domainManager.ServiceType.ToString().ToLower()}_{customAttribute.EventId.ToString()}_v{customAttribute.EventTypeVersion.ToString()}"; serviceBusDetails.Subscription = "solution-logs-subs-qa"; serviceBusDetails.QueueName = customAttribute.QueueName; } } } return(serviceBusDetails); }
protected virtual bool InitializeProperties(System.Collections.IEnumerator enumerator, bool preInit = false) { bool result = true; while (enumerator.MoveNext() && result) { PropertyInfo current = enumerator.Current as PropertyInfo; ConfigureAttribute configAttribute = (current.GetCustomAttribute(typeof(ConfigureAttribute)) as ConfigureAttribute); if (preInit && (configAttribute != null) && configAttribute.PreInit) { result = InitializeProperty(enumerator.Current as PropertyInfo); } else if (((!preInit) && (configAttribute == null)) || ((configAttribute != null) && (!configAttribute.PreInit))) { result = InitializeProperty(enumerator.Current as PropertyInfo); } } return(result); }
protected virtual bool InitializeTemplateTypes(ConfigureAttribute config, PropertyInfo property) { bool result = false; if (this.GetType().GenericTypeArguments.Count() >= (config.InitTypeTemplateCnt - config.InitTypeParameters.Count())) { int i = 0; while (config.InitTypeParameters.Count() < config.InitTypeTemplateCnt) { config.InitTypeParameters.Add(this.GetType().GenericTypeArguments[i]); i++; } if (config.InitType.IsGenericTypeDefinition) { config.InitType = config.InitType.MakeGenericType(config.InitTypeParameters.ToArray()); } property.SetValue(this, Activator.CreateInstance(config.InitType)); result = true; } return(result); }
public virtual bool SetFullProperties() { bool result = true; IEnumerator enumerator = PropertyConfigCollection.GetEnumerator(); while (enumerator.MoveNext()) { PropertyConfig propertyConfig = enumerator.Current as PropertyConfig; if (propertyConfig != null) { if (propertyConfig.Original || string.IsNullOrWhiteSpace(propertyConfig.Key)) { PropertyInfo property = Instance.GetType().GetProperty(propertyConfig.Name); ConfigureAttribute configAttribute = property.GetCustomAttribute(typeof(ConfigureAttribute)) as ConfigureAttribute; if (configAttribute != null) { if (property.PropertyType != typeof(string) || (!string.IsNullOrWhiteSpace(propertyConfig.Value))) { object configValue = Convert.ChangeType(propertyConfig.Value, property.PropertyType); if (!(configAttribute.DefaultValue.Equals(configValue))) { property.SetValue(Instance, configValue); } } } IEnumerator members = propertyConfig.PropertyMembers.GetEnumerator(); while (members.MoveNext()) { PropertyConfig member = members.Current as PropertyConfig; member.Parent.SetProperty(propertyConfig); } } } } return(result); }
public AttributeObject(ConfigureAttribute attribute) { Name = attribute.Name; FatherName = attribute.FatherName; data = attribute.Parameters; }