/// <summary> /// Get the result properties and the subMap properties. /// </summary> /// <param name="configScope"></param> private void GetChildNode(ConfigurationScope configScope) { ResultProperty mapping = null; SubMap subMap = null; #region Load the parameters constructor XmlNodeList nodeList = configScope.NodeContext.SelectNodes(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_CONSTRUCTOR_ARGUMENT), configScope.XmlNamespaceManager); if (nodeList.Count > 0) { Type[] parametersType = new Type[nodeList.Count]; string[] parametersName = new string[nodeList.Count]; for (int i = 0; i < nodeList.Count; i++) { ArgumentProperty argumentMapping = ArgumentPropertyDeSerializer.Deserialize(nodeList[i], configScope); _parameters.Add(argumentMapping); parametersName[i] = argumentMapping.ArgumentName; } ConstructorInfo constructorInfo = this.GetConstructor(_class, parametersName); for (int i = 0; i < _parameters.Count; i++) { ArgumentProperty argumentMapping = (ArgumentProperty)_parameters[i]; configScope.ErrorContext.MoreInfo = "initialize argument property : " + argumentMapping.ArgumentName; argumentMapping.Initialize(configScope, constructorInfo); parametersType[i] = argumentMapping.MemberType; } // Init the object factory _objectFactory = configScope.SqlMapper.ObjectFactory.CreateFactory(_class, parametersType); } else { if (Type.GetTypeCode(_class) == TypeCode.Object) { _objectFactory = configScope.SqlMapper.ObjectFactory.CreateFactory(_class, Type.EmptyTypes); } } #endregion #region Load the Result Properties foreach (XmlNode resultNode in configScope.NodeContext.SelectNodes(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_RESULT), configScope.XmlNamespaceManager)) { mapping = ResultPropertyDeSerializer.Deserialize(resultNode, configScope); configScope.ErrorContext.MoreInfo = "initialize result property: " + mapping.PropertyName; mapping.Initialize(configScope, _class); _properties.Add(mapping); } #endregion #region Load the Discriminator Property XmlNode discriminatorNode = configScope.NodeContext.SelectSingleNode(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_DISCRIMNATOR), configScope.XmlNamespaceManager); if (discriminatorNode != null) { configScope.ErrorContext.MoreInfo = "initialize discriminator"; this.Discriminator = DiscriminatorDeSerializer.Deserialize(discriminatorNode, configScope); this.Discriminator.SetMapping(configScope, _class); } #endregion #region Load the SubMap Properties if (configScope.NodeContext.SelectNodes(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_SUBMAP), configScope.XmlNamespaceManager).Count > 0 && this.Discriminator == null) { throw new ConfigurationException("The discriminator is null, but somehow a subMap was reached. This is a bug."); } foreach (XmlNode resultNode in configScope.NodeContext.SelectNodes(DomSqlMapBuilder.ApplyMappingNamespacePrefix(XML_SUBMAP), configScope.XmlNamespaceManager)) { configScope.ErrorContext.MoreInfo = "initialize subMap"; subMap = SubMapDeSerializer.Deserialize(resultNode, configScope); this.Discriminator.Add(subMap); } #endregion }
/// <summary> /// /// </summary> /// <param name="configScope"></param> public IsEmptyDeSerializer(ConfigurationScope configScope) { _configScope = configScope; }
public IsNotEmptyDeSerializer(ConfigurationScope configScope) { this._configScope = configScope; }
/// <summary> /// /// </summary> /// <param name="configScope"></param> public IterateSerializer(ConfigurationScope configScope) { _configScope = configScope; }
/// <summary> /// /// </summary> /// <param name="configScope"></param> public IsGreaterThanDeSerializer(ConfigurationScope configScope) { _configScope = configScope; }
/// <summary> /// /// </summary> /// <param name="configScope"></param> public IsNotParameterPresentDeSerializer(ConfigurationScope configScope) { _configScope = configScope; }
internal static extern bool SteamAPI_ISteamNetworkingUtils_SetConfigValue(IntPtr utils, ConfigurationValue configurationValue, ConfigurationScope configurationScope, IntPtr scopeObject, ConfigurationDataType dataType, IntPtr value);
private void Configure <TConfiguration, TSpecification>(Func <TConfiguration> constructorFunction, ConfigurationScope scope) where TSpecification : TConfiguration { if (constructorFunction == null) { throw new ArgumentException("Constructor function cannot be null."); } var injectionSpecification = GetNewInjectionSpecification <TConfiguration, TSpecification>(scope, ConfigurationStyle.ConstructorFunction); injectionSpecification.ConstructorFunction = constructorFunction(); StoreInjectionSpecification(injectionSpecification); }
/// <summary> /// Build the properties /// </summary> /// <param name="scope"></param> public void BuildProperties(ConfigurationScope scope) { GetProperties(scope); }
public ConfigurationValueResult GetConfigurationValue(ConfigurationValue configurationValue, ConfigurationScope configurationScope, IntPtr scopeObject, out ConfigurationDataType dataType, out IntPtr result, out IntPtr resultLength) { return(Native.SteamAPI_ISteamNetworkingUtils_GetConfigValue(nativeUtils, configurationValue, configurationScope, scopeObject, out dataType, out result, out resultLength)); }
public IsEqualDeSerializer(ConfigurationScope configScope) { this._configScope = configScope; }
public ConfigurationName(ConfigurationScope scope, string name) { this.scope = scope; this.name = name; }
/// <summary> /// Constructor /// </summary> /// <param name="configScope"></param> public DynamicDeSerializer(ConfigurationScope configScope) { _configScope = configScope; }
public static ConfigurationItemDescriptor GetDescriptorOrNull(ConfigurationScope scope) { ConfigurationItemDescriptor result; return(descriptors.TryGetValue(scope, out result) ? result : null); }
internal static extern ConfigurationValueResult SteamAPI_ISteamNetworkingUtils_GetConfigValue(IntPtr utils, ConfigurationValue configurationValue, ConfigurationScope configurationScope, IntPtr scopeObject, out ConfigurationDataType dataType, out IntPtr result, out IntPtr resultLength);
private InjectionSpecification GetNewInjectionSpecification <TConfiguration, TSpecification>(ConfigurationScope scope, ConfigurationStyle style) { var configurationType = typeof(TConfiguration); var specificationType = typeof(TSpecification); var injectionSpecification = new InjectionSpecification { ConfigurationType = configurationType, SpecificationType = specificationType, ConfigurationScope = scope, ConfigurationStyle = style, }; return(injectionSpecification); }
public ConfigurationScopeAttribute(ConfigurationScope scope) { Scope = scope; }
/// <summary> /// /// </summary> /// <param name="configScope"></param> public IsLessEqualDeSerializer(ConfigurationScope configScope) { _configScope = configScope; }
public IsLessThanDeSerializer(ConfigurationScope configScope) { this._configScope = configScope; }
/// <summary> /// /// </summary> /// <param name="configScope"></param> public IsNotPropertyAvailableDeSerializer(ConfigurationScope configScope) { _configScope = configScope; }
/// <summary> /// Load and build the dao managers. /// </summary> /// <param name="configurationScope">The scope of the configuration</param> private void GetConfig(ConfigurationScope configurationScope) { GetProviders(configurationScope); GetDaoSessionHandlers(configurationScope); GetContexts(configurationScope); }
/// <summary> /// Initialize the PropertyInfo of the result property. /// </summary> /// <param name="resultClass"></param> /// <param name="configScope"></param> public void Initialize(ConfigurationScope configScope, Type resultClass) { if (_propertyName.Length > 0 && _propertyName != "value" && !typeof(IDictionary).IsAssignableFrom(resultClass)) { if (!_isComplexMemberName) { _setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(resultClass, _propertyName); } else // complex member name FavouriteLineItem.Id { MemberInfo propertyInfo = ObjectProbe.GetMemberInfoForSetter(resultClass, _propertyName); string memberName = _propertyName.Substring(_propertyName.LastIndexOf('.') + 1); _setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(propertyInfo.ReflectedType, memberName); } _isGenericIList = TypeUtils.IsImplementGenericIListInterface(this.MemberType); _isIList = typeof(IList).IsAssignableFrom(this.MemberType); // set the list factory if (_isGenericIList) { if (this.MemberType.IsArray) { _listFactory = _arrayListFactory; } else { Type[] typeArgs = this.MemberType.GetGenericArguments(); if (typeArgs.Length == 0)// Custom collection which derive from List<T> { _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } else { Type genericIList = typeof(IList <>); Type interfaceListType = genericIList.MakeGenericType(typeArgs); Type genericList = typeof(List <>); Type listType = genericList.MakeGenericType(typeArgs); if ((interfaceListType == this.MemberType) || (listType == this.MemberType)) { Type constructedType = genericList.MakeGenericType(typeArgs); _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory( constructedType, Type.EmptyTypes); } else // Custom collection which derive from List<T> { _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } } } } else if (_isIList) { if (this.MemberType.IsArray) { _listFactory = _arrayListFactory; } else { if (this.MemberType == typeof(IList)) { _listFactory = _arrayListFactory; } else // custom collection { _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } } } } if (this.CallBackName != null && this.CallBackName.Length > 0) { configScope.ErrorContext.MoreInfo = "Result property '" + _propertyName + "' check the typeHandler attribute '" + this.CallBackName + "' (must be a ITypeHandlerCallback implementation)."; try { Type type = configScope.SqlMapper.TypeHandlerFactory.GetType(this.CallBackName); ITypeHandlerCallback typeHandlerCallback = (ITypeHandlerCallback)Activator.CreateInstance(type); _typeHandler = new CustomTypeHandler(typeHandlerCallback); } catch (Exception e) { throw new ConfigurationException("Error occurred during custom type handler configuration. Cause: " + e.Message, e); } } else { configScope.ErrorContext.MoreInfo = "Result property '" + _propertyName + "' set the typeHandler attribute."; _typeHandler = configScope.ResolveTypeHandler(resultClass, _propertyName, _clrType, _dbType, true); } if (this.IsLazyLoad) { _lazyFactory = new LazyFactoryBuilder().GetLazyFactory(_setAccessor.MemberType); } }
/// <summary> /// Build dao contexts /// </summary> /// <param name="configurationScope">The scope of the configuration</param> private void GetContexts(ConfigurationScope configurationScope) { DaoManager daoManager = null; XmlAttribute attribute = null; // Init DaoManager.Reset(); // Build one daoManager for each context foreach (XmlNode contextNode in configurationScope.DaoConfigDocument.SelectNodes(ApplyNamespacePrefix(XML_DAO_CONTEXT), configurationScope.XmlNamespaceManager)) { configurationScope.ErrorContext.Activity = "build daoManager"; configurationScope.NodeContext = contextNode; #region Configure a new DaoManager attribute = contextNode.Attributes["id"]; daoManager = DaoManager.NewInstance(attribute.Value); configurationScope.ErrorContext.Activity += daoManager.Id; // default attribute = contextNode.Attributes["default"]; if (attribute != null) { if (attribute.Value == "true") { daoManager.IsDefault = true; } else { daoManager.IsDefault = false; } } else { daoManager.IsDefault = false; } #endregion #region Properties ParseGlobalProperties(configurationScope); #endregion #region provider daoManager.DbProvider = ParseProvider(configurationScope); configurationScope.ErrorContext.Resource = string.Empty; configurationScope.ErrorContext.MoreInfo = string.Empty; configurationScope.ErrorContext.ObjectId = string.Empty; #endregion #region DataSource daoManager.DataSource = ParseDataSource(configurationScope); daoManager.DataSource.DbProvider = daoManager.DbProvider; #endregion #region DaoSessionHandler XmlNode nodeSessionHandler = contextNode.SelectSingleNode(ApplyNamespacePrefix(XML_DAO_SESSION_HANDLER), configurationScope.XmlNamespaceManager); configurationScope.ErrorContext.Activity = "configure DaoSessionHandler"; // The resources use to initialize the SessionHandler IDictionary resources = new Hashtable(); // By default, add the DataSource resources.Add("DataSource", daoManager.DataSource); // By default, add the useConfigFileWatcher resources.Add("UseConfigFileWatcher", configurationScope.UseConfigFileWatcher); IDaoSessionHandler sessionHandler = null; Type typeSessionHandler = null; if (nodeSessionHandler != null) { configurationScope.ErrorContext.Resource = nodeSessionHandler.InnerXml.ToString(); typeSessionHandler = configurationScope.DaoSectionHandlers[nodeSessionHandler.Attributes[ID_ATTRIBUTE].Value] as Type; // Parse property node foreach (XmlNode nodeProperty in nodeSessionHandler.SelectNodes(ApplyNamespacePrefix(XML_PROPERTY), configurationScope.XmlNamespaceManager)) { resources.Add(nodeProperty.Attributes["name"].Value, NodeUtils.ParsePropertyTokens(nodeProperty.Attributes["value"].Value, configurationScope.Properties)); } } else { typeSessionHandler = configurationScope.DaoSectionHandlers[DEFAULT_DAOSESSIONHANDLER_NAME] as Type; } // Configure the sessionHandler configurationScope.ErrorContext.ObjectId = typeSessionHandler.FullName; try { sessionHandler = (IDaoSessionHandler)Activator.CreateInstance(typeSessionHandler, EmptyObjects); } catch (Exception e) { throw new ConfigurationErrorsException( string.Format("DaoManager could not configure DaoSessionHandler. DaoSessionHandler of type \"{0}\", failed. Cause: {1}", typeSessionHandler.Name, e.Message), e ); } sessionHandler.Configure(configurationScope.Properties, resources); daoManager.DaoSessionHandler = sessionHandler; configurationScope.ErrorContext.Resource = string.Empty; configurationScope.ErrorContext.MoreInfo = string.Empty; configurationScope.ErrorContext.ObjectId = string.Empty; #endregion #region Build Daos ParseDaoFactory(configurationScope, daoManager); #endregion #region Register DaoManager configurationScope.ErrorContext.MoreInfo = "register DaoManager"; configurationScope.ErrorContext.ObjectId = daoManager.Id; DaoManager.RegisterDaoManager(daoManager.Id, daoManager); configurationScope.ErrorContext.Resource = string.Empty; configurationScope.ErrorContext.MoreInfo = string.Empty; configurationScope.ErrorContext.ObjectId = string.Empty; #endregion } }
public void Initialize(ConfigurationScope configScope, Type resultClass) { if (((this._propertyName.Length > 0) && (this._propertyName != "value")) && !typeof(IDictionary).IsAssignableFrom(resultClass)) { if (!this._isComplexMemberName) { this._setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(resultClass, this._propertyName); } else { MemberInfo memberInfoForSetter = ObjectProbe.GetMemberInfoForSetter(resultClass, this._propertyName); string name = this._propertyName.Substring(this._propertyName.LastIndexOf('.') + 1); this._setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(memberInfoForSetter.ReflectedType, name); } this._isGenericIList = TypeUtils.IsImplementGenericIListInterface(this.MemberType); this._isIList = typeof(IList).IsAssignableFrom(this.MemberType); if (this._isGenericIList) { if (this.MemberType.IsArray) { this._listFactory = _arrayListFactory; } else { Type[] genericArguments = this.MemberType.GetGenericArguments(); if (genericArguments.Length == 0) { this._listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } else { Type type2 = typeof(IList <>).MakeGenericType(genericArguments); Type type3 = typeof(List <>); Type type4 = type3.MakeGenericType(genericArguments); if ((type2 == this.MemberType) || (type4 == this.MemberType)) { Type typeToCreate = type3.MakeGenericType(genericArguments); this._listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(typeToCreate, Type.EmptyTypes); } else { this._listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } } } } else if (this._isIList) { if (this.MemberType.IsArray) { this._listFactory = _arrayListFactory; } else if (this.MemberType == typeof(IList)) { this._listFactory = _arrayListFactory; } else { this._listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } } } if ((this.CallBackName != null) && (this.CallBackName.Length > 0)) { configScope.ErrorContext.MoreInfo = "Result property '" + this._propertyName + "' check the typeHandler attribute '" + this.CallBackName + "' (must be a ITypeHandlerCallback implementation)."; try { ITypeHandlerCallback callback = (ITypeHandlerCallback)Activator.CreateInstance(configScope.SqlMapper.TypeHandlerFactory.GetType(this.CallBackName)); this._typeHandler = new CustomTypeHandler(callback); goto Label_0320; } catch (Exception exception) { throw new ConfigurationException("Error occurred during custom type handler configuration. Cause: " + exception.Message, exception); } } configScope.ErrorContext.MoreInfo = "Result property '" + this._propertyName + "' set the typeHandler attribute."; this._typeHandler = configScope.ResolveTypeHandler(resultClass, this._propertyName, this._clrType, this._dbType, true); Label_0320: if (this.IsLazyLoad) { this._lazyFactory = new LazyFactoryBuilder().GetLazyFactory(this._setAccessor.MemberType); } }
/// <summary> /// Initialize the list of variables defined in the /// properties file. /// </summary> /// <param name="configurationScope">The scope of the configuration</param> private void ParseGlobalProperties(ConfigurationScope configurationScope) { XmlNode nodeProperties = configurationScope.NodeContext.SelectSingleNode(ApplyNamespacePrefix(XML_PROPERTIES), configurationScope.XmlNamespaceManager); configurationScope.ErrorContext.Activity = "add global properties"; if (nodeProperties != null) { if (nodeProperties.HasChildNodes) { foreach (XmlNode propertyNode in nodeProperties.SelectNodes(ApplyNamespacePrefix(XML_PROPERTY), configurationScope.XmlNamespaceManager)) { XmlAttribute keyAttrib = propertyNode.Attributes[KEY_ATTRIBUTE]; XmlAttribute valueAttrib = propertyNode.Attributes[VALUE_ATTRIBUTE]; if (keyAttrib != null && valueAttrib != null) { configurationScope.Properties.Add(keyAttrib.Value, valueAttrib.Value); _logger.Info(string.Format("Add property \"{0}\" value \"{1}\"", keyAttrib.Value, valueAttrib.Value)); } else { // Load the file defined by the attribute XmlDocument propertiesConfig = Resources.GetAsXmlDocument(propertyNode, configurationScope.Properties); foreach (XmlNode node in propertiesConfig.SelectNodes(XML_SETTINGS_ADD)) { configurationScope.Properties[node.Attributes[KEY_ATTRIBUTE].Value] = node.Attributes[VALUE_ATTRIBUTE].Value; _logger.Info(string.Format("Add property \"{0}\" value \"{1}\"", node.Attributes[KEY_ATTRIBUTE].Value, node.Attributes[VALUE_ATTRIBUTE].Value)); } } } } else { // JIRA-38 Fix // <properties> element's InnerXml is currently an empty string anyway // since <settings> are in properties file configurationScope.ErrorContext.Resource = nodeProperties.OuterXml.ToString(); // Load the file defined by the attribute XmlDocument propertiesConfig = Resources.GetAsXmlDocument(nodeProperties, configurationScope.Properties); foreach (XmlNode node in propertiesConfig.SelectNodes(XML_SETTINGS_ADD)) { configurationScope.Properties[node.Attributes[KEY_ATTRIBUTE].Value] = node.Attributes[VALUE_ATTRIBUTE].Value; _logger.Info(string.Format("Add property \"{0}\" value \"{1}\"", node.Attributes[KEY_ATTRIBUTE].Value, node.Attributes[VALUE_ATTRIBUTE].Value)); } } // // Load the file defined by the resource attribut // XmlDocument propertiesConfig = Resources.GetAsXmlDocument(nodeProperties, configurationScope.Properties); // // foreach (XmlNode node in propertiesConfig.SelectNodes("/settings/add")) // { // configurationScope.Properties[node.Attributes["key"].Value] = node.Attributes["value"].Value; // } } configurationScope.ErrorContext.Resource = string.Empty; configurationScope.ErrorContext.MoreInfo = string.Empty; }
/// <summary> /// /// </summary> /// <param name="configScope"></param> public IsNotNullDeSerializer(ConfigurationScope configScope) { _configScope = configScope; }
/// <summary> /// /// </summary> /// <param name="configScope"></param> /// <param name="argumenType">The argument type</param> /// <param name="clrType"></param> /// <param name="dbType"></param> /// <returns></returns> public ITypeHandler ResolveTypeHandler(ConfigurationScope configScope, Type argumenType, string clrType, string dbType) { ITypeHandler handler = null; if (argumenType == null) { handler = configScope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler(); } else if (typeof(IDictionary).IsAssignableFrom(argumenType)) { // IDictionary if (clrType == null || clrType.Length == 0) { handler = configScope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler(); } else { try { Type type = TypeUtils.ResolveType(clrType); handler = configScope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, dbType); } catch (Exception e) { #if dotnet2 throw new Exception("Error. Could not set TypeHandler. Cause: " + e.Message, e); #else throw new ConfigurationException("Error. Could not set TypeHandler. Cause: " + e.Message, e); #endif } } } else if (configScope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(argumenType, dbType) != null) { // Primitive handler = configScope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(argumenType, dbType); } else { // .NET object if (clrType == null || clrType.Length == 0) { handler = configScope.DataExchangeFactory.TypeHandlerFactory.GetUnkownTypeHandler(); } else { try { Type type = TypeUtils.ResolveType(clrType); handler = configScope.DataExchangeFactory.TypeHandlerFactory.GetTypeHandler(type, dbType); } catch (Exception e) { #if dotnet2 throw new Exception("Error. Could not set TypeHandler. Cause: " + e.Message, e); #else throw new ConfigurationException("Error. Could not set TypeHandler. Cause: " + e.Message, e); #endif } } } return(handler); }
public bool SetConfiguratioValue(ConfigurationValue configurationValue, ConfigurationScope configurationScope, IntPtr scopeObject, ConfigurationDataType dataType, IntPtr value) { return(Native.SteamAPI_ISteamNetworkingUtils_SetConfigValue(nativeUtils, configurationValue, configurationScope, scopeObject, dataType, value)); }
internal DynamicSql(ConfigurationScope configScope, IStatement statement) { this._statement = statement; this._usePositionalParameters = configScope.DataSource.DbProvider.UsePositionalParameters; this._dataExchangeFactory = configScope.DataExchangeFactory; }