コード例 #1
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");
        }
コード例 #2
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");
        }
コード例 #3
0
        private void GetData(object sender, RoutedEventArgs e)
        {
            //programmesEntities entities = new programmesEntities();
            //var result = (from item in entities.redux_items
            //              where item.programme_name == "Doctor Who"
            //             select item);
            //dataGrid.ItemsSource = result;

            //using (var items = new ReduxItems())
            //{
            //    var top = items.PipsProgrammes.Take(100);
            //    dataGrid.ItemsSource = top;
            //}

            //using (var items = new ReduxEntities())
            //{
            //    var top = items.redux_items.Take(100);
            //    dataGrid.ItemsSource = top;
            //}

            //var context = new ReduxEntities();
            //var r = context.redux_items.First();
            //var p = context.pips_programmes.First();
            //var rp = context.redux_to_pips.First();

            Progress progress = new Progress();

            progress.Execute(() =>
            {
                var context     = new ReduxEntities();
                Stopwatch watch = new Stopwatch();
                watch.Start();
                do
                {
                    watch.Restart();
                    int firstID = 0;
                    if (context.genres.Count() > 0)
                    {
                        firstID = (from g in context.genres
                                   select g.pips_id).Max();
                    }

                    var pids = (from p in context.pips_programmes
                                where p.id > firstID
                                select new { pid = p.pid, id = p.id }).Take(50).ToList();
                    if (pids.Count == 0)
                    {
                        break;
                    }

                    foreach (var pid in pids)
                    {
                        AddGenres(pid.pid, pid.id, progress);
                        if (progress.IsCancelled)
                        {
                            break;
                        }
                    }
                } while (progress.IsCancelled == false);
            });
        }