Пример #1
0
        //Response Processing
        #region ProcessOutputEntity...
        /// <summary>
        /// This method sets the entity and any associated metadata in to the response.
        /// </summary>
        /// <param name="key">The entity key.</param>
        /// <param name="rq">The original request.</param>
        /// <param name="rs">The outgoing response.</param>
        /// <param name="holderResponse">The underlying storage response.</param>
        protected virtual void ProcessOutputEntity(E entity, PersistenceRepositoryHolder <K, E> rq, PersistenceRepositoryHolder <K, E> rs)
        {
            rs.Entity             = entity;
            rs.Key                = mTransform.KeyMaker(rs.Entity);
            rs.Settings.VersionId = mTransform.Version?.EntityVersionAsString(rs.Entity);

            rs.KeyReference = new Tuple <string, string>(rs.Key.ToString(), rs.Settings.VersionId);
        }
Пример #2
0
        /// <summary>
        /// This method sets the entity and any associated metadata in to the response.
        /// </summary>
        /// <param name="key">The entity key.</param>
        /// <param name="rq">The original request.</param>
        /// <param name="rs">The outgoing response.</param>
        /// <param name="holderResponse">The underlying storage response.</param>
        protected virtual void ProcessOutputEntity(K key, PersistenceRepositoryHolder <K, E> rq, PersistenceRepositoryHolder <K, E> rs, IResponseHolder <E> holderResponse)
        {
            rs.ResponseCode = holderResponse.StatusCode;

            if (holderResponse.IsSuccess)
            {
                ProcessOutputEntity(holderResponse.Entity, rq, rs);
            }
            else
            {
                ProcessOutputError(key, holderResponse, rs);
            }
        }
Пример #3
0
        /// <summary>
        /// This method sets the entity and any associated metadata in to the response.
        /// </summary>
        /// <param name="key">The entity key.</param>
        /// <param name="rq">The original request.</param>
        /// <param name="rs">The outgoing response.</param>
        /// <param name="holderResponse">The underlying storage response.</param>
        protected virtual void ProcessOutputEntity(K key, PersistenceRepositoryHolder <K, E> rq, PersistenceRepositoryHolder <K, E> rs
                                                   , IResponseHolder holderResponse)
        {
            rs.ResponseCode = holderResponse.StatusCode;

            if (holderResponse.IsSuccess)
            {
                ProcessOutputEntity(mTransform.PersistenceEntitySerializer.Deserializer(holderResponse.Content), rq, rs);
            }
            else
            {
                ProcessOutputError(key, holderResponse, rs);
            }
        }
Пример #4
0
        /// <summary>
        /// This method processes the common output method for key based operations such as delete and version.
        /// </summary>
        /// <param name="rq">The incoming request.</param>
        /// <param name="rs">The outgoing response.</param>
        /// <param name="holderResponse">The internal holder response.</param>
        protected virtual void ProcessOutputKey(PersistenceRepositoryHolder <K, Tuple <K, string> > rq, PersistenceRepositoryHolder <K, Tuple <K, string> > rs
                                                , IResponseHolder holderResponse)
        {
            rs.Key          = rq.Key;
            rs.KeyReference = rq.KeyReference;

            rs.ResponseCode = holderResponse.StatusCode;

            if (holderResponse.IsSuccess)
            {
                rs.Settings.VersionId = holderResponse.VersionId;
                rs.Entity             = new Tuple <K, string>(rs.Key, holderResponse.VersionId);
                rs.KeyReference       = new Tuple <string, string>(rs.Key == null ? null : rs.Key.ToString(), holderResponse.VersionId);
            }
            else
            {
                rs.IsTimeout = holderResponse.IsTimeout;
            }
        }
Пример #5
0
            /// <summary>
            /// Records the specified extent.
            /// </summary>
            /// <typeparam name="KT">The key type.</typeparam>
            /// <typeparam name="ET">The entity type.</typeparam>
            /// <param name="extent">The timespan extent.</param>
            /// <param name="rs">The response holder..</param>
            public void Record <KT, ET>(TimeSpan?extent, PersistenceRepositoryHolder <KT, ET> rs)
            {
                if (extent.HasValue)
                {
                    ActiveIncrement();
                    ActiveDecrement(extent.Value);
                }

                if (rs?.IsRetry ?? false)
                {
                    Interlocked.Increment(ref mRetries);
                }

                if (rs?.IsCached ?? false)
                {
                    Interlocked.Increment(ref mCacheHits);
                }

                Interlocked.Add(ref mRetries, rs?.Retry ?? 0);
            }
Пример #6
0
        /// <summary>
        /// This method is used to format the response when the request is not successful.
        /// </summary>
        /// <param name="key">The entity key.</param>
        /// <param name="holderResponse">The response.</param>
        /// <param name="rs">The repository holder.</param>
        protected virtual void ProcessOutputError(K key, IResponseHolder holderResponse, PersistenceRepositoryHolder <K, E> rs)
        {
            if (holderResponse.Ex != null && !rs.IsTimeout)
            {
                Logger.LogException($"Error in persistence {typeof (E).Name}-{key}", holderResponse.Ex);
            }
            else if (rs.ResponseCode != 404)
            {
                Logger.LogMessage(
                    rs.IsTimeout ? LoggingLevel.Warning : LoggingLevel.Info,
                    $"Error in persistence {typeof (E).Name}-{rs.ResponseCode}-{key}-{holderResponse.Ex?.ToString() ?? rs.ResponseMessage}", typeof(E).Name);
            }

            rs.IsTimeout = holderResponse.IsTimeout;
        }