Exemplo n.º 1
0
    private async void EntityChanged(object sender, EntityChangedEventArgs e) {
      if (_ignoreEntityChanged) { return; }

      // Save on propertyChanged (after brief delay)
      if (e.Action == EntityAction.PropertyChange) {
        try {
          CancelDelay();
          // Delay 1 second to let more changes (keystrokes) arrive
          // then save if there are still unsaved changes.
          _saveChangeTokenSource = new CancellationTokenSource();
          await Task.Delay(1000, _saveChangeTokenSource.Token);
          _saveChangeTokenSource = null;
          if (HasChanges) { await Save(); }
        } 
        catch (TaskCanceledException) { } 
        catch (Exception ex) { _logger.Error(ex); }
      }
        // Save Added or Deleted entity immediately
      else if (e.Action == EntityAction.EntityStateChange &&
              ((e.EntityAspect.EntityState & ADD_DELETE) != 0)) {
        CancelDelay();
        try {
          await Save();
          // ReSharper disable once EmptyGeneralCatchClause
          // already handled within Save
        } catch (Exception) {
        }
      }
    }
Exemplo n.º 2
0
        // Handle change in status of any entity
        private void _em_EntityChanged(object sender, EntityChangedEventArgs e) {
            var todo = e.Entity as TodoItem;
            Console.WriteLine("Changed: " + todo.Description + " " + e.Action + " state = " + e.EntityAspect.EntityState);
            if (!_autoSaveEnabled) return;

            if (ValidateEntity(e.Entity)) {
                // Note:  Newly-added entities are saved in the AddNewTodo() method so they don't need to be saved here
                if (e.Action == EntityAction.EntityStateChange && e.EntityAspect.EntityState.IsDeletedOrModified()) {
                    SaveChanges();
                }
            }
            SelectedItem = null;
        }