Exemple #1
0
		public static async Task<bool> Download(Revista rev, Func<IStorageFile, Task> onSucess, Action<string> callBack, Action<double> progressHandler)
		{
			if(!HaveInternetConnection())
			{
				callBack("Sem conexão à Internet");
				return false; 
			}

			BackgroundDownloader bg = new BackgroundDownloader();

			var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(RevistaControllerWrapper.FolderName, CreationCollisionOption.OpenIfExists);
			var file = await folder.CreateFileAsync(RevistaControllerWrapper.GetPdfName(rev), CreationCollisionOption.ReplaceExisting);

			DownloadHelper down = new DownloadHelper(); ;
			try
			{
				var d = bg.CreateDownload(RevistaController.Instance.GetDownloadFile(rev), file);

				await down.HandleDownloadAsync(d, true, onSucess, callBack, progressHandler);
			}
			catch
			{
				return false;
			}
			return true ;
		}
		public async Task<StorageFile> GetPDF(Revista rev)
		{
			try
			{
				var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(FolderName, CreationCollisionOption.OpenIfExists);
				return await folder.GetFileAsync(GetPdfName(rev));
			}
			catch
			{
				return null;
			}
		}
Exemple #3
0
        public bool RefreshLista(string pagHtml)
        {
            const string IMAGEHD = @"http://www.portugal-a-programar.pt/revista-programar/images/ed{0}.{1}";
            const string REGEX = @"(?:<a href="")(?<url>[^""]*)(?:""><img border=""0"" style=""padding: 10px; margin: 10px;"" alt="")(?<nome>[^""]*)(?:"" src="")(?<img>[^""]*)";

            if (string.IsNullOrEmpty(pagHtml))
                return false;

            List<Revista> list = new List<Revista>();

            foreach (Match item in Regex.Matches(pagHtml, REGEX, RegexOptions.Multiline))
            {
                var grp = item.Groups;
                var rev = new Revista()
                {
                    Url = grp["url"].Value
                    ,
                    //ImgUrl = grp["img"].Value //mudar para uma imagem com melhor qualidade
                    //,
                    Name = grp["nome"].Value
                    ,
                    ID = grp["url"].Value.Split('=').LastOrDefault()//um pouco errado, mas funciona :)
                };
                rev.ImgUrl = new Uri(string.Format(IMAGEHD, rev.ID, grp["img"].Value.Split('.').LastOrDefault())); //outra vez, nao muito correcto mas funciona
                list.Add(rev);
            }
            if (list.Count > 0)
                Lista = list;

            return list.Count > 0;
        }
Exemple #4
0
 public Uri GetDownloadFile(Revista rev)
 {
     const string FRM = @"http://www.portugal-a-programar.pt/revista-programar/edicoes/download.php?t=site&e={0}";
     return new Uri(string.Format(FRM, rev.ID), UriKind.Absolute);
 }
		public static string GetPdfName(Revista rev)
		{
			return string.Format("{0}.pdf", rev.ID);
		}