/// <summary>
        /// Converts to.
        /// </summary>
        /// <param name="sqlException">The SQL exception.</param>
        /// <returns>Beyova.Diagnostic.BaseException.</returns>
        public static BaseException ConvertTo(SqlStoredProcedureException sqlException)
        {
            BaseException result = null;

            if (sqlException != null)
            {
                switch (sqlException.Code.Major)
                {
                case ExceptionCode.MajorCode.NullOrInvalidValue:
                    result = new InvalidObjectException(sqlException, reason: sqlException.Code.Minor);
                    break;

                case ExceptionCode.MajorCode.UnauthorizedOperation:
                    result = new UnauthorizedOperationException(sqlException, minorCode: sqlException.Code.Minor);
                    break;

                case ExceptionCode.MajorCode.OperationForbidden:
                    result = new OperationForbiddenException(sqlException.Code.Minor, sqlException);
                    break;

                case ExceptionCode.MajorCode.DataConflict:
                    result = new DataConflictException(sqlException.Code.Minor, innerException: sqlException);
                    break;

                default:
                    result = sqlException;
                    break;
                }
            }

            return(result);
        }
Пример #2
0
        public async Task Db_SalesService_Concurrency_AskClient()
        {
            using (ThreadScopedLifestyle.BeginScope(container))
            {
                SalesService service = container.GetInstance <SalesService>();
                service.SetPolicy(DataConflictPolicy.AskClient);

                var article = await service.GetByIdAsync <Article>(this.dataSet.ArticlesIds.ElementAt(3));

                article.Title = "User1 Title 4";

                this.articlesSqlHelper.ModifyTitle(article.Id, "User2 Title 4");

                DataConflictException dce = Assert.ThrowsAsync <DataConflictException>(async() =>
                {
                    await service.ModifyAsync(article);
                });
                Assert.AreEqual(DalErrorType.BaseServiceDataConflictWithAskClientPolicy, dce.errorType);

                Assert.IsInstanceOf(typeof(Article), dce.CurrentValues);
                Assert.IsInstanceOf(typeof(Article), dce.DatabaseValues);

                Article currentValues  = (Article)dce.CurrentValues;
                Article databaseValues = (Article)dce.DatabaseValues;

                Assert.AreEqual(article.Id, databaseValues.Id);
                Assert.AreEqual("User2 Title 4", databaseValues.Title);

                Assert.AreEqual(article.Id, currentValues.Id);
                Assert.AreEqual("User1 Title 4", currentValues.Title);
            }
        }
Пример #3
0
        public async Task Db_SalesService_Concurrency_AskClient()
        {
            using (IUnityContainer childContainer = this.container.CreateChildContainer())
            {
                IBaseMainService service = childContainer.Resolve <IBaseMainService>();
                service.SetPolicy(DataConflictPolicy.AskClient);

                var category = await service.GetByIdAsync <DbCategory>(this.dataSet.CategoriesIds.ElementAt(2));

                category.Title = "User 1 Category Title 4";

                this.categoriesSqlHelper.ModifyTitle(category.Id, "User 2 Category Title 4");

                DataConflictException dce = Assert.ThrowsAsync <DataConflictException>(async() =>
                {
                    await service.ModifyAsync(category);
                });
                Assert.AreEqual(DalErrorType.BaseServiceDataConflictWithAskClientPolicy, dce.errorType);

                Assert.IsInstanceOf(typeof(DbCategory), dce.CurrentValues);
                Assert.IsInstanceOf(typeof(DbCategory), dce.DatabaseValues);

                DbCategory currentValues  = (DbCategory)dce.CurrentValues;
                DbCategory databaseValues = (DbCategory)dce.DatabaseValues;

                Assert.AreEqual(category.Id, databaseValues.Id);
                Assert.AreEqual("User 2 Category Title 4", databaseValues.Title);

                Assert.AreEqual(category.Id, currentValues.Id);
                Assert.AreEqual("User 1 Category Title 4", currentValues.Title);
            }
        }
        /// <summary>
        /// To the exception.
        /// </summary>
        /// <param name="exceptionInfo">The exception information.</param>
        /// <returns>System.Exception.</returns>
        public static Exception ToException(this ExceptionInfo exceptionInfo)
        {
            Exception result = null;

            if (exceptionInfo != null)
            {
                var innerException = exceptionInfo.InnerException;

                switch (exceptionInfo.ExceptionType)
                {
                case "Beyova.Diagnostic.HttpOperationException":
                    return(new HttpOperationException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint));

                case "Beyova.Diagnostic.SqlStoredProcedureException":
                    return(new SqlStoredProcedureException(exceptionInfo.Message, exceptionInfo.Code));

                default:
                    break;
                }

                switch (exceptionInfo.Code.Major)
                {
                case ExceptionCode.MajorCode.CreditNotAfford:
                    result = new CreditNotAffordException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.DataConflict:
                    result = new DataConflictException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.NotImplemented:
                    result = new UnimplementedException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.NullOrInvalidValue:
                    result = new InvalidObjectException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.OperationFailure:
                    result = new OperationFailureException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.OperationForbidden:
                    result = new OperationForbiddenException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.ResourceNotFound:
                    result = new ResourceNotFoundException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.ServiceUnavailable:
                    result = new ServiceUnavailableException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.UnauthorizedOperation:
                    result = new UnauthorizedOperationException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.HttpBlockError:
                    result = new HttpOperationException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                case ExceptionCode.MajorCode.Unsupported:
                    result = new UnsupportedException(exceptionInfo.Key ?? Guid.NewGuid(), exceptionInfo.CreatedStamp ?? DateTime.UtcNow, exceptionInfo.Message, exceptionInfo.Scene, exceptionInfo.Code, ToException(innerException), exceptionInfo.OperatorCredential, exceptionInfo.Data, exceptionInfo.Hint);
                    break;

                default:
                    result = new Exception(exceptionInfo.Message);
                    break;
                }
            }

            return(result);
        }