Beispiel #1
0
        public SaveResult SaveChanges(JObject saveBundle, TransactionSettings transactionSettings = null)
        {
            JsonSerializer = CreateJsonSerializer();

            var dynSaveBundle  = (dynamic)saveBundle;
            var entitiesArray  = (JArray)dynSaveBundle.entities;
            var dynSaveOptions = dynSaveBundle.saveOptions;

            SaveOptions   = (SaveOptions)JsonSerializer.Deserialize(new JTokenReader(dynSaveOptions), typeof(SaveOptions));
            SaveWorkState = new SaveWorkState(this, entitiesArray);

            transactionSettings = transactionSettings ?? BreezeConfig.Instance.GetTransactionSettings();
            try {
                if (transactionSettings.TransactionType == TransactionType.TransactionScope)
                {
                    var txOptions = transactionSettings.ToTransactionOptions();
                    using (var txScope = new TransactionScope(TransactionScopeOption.Required, txOptions)) {
                        OpenAndSave(SaveWorkState);
                        txScope.Complete();
                    }
                }
                else if (transactionSettings.TransactionType == TransactionType.DbTransaction)
                {
                    this.OpenDbConnection();
                    using (IDbTransaction tran = BeginTransaction(transactionSettings.IsolationLevelAs)) {
                        try {
                            OpenAndSave(SaveWorkState);
                            tran.Commit();
                        } catch {
                            tran.Rollback();
                            throw;
                        }
                    }
                }
                else
                {
                    OpenAndSave(SaveWorkState);
                }
            } catch (EntityErrorsException e) {
                // SaveWorkState.EntityErrors = e.EntityErrors;
                var error = new SaveError(e.EntityErrors);
                var resp  = new HttpResponseMessage(e.StatusCode)
                {
                    Content      = new ObjectContent(typeof(SaveError), error, JsonFormatter.Create()),
                    ReasonPhrase = e.Message ?? "Entity Errors exception"
                };
                throw new HttpResponseException(resp);
            } catch (Exception e2) {
                if (!HandleSaveException(e2, SaveWorkState))
                {
                    throw;
                }
            } finally {
                CloseDbConnection();
            }

            return(SaveWorkState.ToSaveResult());
        }
    public SaveResult SaveChanges(JObject saveBundle, TransactionSettings transactionSettings = null) {
      JsonSerializer = CreateJsonSerializer();

      var dynSaveBundle = (dynamic)saveBundle;
      var entitiesArray = (JArray)dynSaveBundle.entities;
      var dynSaveOptions = dynSaveBundle.saveOptions;
      SaveOptions = (SaveOptions) JsonSerializer.Deserialize(new JTokenReader(dynSaveOptions), typeof(SaveOptions));
      SaveWorkState = new SaveWorkState(this, entitiesArray);

      transactionSettings = transactionSettings ?? BreezeConfig.Instance.GetTransactionSettings();
      try {
        if (transactionSettings.TransactionType == TransactionType.TransactionScope) {
          var txOptions = transactionSettings.ToTransactionOptions();
          using (var txScope = new TransactionScope(TransactionScopeOption.Required, txOptions)) {           
            OpenAndSave(SaveWorkState);           
            txScope.Complete();
          }
        } else if (transactionSettings.TransactionType == TransactionType.DbTransaction) {
          this.OpenDbConnection();
          using (IDbTransaction tran = BeginTransaction(transactionSettings.IsolationLevelAs)) {
            try {
              OpenAndSave(SaveWorkState);
              tran.Commit();
            } catch {
              tran.Rollback();
              throw;
            }
          }          
        } else {
          OpenAndSave(SaveWorkState);
        }
      } catch (EntityErrorsException e) {
        // SaveWorkState.EntityErrors = e.EntityErrors;
        var error = new SaveError(e.EntityErrors);
        var resp = new HttpResponseMessage(e.StatusCode) {
          Content = new ObjectContent(typeof(SaveError), error, JsonFormatter.Create()),
          ReasonPhrase = e.Message ?? "Entity Errors exception"
        };
        throw new HttpResponseException(resp);
      } catch(Exception e2) {
        if (!HandleSaveException(e2, SaveWorkState)) {
          throw;
        }
      } finally {
        CloseDbConnection();
      }

      return SaveWorkState.ToSaveResult();

    }
        /// <summary>
        /// See <see cref="Object.Equals(Object)"/>.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(Object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            TransactionSettings other = obj as TransactionSettings;

            if (other == null)
            {
                return(false);
            }
            return(other.IsolationLevel.Equals(this.IsolationLevel) &&
                   other.Timeout.Equals(this.Timeout) &&
                   other.TransactionType.Equals(this.TransactionType));
        }
Beispiel #4
0
        public SaveResult SaveChanges(JObject saveBundle, TransactionSettings transactionSettings = null)
        {
            JsonSerializer = CreateJsonSerializer();

            var dynSaveBundle  = (dynamic)saveBundle;
            var entitiesArray  = (JArray)dynSaveBundle.entities;
            var dynSaveOptions = dynSaveBundle.saveOptions;

            SaveOptions   = (SaveOptions)JsonSerializer.Deserialize(new JTokenReader(dynSaveOptions), typeof(SaveOptions));
            SaveWorkState = new SaveWorkState(this, entitiesArray);

            transactionSettings = transactionSettings ?? BreezeConfig.Instance.GetTransactionSettings();
            try {
                if (transactionSettings.TransactionType == TransactionType.TransactionScope)
                {
                    var txOptions = transactionSettings.ToTransactionOptions();
                    using (var txScope = new TransactionScope(TransactionScopeOption.Required, txOptions)) {
                        OpenAndSave(SaveWorkState);
                        txScope.Complete();
                    }
                }
                else if (transactionSettings.TransactionType == TransactionType.DbTransaction)
                {
                    this.OpenDbConnection();
                    using (IDbTransaction tran = BeginTransaction(transactionSettings.IsolationLevelAs)) {
                        try {
                            OpenAndSave(SaveWorkState);
                            tran.Commit();
                        } catch {
                            tran.Rollback();
                            throw;
                        }
                    }
                }
                else
                {
                    OpenAndSave(SaveWorkState);
                }
            } catch (EntityErrorsException e) {
                SaveWorkState.EntityErrors = e.EntityErrors;
            } finally {
                CloseDbConnection();
            }

            return(SaveWorkState.ToSaveResult());
        }