Beispiel #1
0
        private async void GetPipsForNewReduxData(object sender, RoutedEventArgs e)
        {
            Thumbnail thumbnail = new Thumbnail();

            thumbnail.Show();
            Progress progress = new Progress();

            progress.Show();
            var itemStore  = new ReduxEntities();
            var notmatched = (from r in itemStore.redux_items
                              from rp in itemStore.redux_to_pips
                              where r.id == rp.redux_id && rp.pips_id == 0
                              select r.aired).ToList().Select(d => d.Date).Distinct().OrderBy(d => d).ToList();

            Fetcher fetcher = new Fetcher();

            notmatched = notmatched.Where(d => d >= new DateTime(2011, 02, 04)).ToList();

            var earliest = notmatched.First();  //itemStore.redux_items.Min(r => r.aired).Date;

            var latest = notmatched.Last();     //itemStore.redux_items.Max(r => r.aired).Date;

            foreach (DateTime dt in notmatched)
            {
                await fetcher.GetDayScheduleAsync(dt, progress, thumbnail);

                if (progress.IsCancelled)
                {
                    break;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Scan the pips programmes data for redux programmes for which we don't have
        /// metadata
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ScanAll_Click(object sender, RoutedEventArgs e)
        {
            Thumbnail thumbnail = new Thumbnail();

            thumbnail.Show();
            cancelButton.IsEnabled = true;
            var itemStore  = reduxItems;
            var notmatched = (from r in itemStore.redux_items
                              from rp in itemStore.redux_to_pips
                              where r.id == rp.redux_id && rp.pips_id == 0
                              select r.aired.Date).Distinct().OrderBy(d => d).ToList();

            var earliest = notmatched.First();                  //itemStore.redux_items.Min(r => r.aired).Date;
            var latest   = notmatched.Last();                   //itemStore.redux_items.Max(r => r.aired).Date;

            Task.Factory.StartNew(() =>
            {
                for (DateTime dt = earliest; dt <= latest; dt = dt.AddDays(1))
                {
                    ScanWholeDay(dt, thumbnail);
                    if (_cancelled)
                    {
                        Dispatcher.Invoke((MyDelegate) delegate
                        {
                            cancelButton.IsEnabled = false;
                            working.Content        = "Cancelled";
                        });
                        break;
                    }
                }
                _cancelled = false;
            });
        }
Beispiel #3
0
        private async void StartFetching()
        {
            var ctx       = new ReduxEntities();
            var thumbnail = new Thumbnail();

            thumbnail.Show();
            while (IsCancelled == false)
            {
                var nextSixteen = (from item in ctx.scan_pips_contributors
                                   where item.scanned == false
                                   select item).Take(16).ToList();
                if (nextSixteen.Count == 0)
                {
                    IsCancelled = true;
                }
                else
                {
                    await TaskEx.WhenAll(from item in nextSixteen select FetchItemGenreAndIonAsync(item, thumbnail, this, IsTags, IsIonContributors, IsCategories));

                    ctx.SaveChanges();
                }
            }
            IsRunning   = false;
            IsCancelled = false;
        }
Beispiel #4
0
        private void Images_Click(object sender, RoutedEventArgs e)
        {
            Thumbnail thumbs = new Thumbnail();

            thumbs.Show();
            thumbs.ShowImage("http://node2.bbcimg.co.uk/iplayer/images/episode/b00w43sd_314_176.jpg");
        }
        private async void JoinEm(object sender, RoutedEventArgs e)
        {
            Fetcher  fetcher   = new Fetcher();
            Progress progress  = new Progress();
            var      thumbnail = new Thumbnail();

            progress.Show();
            thumbnail.Show();
            await fetcher.GetDayScheduleAsync(viewModel.Date, progress, thumbnail);

            MessageBox.Show("Updated schedules for " + viewModel.Date.ToString());
        }
Beispiel #6
0
        private void TestThumbnails(object sender, RoutedEventArgs e)
        {
            Thumbnail thumbnail = new Thumbnail();

            thumbnail.Show();
            ReduxEntities ctx  = new ReduxEntities();
            var           pids = from p in ctx.pips_programmes.OrderByDescending(p => p.start_gmt).Take(50)
                                 select p.pid;

            foreach (var pid in pids)
            {
                thumbnail.ShowImage("http://node2.bbcimg.co.uk/iplayer/images/episode/" + pid + "_314_176.jpg");
            }
        }
Beispiel #7
0
        private async void MissingGenres(object sender, RoutedEventArgs e)
        {
            Thumbnail thumbnail = new Thumbnail();

            thumbnail.Show();
            Progress progress = new Progress();

            progress.Show();
            var itemStore = new ReduxEntities();
            var nogenres  = from p in itemStore.pips_programmes
                            join g in itemStore.genres on p.id equals g.pips_id into joined
                            from j in joined.DefaultIfEmpty()
                            where j == null
                            select p;
            var    ng  = nogenres.ToList();
            Random rnd = new Random();

            for (int i = ng.Count; i == 0; i--)
            {
                int             pos = rnd.Next(i);
                pips_programmes tmp = ng[i - 1];
                ng[i - 1] = ng[pos];
                ng[pos]   = tmp;
            }
            List <Task> tasks   = new List <Task>();
            Fetcher     fetcher = new Fetcher();

            foreach (var prog in ng)
            {
                tasks.Add(fetcher.AddGenresAsync(prog.pid, prog.id, progress, thumbnail));
                if (tasks.Count >= 16)
                {
                    await TaskEx.WhenAll(tasks);

                    tasks.Clear();
                    if (progress.IsCancelled)
                    {
                        break;
                    }
                }
            }
        }
Beispiel #8
0
        private async void GetDataAsync(object sender, RoutedEventArgs e)
        {
            Progress progress = new Progress();

            progress.Show();
            Thumbnail thumbnail = new Thumbnail();

            thumbnail.Show();
            var       context = new ReduxEntities();
            Stopwatch watch   = new Stopwatch();

            watch.Start();
            do
            {
                watch.Restart();
                int firstID = 0;

                if (await TaskEx.Run <bool>(() => { return(context.genres.Count() > 0); }))
                {
                    firstID = (from g in context.genres
                               select g.pips_id).Max();
                    //firstID = await TaskEx.Run<int>(() =>
                    //{
                    //    return (from g in context.genres
                    //            select g.pips_id).Max();
                    //});
                }

                var pids = (from p in context.pips_programmes
                            where p.id > firstID
                            select new PidItem {
                    Pid = p.pid, Id = p.id
                }).Take(50).ToList();

                //var pids = await TaskEx.Run<List<PidItem>>(() =>
                //{
                //    return (from p in context.pips_programmes
                //            where p.id > firstID
                //            select new PidItem { Pid = p.pid, Id = p.id }).Take(50).ToList();
                //});
                if (pids.Count == 0)
                {
                    break;
                }

                //foreach (var pid in pids)
                //{
                //    thumbnail.ShowImage("http://node2.bbcimg.co.uk/iplayer/images/episode/" + pid.Pid + "_314_176.jpg");
                //}

                await TaskEx.WhenAll(from pid in pids select AddGenresAsync(pid.Pid, pid.Id, progress, thumbnail));

                //foreach (var pid in pids)
                //{
                //    AddGenresAsync(pid.Pid, pid.Id, progress);
                //    if (progress.IsCancelled)
                //    {
                //        break;
                //    }
                //}
            } while (progress.IsCancelled == false);
            progress.WriteLine("Fetching has been cancelled");
        }
Beispiel #9
0
        private async void RunMatcherClick(object sender, RoutedEventArgs e)
        {
            Thumbnail thumbnails = new Thumbnail();

            thumbnails.Show();
            Progress progress = new Progress();

            progress.Show();
            ReduxEntities ctx = new ReduxEntities();
            //DateTime cutoff = new DateTime(2010, 5, 1);
            var unmatched = (from r in ctx.redux_items
                             from rp in ctx.redux_to_pips
                             where r.id == rp.redux_id && rp.pips_id == 0
                             //&& r.aired >= cutoff
                             select r).ToList();;
            int count = 0;

            foreach (var unmatcheditem in unmatched)
            {
                if (progress.IsCancelled)
                {
                    break;
                }

                var item = new UnmatchedItem(unmatcheditem, ctx.redux_to_pips.FirstOrDefault(rp => rp.redux_id == unmatcheditem.id));
                if (item.rp == null || item.rp.pips_id > 0)
                {
                    continue;
                }

                var rangestart  = item.r.aired.AddMinutes(-5);
                var rangeend    = item.r.aired.AddMinutes(5);
                var pipsmatches = await TaskEx.Run <List <pips_programmes> >(() =>
                {
                    return((from p in ctx.pips_programmes
                            where p.start_gmt == item.r.aired &&
                            p.service_id == item.r.service_id
                            select p).ToList());
                });

                string matchedpid  = null;
                bool   isMatchMade = false;
                if (pipsmatches.Count == 0)
                {
                    //progress.WriteLine("Unmatched: {0} {1} {2}", item.r.disk_reference, item.r.programme_name, item.r.aired);
                }
                else if (pipsmatches.Count == 1)
                {
                    var p = pipsmatches.First();
                    if (PartialMatch.GetSimpleWeighting(item.r, p) > 0)
                    {
                        MakeMatch(ctx, item, p);
                        matchedpid  = p.pid;
                        isMatchMade = true;
                        //progress.WriteLine("Matched: {0} {1} {2} -> {3} {4} {5}", item.r.disk_reference, item.r.programme_name, item.r.aired, p.pid, p.display_title, p.start_gmt);
                    }
                }
                else
                {
                    //progress.WriteLine("Matched: {0} {1} {2} ->", item.r.disk_reference, item.r.programme_name, item.r.aired);
                    //foreach (var pipsmatch in pipsmatches)
                    //{
                    //    var p = pipsmatch;
                    //    progress.WriteLine("         -> {0} {1} {2}", p.pid, p.display_title, p.start_gmt);
                    //}
                    //matchedpid = pipsmatches.First().pid;
                }

                if (isMatchMade == false)
                {
                    pipsmatches = await TaskEx.Run <List <pips_programmes> >(() =>
                    {
                        DateTime fiveminutesbefore = item.r.aired.AddMinutes(-5);
                        DateTime fiveminutesafter  = item.r.aired.AddMinutes(5);
                        return((from p in ctx.pips_programmes
                                join rp in ctx.redux_to_pips on p.id equals rp.pips_id into joined
                                from j in joined.DefaultIfEmpty()
                                where j == null && p.start_gmt >= fiveminutesbefore &&
                                p.start_gmt <= fiveminutesafter &&
                                p.service_id == item.r.service_id
                                select p).ToList());
                    });

                    var suitable = pipsmatches.Where(p => PartialMatch.GetSimpleWeighting(item.r, p) > 0)
                                   .OrderByDescending(p => PartialMatch.GetSimpleWeighting(item.r, p))
                                   .OrderBy(p => Math.Abs((p.start_gmt - item.r.aired).TotalSeconds))
                                   .OrderBy(p => Math.Abs(p.duration - item.r.duration))
                                   .ToList();
                    if (suitable.Count > 0)
                    {
                        pips_programmes matchedpips = suitable.First();
                        MakeMatch(ctx, item, matchedpips);
                        isMatchMade = true;
                        matchedpid  = matchedpips.pid;
                    }
                }

                if (matchedpid != null)
                {
                    thumbnails.ShowImage("http://node2.bbcimg.co.uk/iplayer/images/episode/" + matchedpid + "_314_176.jpg");
                }
                if (isMatchMade == false)
                {
                    progress.WriteLine("Failed to match {0} {1} {2}", item.r.programme_name, item.r.disk_reference, item.r.aired);
                }
            }
            MessageBox.Show("Finished matching unmatched items");
        }