예제 #1
0
        public void Commit()
        {
            if (!IsStarted)
            {
                throw new InvalidOperationException();
            }
            if (IsDismissed)
            {
                throw new InvalidOperationException();
            }
            var completionSet = SelectedCompletionSet;
            var completion    = completionSet?.SelectionStatus.Completion;

            if (completion != null)
            {
                Debug.Assert(completionSet.SelectionStatus.IsSelected);
                if (completion is ICustomCommit customCommit)
                {
                    customCommit.Commit();
                }
                else
                {
                    var insertionText = completion.InsertionText;
                    if (insertionText != null)
                    {
                        var replaceSpan = completionSet.ApplicableTo;
                        var buffer      = replaceSpan.TextBuffer;
                        var span        = replaceSpan.GetSpan(buffer.CurrentSnapshot);
                        buffer.Replace(span.Span, insertionText);
                    }
                }
            }
            Committed?.Invoke(this, EventArgs.Empty);
            Dismiss();
        }
예제 #2
0
        public void CommitTransaction()
        {
            var operationId = Guid.Empty;

            try
            {
                operationId = _diagnosticListener.WriteDbSessionCommitBefore(this);
                #region Impl
                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    _logger.LogDebug("CommitTransaction.");
                }
                if (Transaction == null)
                {
                    if (_logger.IsEnabled(LogLevel.Error))
                    {
                        _logger.LogError("Before CommitTransaction,Please BeginTransaction first!");
                    }
                    throw new SmartSqlException("Before CommitTransaction,Please BeginTransaction first!");
                }
                Transaction.Commit();
                ReleaseTransaction();
                Committed?.Invoke(this, DbSessionEventArgs.None);
                #endregion
                _diagnosticListener.WriteDbSessionCommitAfter(operationId, this);
            }
            catch (Exception ex)
            {
                _diagnosticListener.WriteDbSessionCommitError(operationId, this, ex);
                throw;
            }
        }
예제 #3
0
        private void OnCommit()
        {
            hotSpot.Text = Text.Trim();

            Committed?.Invoke(this, EventArgs.Empty);

            Visible = false;
        }
예제 #4
0
 protected virtual void OnCommitted()
 {
     if (Committed == null)
     {
         return;
     }
     Committed.Invoke(this, new EventArgs());
 }
예제 #5
0
        /// <summary>
        ///     Asynchronously commits all changes made in this unit of work context to the database.
        /// </summary>
        /// <param name="cancellationToken">
        ///     The token that propagates a cancellation request to interrupt the operation.
        /// </param>
        /// <returns>
        ///     A task that represents the asynchronous commit operation.
        ///     The task result contains the number of affected entries in the database.
        /// </returns>
        /// <exception cref="DbUpdateException">Thrown when an error is encountered while saving to the database.</exception>
        /// <exception cref="DbUpdateConcurrencyException">Thrown when a concurrency violation is encountered while saving to the database.</exception>
        public virtual async Task <int> CommitAsync(CancellationToken cancellationToken = default)
        {
            Committing?.Invoke(this, new UnitOfWorkCommittingEventArgs(_registeredRepositories));

            var affectedEntries = await Context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            Committed?.Invoke(this, new UnitOfWorkCommittedEventArgs(affectedEntries, _registeredRepositories));

            return(affectedEntries);
        }
예제 #6
0
        /// <summary>
        ///     Commits all changes made in this unit of work context to the database.
        /// </summary>
        /// <returns>The number of affected entries in the database.</returns>
        /// <exception cref="DbUpdateException">Thrown when an error is encountered while saving to the database.</exception>
        /// <exception cref="DbUpdateConcurrencyException">Thrown when a concurrency violation is encountered while saving to the database.</exception>
        public virtual int Commit()
        {
            Committing?.Invoke(this, new UnitOfWorkCommittingEventArgs(_registeredRepositories));

            var affectedEntries = Context.SaveChanges();

            Committed?.Invoke(this, new UnitOfWorkCommittedEventArgs(affectedEntries, _registeredRepositories));

            return(affectedEntries);
        }
예제 #7
0
파일: UnitOfWork.cs 프로젝트: thomasvt/pose
        public void Dispose()
        {
            if (_isCommitted)
            {
                throw new Exception("UnitOfWork was already disposed earlier.");
            }

            Committed?.Invoke(this, EventArgs.Empty);
            _isCommitted = true;
        }
        public async Task Commit(CompletionItem item = null)
        {
            if (item == null)
            {
                item = CompletionListControl.Items[CompletionListControl.SelectedIndex].item;
            }

            Committed?.Invoke(this, new CompletionCommitEventArgs(item));

            await SetSelectedIndex(-1);
        }
예제 #9
0
파일: Crimes.cs 프로젝트: war-man/Mafia.NET
        public Notification Crime(IRole role, Enum key)
        {
            if (Framing != null)
            {
                return(Notification.Chat(role, key, User, Framing.Crime));
            }
            if (Innocent())
            {
                return(Notification.Chat(CrimeKey.NotGuilty, User));
            }

            var randomIndex = User.Match.Random.Next(Committed.Count);
            var crime       = Committed.ElementAt(randomIndex);

            return(Notification.Chat(role, key, User, crime));
        }
예제 #10
0
 public void Commit()
 {
     if (!IsStarted)
     {
         throw new InvalidOperationException();
     }
     if (IsDismissed)
     {
         throw new InvalidOperationException();
     }
     if (SelectedCompletionSet.SelectionStatus.IsSelected)
     {
         SelectedCompletionSet.Commit();
     }
     Committed?.Invoke(this, EventArgs.Empty);
     Dismiss();
 }
예제 #11
0
        private void OnCommit()
        {
            hotSpot.Text = Text.Trim();

            try
            {
                hotSpot.Node.Update(hotSpot);
            }
            catch (Exception ex)
            {
                Program.Logger.Log(ex);
            }

            Committed?.Invoke(this, EventArgs.Empty);

            Visible = false;
        }
예제 #12
0
        /// <summary>
        /// Commits the current transaction.
        /// </summary>
        public void Commit()
        {
            if (!_isInTransaction)
            {
                throw new InvalidOperationException("The transaction was either already committed or rolled back.");
            }

            _rollbackOnDispose = false;
            _isInTransaction   = false;

            Committing?.Invoke(this, EventArgs.Empty);

            _parentTransaction.Release(_savePoint);

            Committed?.Invoke(this, EventArgs.Empty);
            Finished?.Invoke(this, EventArgs.Empty);
        }
예제 #13
0
        /// <summary>
        /// Commits the current transaction.
        /// </summary>
        public void Commit()
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            if (!_isInTransaction)
            {
                throw new InvalidOperationException("The transaction was either already committed or rolled back.");
            }

            Committing?.Invoke(this, EventArgs.Empty);
            _connection.Commit();
            Committed?.Invoke(this, EventArgs.Empty);

            FinishTransaction();
        }
예제 #14
0
        public TEntity Create <TEntity>(TEntity entity)
            where TEntity : class
        {
            PendingActions.Add(() =>
            {
                Committed.Add(entity);

                if (EntityHelper.IsIdentityType(typeof(TEntity)))
                {
                    int maxKey = GetAll <TEntity>().Max(ent => EntityHelper.GetKeys(ent).OfType <int>().First());
                    EntityHelper.SetKeys(entity, maxKey + 1);
                }
            });

            UpdateAssociations(entity);

            return(entity);
        }
예제 #15
0
        public void Delete <TEntity>(params TEntity[] entities)
            where TEntity : class
        {
            if (entities == null)
            {
                throw new ApplicationException("InMemoryDataAccesor: Passed null to delete");
            }

            foreach (TEntity entity in entities)
            {
                TEntity current = entity;
                if (!Committed.Contains(current))
                {
                    throw new ApplicationException("InMemoryDataAccesor: Trying to delete entity that is not in the database");
                }

                PendingActions.Add(() => Committed.Remove(current));
            }
        }
예제 #16
0
 private void UpdateAssociations <TEntity>(TEntity entity)
 {
     foreach (PropertyInfo associationProp in EntityHelper.AssociationPropertyMap[typeof(TEntity)])
     {
         IEnumerable values = (IEnumerable)associationProp.GetValue(entity);
         foreach (object value in values)
         {
             Type   objType  = value.GetType();
             object original = Committed.FirstOrDefault(obj => obj.GetType() == value.GetType() && EntityHelper.AreKeysEqual(obj, value));
             if (original == null)
             {
                 CreateMethod.MakeGenericMethod(objType).Invoke(this, new[] { value });
             }
             else
             {
                 UpdateMethod.MakeGenericMethod(objType).Invoke(this, new[] { value });
             }
         }
     }
 }
예제 #17
0
        public void Commit()
        {
            if (SelectedCompletionSet != null)
            {
                Completion selectedCompletion = SelectedCompletionSet.SelectionStatus.Completion;
                if (selectedCompletion != null && selectedCompletion.InsertionText != null)
                {
                    ITrackingSpan applicableTo = SelectedCompletionSet.ApplicableTo;
                    ITextBuffer   buffer       = applicableTo.TextBuffer;
                    ITextSnapshot snapshot     = buffer.CurrentSnapshot;
                    SnapshotSpan  replaceSpan  = applicableTo.GetSpan(snapshot);

                    buffer.Replace(replaceSpan.Span, selectedCompletion.InsertionText);
                    TextView.Caret.EnsureVisible();
                }
            }

            Committed?.Invoke(this, EventArgs.Empty);
            Dismiss();
        }
예제 #18
0
        /// <summary>
        ///     Completes the unit of work.
        /// </summary>
        /// <remarks>
        ///     By default, if the subject of the unit of work implements <see cref="IDisposable" />, then it will disposed when the root unit of work is disposed.
        /// </remarks>
        public void Dispose()
        {
            var subject = Subject;

            if (!canCommit && subject != null)
            {
                RejectAll();
            }

            if (isOutermost)
            {
                if (!rejected && subject != null)
                {
                    try
                    {
                        commit(this);

                        // check again that Commit did not fail in a way that requires rejection
                        if (!rejected)
                        {
                            Committed?.Invoke(this, subject);
                        }
                        else
                        {
                            RejectAll();
                        }
                    }
                    catch (Exception ex)
                    {
                        RejectDueTo(ex);
                        RejectAll();
                    }
                }
                SetInContext(null);

                disposables.Dispose();
                resources.Clear();
            }

            disposed = true;
        }
예제 #19
0
파일: Crimes.cs 프로젝트: war-man/Mafia.NET
 public void Add(Key crime)
 {
     Committed.Add(crime);
 }
예제 #20
0
 protected virtual void OnCommitted(SvnCommittedEventArgs e)
 {
     Committed?.Invoke(this, e);
 }
예제 #21
0
 public void Commit()
 {
     raw.Commit();
     Committed?.Invoke(this, EventArgs.Empty);
 }
예제 #22
0
 public IQueryable <TEntity> GetAll <TEntity>()
     where TEntity : class
 {
     return(Committed.OfType <TEntity>().AsQueryable());
 }
예제 #23
0
 private void OnCommitted(CommitResult commitResult)
 => Committed?.Invoke(this, new CommitResultEventArgs(commitResult));
예제 #24
0
 private void Commit(string credential)
 => Committed?.Invoke(credential);