Exemplo n.º 1
0
        private IEnumerable <IResult> LoadUsers()
        {
            yield return(new SingleResult
            {
                Action = () =>
                {
                    LoadText = "Loading...";
                    TotalUsedSpace = 0;
                }
            });

            var loadResult = new LoadResult {
                Filer = CreateFilter(PageSize)
            };

            yield return(loadResult);

            Users.Clear();

            long usedSpace = 0;

            foreach (AdminUserDTO adminUserDto in loadResult.Users)
            {
                usedSpace += adminUserDto.DatabaseSize ?? 0;
                Users.Add(MapToViewModel(adminUserDto));
            }

            TotalUsedSpace = usedSpace;
            LoadText       = "Load";
        }
 public void Logout()
 {
     _dataService.Disconnect();
     CurrentUserName = _dataService.UserName;
     _week.Clear();
     NotifyVisibilityChanged();
 }
Exemplo n.º 3
0
        private void SynchronizeSelectionCollections <TSource, TTarget>(IObservableCollection <TTarget> collection, Func <TSource, TTarget> getItem, NotifyCollectionChangedEventArgs e)
        {
            if (synchronizingSelection)
            {
                return;
            }

            synchronizingSelection = true;
            if (e.NewItems != null)
            {
                foreach (TSource newItem in e.NewItems)
                {
                    var targetItem = getItem(newItem);
                    collection.Add(targetItem);
                }
            }
            if (e.OldItems != null)
            {
                foreach (TSource oldItem in e.OldItems)
                {
                    var targetItem = getItem(oldItem);
                    collection.Remove(targetItem);
                }
            }
            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                collection.Clear();
            }
            synchronizingSelection = false;
        }
Exemplo n.º 4
0
 public static void Replace <T>(this IObservableCollection <T> collection, IEnumerable <T> items)
 {
     collection.IsNotifying = false;
     collection.Clear();
     collection.AddRange(items);
     collection.IsNotifying = true;
     collection.Refresh();
 }
Exemplo n.º 5
0
        public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
        {
            if (managerType == typeof(CollectionChangedEventManager))
            {
                NotifyCollectionChangedEventArgs arg = e as NotifyCollectionChangedEventArgs;
                if (arg != null)
                {
                    switch (arg.Action)
                    {
                    case NotifyCollectionChangedAction.Add:
                        if (arg.NewItems != null)
                        {
                            for (int itemIndex = 0; itemIndex < arg.NewItems.Count; itemIndex++)
                            {
                                _syncCollection.Insert(arg.NewStartingIndex +
                                                       itemIndex, _create(arg.NewItems[itemIndex] as T));
                            }
                            break;
                        }
                        break;

                    case NotifyCollectionChangedAction.Move:
                        _syncCollection.RemoveAt(arg.OldStartingIndex);
                        _syncCollection.Insert(arg.NewStartingIndex, _create(arg.NewItems[0] as T));
                        break;

                    case NotifyCollectionChangedAction.Remove:
                        if (arg.OldItems != null && _syncCollection.Count > 0)
                        {
                            for (int itemIndex = 0; itemIndex < arg.OldItems.Count; itemIndex++)
                            {
                                _syncCollection.RemoveAt(arg.OldStartingIndex);
                            }
                        }
                        break;

                    case NotifyCollectionChangedAction.Replace:
                        if (arg.NewItems == null)
                        {
                            for (int itemIndex = 0; itemIndex < arg.NewItems.Count; itemIndex++)
                            {
                                _syncCollection[arg.NewStartingIndex + itemIndex] = _create(arg.NewItems[itemIndex] as T);
                            }
                        }
                        break;

                    case NotifyCollectionChangedAction.Reset:
                        _syncCollection.Clear();
                        break;

                    default:
                        break;
                    }
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        private void RefreshServersFromPhysicalModel()
        {
            var groupedServers = physicalModel.Endpoints.GroupBy(x => x.ServerName);

            servers.Clear();

            foreach (var keys in groupedServers)
            {
                servers.Add(new Server {
                    Name = keys.Key
                });
            }
        }
Exemplo n.º 7
0
 public void Init()
 {
     CodeTemplate[] templates = new CodeTemplate[0];
     _provider.ExecuteScopedWork(provider =>
     {
         IDataContract contract = provider.GetRequiredService <IDataContract>();
         templates = contract.CodeTemplates.OrderBy(m => !m.IsSystem).ThenBy(m => m.Order).ToArray();
     });
     Templates.Clear();
     foreach (CodeTemplate template in templates)
     {
         TemplateViewModel model = _provider.GetRequiredService <TemplateViewModel>();
         model = template.MapTo(model);
         Templates.Add(model);
     }
 }
        /// <summary>
        /// Função chamada quando a tela é exibida
        /// </summary>
        protected override void OnActivate()
        {
            _manipulacoes.Clear();

            // Recupera uma referência do banco
            using (var db = new DataBase.ManipulaImagemContext())
            {
                // Carrega as manipulações cadastradas
                _manipulacoes.AddRange(
                    db.Manipulacoes.ToArray().Select(m =>
                {
                    var i         = IoC.Get <ManipulacaoItemViewModel>();
                    i.Manipulacao = m;
                    i.Excluido   += (s, e) => _manipulacoes.Remove(i);
                    return(i);
                }));
            }
        }
Exemplo n.º 9
0
        private static void ReorderRecentFiles(IObservableCollection <RecentFileInfo> target)
        {
            if (target == null)
            {
                return;
            }

            var orderedItem = new List <RecentFileInfo>();

            orderedItem.AddRange(target.Where(p => p.FixedAt.HasValue).OrderByDescending(p => p.FixedAt));
            orderedItem.AddRange(target.Where(p => !p.FixedAt.HasValue).OrderByDescending(p => p.LastOpenedAt));

            target.IsNotifying = false;

            target.Clear();

            target.IsNotifying = true;

            target.AddRange(orderedItem);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Download all transactions for specific account of the specific user.
        /// </summary>
        /// <returns>Operation result.</returns>
        public IEnumerable <IResult> DownloadAllTransactions()
        {
            yield return(Show.Busy(new BusyScreen {
                Message = "Loading..."
            }));

            var request = new GetAllTransactionsResult(userId, CurrentAccount.Id);

            yield return(request);

            TransactionRecords.Clear();
            TransactionRecords.AddRange(request.TransactionRecords);

            if (Reloaded != null)
            {
                Reloaded(this, EventArgs.Empty);
            }

            yield return(Show.NotBusy());
        }
        private void ReloadApproaches()
        {
            this.SelectedApproache = null;
            approachesCache.Clear();
            IReadOnlyList <ApproachSummaryDto> dtos = this.approachService.GetApproaches();

            foreach (ApproachSummaryDto dto in dtos)
            {
                IApproachDetailsViewModel detailsViewModel = this.detailsViewModelFactory.Invoke();
                detailsViewModel.Load(dto.Id, dto.Name, dto.Criteria);
                approachesCache.Add(detailsViewModel);
            }

            this.NotifyOfPropertyChange(() => this.Approaches);
            this.NotifyOfPropertyChange(() => this.SelectedApproache);
            this.NotifyOfPropertyChange(() => this.CanCreate);
            this.NotifyOfPropertyChange(() => this.CanDelete);
            this.NotifyOfPropertyChange(() => this.CanEdit);
            this.NotifyOfPropertyChange(() => this.CanOpen);
        }
Exemplo n.º 12
0
        public static void BuildPlugins(IEnumerable <Lazy <IDPlugin, IPluginMetaData> > _plugins,
                                        IObservableCollection <IDPlugin> items, string id)
        {
            items.Clear();

            var plugins = _plugins.Where(x => x.Metadata.ParentId == id)
                          .OrderBy(x => x.Metadata.Priority);

            foreach (var v in plugins)
            {
                var screen = v.Value;
                if (screen is IDPlugin iScreen)
                {
                    iScreen.DisplayName = v.Metadata.Name.Translate();
                    iScreen.Panel.Icon  = v.Metadata.Icon;
                    iScreen.Panel.Id    = v.Metadata.Id;
                }

                items.Add(v.Value);
            }
        }
Exemplo n.º 13
0
 public void ClearConsole()
 {
     Console.Clear();
 }
        private void TestEvents(IObservableCollection<string> instance)
        {
            var stringToAdd = "Adam is awesome";
            var addingCallCount = 0;
            var addedCallCount = 0;
            var removingCallCount = 0;
            var removedCallCount = 0;
            var clearingCallCount = 0;
            var clearedCallCount = 0;

            EventHandler<ObservableCollectionChangingEventArgs<string>> cancelAddHandler = (sender, eventArgs) =>
            {
                addingCallCount++;
                eventArgs.Items.Should().Contain(stringToAdd);
                eventArgs.Items.Count().Should().Be(1);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsAdded);
                eventArgs.CancelOperation.Should().BeFalse();
                eventArgs.CancelOperation = true;
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().NotContain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangingEventArgs<string>> allowAddHandler = (sender, eventArgs) =>
            {
                addingCallCount++;
                eventArgs.Items.Should().Contain(stringToAdd);
                eventArgs.Items.Count().Should().Be(1);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsAdded);
                eventArgs.CancelOperation.Should().BeFalse();
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().NotContain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangedEventArgs<string>> addChangedHandler = (sender, eventArgs) =>
            {
                addedCallCount++;
                eventArgs.Items.Should().Contain(stringToAdd);
                eventArgs.Items.Count().Should().Be(1);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsAdded);
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().Contain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangingEventArgs<string>> cancelRemoveHandler = (sender, eventArgs) =>
            {
                removingCallCount++;
                eventArgs.Items.Should().Contain(stringToAdd);
                eventArgs.Items.Count().Should().Be(1);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsRemoved);
                eventArgs.CancelOperation.Should().BeFalse();
                eventArgs.CancelOperation = true;
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().Contain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangingEventArgs<string>> allowRemoveHandler = (sender, eventArgs) =>
            {
                removingCallCount++;
                eventArgs.Items.Should().Contain(stringToAdd);
                eventArgs.Items.Count().Should().Be(1);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsRemoved);
                eventArgs.CancelOperation.Should().BeFalse();
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().Contain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangedEventArgs<string>> removeChangedHandler = (sender, eventArgs) =>
            {
                removedCallCount++;
                eventArgs.Items.Should().Contain(stringToAdd);
                eventArgs.Items.Count().Should().Be(1);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsRemoved);
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().NotContain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangingEventArgs<string>> cancelClearHandler = (sender, eventArgs) =>
            {
                clearingCallCount++;
                eventArgs.Items.Count().Should().Be(2);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsRemoved);
                eventArgs.CancelOperation.Should().BeFalse();
                eventArgs.CancelOperation = true;
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().Contain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangingEventArgs<string>> allowClearHandler = (sender, eventArgs) =>
            {
                clearingCallCount++;
                eventArgs.Items.Count().Should().Be(2);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsRemoved);
                eventArgs.CancelOperation.Should().BeFalse();
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().Contain(x => eventArgs.Items.Contains(x));
            };

            EventHandler<ObservableCollectionChangedEventArgs<string>> clearChangedHandler = (sender, eventArgs) =>
            {
                clearedCallCount++;
                eventArgs.Items.Count().Should().Be(2);
                eventArgs.ChangeType.Should().Be(ObservableCollectionChangeTypes.ItemsRemoved);
                var collection = sender as IEnumerable<string>;
                collection.Should().NotBeNull();
                collection.Should().NotContain(x => eventArgs.Items.Contains(x));
            };

            // try to add with cancelAddHandler first, then with allowAddHandler, then remove with cancelRemoveHandler, then allowRemoveHandler

            instance.Clear();
            instance.Should().BeEmpty();
            instance.Changing += cancelAddHandler;
            instance.Changed += addChangedHandler;

            instance.Add(null);
            instance.Should().BeEmpty();
            addingCallCount.Should().Be(0);
            addedCallCount.Should().Be(0);

            instance.Add(stringToAdd);
            instance.Should().BeEmpty();
            addingCallCount.Should().Be(1);
            addedCallCount.Should().Be(0);

            instance.Changing -= cancelAddHandler;
            instance.Changing += allowAddHandler;

            instance.Add(stringToAdd);
            instance.Should().Contain(stringToAdd);
            instance.Count.Should().Be(1);
            addingCallCount.Should().Be(2);
            addedCallCount.Should().Be(1);

            instance.Changing -= allowAddHandler;
            instance.Changed -= addChangedHandler;
            instance.Changing += cancelRemoveHandler;
            instance.Changed += removeChangedHandler;

            instance.Remove(null);
            instance.Count.Should().Be(1);
            removingCallCount.Should().Be(0);
            removedCallCount.Should().Be(0);

            instance.Remove(stringToAdd);
            instance.Should().Contain(stringToAdd);
            instance.Count.Should().Be(1);
            removingCallCount.Should().Be(1);
            removedCallCount.Should().Be(0);

            instance.Changing -= cancelRemoveHandler;
            instance.Changing += allowRemoveHandler;
            instance.Remove(stringToAdd);
            instance.Should().BeEmpty();
            removingCallCount.Should().Be(2);
            removedCallCount.Should().Be(1);

            instance.Changing -= allowRemoveHandler;
            instance.Changed -= removeChangedHandler;

            instance.Changing += cancelClearHandler;
            instance.Changed += clearChangedHandler;
            instance.Clear();
            clearingCallCount.Should().Be(0);
            clearedCallCount.Should().Be(0);

            instance.Changing -= cancelClearHandler;
            instance.Changed -= clearChangedHandler;
            instance.Add("a");
            instance.Add("b");
            instance.Count.Should().Be(2);
            instance.Changing += cancelClearHandler;
            instance.Changed += clearChangedHandler;
            instance.Clear();
            instance.Count.Should().Be(2);
            clearingCallCount.Should().Be(1);
            clearedCallCount.Should().Be(0);
            instance.Changing -= cancelClearHandler;
            instance.Changing += allowClearHandler;
            instance.Clear();
            instance.Should().BeEmpty();
            clearingCallCount.Should().Be(2);
            clearedCallCount.Should().Be(1);
            instance.Changing -= allowClearHandler;
            instance.Changed -= clearChangedHandler;
        }
Exemplo n.º 15
0
 public void Clear() => _collectionImplementation.Clear();
Exemplo n.º 16
0
 void Reset()
 {
     Datas.Clear();
     SelectedData = null;
 }
 /// <summary>
 /// Limpa a coleção.
 /// </summary>
 public void Clear()
 {
     _source.Clear();
 }