Ejemplo n.º 1
0
        private void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            var added   = e.NewItems != null ? e.NewItems[0] as TwitterAccount : null;
            var removed = e.OldItems != null ? e.OldItems[0] as TwitterAccount : null;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                if (added == null)
                {
                    throw new ArgumentException("added item is null.");
                }
                _accountCache[added.Id] = added;
                Task.Run(() => AccountProxy.AddAccountAsync(added.Id));
                break;

            case NotifyCollectionChangedAction.Remove:
                if (removed == null)
                {
                    throw new ArgumentException("removed item is null.");
                }
                TwitterAccount removal;
                _accountCache.TryRemove(removed.Id, out removal);
                Task.Run(() => AccountProxy.RemoveAccountAsync(removed.Id));
                break;

            case NotifyCollectionChangedAction.Replace:
                if (added == null)
                {
                    throw new ArgumentException("added item is null.");
                }
                if (removed == null)
                {
                    throw new ArgumentException("removed item is null.");
                }
                _accountCache[added.Id] = added;
                TwitterAccount replacee;
                _accountCache.TryRemove(removed.Id, out replacee);
                Task.Run(() => AccountProxy.AddAccountAsync(added.Id));
                Task.Run(() => AccountProxy.RemoveAccountAsync(removed.Id));
                break;

            case NotifyCollectionChangedAction.Reset:
                _accountCache.Clear();
                _accountObservableCollection.ForEach(a => _accountCache[a.Id] = a);
                Task.Run(() => AccountProxy.RemoveAllAccountsAsync());
                break;
            }
            _settingItem.Value = _accountObservableCollection.ToList();
        }
Ejemplo n.º 2
0
 private async Task RemoveAccountSub(long id)
 {
     await AccountProxy.RemoveAccountAsync(id).ConfigureAwait(false);
 }
Ejemplo n.º 3
0
 private async Task RemoveAccountSub(long id)
 {
     await AccountProxy.RemoveAccountAsync(id);
 }