コード例 #1
0
 // basic constructor to set properties for the service
 public AzureSearchIndexer(string ServiceName, string ServiceKey, string Index, WordPressPosts Posts)
 {
     this.ServiceKey     = ServiceKey;
     this.ServiceName    = ServiceName;
     this.Index          = Index;
     this.WordPressPosts = Posts;
 }
コード例 #2
0
        /// <summary>
        /// Loads WordPress posts from any WordPress blog.
        /// </summary>
        /// <param name="URL">WordPress blog URL</param>
        /// <returns></returns>

        public static WordPressPosts LoadAllPosts(string URL)
        {
            try
            {
                WordPressPosts wordPressPosts = new WordPressPosts();
                string         query          = "?json=get_posts";
                WebClient      client         = new WebClient();
                Stream         stream         = client.OpenRead(URL + query);
                StreamReader   reader         = new StreamReader(stream);
                var            results        = JObject.Parse(reader.ReadLine());
                var            JsonPosts      = results["posts"];
                if (JsonPosts != null)
                {
                    foreach (var JsonPost in JsonPosts)
                    {
                        wordPressPosts.Posts.Add(loadPostFromJToken(JsonPost));
                    }
                }
                if (results["pages"] != null)
                {
                    int pages = (int)results["pages"];
                    if (pages > 1)
                    {
                        for (int i = 2; i <= pages; i++)
                        {
                            query     = "?json=get_posts&page=" + i;
                            stream    = client.OpenRead(URL + query);
                            reader    = new StreamReader(stream);
                            results   = JObject.Parse(reader.ReadLine());
                            JsonPosts = results["posts"];

                            foreach (var JsonPost in JsonPosts)
                            {
                                wordPressPosts.Posts.Add(loadPostFromJToken(JsonPost));
                            }
                        }
                    }
                }
                return(wordPressPosts);
            }
            catch (Exception e)
            {
                throw;
            }
        }