示例#1
0
 public MalArticleQuery(string url, string title, MalNewsType type)
 {
     _type = type;
     _title = title;
     Request =
         WebRequest.Create(Uri.EscapeUriString(url));
     Request.ContentType = "application/x-www-form-urlencoded";
     Request.Method = "GET";
 }
示例#2
0
 public MalArticleQuery(string url, string title, MalNewsType type)
 {
     _type   = type;
     _title  = title;
     Request =
         WebRequest.Create(Uri.EscapeUriString(url));
     Request.ContentType = "application/x-www-form-urlencoded";
     Request.Method      = "GET";
 }
示例#3
0
 public static async Task <string> RetrieveArticleContentData(string title, MalNewsType type)
 {
     try
     {
         return
             (await
              DataCacheService.RetrieveData <string>(
                  $"mal_{(type == MalNewsType.Article ? "article" : "news")}_html_{title}.json", "Articles", 0));
     }
     catch (Exception)
     {
         //No file
     }
     return(null);
 }
示例#4
0
        public static async Task <string> RetrieveArticleContentData(string title, MalNewsType type)
        {
            try
            {
                var folder =
                    await
                    ApplicationData.Current.LocalFolder.CreateFolderAsync("Articles",
                                                                          CreationCollisionOption.OpenIfExists);

                var file = await folder.GetFileAsync($"mal_{(type == MalNewsType.Article ? "article" : "news")}_html_{title}.json");

                var data = await FileIO.ReadTextAsync(file);

                var tuple =
                    JsonConvert.DeserializeObject <Tuple <DateTime, string> >(data);
                return(CheckForOldDataDetails(tuple.Item1) ? tuple.Item2 : null); //7 days of validnessssss
            }
            catch (Exception)
            {
                //No file
            }
            return(null);
        }
示例#5
0
 public static async void SaveArticleContentData(string title, string htmlData, MalNewsType type)
 {
     try
     {
         await Task.Run(async() =>
         {
             await
             DataCacheService.SaveData(htmlData,
                                       $"mal_{(type == MalNewsType.Article ? "article" : "news")}_html_{title}.json", "Articles");
         });
     }
     catch (Exception e)
     {
         //magic
     }
 }
示例#6
0
        public async void TestArticlesIndexQuery(MalNewsType type, string url)
        {
            var articles = await new MalArticleQuery(url, "", type).GetArticleHtml();

            Assert.False(string.IsNullOrEmpty(articles));
        }
示例#7
0
 public static async void SaveArticleContentData(string title, string htmlData, MalNewsType type)
 {
     try
     {
         await Task.Run(async() =>
         {
             var folder =
                 await
                 ApplicationData.Current.LocalFolder.CreateFolderAsync(
                     "Articles",
                     CreationCollisionOption.OpenIfExists);
             var json =
                 JsonConvert.SerializeObject(new Tuple <DateTime, string>(DateTime.UtcNow, htmlData));
             var file =
                 await
                 folder.CreateFileAsync($"mal_{(type == MalNewsType.Article ? "article" : "news")}_html_{title}.json",
                                        CreationCollisionOption.ReplaceExisting);
             await FileIO.WriteTextAsync(file, json);
         });
     }
     catch (Exception e)
     {
         //magic
     }
 }
示例#8
0
 public async void TestArticlesIndexQuery(MalNewsType type,string url)
 {
     var articles = await new MalArticleQuery(url,"",type).GetArticleHtml();
     Assert.False(string.IsNullOrEmpty(articles));
 }