protected virtual void PersistConnectorSettings() { var connectorSettingDictionary = Context.ConnectorSettings.ToDictionary(connectorSetting => connectorSetting.SettingKey, StringComparer.CurrentCultureIgnoreCase); TraverseConnectorSettingAttributeMembers((memberInfo, connectorSettingAttribute) => { var connectorSetting = default(ConnectorSetting); if (connectorSettingDictionary.TryGetValue(connectorSettingAttribute.SettingKey, out connectorSetting)) { var memberValue = default(Object); switch (memberInfo.MemberType) { case MemberTypes.Field: memberValue = ((FieldInfo)memberInfo).GetValue(this); break; case MemberTypes.Property: memberValue = ((PropertyInfo)memberInfo).GetValue(this, null); break; } connectorSetting.Value = TypeConverterService.ConvertToString(memberValue); } }); Unit.Save(); }
public virtual TResult GetVendorSetting <TResult>(String settingKey, CultureInfo culture, TResult defaultValue = default(TResult)) { var value = GetVendorSetting(settingKey); return(value != null ? TypeConverterService.ConvertFromString <TResult>(value, culture) : defaultValue); }
public static TResult Get <TResult>(this IDataReader dataReader, Int32 index, CultureInfo cultureInfo = null) { var value = dataReader.GetValue(index); return(value != DBNull.Value ? TypeConverterService.ConvertFrom <TResult>(value, cultureInfo) : TypeConverterService.ConvertFrom <TResult>(null, cultureInfo)); }
protected virtual void ParseQuery() { var query = new Dictionary <String, String>(Request.Query as IDictionary <String, String>, StringComparer.CurrentCultureIgnoreCase); foreach (var propertyInfo in GetType().GetProperties(Bindings | BindingFlags.SetProperty)) { var queryAttribute = propertyInfo .GetCustomAttributes(true) .OfType <QueryAttribute>() .SingleOrDefault(); if (queryAttribute != null) { var parameter = queryAttribute.Parameter ?? propertyInfo.Name; var parameterValue = TypeConverterService.ConvertFromString(propertyInfo.PropertyType, query.GetValueOrDefault(parameter, String.Empty)); propertyInfo.SetValue(this, parameterValue, null); } } }
public void Upsert(ConnectorProductAttributeMapping connectorProductAttributeMapping) { Validate(connectorProductAttributeMapping); ValidateProperties(connectorProductAttributeMapping.Properties); var status = ConnectorProductAttributeRepository.Upsert(new ConnectorProductAttribute { ConnectorID = connectorProductAttributeMapping.Connector.ConnectorID, DefaultValue = TypeConverterService.Default[connectorProductAttributeMapping.ProductAttributeType].ConvertToString(connectorProductAttributeMapping.DefaultValue), IsFilter = connectorProductAttributeMapping.IsFilter, ProductAttributeID = connectorProductAttributeMapping.ProductAttribute.AttributeID, ProductAttributeType = connectorProductAttributeMapping.ProductAttributeType.FullName }); var connectorProductAttribute = ConnectorProductAttributeRepository.GetSingle( connectorProductAttributeMapping.Connector.ConnectorID, connectorProductAttributeMapping.ProductAttribute.AttributeID, connectorProductAttributeMapping.IsFilter); if (status == RepositoryOperationStatus.Created) { foreach (var connectorProductAttributeSettingTemplate in ConnectorProductAttributeSettingTemplateRepository.GetMultiple(connectorProductAttributeMapping.Connector.ConnectorSystemID)) { var templateSettingCode = connectorProductAttributeSettingTemplate.Code; if (!connectorProductAttributeMapping.Properties.ContainsKey(templateSettingCode)) { var templateSettingType = Type.GetType(connectorProductAttributeSettingTemplate.Type); if (templateSettingType != null) { var templateSettingValue = TypeConverterService.ConvertFromString(templateSettingType, connectorProductAttributeSettingTemplate.Value); connectorProductAttributeMapping.Properties[templateSettingCode] = templateSettingValue; } } } } SynchronizeProperties(connectorProductAttribute, connectorProductAttributeMapping.Properties); }
public IEnumerable <ConnectorProductAttributeMapping> Get(Int32?connectorID, Int32?productAttributeID, Boolean?isFilter) { var connectorProductAttributes = ConnectorProductAttributeRepository .GetMultiple(connectorID, productAttributeID, isFilter) .ToArray(); foreach (var connectorProductAttribute in connectorProductAttributes) { var connectorProductAttributeSettings = ConnectorProductAttributeSettingRepository .GetMultiple(connectorProductAttribute.ConnectorProductAttributeID) .ToArray(); var settingTypesByCode = connectorProductAttributeSettings.ToDictionary( connectorProductAttributeSetting => connectorProductAttributeSetting.Code, connectorProductAttributeSetting => Type.GetType(connectorProductAttributeSetting.Type)); if (settingTypesByCode.Any(pair => pair.Value == null)) { throw new Exception("One or more types could not be found:\r\n" + String.Join(Environment.NewLine, settingTypesByCode .Where(pair => pair.Value == null) .Select(pair => String.Format(" - Code: '{0}', Type: '{1}'", pair.Key, pair.Value)) .ToArray())); } var properties = connectorProductAttributeSettings.ToDictionary( settting => settting.Code, setting => TypeConverterService.ConvertFromString(settingTypesByCode[setting.Code], setting.Value)); var productAttributeType = Type.GetType(connectorProductAttribute.ProductAttributeType); yield return(new ConnectorProductAttributeMapping(properties) { Connector = ConnectorRepository.GetSingle(connector => connector.ConnectorID == connectorProductAttribute.ConnectorID), DefaultValue = TypeConverterService.ConvertFromString(productAttributeType, connectorProductAttribute.DefaultValue), IsFilter = connectorProductAttribute.IsFilter, ProductAttribute = ProductAttributeRepository.GetSingle(productAttribute => productAttribute.AttributeID == connectorProductAttribute.ProductAttributeID), ProductAttributeType = Type.GetType(connectorProductAttribute.ProductAttributeType) }); } }
/// <summary> /// Apply the connector setting values to each field or property decorated with the <see cref="Concentrator.Tasks.ConnectorSettingAttribute"/> using the current connector. /// </summary> protected virtual Boolean ApplyConnectorSettings() { var connectorSettingDictionary = Context.ConnectorSettings.ToDictionary( connectorSetting => connectorSetting.SettingKey, connectorSetting => connectorSetting.Value, StringComparer.CurrentCultureIgnoreCase); var result = true; TraverseConnectorSettingAttributeMembers((memberInfo, connectorSettingAttribute) => { var memberType = default(Type); switch (memberInfo.MemberType) { case MemberTypes.Field: memberType = ((FieldInfo)memberInfo).FieldType; break; case MemberTypes.Property: memberType = ((PropertyInfo)memberInfo).PropertyType; break; } var connectorSettingValue = String.Empty; var memberValue = connectorSettingAttribute.DefaultValue; if (connectorSettingDictionary.TryGetValue(connectorSettingAttribute.SettingKey, out connectorSettingValue)) { try { memberValue = TypeConverterService.ConvertFromString(memberType, connectorSettingValue); } catch (Exception exception) { result = false; TraceCritical(exception); } } else if (connectorSettingAttribute.IsRequired) { result = false; TraceError("{0}: Connector setting '{1}' is required, but is not defined.", Context.Name, connectorSettingAttribute.SettingKey); } switch (memberInfo.MemberType) { case MemberTypes.Field: ((FieldInfo)memberInfo).SetValue(this, memberValue); break; case MemberTypes.Property: ((PropertyInfo)memberInfo).SetValue(this, memberValue, null); break; } }); return(result); }