示例#1
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;
		}
示例#2
0
		private async Task FetchItemGenreAndIonAsync(scan_pips_contributors item, Thumbnail thumbnail, IProgress progress, bool isTags, bool isIonContributors, bool isCategories)
		{
			if (progress.IsCancelled)
			{
				return;
			}
			thumbnail.ShowImage("http://node2.bbcimg.co.uk/iplayer/images/episode/" + item.pid + "_314_176.jpg");

			try
			{

				if (isTags || isIonContributors)
				{
					WebClient client = new WebClient();
					string result = await client.DownloadStringTaskAsync("http://www.bbc.co.uk/iplayer/ion/episodedetail/episode/" + item.pid + "/format/xml");

					XElement episode = XElement.Parse(result);
					XNamespace ion = "http://bbc.co.uk/2008/iplayer/ion";
					if (isIonContributors)
					{
						await TaskEx.Run(() =>
							{
								var contributors = episode.Elements(ion + "blocklist")
													.Elements(ion + "episode_detail")
													.Elements(ion + "contributors")
													.Elements(ion + "contributor");
								var data = new ReduxEntities();
								foreach (var contributor in contributors)
								{
									var ct = new contributor
									{
										character_name = contributor.Element(ion + "character_name").Value,
										family_name = contributor.Element(ion + "family_name").Value,
										given_name = contributor.Element(ion + "given_name").Value,
										role = contributor.Element(ion + "role").Value,
										role_name = contributor.Element(ion + "role_name").Value,
										type = contributor.Element(ion + "type").Value,
										contributor_id = Convert.ToInt32(contributor.Element(ion + "id").Value),
										pid = item.pid
									};
									data.AddObject("contributors", ct);
								}
								data.SaveChanges();
							});
					}
					if (isTags)
					{
						await TaskEx.Run(() =>
							{
								var tags = episode.Elements(ion + "blocklist")
													.Elements(ion + "episode_detail")
													.Elements(ion + "tag_schemes")
													.Elements(ion + "tag_scheme")
													.Elements(ion + "tags")
													.Elements(ion + "tag");
								var data = new ReduxEntities();
								foreach (var tag in tags)
								{
									var tg = new tag
									{
										tag_id = tag.Element(ion + "id").Value,
										name = tag.Element(ion + "name").Value,
										value = tag.Element(ion + "value").Value,
										pid = item.pid
									};
									data.AddObject("tags", tg);
								}
								data.SaveChanges();
							});
					}
				}
				if (isCategories)
				{
					WebClient catClient = new WebClient();
					var catresult = await catClient.DownloadStringTaskAsync("http://www.bbc.co.uk/programmes/" + item.pid + ".xml");
					var root = XElement.Parse(catresult);

					await TaskEx.Run(() =>
						{
							var cats = from cat in root.XPathSelectElements("categories/category[@type != 'genre']")
									   select new category()
									   {
										   pid = item.pid,
										   type = cat.Attribute("type").Value,
										   catkey = cat.Attribute("key").Value,
										   title = cat.Element("title").Value
									   };
							var db = new ReduxEntities();
							foreach (var c in cats)
							{
								db.AddObject("categories", c);
							}
							db.SaveChanges();
						});
				}
				item.scanned = true;
			}
			catch (WebException wex)
			{
				MessageBox.Show("Can't find programme " + item.pid);
				//throw new Exception("Couldn't find programme " + item.pid, wex);
			}
		}
示例#3
0
		private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			var g = ((ListBox)sender).SelectedItem as GenrePid;
			var ctx = new ReduxEntities();
			var path = ctx.genre_pids.First(ge => ge.path == GenrePath.Path);
			path.pid = g.Pid;
			ctx.SaveChanges();
			GenrePath.Pid = g.Pid;
		}
示例#4
0
 // This is a quick(ish) way to scan all the programmes in pips_programmes
 // and find all gaps in the schedule.
 // Note that this process will find all actual gaps where
 // the channel is not transmitting
 private void ScanGaps_Click(object sender, RoutedEventArgs e)
 {
     List<Gap> gaps = new List<Gap>();
     Task.Factory.StartNew(() =>
         {
             StringBuilder sql = new StringBuilder();
             sql.AppendLine("insert into gaps (programme_id, service_id, gapstart,gapend)");// VALUES(1234,1,"2007-06-28 03:00","2007-06-28 06:00")
             using (var data = new ReduxEntities())
             {
                 var programmes = (from prog in data.pips_programmes
                                   //orderby prog.ServiceId, prog.StartTime
                                   select prog).ToList();
                 programmes = (from prog in programmes
                              orderby prog.service_id, prog.start_gmt
                              select prog).ToList();
                 pips_programmes prev = null;
                 using (var newdata = new ReduxEntities())
                 {
                     foreach (var prog in programmes)
                     {
                         if (prev != null && prev.service_id == prog.service_id && prev.end_gmt < prog.start_gmt)
                         {
                             gap gap = new gap
                             {
                                 programme_id = prog.id,
                                 service_id = prog.service_id,
                                 gapstart = prev.end_gmt,
                                 gapend = prog.start_gmt
                             };
                             newdata.gaps.AddObject(gap);
                             Dispatcher.Invoke((MyDelegate)delegate { gapLabel.Content = string.Format("{0}", gap.gapstart); });
                         }
                         if (prev == null || prog.service_id != prev.service_id || prog.end_gmt > prev.end_gmt)
                         {
                             prev = prog;
                         }
                     }
                     newdata.SaveChanges();
                 }
                 Dispatcher.Invoke((MyDelegate)delegate { gapGrid.ItemsSource = data.gaps; });
             }
         });
 }