private void SetupNodes() { ViewModelNode start = new ViewModelNode(this) { Name = "Start", NameEnable = false, CanBeDelete = false }; start.Input.Visible = null; Nodes.Add(start); ViewModelNode end = new ViewModelNode(this) { Name = "End", NameEnable = false, CanBeDelete = false, Point1 = new MyPoint(100, 100) }; end.TransitionsVisible = null; end.RollUpVisible = null; Nodes.Add(end); }
public void AddInvokesAnAddChange() { var person = new Person("Adult1", 50); _collection.Add(person); Assert.AreEqual(1, _results.Messages.Count, "Should be 1 updates"); Assert.AreEqual(1, _results.Data.Count, "Should be 1 item in the cache"); Assert.AreEqual(person, _results.Data.Items.First(), "Should be same person"); }
public void AddMenu(params MenuDefinition[] menu) { foreach (var menuDefinition in menu) { _items.Add(menuDefinition); } }
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; }
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); } }
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"; }
private IPresenter EnsurePresenter(IPresenter presenter) { int index = _presenters.IndexOf(presenter); if (index == -1) { _presenters.Add(presenter); } else { presenter = _presenters[index]; } var node = presenter as IPresenterNode; if (node != null) { node.Parent = this; } if (IsInitialized) { presenter.Initialize(); } return(presenter); }
public void Handle(VideoFileOperationCoroutine message) { if (!desiredFileOperationsStack.Contains(message) && message.DesiredFileAction == AcceptableFileAction) { desiredFileOperationsStack.Add(message.Register(desiredFileOperationsStack)); FindAcceptingFolder(message); } }
public void Handle(VideoFileOperationCoroutine message) { if (!fileOperationsStack.Contains(message) && message.DesiredFileAction != VideoArchiveAction.NoAction) { fileOperationsStack.Add(message.Register(fileOperationsStack)); } //Items.SelectMany(sg => sg.VideoFileTree).Cast<VideoFileStorageDevice>() // .Apply(sd => sd.AvailableFreeSpace = sd.StorageDevice.AvailableFreeSpace // + fileOperationsStack.Where(op => (op.AcceptedFileAction == VideoArchiveAction.ToArchive || op.AcceptedFileAction == VideoArchiveAction.ToPrelimArchive) && op.BaseFile.ParentFolder.StorageDevice.FolderPath == sd.SeriesDirectoryAsPath).Sum(op => op.ByteVolume) // - fileOperationsStack.Where(op => (op.AcceptedFileAction == VideoArchiveAction.ToArchive || op.AcceptedFileAction == VideoArchiveAction.ToPrelimArchive || op.AcceptedFileAction == VideoArchiveAction.TransferCopy) && op.DestinationSeriesFolder.StorageDevice.FolderPath == sd.SeriesDirectoryAsPath).Sum(op => op.ByteVolume)); }
public bool TryAddMessage(ChatMessageViewModel message) { if (!ReferenceEquals(message.User, User)) { return(false); } _messages.Add(message); LastMessageDateTime = message.MessageDateTime; UnreadMessageCount = _messages.Count(x => !x.HasBeenSeen); return(true); }
public CollectionSyncer(ICollection <T> t, Func <T, U> create) { _create = create; INotifyCollectionChanged collection = t as INotifyCollectionChanged; if (collection == null) { throw new ArgumentException("The ICollection<T> must be INotifyCollectionChanged"); } CollectionChangedEventManager.AddListener(collection, this); _syncCollection = new BindableCollection <U>(); t.Apply(item => _syncCollection.Add(_create(item))); }
public bool Add(object name, object id, object count, object timeout) { if (name is FloodRule rule) { rules.Add(rule); return(true); } else if ((name is string || name is ConcatenatedString) && (id is int || id is double) && (count is int || count is double) && (timeout is int || timeout is double)) { rules.Add(new FloodRule(script, name.ToString(), Convert.ToInt32(id), Convert.ToDouble(count), Convert.ToDouble(timeout))); return(true); } return(false); }
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 }); } }
public ShellViewModel() { TeamMembers = new BindableCollection <TeamMember>(); TeamMembers.Add(new TeamMember { FirstName = "Noga", LastName = "Lavan", Age = 19 }); TeamMembers.Add(new TeamMember { FirstName = "Aviad", LastName = "Rozenkof", Age = 24 }); TeamMembers.Add(new TeamMember { FirstName = "Shir", LastName = "Magen", Age = 22 }); }
private void DoUpdate(IChangeSet <TObject, TKey> updates, IObservableCollection <TObject> list) { updates.ForEach(update => { switch (update.Reason) { case ChangeReason.Add: list.Add(update.Current); break; case ChangeReason.Remove: list.Remove(update.Current); break; case ChangeReason.Update: { list.Remove(update.Previous.Value); list.Add(update.Current); } break; } }); }
public DirectoryViewModel(string path, ITreeNode parrent = null, IObservableCollection<FileViewModel> allFiles = null, SynchronizationContext synchronizationContext = null) { if (synchronizationContext == null) { if (parrent is DirectoryViewModel) synchronizationContext = ((DirectoryViewModel)parrent).m_synchronizationContext; if (synchronizationContext == null) synchronizationContext = SynchronizationContext.Current; } Debug.Assert(synchronizationContext != null, "SynchronizationContext should not be null"); m_synchronizationContext = synchronizationContext; m_children = new SortedObservableCollection<ITreeNode>(new AsyncObservableCollection<ITreeNode>(synchronizationContext), (node, treeNode) => (String.Compare(node.Name, treeNode.Name, StringComparison.Ordinal) + (node is DirectoryViewModel ? -1000 : 0) + (treeNode is DirectoryViewModel ? 1000 : 0)), m_synchronizationContext); m_path = path; m_parrent = parrent; m_name = System.IO.Path.GetFileName(path); if (!Directory.Exists(path)) return; if (allFiles == null) { m_allFiles = new SortedObservableCollection<FileViewModel>(new AsyncObservableCollection<FileViewModel>(), (model, viewModel) => String.Compare(model.Name, viewModel.Name, StringComparison.Ordinal)); allFiles = AllFiles; } foreach (string directory in Directory.GetDirectories(path)) Children.Add(new DirectoryViewModel(directory, this, allFiles, m_synchronizationContext)); foreach (string file in Directory.GetFiles(path)) { FileViewModel fileViewModel = new FileViewModel(file, this); Children.Add(fileViewModel); allFiles.Add(fileViewModel); } if (parrent == null) { m_externalChanges = new Dictionary<string, DateTime>(); m_fileSystemWatcher = new FileSystemWatcher(path) { NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite, IncludeSubdirectories = true }; m_fileSystemWatcher.Created += FileSystemWatcherOnCreated; m_fileSystemWatcher.Deleted += FileSystemWatcherOnDeleted; m_fileSystemWatcher.Changed += FileSystemWatcherOnChanged; m_fileSystemWatcher.Renamed += FileSystemWatcherOnRenamed; m_fileSystemWatcher.EnableRaisingEvents = true; m_cleanUpTimer = new Timer(ClanUp, null, 5000, Timeout.Infinite); } }
internal void ProcessMessage(ChatMessageViewModel viewModel, bool suppressUnreadNotifications = false) { viewModel.HasBeenSeen = IsRoomVisible(suppressUnreadNotifications); var lastGroupMessage = _messages.LastOrDefault() as ChatMessageGroupViewModel; if (lastGroupMessage == null || !lastGroupMessage.TryAddMessage(viewModel)) { var groupViewModel = new ChatMessageGroupViewModel(viewModel); _messages.Add(groupViewModel); } UpdateUnreadMessageCount(); }
internal void AddUser(UserViewModel userViewModel) { if (_users.Any(x => x.User.Equals(userViewModel))) { return; } var userVm = new RoomUserViewModel(userViewModel); userVm.IsOwner = _owners.Any(x => x.Equals(userVm.User.Name)); _users.Add(userVm); // TODO: Implement notification to the room of the joined user }
/// <summary> /// Adds a collection of assemblies to AssemblySource /// </summary> /// <param name="assemblies">The assemblies to add</param> public static void AddRange(IEnumerable <Assembly> assemblies) { foreach (var assembly in assemblies) { try { if (!Instance.Contains(assembly)) { Instance.Add(assembly); } } catch (ArgumentException) { // ignore } } }
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); }
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); } }
internal void Initialize(IObservableCollection <T> collection, Func <T, TProxy> proxyCreator, Func <TProxy, T> itemCreator) { _internalCollection = collection; _proxyCreator = proxyCreator; _itemCreator = itemCreator; _proxyCollection = new BaseObservableCollection <ProxyEntry>(); foreach (var i in collection) { _proxyCollection.Add(new ProxyEntry(_proxyCreator(i), i != null ? i.GetHashCode() : 0)); } _proxyCollection.PropertyChanged += ProxyCollectionPropertyChanged; _proxyCollection.CollectionChanged += ProxyCollectionCollectionChanged; if (collection is INotifyCollectionChangedDispatcher) { ((INotifyCollectionChangedDispatcher)collection).AddCollectionChanged(InnerCollectionChanged, NotifyCollectionChangedDispatcherPriority.High); } else { collection.CollectionChanged += InnerCollectionChanged; } }
private void UpdateTotalRecord() { _week.Remove(_week.SingleOrDefault(t => t.IsTotal)); var total = new TimeSheetItem { IsTotal = true, Name = "TOTAL" }; foreach (var item in _week) { total.WorkRemaining = total.WorkRemaining .AddHours(item.WorkRemaining.Hour) .AddMinutes(item.WorkRemaining.Minute) .AddSeconds(item.WorkRemaining.Second); total.Monday = total.Monday .AddHours(item.Monday.Hour) .AddMinutes(item.Monday.Minute) .AddSeconds(item.Monday.Second); total.Tuesday = total.Tuesday .AddHours(item.Tuesday.Hour) .AddMinutes(item.Tuesday.Minute) .AddSeconds(item.Tuesday.Second); total.Wednesday = total.Wednesday .AddHours(item.Wednesday.Hour) .AddMinutes(item.Wednesday.Minute) .AddSeconds(item.Wednesday.Second); total.Thursday = total.Thursday .AddHours(item.Thursday.Hour) .AddMinutes(item.Thursday.Minute) .AddSeconds(item.Thursday.Second); total.Friday = total.Friday .AddHours(item.Friday.Hour) .AddMinutes(item.Friday.Minute) .AddSeconds(item.Friday.Second); } _week.Add(total); }
// add, 2014-04-14, rein // ref: http://social.msdn.microsoft.com/Forums/vstudio/en-US/2e278e3c-27ab-42b5-8a7b-6828ddbb9caf/how-to-sync-two-observable-collection-?forum=wpf // cannot use with Caliburn.Micro BindinableCollection public static void Sync <T>(this IObservableCollection <T> target, INotifyCollectionChanged source) { source.CollectionChanged += (sender, e) => { // target.CollectionChanged -= coll2_CollectionChanged; if (e.NewItems != null) { foreach (var newItem in e.NewItems) { target.Add((T)newItem); } } if (e.OldItems != null) { foreach (var oldItem in e.OldItems) { target.Remove((T)oldItem); } } // target.CollectionChanged += coll2_CollectionChanged; }; }
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; }
public void Add(TGlyphData item) { _collectionImplementation.Add(item); item.DependencyResolver = _parentData.DependencyResolver; }
/// <summary> /// Insere o item na coleção /// </summary> /// <param name="index"></param> /// <param name="item"></param> public void Insert(int index, T item) { _source.Add(item); }
private void AddFreeConnect(ViewModelConnector fromConnector) { DraggedConnect = new ViewModelConnect(fromConnector); Connects.Add(DraggedConnect); }
public MainViewModel() { Task.Run(() => Enumerable.Range(1, 10000).ToList().ForEach(x => partyList.Add(new PartyItemViewModel(x, x * 2)))); }
public void Handle(TorrentAddedMessage message) { _torrents.Add(message.Torrent); }
public void Handle(RightEvent message) { history.Add(message.Number); }
public void AddChild(IrcTabViewModel child) { child.ParentTab = this; Children.Add(child); }