public override void RegisterMessenger()
 {
     MessengerInstance.Register <Address>(this, MSG_PERSON_ADD_ADDRESS, (address) =>
     {
         Addresses.Add(address);
     });
     MessengerInstance.Register <ContactMethod>(this, MSG_PERSON_ADD_CONTACT, (contact) =>
     {
         Contacts.Add(contact);
     });
     MessengerInstance.Register <Email>(this, MSG_PERSON_ADD_EMAIL, (email) =>
     {
         Emails.Add(email);
     });
     MessengerInstance.Register <Address>(this, MSG_PERSON_DEL_ADDRESS, (address) =>
     {
         Addresses.Remove(address);
     });
     MessengerInstance.Register <ContactMethod>(this, MSG_PERSON_DEL_CONTACT, (contact) =>
     {
         Contacts.Remove(contact);
     });
     MessengerInstance.Register <Email>(this, MSG_PERSON_DEL_EMAIL, (email) =>
     {
         Emails.Remove(email);
     });
 }
예제 #2
0
 public override void RegisterMessenger()
 {
     MessengerInstance.Register <IdentificationDocument>(this, MSG_PERSON_ADD_DOCUMENT, (doc) =>
     {
         Documents.Add(doc);
     });
     MessengerInstance.Register <IdentificationDocument>(this, MSG_PERSON_DEL_DOCUMENT, (doc) =>
     {
         Documents.Remove(doc);
     });
 }
예제 #3
0
 /// <summary>
 /// Remove the specified group from the collection.
 /// </summary>
 /// <param name="group">The group to remove</param>
 private void RemoveGroup(Group group)
 {
     if (!_groups.Remove(group))
     {
         throw new ArgumentException("Group " + group.Name + " does not exist");
     }
     //Remove the group's categories
     foreach (Category category in group.Categories)
     {
         _categories.Remove(category);
     }
 }
예제 #4
0
        public void RemoveTodoItem()
        {
            allitems.Remove(this.selectedItem);
            var db = App.conn;

            using (var statement = db.Prepare("DELETE FROM todolist WHERE Id = ?;"))
            {
                statement.Bind(1, selectedItem.id);
                statement.Step();
            }
            this.selectedItem = null;
        }
예제 #5
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (MainWindow.Paused)
            {
                return;
            }

            if (JobQueue.Count == 0 && PriorityJobQueue.Count == 0)
            {
                return;
            }

            var job = (PriorityJobQueue.Count > 0) ? PriorityJobQueue.Dequeue() : JobQueue.Dequeue();

            UIContext.Send((a) =>
            {
                try
                {
                    switch (job.Item2)
                    {
                    case Action.Add:
                        collection.Add(job.Item1);
                        break;

                    case Action.Remove:
                        if (equilityComparer == null)
                        {
                            collection.Remove(job.Item1);
                        }
                        else
                        {
                            T toRemove = default(T);
                            foreach (T item in collection)
                            {
                                if (equilityComparer(job.Item1, item))
                                {
                                    toRemove = item; break;
                                }
                            }
                            collection.Remove(toRemove);
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    // ignore for now
                }
            }, null);

            if (JobQueue.Count + PriorityJobQueue.Count >= 500)
            {
                timer.Interval = TimeSpan.FromMilliseconds(30);
            }
            else
            {
                timer.Interval = TimeSpan.FromMilliseconds(60);
            }

            JobFinished?.Invoke(this, job, collection);
        }
예제 #6
0
        public void MyObservableCollectionTest()
        {
            char xChar         = '-';
            char xChar2        = '-';
            int  xIndex        = -1;
            var  collection    = new MyObservableCollection <char>();
            bool attachedEvent = false;

            collection.ItemAttached += (sender, newItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                Assert.AreEqual(xChar, newItem);
                Assert.AreEqual(xIndex, index);
                attachedEvent = true;
            };
            bool detachedEvent = false;

            collection.ItemDetached += (sender, oldItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                Assert.AreEqual(xChar2, oldItem);
                Assert.AreEqual(xIndex, index);
                detachedEvent = true;
            };
            bool addedEvent = false;

            collection.ItemAdded += (sender, newItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                Assert.AreEqual(xChar, newItem);
                Assert.AreEqual(xIndex, index);
                addedEvent = true;
            };
            bool removedEvent = false;

            collection.ItemRemoved += (sender, oldItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                Assert.AreEqual(xChar2, oldItem);
                Assert.AreEqual(xIndex, index);
                removedEvent = true;
            };
            bool movedEvent = false;

            collection.ItemMoved += (sender, oldIndex, newIndex) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                Assert.AreEqual(xChar, oldIndex);
                Assert.AreEqual(xIndex, newIndex);
                movedEvent = true;
            };
            bool changedEvent = false;

            collection.ItemChanged += (sender, oldItem, newItem, index) =>
            {
                Assert.IsTrue(ReferenceEquals(sender, collection));
                Assert.AreEqual(xChar2, oldItem);
                Assert.AreEqual(xChar, newItem);
                Assert.AreEqual(xIndex, index);
                changedEvent = true;
            };

            xChar  = 'a';
            xChar2 = xChar;
            xIndex = 0;
            collection.Add('a');
            Assert.IsTrue(addedEvent);
            Assert.IsTrue(attachedEvent);
            xChar  = 'b';
            xChar2 = xChar;
            xIndex = 1;
            collection.Add('b');

            collection.Remove('b');
            Assert.IsTrue(removedEvent);
            Assert.IsTrue(detachedEvent);
            removedEvent  = false;
            detachedEvent = false;
            collection.Add('b');
            addedEvent    = false;
            attachedEvent = false;
            xChar         = 'c';
            collection[1] = 'c';
            Assert.IsTrue(changedEvent);
            Assert.IsTrue(detachedEvent);
            Assert.IsTrue(attachedEvent);
            changedEvent  = false;
            detachedEvent = false;
            attachedEvent = false;

            int removedCount = 0;
        }