Пример #1
0
        public SaveResult SaveChanges(JObject saveBundle, TransactionSettings transactionSettings = null)
        {
            if (SaveWorkState == null || SaveWorkState.WasUsed)
            {
                InitializeSaveState(saveBundle);
            }

            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;
                throw;
            }
            catch (Exception e2)
            {
                if (!HandleSaveException(e2, SaveWorkState))
                {
                    throw;
                }
            }
            finally
            {
                CloseDbConnection();
            }

            return(SaveWorkState.ToSaveResult());
        }
Пример #2
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;
                throw;
            } catch (Exception e2) {
                if (!HandleSaveException(e2, SaveWorkState))
                {
                    throw;
                }
            } finally {
                CloseDbConnection();
            }

            return(SaveWorkState.ToSaveResult());
        }
Пример #3
0
        /// <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));
        }
Пример #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;
        throw; 
      } catch(Exception e2) {
        if (!HandleSaveException(e2, SaveWorkState)) {
          throw;
        }
      } finally {
        CloseDbConnection();
      }

      return SaveWorkState.ToSaveResult();

    }
Пример #5
0
    public SaveResult SaveChanges(JObject saveBundle, TransactionSettings transactionSettings = null) {

      if (SaveWorkState == null || SaveWorkState.WasUsed) {
        InitializeSaveState(saveBundle);
      }

      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;
        throw; 
      } catch(Exception e2) {
        if (!HandleSaveException(e2, SaveWorkState)) {
          throw;
        }
      } finally {
        CloseDbConnection();
      }

      return SaveWorkState.ToSaveResult();
    }
Пример #6
0
        public Breeze.ContextProvider.SaveResult Commit(Newtonsoft.Json.Linq.JObject changeSet)
        {
            TransactionSettings transactionSettings = new TransactionSettings() { TransactionType = TransactionType.TransactionScope };

            return contextProvider.SaveChanges(changeSet, transactionSettings);
        }
Пример #7
0
 public Task <SaveResult> SaveChangesAsync(JObject saveBundle, TransactionSettings transactionSettings = null)
 {
     return(SaveChangesAsync(saveBundle, CancellationToken.None, transactionSettings));
 }