protected virtual async Task ProcessVersion(PersistenceRequestHolder <K, Tuple <K, string> > holder) { IResponseHolder result = null; if (mCacheManager.IsActive) { result = await mCacheManager.VersionRead(mTransform, holder.Rq.Key); } if (result == null || !result.IsSuccess) { if (mTransform.Version == null) { //If we don't set a version maker then how can we return the version. result = new PersistenceResponseHolder(PersistenceResponse.NotImplemented501) { IsSuccess = false } } ; else { result = await InternalVersion(holder.Rq.Key, holder); } if (mCacheManager.IsActive && !mCacheManager.IsReadOnly && result.IsSuccess) { mCacheManager.WriteVersion(mTransform, holder.Rq.Key, result.VersionId); } } ProcessOutputKey(holder.Rq, holder.Rs, result); }
protected virtual async Task ProcessRead(PersistenceRequestHolder <K, E> holder) { IResponseHolder <E> result = null; if (mCacheManager.IsActive && holder.Rq.Settings.UseCache) { result = await mCacheManager.Read(mTransform, holder.Rq.Key); } if (result == null || !result.IsSuccess) { result = await InternalRead(holder.Rq.Key, holder); if (mCacheManager.IsActive && !mCacheManager.IsReadOnly && result.IsSuccess) { mCacheManager.Write(mTransform, result.Entity); } } else { result.IsCacheHit = true; } ProcessOutputEntity(holder.Rq.Key, holder.Rq, holder.Rs, result); }
/// <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); } }
/// <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; }
/// <summary> /// This is the entity search. /// </summary> /// <param name="holder">The is the entity search data.</param> /// <returns>This is an async task.</returns> protected virtual async Task ProcessSearch(PersistenceRequestHolder <SearchRequest, SearchResponse> holder) { IResponseHolder <SearchResponse> result = null; result = await InternalSearch(holder.Rq.Key, holder); holder.Rs.Entity = result.Entity; holder.Rs.Key = holder.Rq.Key; //rs.Settings.VersionId = mTransform.Version?.EntityVersionAsString(rs.Entity); //rs.KeyReference = new Tuple<string, string>(rs.Key.ToString(), rs.Settings.VersionId); //holder.Rs.ResponseCode = (int)PersistenceResponse.NotImplemented501; //holder.Rs.ResponseMessage = "Search is not implemented."; }
/// <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; } }
protected virtual async Task ProcessVersionByRef(PersistenceRequestHolder <K, Tuple <K, string> > holder) { IResponseHolder result = null; if (mCacheManager.IsActive) { result = await mCacheManager.VersionRead(mTransform, holder.Rq.KeyReference); } if (result == null || !result.IsSuccess) { result = await InternalVersionByRef(holder.Rq.KeyReference, holder); if (mCacheManager.IsActive && !mCacheManager.IsReadOnly && result.IsSuccess) { mCacheManager.WriteReference(mTransform, holder.Rq.KeyReference, holder.Rq.Key, result.VersionId); } } else { holder.Rq.Key = mTransform.KeyDeserializer(result.Id); // Pass back the entities actual id in the key field } ProcessOutputKey(holder.Rq, holder.Rs, result); }
/// <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); } }