예제 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="serviceContract"></param>
 void VerifyServiceContract(IDataServiceContract serviceContract)
 {
     if (null == serviceContract)
     {
         throw new ArgumentNullException(string.Format("The attribute '{0}' is not declared in the previous section.", typeof(DataServiceContractAttribute).FullName));
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="serviceContract"></param>
        /// <returns></returns>
        public static EndpointAddress GetDataServiceEndpoint(IDataServiceContract serviceContract)
        {
            if (string.IsNullOrEmpty(serviceContract.Host))
            {
                throw new ArgumentNullException("serviceContract.Host");
            }

            return(new EndpointAddress(serviceContract.Host));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="serviceContract"></param>
        /// <param name="queryAction"></param>
        /// <returns></returns>
        public DbQueryOperatingSession CreateSession(IDataServiceContract serviceContract, DbQueryActions queryAction)
        {
            var _connection       = _connectionPool.DetachConnection(serviceContract);
            var _operatingSession = new DbQueryOperatingSession(this, _connection, queryAction);

            _operatingSession.OperationFailed += new DbQueryFailedEventHandler(_OnOperationFailed);

            _innerSessionRepository.Add(_operatingSession);

            return(_operatingSession);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="serviceContract"></param>
        protected DataServiceProxy(IDataServiceContract serviceContract)
        {
            _serviceContract = serviceContract;

            if (null == _serviceContract)
            {
                throw new InvalidOperationException("The service contract is not declared.");
            }

            var _binding  = DataServiceContractHelpers.GetDataServiceBinding(serviceContract);
            var _endPoint = DataServiceContractHelpers.GetDataServiceEndpoint(serviceContract);

            _innerChannelFactory = new ChannelFactory <TService>(_binding, _endPoint);
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="serviceContract"></param>
        /// <returns></returns>
        public IDbQueryContext CreateDbQueryContext(IDataServiceContract serviceContract)
        {
            var _command      = Connection.CreateDbCommand();
            var _provider     = serviceContract.Provider ?? typeof(DbQueryContext);
            var _queryContext = DbQueryContext.Initializer.Initialize(_provider, _command);

            if (OperationContext.ExecutionTimeout.HasValue)
            {
                _queryContext.ExecutionTimeout = OperationContext.ExecutionTimeout;
            }

            _queryContext.Failed    += new DbQueryFailedEventHandler(_OnFailed);
            _queryContext.Executed  += new DbQueryExecutedEventHandler(_OnExecuted);
            _queryContext.Executing += new DbQueryExecutingEventHandler(_OnExecuting);

            return(_queryContext);
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="serviceContract"></param>
        /// <returns></returns>
        public DbConnection DetachConnection(IDataServiceContract serviceContract)
        {
            if (null != serviceContract)
            {
                if (!_innerCacheRepository.ContainsKey(serviceContract.Host))
                {
                    lock (_syncRoot)
                    {
                        _innerCacheRepository.Add(serviceContract.Host, new DbConnection(OperationContext, serviceContract));
                    }
                }

                return(_innerCacheRepository[serviceContract.Host]);
            }

            return(null);
        }
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="operationContext"></param>
 /// <param name="serviceContract"></param>
 public DbConnection(DbQueryOperationContext operationContext, IDataServiceContract serviceContract)
     : base(operationContext)
 {
     _contract   = serviceContract;
     _connection = new SqlConnection(_contract.Host);
 }
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="operatingSession"></param>
        /// <param name="entity"></param>
        /// <param name="memberDescriptor"></param>
        /// <param name="serviceContract"></param>
        /// <param name="queryContract"></param>
        protected virtual void ExecuteQueryImpl(DbQueryOperatingSession operatingSession, object entity, IEntryDescriptor memberDescriptor, IDataServiceContract serviceContract, IDbQueryContract queryContract)
        {
            var _queryContract = queryContract ?? operatingSession.GetDbQueryContract(memberDescriptor);

            InitializeRequiredProperties(operatingSession.OperationContext, _queryContract);

            var _queryContext = operatingSession.CreateDbQueryContext(serviceContract);

            InitializeRequiredProperties(_queryContext, _queryContract);

            var _parameterMapper   = operatingSession.CreateDbQueryParameterMapper(memberDescriptor);
            var _operationExecutor = operatingSession.CreateDbQueryOperationExecutor(memberDescriptor);
            var _propertyValidator = operatingSession.CreateDbQueryPropertyValidator(memberDescriptor);

            _propertyValidator.Validate(entity);

            _parameterMapper.Map(_queryContext, entity);

            _operationExecutor.Execute(entity, _queryContext);

            var _queryResult = _queryContext.Execute();

            if (null != _queryResult && _queryResult.HasResult)
            {
                var _resultMapper = operatingSession.CreateDbQueryResultMapper(memberDescriptor);

                _resultMapper.Map(entity, _queryResult);
            }
        }
예제 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="entity"></param>
        /// <param name="queryAction"></param>
        /// <param name="serviceContract"></param>
        /// <param name="queryContract"></param>
        /// <returns></returns>
        protected OperationResult <TEntity> ExecuteQuery <TEntity>(TEntity entity, DbQueryActions queryAction, IDataServiceContract serviceContract, IDbQueryContract queryContract)
            where TEntity : class
        {
            using (var _operationContext = new DbQueryOperationContext())
            {
                if (!IsExceptionalType(entity))
                {
                    var _memberDescriptor = _operationContext.DescriptorManager.GetDescriptor(entity);
                    var _serviceContract  = serviceContract ?? _memberDescriptor.ServiceContract;
                    var _operationSession = _operationContext.CreateSession(_serviceContract, queryAction);

                    _operationSession.Open();

                    ExecuteQueryImpl(_operationSession, entity, _memberDescriptor, _serviceContract, queryContract);

                    _operationSession.Close();
                }
                else
                {
                    var _entities = entity as IList;

                    for (var i = 0; i < _entities.Count; i++)
                    {
                        if (!_operationContext.HasErrors)
                        {
                            var _memberDescriptor = _operationContext.DescriptorManager.GetDescriptor(_entities[i]);
                            var _serviceContract  = serviceContract ?? _memberDescriptor.ServiceContract;
                            var _operationSession = _operationContext.CreateSession(_serviceContract, queryAction);

                            _operationSession.Open();

                            ExecuteQueryImpl(_operationSession, _entities[i], _memberDescriptor, _serviceContract, queryContract);

                            _operationSession.Close();

                            continue;
                        }

                        break;
                    }
                }

                if (_operationContext.HasErrors)
                {
                    return(new OperationResult <TEntity>(entity, _operationContext.Errors));
                }
            }

            return(new OperationResult <TEntity>(entity));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="serviceContract"></param>
        /// <returns></returns>
        public static Binding GetDataServiceBinding(IDataServiceContract serviceContract)
        {
            if (!string.IsNullOrEmpty(serviceContract.Protocol))
            {
                switch (serviceContract.Protocol.ToLower())
                {
                case "http":
                case "basichttp":

                    return(new BasicHttpBinding()
                    {
                        MaxBufferSize = 2147483647,
                        MaxReceivedMessageSize = 2147483647,

                        CloseTimeout = new TimeSpan(1, 50, 0),
                        OpenTimeout = new TimeSpan(1, 50, 0),
                        SendTimeout = new TimeSpan(1, 50, 0),
                        ReceiveTimeout = new TimeSpan(1, 50, 0),

                        ReaderQuotas = new XmlDictionaryReaderQuotas()
                        {
                            MaxDepth = 128,
                            MaxArrayLength = 2147483646,
                            MaxBytesPerRead = 4096,
                            MaxNameTableCharCount = 16384,
                            MaxStringContentLength = 8388608,
                        },
                    });

                case "https":
                case "basichttps":
                    return(new BasicHttpsBinding());

                case "nethttp":
                    return(new NetHttpBinding());

                case "nethttps":
                    return(new NetHttpsBinding());

                case "namedpipe":
                case "netnamedpipe":
                    return(new NetNamedPipeBinding());

                case "tcp":
                case "nettcp":
                    return(new NetTcpBinding());

                case "udp":
                    return(new UdpBinding());

                case "web":
                case "webhttp":
                    return(new WebHttpBinding());

                case "wsdual":
                case "wsdualhttp":
                    return(new WSDualHttpBinding());

                case "wsfederation":
                case "wsfederationhttp":
                    return(new WSFederationHttpBinding());

                case "ws2007federation":
                case "ws2007federationhttp":
                    return(new WS2007FederationHttpBinding());

                case "ws":
                case "wshttp":
                    return(new WSHttpBinding());

                case "ws2007":
                case "ws2007http":
                    return(new WS2007HttpBinding());
                }

                throw new NotSupportedException(string.Format("The '{0}' protocol is not supported.", serviceContract.Protocol));
            }

            throw new ArgumentNullException("serviceContract.Protocol");
        }