Exemplo n.º 1
0
        private async void CheckTranscripts(object sender, RoutedEventArgs e)
        {
            Progress progress = new Progress();

            progress.Show();
            EnsureLoginToken();

            var transcripts = Directory.GetFiles(@"C:\Users\James\Downloads\BBC Batch 1A  - 11th March");

            foreach (var path in transcripts)
            {
                string diskref = Path.GetFileNameWithoutExtension(path);
                string url     = string.Format("http://api.bbcredux.com/content/{0}/data?token={1}", diskref, loginToken);
                try
                {
                    XElement data = await GetXml(url);

                    progress.WriteLine("{0} succeeded", url);
                }
                catch (WebException)
                {
                    progress.WriteLine("{0} failed", url);
                }
            }
        }
Exemplo n.º 2
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;
                }
            }
        }
Exemplo n.º 3
0
        async private void RunAsyncFetches()
        {
            Progress progress = new Progress();

            progress.Show();

            int genrecount = await TaskEx.Run <int>(() =>
            {
                var ctx = new ReduxEntities();
                return(ctx.genres.Count());
            });

            progress.WriteLine("We have {0} genres", genrecount);

            WebClient client = new WebClient();

            progress.WriteLine("Fetching daily schedule");
            var result = await client.DownloadStringTaskAsync("http://www.bbc.co.uk/bbcone/programmes/schedules/london/today.xml");

            progress.WriteLine("Got Schedule");
            var doc = XElement.Parse(result);

            var pids = from pid in doc.XPathSelectElements("./day/broadcasts/broadcast/programme[@type='episode']/pid")
                       select pid.Value;
            await TaskEx.WhenAll((from p in pids select FetchPidDataAsync(p, progress)));

            progress.WriteLine("Finished");
        }
Exemplo n.º 4
0
        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());
        }
Exemplo n.º 5
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;
                    }
                }
            }
        }
Exemplo n.º 6
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");
        }
Exemplo n.º 7
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");
        }