Example #1
0
        private void btnAddDescription_Click(object sender, RoutedEventArgs e)
        {
            description Description = new description()
            {
                name       = "Третьи соревнования",
                start_date = new DateTime(2016, 11, 25)
            };

            Thread th = new Thread(() =>
            {
                descriptionCollection.Add(Description);
                if (!ChangesSavedSuccessfully)
                {
                    descriptionCollection.CollectionChanged -= descriptionCollection_CollectionChanged;
                    descriptionCollection.Remove(Description);
                    descriptionCollection.CollectionChanged += descriptionCollection_CollectionChanged;
                }
            })
            {
                IsBackground = true
            };

            th.SetApartmentState(ApartmentState.STA);
            th.Start();
        }
Example #2
0
        private void UpdateInventoryItems()
        {
            List <IInventoryItem> wieldedItems  = player.WieldedItems;
            List <IInventoryItem> itemsToRemove = new List <IInventoryItem>();

            foreach (IInventoryItem item in inventory)
            {
                if (wieldedItems.Contains(item))
                {
                    itemsToRemove.Add(item);
                }
            }

            foreach (IInventoryItem item in itemsToRemove)
            {
                inventory.Remove(item);
            }

            foreach (IInventoryItem item in player.Inventory.Where(x => !wieldedItems.Contains(x)))
            {
                if (!inventory.Contains(item))
                {
                    inventory.Add(item);
                }
            }
        }
Example #3
0
        public void Update()
        {
            _header.Text = this.Value.Signature;

            foreach (var item in _listViewItemCollection.OfType <BoxTreeViewItem>().ToArray())
            {
                if (!_value.Boxes.Any(n => object.ReferenceEquals(n, item.Value)))
                {
                    _listViewItemCollection.Remove(item);
                }
            }

            foreach (var item in _value.Boxes)
            {
                if (!_listViewItemCollection.OfType <BoxTreeViewItem>().Any(n => object.ReferenceEquals(n.Value, item)))
                {
                    var treeViewItem = new BoxTreeViewItem(item);
                    treeViewItem.Parent = this;

                    _listViewItemCollection.Add(treeViewItem);
                }
            }

            this.Sort();
        }
Example #4
0
        void ActiveEvents_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case   NotifyCollectionChangedAction.Add:
                foreach (IEvent ev in e.NewItems)
                {
                    if (_filter.Apply(ev.Definition))
                    {
                        _events.Insert(0, new EventViewModel(ev));
                    }
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (IEvent ev in e.OldItems)
                {
                    foreach (EventViewModel evm in _events)
                    {
                        if (evm.Definition.Id == ev.Definition.Id)
                        {
                            _events.Remove(evm);
                            break;
                        }
                    }
                }

                break;

            case NotifyCollectionChangedAction.Reset:
                _events.Clear();
                break;
            }
        }
Example #5
0
        protected override bool OnUpdateFrom(Device newDevice, List <string> updatedPropertyNames)
        {
            var isUpdated = UpdateValue(() => CreatedAt, newDevice, updatedPropertyNames);

            isUpdated = UpdateValue(() => Id, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => LastSeenAt, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => Name, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => Platform, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => PlatformVersion, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => ProductVersion, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => Provides, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => PublicAddress, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => ScreenDensity, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => ScreenResolution, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => Token, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => Vendor, newDevice, updatedPropertyNames) | isUpdated;
            isUpdated = UpdateValue(() => Version, newDevice, updatedPropertyNames) | isUpdated;

            foreach (var connection in Connections.ToList().Where(con => newDevice.Connections.All(c => c.Uri != con.Uri)))
            {
                Connections.Remove(connection);
                isUpdated = true;
            }

            foreach (var connection in newDevice.Connections.Where(con => Connections.All(c => c.Uri != con.Uri)))
            {
                Connections.Add(connection);
                isUpdated = true;
            }

            return(isUpdated);
        }
Example #6
0
        public void Update()
        {
            _header.Text = string.Format("{0} ({1})", _value.SearchItem.Name, _hit);

            base.IsExpanded = this.Value.IsExpanded;

            foreach (var item in _listViewItemCollection.OfType <SearchTreeViewItem>().ToArray())
            {
                if (!_value.Children.Any(n => object.ReferenceEquals(n, item.Value)))
                {
                    _listViewItemCollection.Remove(item);
                }
            }

            foreach (var item in _value.Children)
            {
                if (!_listViewItemCollection.OfType <SearchTreeViewItem>().Any(n => object.ReferenceEquals(n.Value, item)))
                {
                    var treeViewItem = new SearchTreeViewItem(item);
                    treeViewItem.Parent = this;

                    _listViewItemCollection.Add(treeViewItem);
                }
            }

            this.Sort();
        }
        public void Update()
        {
            _header.Text = this.Value.Name;

            base.IsExpanded = this.Value.IsExpanded;

            foreach (var item in _listViewItemCollection.OfType <StoreCategorizeTreeViewItem>().ToArray())
            {
                if (!_value.Children.Any(n => object.ReferenceEquals(n, item.Value)))
                {
                    _listViewItemCollection.Remove(item);
                }
            }

            foreach (var item in _value.Children)
            {
                if (!_listViewItemCollection.OfType <StoreCategorizeTreeViewItem>().Any(n => object.ReferenceEquals(n.Value, item)))
                {
                    var treeViewItem = new StoreCategorizeTreeViewItem(item);
                    treeViewItem.Parent = this;

                    _listViewItemCollection.Add(treeViewItem);
                }
            }

            foreach (var item in _listViewItemCollection.OfType <StoreTreeViewItem>().ToArray())
            {
                if (!_value.StoreTreeItems.Any(n => object.ReferenceEquals(n, item.Value)))
                {
                    _listViewItemCollection.Remove(item);
                }
            }

            foreach (var item in _value.StoreTreeItems)
            {
                if (!_listViewItemCollection.OfType <StoreTreeViewItem>().Any(n => object.ReferenceEquals(n.Value, item)))
                {
                    var treeViewItem = new StoreTreeViewItem(item);
                    treeViewItem.Parent = this;

                    _listViewItemCollection.Add(treeViewItem);
                }
            }

            this.Sort();
        }
Example #8
0
        private void RemoveIfRequired(IEnumerable <Video> nowPlaying, Video video)
        {
            if (!nowPlaying.Any(v => VideosMatchByServerAndPlayer(v, video)))
            {
                var connectionKey = video.PlexServerConnection.MachineIdentifier;
                var playerKey     = video.Player.MachineIdentifier;

                Dictionary <string, Video> byPlayer;
                if (_nowPlayingByServerAndPlayer.TryGetValue(connectionKey, out byPlayer))
                {
                    if (byPlayer.Remove(playerKey) && !byPlayer.Any())
                    {
                        _nowPlayingByServerAndPlayer.Remove(connectionKey);
                    }
                }

                _videosNowPlaying.Remove(video);
            }
        }
Example #9
0
        public void Update()
        {
            this.NotifyPropertyChanged(nameof(this.Name));
            this.NotifyPropertyChanged(nameof(this.IsExpanded));

            foreach (var item in _children.OfType <StoreCategorizeTreeViewModel>().ToArray())
            {
                if (!_value.Children.Any(n => object.ReferenceEquals(n, item.Value)))
                {
                    _children.Remove(item);
                }
            }

            foreach (var item in _value.Children)
            {
                if (!_children.OfType <StoreCategorizeTreeViewModel>().Any(n => object.ReferenceEquals(n.Value, item)))
                {
                    _children.Add(new StoreCategorizeTreeViewModel(this, item));
                }
            }

            foreach (var item in _children.OfType <StoreTreeViewModel>().ToArray())
            {
                if (!_value.StoreTreeItems.Any(n => object.ReferenceEquals(n, item.Value)))
                {
                    _children.Remove(item);
                }
            }

            foreach (var item in _value.StoreTreeItems)
            {
                if (!_children.OfType <StoreTreeViewModel>().Any(n => object.ReferenceEquals(n.Value, item)))
                {
                    _children.Add(new StoreTreeViewModel(this, item));
                }
            }

            this.Sort();
        }
Example #10
0
        private static void TestCase3()
        {
            ObservableCollectionEx <Person> coll = new ObservableCollectionEx <Person>();

            coll.CollectionChanged += OnCollectionChanged2;

            var eric    = new Person("Eric");
            var charles = new Person("Charles");

            coll.Add(eric);
            coll.Add(charles);

            coll.Remove(eric);

            coll.Clear(); // Will Charles say 'goodbye' to us?
        }
Example #11
0
        private void removeBuildingByName(string name)
        {
            string leavingPeer = name;

            XMLLogger.WriteLocalActivity("Peer: " + leavingPeer + " is down!");

            //Remove the deadly peer but first alert the folks.
            Connector.channel.peerDown(MessageFactory.createPeerIsDownMessage("@All", this.name, leavingPeer));

            lock (_connectionLock)
            {
                //Alert Remote Resolvers
                foreach (var remConn in _remoteConnections)
                {
                    NetTcpBinding   tcpBinding     = new NetTcpBinding();
                    EndpointAddress remoteEndpoint = new EndpointAddress(remConn.remoteResolver.netAddress);
                    tcpBinding.Security.Mode = SecurityMode.None;

                    ChannelFactory <IRemote> cf = new ChannelFactory <IRemote>(tcpBinding, remoteEndpoint);
                    IRemote tChannel            = cf.CreateChannel();

                    try
                    {
                        tChannel.PeerDownAlert(MessageFactory.createPeerIsDownMessage("@All", this.name, leavingPeer));
                    }
                    catch (Exception ex)
                    {
                        XMLLogger.WriteErrorMessage(this.GetType().FullName.ToString(), "Error in sending Remote Peer Alert Message" + ex.ToString());
                    }
                }
            }

            updateLocalConnectionsList(leavingPeer);

            var itemToRemove = from b in _buildings
                               where b.Name == leavingPeer
                               select b;

            lock (_lLock)
            {
                if (itemToRemove.Count() > 0)
                {
                    _buildings.Remove(itemToRemove.First());
                }
            }
        }
Example #12
0
        public void RemoveSelectedElementTest()
        {
            var element1         = new SelectableElementStub();
            var element2         = new SelectableElementStub();
            var selectionManager = new SelectionManager();
            var collection       = new ObservableCollectionEx <SelectableElementStub>
            {
                element1,
                element2
            };

            selectionManager.AddCollection(collection);
            element2.Selected = true;
            collection.Remove(element2);

            Assert.AreEqual(element1, selectionManager.SelectedElement);
            Assert.IsTrue(element1.Selected);
        }
Example #13
0
        public void ProcessRedo()
        {
            if (_Redo.Count > 0)
            {
                var item = _Redo.Last();
                _Redo.Remove(item);

                var undoItem = _UndoHistory.Last();
                _Undo.Add(undoItem);
                _UndoHistory.Remove(undoItem);

                foreach (var historyTile in item.Reverse())
                {
                    _world.Tiles[historyTile.Location.X, historyTile.Location.Y] = historyTile.Tile;
                    _renderer.UpdateWorldImage(new PointInt32(historyTile.Location.X, historyTile.Location.Y));
                }
            }
        }
Example #14
0
        public void UpdatedManifestList(ManifestListUpdate listUpdate)
        {
            if (listUpdate.State == ManifestListUpdateState.Add)
            {
                foreach (String manifestItem in listUpdate.List)
                {
                    m_ManifestList.Add(manifestItem);
                }
            }
            else if (listUpdate.State == ManifestListUpdateState.Delete)
            {
                foreach (String manifest in listUpdate.List)
                {
                    m_ManifestList.Remove(manifest);
                }
            }

            //TODO: Fire Event Here
        }
Example #15
0
        public void ProcessUndo()
        {
            if (_Undo.Count > 0)
            {
                var item = _Undo.Last();
                _Undo.Remove(item);

                var redo = new Queue <HistoryTile>();
                foreach (var historyTile in item.Reverse())
                {
                    redo.Enqueue(new HistoryTile(historyTile.Location, (Tile)_world.Tiles[historyTile.Location.X, historyTile.Location.Y].Clone()));
                    _world.Tiles[historyTile.Location.X, historyTile.Location.Y] = historyTile.Tile;
                    _renderer.UpdateWorldImage(new PointInt32(historyTile.Location.X, historyTile.Location.Y));
                }

                _UndoHistory.Add(item);
                _Redo.Add(redo.ToArray());
            }
        }
Example #16
0
        public void PropertiesListItemRemovedJointList()
        {
            var baseObj    = new object();
            var derivedObj = new object();

            var baseProperty = new Mock <IPropertyInfo> ();

            baseProperty.SetupGet(pi => pi.Type).Returns(typeof(string));

            var baseProperties = new ObservableCollectionEx <IPropertyInfo> {
                baseProperty.Object
            };
            var derivedProperties = new ObservableCollectionEx <IPropertyInfo> {
                baseProperty.Object
            };

            var baseEditorMock = new Mock <IObjectEditor> ();

            baseEditorMock.SetupGet(e => e.Properties).Returns(baseProperties);
            baseEditorMock.SetupGet(e => e.Target).Returns(baseObj);

            var derivedEditorMock = new Mock <IObjectEditor> ();

            derivedEditorMock.SetupGet(e => e.Properties).Returns(derivedProperties);
            derivedEditorMock.SetupGet(e => e.Target).Returns(derivedObj);

            var providerMock = new Mock <IEditorProvider> ();

            providerMock.Setup(ep => ep.GetObjectEditorAsync(baseObj)).ReturnsAsync(baseEditorMock.Object);
            providerMock.Setup(ep => ep.GetObjectEditorAsync(derivedObj)).ReturnsAsync(derivedEditorMock.Object);

            var vm = new PanelViewModel(providerMock.Object, TargetPlatform.Default);

            vm.SelectedObjects.AddItems(new[] { baseObj, derivedObj });

            Assume.That(vm.Properties.Count, Is.EqualTo(1));
            Assume.That(vm.Properties.Cast <PropertyViewModel>().Select(v => v.Property), Contains.Item(baseProperty.Object));

            derivedProperties.Remove(baseProperty.Object);
            Assert.That(vm.Properties, Is.Empty);
        }
Example #17
0
        public void Update()
        {
            this.Update_Header();

            foreach (var item in _children.OfType <BoxTreeViewModel>().ToArray())
            {
                if (!_value.Boxes.Any(n => object.ReferenceEquals(n, item.Value)))
                {
                    _children.Remove(item);
                }
            }

            foreach (var item in _value.Boxes)
            {
                if (!_children.OfType <BoxTreeViewModel>().Any(n => object.ReferenceEquals(n.Value, item)))
                {
                    _children.Add(new BoxTreeViewModel(this, item));
                }
            }

            this.Sort();
        }
Example #18
0
        private void ShowDownloadItem()
        {
            try
            {
                for (;;)
                {
                    var informaitonDic = new Dictionary <int, Information>();

                    {
                        string[] words = null;

                        {
                            string searchText = null;

                            this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                            {
                                searchText = _searchTextBox.Text;
                            }));

                            if (!string.IsNullOrWhiteSpace(searchText))
                            {
                                words = searchText.ToLower().Split(new string[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries);
                            }
                        }

                        foreach (var item in _amoebaManager.DownloadingInformation.ToArray())
                        {
                            if (words != null)
                            {
                                var text = ((string)item["Path"] ?? "").ToLower();
                                if (!words.All(n => text.Contains(n)))
                                {
                                    continue;
                                }
                            }

                            informaitonDic[(int)item["Id"]] = item;
                        }
                    }

                    var listViewModelDic = new Dictionary <int, DownloadListViewModel>();
                    var removeList       = new List <DownloadListViewModel>();

                    this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                    {
                        foreach (var item in _listViewModelCollection.ToArray())
                        {
                            listViewModelDic[item.Id] = item;

                            if (!informaitonDic.ContainsKey(item.Id))
                            {
                                removeList.Add(item);
                            }
                        }
                    }));

                    var resultList = new List <DownloadListViewModel>();
                    var updateDic  = new Dictionary <DownloadListViewModel, Information>();

                    bool clearFlag   = false;
                    var  selectItems = new List <DownloadListViewModel>();

                    if (removeList.Count > 100)
                    {
                        clearFlag = true;

                        removeList.Clear();
                        updateDic.Clear();

                        foreach (var information in informaitonDic.Values)
                        {
                            resultList.Add(new DownloadListViewModel(information));
                        }

                        var hid = new HashSet <int>();

                        this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                        {
                            hid.UnionWith(_listView.SelectedItems.OfType <DownloadListViewModel>().Select(n => n.Id));
                        }));

                        foreach (var item in resultList)
                        {
                            if (hid.Contains(item.Id))
                            {
                                selectItems.Add(item);
                            }
                        }
                    }
                    else
                    {
                        foreach (var information in informaitonDic.Values)
                        {
                            DownloadListViewModel item;

                            if (listViewModelDic.TryGetValue((int)information["Id"], out item))
                            {
                                updateDic[item] = information;
                            }
                            else
                            {
                                resultList.Add(new DownloadListViewModel(information));
                            }
                        }
                    }

                    this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                    {
                        bool sortFlag = false;

                        if (resultList.Count != 0)
                        {
                            sortFlag = true;
                        }
                        if (removeList.Count != 0)
                        {
                            sortFlag = true;
                        }
                        if (updateDic.Count != 0)
                        {
                            sortFlag = true;
                        }

                        if (clearFlag)
                        {
                            _listViewModelCollection.Clear();
                        }

                        foreach (var item in resultList)
                        {
                            _listViewModelCollection.Add(item);
                        }

                        foreach (var item in removeList)
                        {
                            _listViewModelCollection.Remove(item);
                        }

                        foreach (var item in updateDic)
                        {
                            item.Key.Information = item.Value;
                        }

                        if (clearFlag)
                        {
                            _listView.SelectedItems.Clear();
                            _listView.SetSelectedItems(selectItems);
                        }

                        if (sortFlag)
                        {
                            this.Sort();
                        }
                    }));

                    for (int i = 0; i < 10; i++)
                    {
                        Thread.Sleep(1000 * 3);
                        if (_mainWindow.SelectedTab == MainWindowTabType.Download)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Example #19
0
        /// <summary>
        ///A test for GetDelayedNotifier
        ///</summary>
        public void DelayedNotificationTestHelper <T>() where T : new()
        {
            ObservableCollectionEx <T> target = CreateTargetHelper <T>();

            T item0 = new T();
            T item1 = new T();
            T item2 = new T();
            T item3 = new T();
            T item4 = new T();


            // Testing Add
            this._firedCollectionEvents.Clear();
            this._firedPropertyEvents.Clear();
            using (ObservableCollectionEx <T> iTarget = target.DelayNotifications())
            {
                iTarget.Add(item0);
                iTarget.Add(item1);
                iTarget.Add(item2);
                iTarget.Add(item3);
                iTarget.Add(item4);

                Assert.IsTrue(5 == target.Count, "Count is incorrect");
                Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
                Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");
            }

            Assert.IsTrue(5 == target.Count, "Count is incorrect");
            Assert.IsTrue(2 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
            Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");

            // Testing Replace
            this._firedCollectionEvents.Clear();
            this._firedPropertyEvents.Clear();
            using (ObservableCollectionEx <T> iTarget = target.DelayNotifications())
            {
                iTarget[1] = item0;
                iTarget[2] = item1;
                iTarget[3] = item2;
                iTarget[4] = item3;
                iTarget[0] = item4;

                using (ObservableCollectionEx <T> iNested = iTarget.DelayNotifications())
                {
                    iNested.Add(item4);
                    iNested.Add(item4);

                    Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
                    Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");
                }

                Assert.IsTrue(7 == target.Count, "Count is incorrect");
                Assert.IsTrue(2 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
                Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");
            }

            Assert.IsTrue(7 == target.Count, "Count is incorrect");
            Assert.IsTrue(3 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
            Assert.IsTrue(2 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");

            // Testing Remove
            this._firedCollectionEvents.Clear();
            this._firedPropertyEvents.Clear();
            using (ObservableCollectionEx <T> iTarget = target.DelayNotifications())
            {
                iTarget.Remove(item0);
                iTarget.Remove(item1);
                iTarget.Remove(item2);
                iTarget.Remove(item3);
                iTarget.Remove(item4);

                Assert.IsTrue(2 == target.Count, "Count is incorrect");
                Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
                Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");

                try
                {
                    iTarget.Add(item0);
                    Assert.Fail("Mixed operation is not handled");
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(InvalidOperationException));
                }
            }

            Assert.IsTrue(3 == target.Count, "Count is incorrect");
            Assert.IsTrue(2 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
            Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");

            this._firedCollectionEvents.Clear();
            this._firedPropertyEvents.Clear();
            using (ObservableCollectionEx <T> iTarget = target.DelayNotifications())
            {
                iTarget.Clear();
            }

            Assert.IsTrue(0 == target.Count, "Count is incorrect");
            Assert.IsTrue(2 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications");
            Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications");
        }
Example #20
0
        private void ShowDownloadItem()
        {
            try
            {
                for (; ;)
                {
                    Thread.Sleep(100);
                    if (_mainWindow.SelectedTab != MainWindowTabType.Download)
                    {
                        continue;
                    }

                    var downloadingInformation        = _amoebaManager.DownloadingInformation.ToArray();
                    Dictionary <int, Information> dic = new Dictionary <int, Information>();

                    foreach (var item in downloadingInformation.ToArray())
                    {
                        dic[(int)item["Id"]] = item;
                    }

                    Dictionary <int, DownloadListViewItem> dic2 = new Dictionary <int, DownloadListViewItem>();

                    this.Dispatcher.Invoke(DispatcherPriority.ContextIdle, new Action(() =>
                    {
                        foreach (var item in _listViewItemCollection.ToArray())
                        {
                            dic2[item.Id] = item;
                        }
                    }));

                    List <DownloadListViewItem> removeList = new List <DownloadListViewItem>();

                    this.Dispatcher.Invoke(DispatcherPriority.ContextIdle, new Action(() =>
                    {
                        foreach (var item in _listViewItemCollection.ToArray())
                        {
                            if (!dic.ContainsKey(item.Id))
                            {
                                removeList.Add(item);
                            }
                        }
                    }));

                    List <DownloadListViewItem> newList = new List <DownloadListViewItem>();
                    Dictionary <DownloadListViewItem, Information> updateDic = new Dictionary <DownloadListViewItem, Information>();

                    bool clearFlag   = false;
                    var  selectItems = new List <DownloadListViewItem>();

                    if (removeList.Count > 100)
                    {
                        clearFlag = true;
                        removeList.Clear();
                        updateDic.Clear();

                        foreach (var information in downloadingInformation)
                        {
                            newList.Add(new DownloadListViewItem(information));
                        }

                        HashSet <int> hid = new HashSet <int>();

                        this.Dispatcher.Invoke(DispatcherPriority.ContextIdle, new Action(() =>
                        {
                            hid.UnionWith(_listView.SelectedItems.OfType <DownloadListViewItem>().Select(n => n.Id));
                        }));

                        foreach (var item in newList)
                        {
                            if (hid.Contains(item.Id))
                            {
                                selectItems.Add(item);
                            }
                        }
                    }
                    else
                    {
                        foreach (var information in downloadingInformation)
                        {
                            DownloadListViewItem item = null;

                            if (dic2.ContainsKey((int)information["Id"]))
                            {
                                item = dic2[(int)information["Id"]];
                            }

                            if (item != null)
                            {
                                if (!CollectionUtilities.Equals(item.Information, information))
                                {
                                    updateDic[item] = information;
                                }
                            }
                            else
                            {
                                newList.Add(new DownloadListViewItem(information));
                            }
                        }
                    }

                    this.Dispatcher.Invoke(DispatcherPriority.ContextIdle, new Action(() =>
                    {
                        bool sortFlag = false;

                        if (newList.Count != 0)
                        {
                            sortFlag = true;
                        }
                        if (removeList.Count != 0)
                        {
                            sortFlag = true;
                        }
                        if (updateDic.Count != 0)
                        {
                            sortFlag = true;
                        }

                        if (clearFlag)
                        {
                            _listViewItemCollection.Clear();
                        }

                        foreach (var item in newList)
                        {
                            _listViewItemCollection.Add(item);
                        }

                        foreach (var item in removeList)
                        {
                            _listViewItemCollection.Remove(item);
                        }

                        foreach (var item in updateDic)
                        {
                            item.Key.Information = item.Value;
                        }

                        if (clearFlag)
                        {
                            _listView.SelectedItems.Clear();
                            _listView.SetSelectedItems(selectItems);
                        }

                        if (sortFlag)
                        {
                            this.Sort();
                        }
                    }));

                    Thread.Sleep(1000 * 3);
                }
            }
            catch (Exception)
            {
            }
        }
Example #21
0
 /// <summary>
 /// Remove Rally from Playlist
 /// </summary>
 /// <param name="r">Rally to Remove</param>
 public void Remove(Rally r)
 {
     rallyIDs.Remove(r.ID);
 }
Example #22
0
        private void ShowConnectionInfomation()
        {
            try
            {
                for (;;)
                {
                    var connectionInformation = _amoebaManager.ConnectionInformation.ToArray();
                    var dic = new Dictionary <int, Information>();

                    foreach (var item in connectionInformation.ToArray())
                    {
                        dic[(int)item["Id"]] = item;
                    }

                    var dic2 = new Dictionary <int, ConnectionListViewModel>();

                    this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                    {
                        foreach (var item in _listViewModelCollection.ToArray())
                        {
                            dic2[item.Id] = item;
                        }
                    }));

                    var removeList = new List <ConnectionListViewModel>();

                    this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                    {
                        foreach (var item in _listViewModelCollection.ToArray())
                        {
                            if (!dic.ContainsKey(item.Id))
                            {
                                removeList.Add(item);
                            }
                        }
                    }));

                    var newList   = new List <ConnectionListViewModel>();
                    var updateDic = new Dictionary <ConnectionListViewModel, Information>();

                    bool clearFlag   = false;
                    var  selectItems = new List <ConnectionListViewModel>();

                    if (removeList.Count > 100)
                    {
                        clearFlag = true;
                        removeList.Clear();
                        updateDic.Clear();

                        foreach (var information in connectionInformation)
                        {
                            newList.Add(new ConnectionListViewModel(information));
                        }

                        var hid = new HashSet <int>();

                        this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                        {
                            hid.UnionWith(_listView.SelectedItems.OfType <ConnectionListViewModel>().Select(n => n.Id));
                        }));

                        foreach (var item in newList)
                        {
                            if (hid.Contains(item.Id))
                            {
                                selectItems.Add(item);
                            }
                        }
                    }
                    else
                    {
                        foreach (var information in connectionInformation)
                        {
                            ConnectionListViewModel item = null;

                            if (dic2.ContainsKey((int)information["Id"]))
                            {
                                item = dic2[(int)information["Id"]];
                            }

                            if (item != null)
                            {
                                updateDic[item] = information;
                            }
                            else
                            {
                                newList.Add(new ConnectionListViewModel(information));
                            }
                        }
                    }

                    this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                    {
                        bool sortFlag = false;

                        if (newList.Count != 0)
                        {
                            sortFlag = true;
                        }
                        if (removeList.Count != 0)
                        {
                            sortFlag = true;
                        }
                        if (updateDic.Count != 0)
                        {
                            sortFlag = true;
                        }

                        if (clearFlag)
                        {
                            _listViewModelCollection.Clear();
                        }

                        foreach (var item in newList)
                        {
                            _listViewModelCollection.Add(item);
                        }

                        foreach (var item in removeList)
                        {
                            _listViewModelCollection.Remove(item);
                        }

                        foreach (var item in updateDic)
                        {
                            item.Key.Information = item.Value;
                        }

                        if (clearFlag)
                        {
                            _listView.SelectedItems.Clear();
                            _listView.SetSelectedItems(selectItems);
                        }

                        if (sortFlag)
                        {
                            this.Sort();
                        }
                    }));

                    Thread.Sleep(1000 * 3);
                }
            }
            catch (Exception)
            {
            }
        }
        private void InitViewCommands()
        {
            AddNote = new RelayCommand(() =>
            {
                if (SelectedCrmEntry != null)
                {
                    var selectedEntry = _internalCrmEntries.FirstOrDefault(entry => entry.ID.Equals(SelectedCrmEntry.ID));
                    if (selectedEntry != null)
                    {
                        NewCrmEntryNote.OriginatorClient = _settingsRepository.GetSettings().ClientCredential.UserName;
                        selectedEntry.Notes.Add(NewCrmEntryNote);
                    }

                    _wcfCrmClient.ModifyEntry(selectedEntry);
                }
            });

            RemoveNote = new RelayCommand(() =>
            {
                if (MessageBox.Show("Are you sure you want to delete the selected note?", "Confirm delete", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                {
                    return;
                }

                if (SelectedCrmEntry != null && SelectedCrmEntryNote != null)
                {
                    var selectedEntry = _internalCrmEntries.FirstOrDefault(entry => entry.ID.Equals(SelectedCrmEntry.ID));
                    if (selectedEntry != null)
                    {
                        selectedEntry.Notes.Remove(SelectedCrmEntryNote);
                    }

                    _wcfCrmClient.ModifyEntry(selectedEntry);
                }
            });

            ModifySelectedCrmEntry = new RelayCommand(() =>
            {
                if (SelectedCrmEntry != null)
                {
                    if (string.IsNullOrEmpty(SelectedCrmEntry.PhoneNumber))
                    {
                        MessageBox.Show("Your contact must have a phone number!", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }

                    var selectedEntry = _internalCrmEntries.FirstOrDefault(entry => entry.ID.Equals(SelectedCrmEntry.ID));
                    if (selectedEntry != null)
                    {
                        selectedEntry = SelectedCrmEntry;
                    }

                    _wcfCrmClient.ModifyEntry(selectedEntry);
                }
            });

            RevertSelectedCrmEntry = new RelayCommand(() =>
            {
                if (SelectedCrmEntry != null)
                {
                    var selectedEntry = _internalCrmEntries.FirstOrDefault(entry => entry.ID.Equals(SelectedCrmEntry.ID));
                    if (selectedEntry != null)
                    {
                        SelectedCrmEntry = selectedEntry;
                    }
                }
            });

            Delete = new RelayCommand(() =>
            {
                if (MessageBox.Show("Are you sure you want to delete this entry?", "Confirm delete", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                {
                    return;
                }

                if (SelectedCrmEntry != null)
                {
                    var selectedEntry = _internalCrmEntries.FirstOrDefault(entry => entry.ID.Equals(SelectedCrmEntry.ID));
                    if (selectedEntry != null)
                    {
                        _internalCrmEntries.Remove(selectedEntry);
                    }

                    _wcfCrmClient.DeleteEntry(selectedEntry);
                }
            });
        }
 private void _browser_ServiceRemoved(object sender, NetServiceEventArgs e)
 {
     _discoveredServices.Remove(e.Service.Name);
 }