Exemplo n.º 1
0
        public virtual async Task <T> Get(TKey key, bool toRetrieve)//, bool useHttp)
        {
            T item = SpoolGet(key);

            if (item != null || !toRetrieve)
            {
                return(item);
            }

            try
            {
                item = await RetrieveStorageItem(key);

                this.SpoolAddOrUpdate(key, item);

                return(item);
            }
            catch (Exception ex)
            {
                string msg = $"Conflict in Get key={key} : {ex.Message}";
                ex = new StoreException(EType.Get, msg, ex);
                //
                throw ex;
            }
        }
Exemplo n.º 2
0
        public virtual async Task <List <T> > List(bool toRetrieve)
        {
            if (!toRetrieve)
            {
                return(SpoolList());
            }
            SpoolClear();

            try
            {
                Dictionary <TKey, T> _dic = await RetrieveStorageItemsList();

                if (_dic != null)
                {
                    foreach (var(key, value) in _dic)
                    {
                        SpoolAddOrUpdate(key, value);
                    }
                }
                return(SpoolList());
            }
            catch (Exception ex)
            {
                string msg = $"Conflict in List ";
                ex = new StoreException(EType.List, msg, ex);
                Log.LogError(ex.Message, ex);
                throw ex;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 統一處理紀錄 Sql 錯誤,並將轉換後的 StoreException 拋回
        /// </summary>
        /// <param name="ex">SQL 錯誤物件</param>
        /// <param name="sql">當下執行的 TSQL</param>
        /// <returns></returns>
        private StoreException ProcessStoreException(SqlException ex, string sql)
        {
            // 將原本的錯誤資訊物件 ex 轉型為我們自訂的 StoreException
            var exception = new StoreException(ex);

            // Log into ErrorLog in DB
            var id = _errorLogStore.InsertStoreExceptionLog(exception, sql);

            // 並把 ErrorLog 所記錄的代碼寫到 exception 後拋出,提供前端利用
            exception.ErrorLogId = id;

            return exception;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets the stub of StoreOperationGlobal.OnStoreException(StoreException se)
        /// </summary>
        public override ShardManagementException OnStoreException(StoreException se)
        {
            Func <StoreException, ShardManagementException> func1 = this.OnStoreExceptionStoreException;

            if (func1 != null)
            {
                return(func1(se));
            }
            if (this.___callBase)
            {
                return(base.OnStoreException(se));
            }
            return(this.InstanceBehavior.Result <StubFindMappingByKeyGlobalOperation, ShardManagementException>(this, "OnStoreException"));
        }
        /// <summary>
        /// Sets the stub of StoreOperation.OnStoreException(StoreException se, StoreOperationState state)
        /// </summary>
        public override ShardManagementException OnStoreException(StoreException se, StoreOperationState state)
        {
            Func <StoreException, StoreOperationState, ShardManagementException> func1 = this.OnStoreExceptionStoreExceptionStoreOperationState;

            if (func1 != null)
            {
                return(func1(se, state));
            }
            if (this.___callBase)
            {
                return(base.OnStoreException(se, state));
            }
            return(this.InstanceBehavior.Result <StubUpdateMappingOperation, ShardManagementException>(this, "OnStoreException"));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Update value if this just exists
        /// In Hasn updated those Store value without Updating !!!
        /// </summary>
        /// <param name="key"></param>
        /// <param name="valueIn"></param>
        /// <param name="usePersist"></param>
        /// <returns></returns>
        public virtual async Task <T> Update(TKey key, T valueIn, bool toRetrieve)
        {
            T item = null;

            if (!toRetrieve)
            {
                SpoolAddOrUpdate(key, valueIn, out item);
                return(item);
            }


            //If value isn't exist return null
            if (!HasItem(key))
            {
                Exception ex = new StoreException(EType.Update,
                                                  $"The item with key={key} not present");
                //Log.LogError(ex.Message, ex);
                throw ex;
            }


            try
            {
                item = await TryUpdateStorageItem(key, valueIn);
            }
            catch (Exception ex)
            {
                SpoolDelete(key);
                ex = new StoreException(EType.Update,
                                        $"Update conflict key={key}", ex);
                //            Log.LogError(ex.Message, ex);
                throw ex;
            }
            if (item == null)
            {
                SpoolDelete(key);

                Exception ex = new StoreException(EType.Update,
                                                  $"Update conflict key={key}");
                //           Log.LogError(ex.Message, ex);
                throw ex;
            }

            return(item);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Insert returns stored  item if this one doesn;t existed before,
        /// Oothewise  - null
        /// </summary>
        /// <param name="key"></param>
        /// <param name="valueIn"></param>
        /// <param name="usePersist"></param>
        /// <returns></returns>
        public virtual async Task <T> Insert(TKey key, T valueIn, bool toRetrieve)
        {
            T item = null;

            if (!toRetrieve)
            {
                SpoolAddOrUpdate(key, valueIn, out item);
                return(item);
            }

            if (HasItem(key))
            {
                Exception ex = new StoreException(EType.Insert, $"The item with key={key} just present ");
                Log.LogError(ex.Message, ex);
                throw ex;
            }


            try
            {
                item = await TryInserStoragetItem(key, valueIn);
            }
            catch (Exception ex)
            {
                string msg = $"Insert Conflict key={key} ";
                ex = new StoreException(EType.Insert, $"Insert Conflict key={key} ", ex);
                // Log.LogError(ex.Message, ex);
                throw ex;
            }

            if (item == null)
            {
                string    msg = $"Insert Conflict key={key} ";
                Exception ex  = new StoreException(EType.Insert, $"Insert conflict, key={key}");
                // Log.LogError(ex.Message, ex);
                throw ex;
            }


            SpoolAddOrUpdate(key, item, out item);
            return(item);
        }
Exemplo n.º 8
0
 public ErrorActionResult(StoreException e)
 {
     _e = e;
 }
 /// <summary>
 /// Sets the stub of StoreOperation.OnStoreException(StoreException se, StoreOperationState state)
 /// </summary>
 public override ShardManagementException OnStoreException(StoreException se, StoreOperationState state)
 {
     Func<StoreException, StoreOperationState, ShardManagementException> func1 = this.OnStoreExceptionStoreExceptionStoreOperationState;
     if (func1 != null)
         return func1(se, state);
     if (this.___callBase)
         return base.OnStoreException(se, state);
     return this.InstanceBehavior.Result<StubReplaceMappingsOperation, ShardManagementException>(this, "OnStoreException");
 }
 public virtual ShardManagementException OnStoreException(StoreException se, StoreOperationState state)
 {
     return this.inner.OnStoreException(se, state);
 }
Exemplo n.º 11
0
 /// <summary>
 /// 回傳 API 伺服器處理錯誤,狀態碼為 500 (Internal Server Error),ResultNumber 為 -99999
 /// 錯誤類型為資料存取層錯誤 (StoreException)
 /// </summary>
 /// <param name="exception">觸發的資料存取層 Exception 物件</param>
 /// <returns></returns>
 protected IHttpActionResult ApiServerError(StoreException exception)
 {
     return(this.ApiContent <string>(HttpStatusCode.InternalServerError,
                                     String.Format("系統發生錯誤,紀錄代碼為 {0}", exception.ErrorLogId),
                                     -99999));
 }
Exemplo n.º 12
0
 public virtual ShardManagementException OnStoreException(StoreException se, StoreOperationState state)
 {
     return(this.inner.OnStoreException(se, state));
 }
 /// <summary>
 /// Sets the stub of StoreOperationGlobal.OnStoreException(StoreException se)
 /// </summary>
 public override ShardManagementException OnStoreException(StoreException se)
 {
     Func<StoreException, ShardManagementException> func1 = this.OnStoreExceptionStoreException;
     if (func1 != null)
         return func1(se);
     if (this.___callBase)
         return base.OnStoreException(se);
     return this.InstanceBehavior.Result<StubFindMappingByKeyGlobalOperation, ShardManagementException>(this, "OnStoreException");
 }
Exemplo n.º 14
0
        public int InsertStoreExceptionLog(StoreException ex, string sql)
        {
            var message = $"發生於 TSQL 行 : {ex.LineNumber}。\r\n{ex.Message}";

            return(this.InsertLog(message, sql, ex.Source, ex.StackTrace));
        }