示例#1
0
        private void UpdateLabelsList(TorrentLabelCollection labels)
        {
            var allLabelsVM = GetGroup(GroupType.AllLabels);

            UpdateOrAddLabelVMs(labels, allLabelsVM, _groupItemFactory);
            RemoveOldLabelVMs(labels, allLabelsVM);
        }
示例#2
0
        public static void UpdateOrAddLabelVMs(TorrentLabelCollection labels, GroupItemViewModel labelsGroupVM, Func <GroupItemViewModel> groupItemFactory)
        {
            foreach (var label in labels)
            {
                var labelVM = labelsGroupVM.Childs.FirstOrDefault(item => item.Text == label.Text);

                if (labelVM != null)
                {
                    labelVM.Count = label.Count;
                }
                else
                {
                    labelsGroupVM.Childs.Add(groupItemFactory().With(GroupType.Label, label.Text, label.Count));
                }
            }
        }
            public void UpdateOrAddLabelVMs_NewLabel_NewLabelCreatedAndOldLabelStaysAsIs()
            {
                var labels = new TorrentLabelCollection()
                {
                    { "My Label", 1 },
                };

                GroupsViewModel.UpdateOrAddLabelVMs(labels, _labelsGroupVM, _groupItemFactory);

                Assert.AreEqual(2, _labelsGroupVM.Childs.Count);
                var noLabelVM = _labelsGroupVM.Childs.FirstOrDefault(x => x.Type == GroupType.NoLabel);

                Assert.IsNotNull(noLabelVM);
                var customLabelVM = _labelsGroupVM.Childs.FirstOrDefault(x => x.Type == GroupType.Label);

                Assert.AreEqual(labels.First().Text, customLabelVM.Text);
                Assert.AreEqual(labels.First().Count, customLabelVM.Count);
            }
            public void RemoveOldLabelVMs_LabelRemoved_LabelIsGone()
            {
                var labels = new TorrentLabelCollection()
                {
                    { "My Label", 1 },
                };

                GroupsViewModel.UpdateOrAddLabelVMs(labels, _labelsGroupVM, _groupItemFactory);
                labels.RemoveAt(0);
                GroupsViewModel.RemoveOldLabelVMs(labels, _labelsGroupVM);

                Assert.AreEqual(1, _labelsGroupVM.Childs.Count);
                var noLabelVM = _labelsGroupVM.Childs.FirstOrDefault(x => x.Type == GroupType.NoLabel);

                Assert.IsNotNull(noLabelVM);
                var customLabelVM = _labelsGroupVM.Childs.FirstOrDefault(x => x.Type == GroupType.Label);

                Assert.IsNull(customLabelVM);
            }
            public void UpdateOrAddLabelVMs_ModifiedLabelCount_LabelCountValueIncremented()
            {
                var labels = new TorrentLabelCollection()
                {
                    { "My Label", 1 },
                };

                GroupsViewModel.UpdateOrAddLabelVMs(labels, _labelsGroupVM, _groupItemFactory);
                labels.First().Count++;
                GroupsViewModel.UpdateOrAddLabelVMs(labels, _labelsGroupVM, _groupItemFactory);

                Assert.AreEqual(2, _labelsGroupVM.Childs.Count);
                var noLabelVM = _labelsGroupVM.Childs.FirstOrDefault(x => x.Type == GroupType.NoLabel);

                Assert.IsNotNull(noLabelVM);
                var customLabelVM = _labelsGroupVM.Childs.FirstOrDefault(x => x.Type == GroupType.Label);

                Assert.AreEqual(labels.First().Text, customLabelVM.Text);
                Assert.AreEqual(labels.First().Count, customLabelVM.Count);
            }
        private void GetTorrentsAndLabelsFresh()
        {
			TorrentsAndLabels CurrentTorrents = ServiceClient.GetAllTorrentsAndLabels(_token);

			_torrents = new TorrentCollection(this);
			_torrents.Parse(CurrentTorrents.Torrents, true);

			_labels = new TorrentLabelCollection();
			_labels.Parse(CurrentTorrents.Labels);

			SetCache(CurrentTorrents.CacheID);
			
        }
示例#7
0
        public static void RemoveOldLabelVMs(TorrentLabelCollection labels, GroupItemViewModel allLabelsVM)
        {
            var removedCustomLabelVMs = allLabelsVM.Childs.Where(item => item.Type != GroupType.NoLabel && !labels.Contains(item.DisplayName));

            allLabelsVM.Childs.RemoveRange(removedCustomLabelVMs.ToList());
        }
        private void GetTorrentsAndLabelsFresh()
        {
            if(_token == null)
                return;

            try
            {
                TorrentsAndLabels CurrentTorrents = ServiceClient.GetAllTorrentsAndLabels(_token);

                _torrents = new TorrentCollection(this);
                _torrents.Parse(CurrentTorrents.Torrents, true);

                _labels = new TorrentLabelCollection(this);
                _labels.Parse(CurrentTorrents.Labels);

                SetCache(CurrentTorrents.CacheID);
            }
            catch(System.ServiceModel.ProtocolException e)
            {
                // Token possibly expired, get new token.
                Trace.TraceError(e.Message + e.StackTrace);
                GetToken();
            }
        }