/// <summary> /// /// </summary> /// <returns></returns> public static IValueValidatorFactory GetValueValidatorFactory() { var _stackFrame = StackTraceHelpers.GetStackFrameByIndex(2); var _factoryProvider = typeof(IValueValidatorFactoryProvider); var _memberDescriptor = (AttributeMemberDescriptor)null; if (null != _stackFrame) { if (_stackFrame.MethodDescriptor.HasAttributeMembers) { _memberDescriptor = _stackFrame.MethodDescriptor.GetAttributeDescriptorByAttributeType(_factoryProvider); if (null != _memberDescriptor) { return((_memberDescriptor.Member as IValueValidatorFactoryProvider).ValueValidatorFactory); } } var _declaringType = _stackFrame.MethodDescriptor.Member.DeclaringType; var _descriptors = AttributeMemberHelpers.RetrieveMemberDescriptors(_declaringType, _factoryProvider); if (null != _descriptors) { _memberDescriptor = _descriptors.GetDescriptorByAttributeType(_factoryProvider); return((_memberDescriptor.Member as IValueValidatorFactoryProvider).ValueValidatorFactory); } } return(CreateValueValidatorFactory()); }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="value"></param> /// <param name="valueType"></param> protected void SetValue(string name, object value, RegistryValueKind valueType = RegistryValueKind.String) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } if (!IsDeleted && !_childNodeName.IsCompiled) { var _stackFrame = StackTraceHelpers.GetStackFrameByIndex(1); var _propertyName = _stackFrame.Method.Name.Replace("get_", string.Empty).Replace("set_", string.Empty); _childNodeName.Replace(_propertyName, value); if (!_childNodeName.IsCompiled) { _innerRepository.Add(name, new RegistryNameValuePair(name, value, valueType)); return; } else { _nodePathInfo = RegistryNodePath.Parse(_nodePathInfo.RootType, _childNodeName); using (var _registryKey = RegistryNodeHelpers.GetRegistryKey(_nodePathInfo)) { if (0 < _innerRepository.Count) { foreach (var _value in _innerRepository.Values) { if (!_value.IsDeleted) { _registryKey.SetValue(_value.Name, _value.Value, _value.ValueType); continue; } _registryKey.DeleteValue(_value.Name, false); } _innerRepository.Clear(); } } } } if (CanWrite) { using (var _registryKey = RegistryNodeHelpers.GetRegistryKey(_nodePathInfo)) { if (null == value) { _registryKey.DeleteValue(name, false); return; } _registryKey.SetValue(name, value); } } }
/// <summary> /// /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="entity"></param> /// <returns></returns> protected OperationResult <TEntity> BaseFetch <TEntity>(TEntity entity) where TEntity : class { var _stackFrame = StackTraceHelpers.GetStackFrameByIndex(1); var _queryContract = RetrieveDbQueryContract(_stackFrame); var _serviceContract = RetrieveDataServiceContract(_stackFrame); return(ExecuteQuery <TEntity>(entity, DbQueryActions.Fetch, _serviceContract, _queryContract)); }
/// <summary> /// /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="predicate"></param> /// <returns></returns> protected OperationResult <TEntity> ExecuteQuery <TEntity>(Action <IDbQueryParameterizable> predicate = default(Action <IDbQueryParameterizable>)) where TEntity : class, new() { var _entity = new TEntity(); var _stackFrame = StackTraceHelpers.GetStackFrameByIndex(1); var _queryContract = RetrieveDbQueryContract(_stackFrame); var _serviceContract = RetrieveDataServiceContract(_stackFrame); VerifyQueryContract(_queryContract); VerifyServiceContract(_serviceContract); using (var _operationContext = new DbQueryOperationContext()) { InitializeRequiredProperties(_operationContext, _queryContract); var _memberDescriptor = _operationContext.DescriptorManager.GetDescriptor(_entity); var _operatingSession = _operationContext.CreateSession(_serviceContract, _queryContract.QueryAction); var _queryContext = _operatingSession.CreateDbQueryContext(_memberDescriptor); InitializeRequiredProperties(_queryContext, _queryContract); _operatingSession.Open(); if (default(Action <IDbQueryParameterizable>) != predicate) { predicate(_queryContext); } var _queryResult = _queryContext.Execute(); if (null != _queryResult && _queryResult.HasResult) { var _resultMapper = _operatingSession.CreateDbQueryResultMapper(_memberDescriptor); _resultMapper.Map(_entity, _queryResult); } _operatingSession.Close(); if (_operationContext.HasErrors) { return(new OperationResult <TEntity>(_entity, _operationContext.Errors)); } } return(new OperationResult <TEntity>(_entity)); }
/// <summary> /// /// </summary> /// <param name="predicate"></param> /// <returns></returns> protected OperationResult <IDbQueryResult> ExecuteQuery(Action <IDbQueryParameterizable> predicate = default(Action <IDbQueryParameterizable>)) { var _queryResult = (IDbQueryResult)null; var _stackFrame = StackTraceHelpers.GetStackFrameByIndex(1); var _queryContract = RetrieveDbQueryContract(_stackFrame); var _serviceContract = RetrieveDataServiceContract(_stackFrame); VerifyQueryContract(_queryContract); VerifyServiceContract(_serviceContract); using (var _operationContext = new DbQueryOperationContext()) { InitializeRequiredProperties(_operationContext, _queryContract); var _operatingSession = _operationContext.CreateSession(_serviceContract, _queryContract.QueryAction); var _queryContext = _operatingSession.CreateDbQueryContext(_serviceContract); InitializeRequiredProperties(_queryContext, _queryContract); _operatingSession.Open(); if (default(Action <IDbQueryParameterizable>) != predicate) { predicate(_queryContext); } _queryResult = _queryContext.Execute(); _operatingSession.Close(); if (_operationContext.HasErrors) { return(new OperationResult <IDbQueryResult>(_queryResult, _operationContext.Errors)); } } return(new OperationResult <IDbQueryResult>(_queryResult)); }
/// <summary> /// /// </summary> public DbQueryOperationContext() { var _currentStackFrame = StackTraceHelpers.GetStackFrameByIndex(1); var _currentCacheKey = GenerateUniqueCacheKey(_currentStackFrame); var _operationContext = (DbQueryOperationContext)null; if (0 < s_innerCacheRepository.Count) { var _stackFrames = StackTraceHelpers.GetStackFrames(); for (var i = 0; i < _stackFrames.Length; i++) { var _stackFrame = _stackFrames[i]; var _cacheKey = GenerateUniqueCacheKey(_stackFrame); if (!string.IsNullOrEmpty(_cacheKey) && s_innerCacheRepository.ContainsKey(_cacheKey)) { _operationContext = s_innerCacheRepository[_cacheKey]; break; } } } if (null != _operationContext) { _isNested = true; _connectionPool = _operationContext._connectionPool; _descriptorManager = _operationContext._descriptorManager; _innerSharedRepository = _operationContext._innerSharedRepository; _innerSessionRepository = _operationContext._innerSessionRepository; _innerCacheKeyRepository = _operationContext._innerCacheKeyRepository; _executionTimeout = _operationContext._executionTimeout; _asynchronousProcessing = _operationContext._asynchronousProcessing; _requiresTransaction = _operationContext._requiresTransaction; _requiresEnvironmentVariables = _operationContext._requiresEnvironmentVariables; _innerErrorRepository = new ListCollection <DbQueryException>(_syncRoot); } else { _innerSharedRepository = new NameValueCollection <string, object>(StringComparer.InvariantCultureIgnoreCase); _innerSessionRepository = new ListCollection <DbQueryOperatingSession>(_syncRoot); _innerCacheKeyRepository = new ListCollection <string>(_syncRoot); _connectionPool = new DbConnectionPool(this); _descriptorManager = new EntryDescriptorManager(this); _innerErrorRepository = new ListCollection <DbQueryException>(_syncRoot); } if (!IsDbQueryOperationMember(_currentStackFrame)) { VerifyCacheKey(_currentCacheKey); _innerCacheKeyRepository.Add(_currentCacheKey); s_innerCacheRepository.Add(_currentCacheKey, this); } }