private JObject CreateCategory(WordpressCategory category)
 {
     return(new JObject(
                new JProperty("ContentItemId", $"wpcat-{category.Id.ToString()}"),
                new JProperty("ContentItemVersionId", null),
                new JProperty("ContentType", "Category"),
                new JProperty("DisplayText", category.Name),
                new JProperty("Latest", false),
                new JProperty("Published", false),
                new JProperty("ModifiedUtc", creationDateTime),
                new JProperty("PublishedUtc", null),
                new JProperty("CreatedUtc", null),
                new JProperty("Owner", null),
                new JProperty("Author", "WP Import"),
                new JProperty("Category", new JObject()),
                new JProperty("TitlePart", new JObject(
                                  new JProperty("Title", category.Name)
                                  )),
                new JProperty("Terms", new JArray(
                                  from child in wordpressCategories
                                  where child.ParentName == category.NiceName
                                  select CreateCategory(child)
                                  )
                              )
                ));
 }
        private WordpressCategory ParseCategory(XmlReader categoryReader)
        {
            WordpressCategory category = new WordpressCategory();

            while (!categoryReader.EOF)
            {
                if (categoryReader.IsStartElement())
                {
                    switch (categoryReader.Name)
                    {
                    case "wp:term_id":
                        category.Id = categoryReader.ReadElementContentAsLong();
                        break;

                    case "wp:category_nicename":
                        category.NiceName = categoryReader.ReadElementContentAsString();
                        break;

                    case "wp:category_parent":
                        category.ParentName = categoryReader.ReadElementContentAsString();
                        break;

                    case "wp:cat_name":
                        category.Name = categoryReader.ReadElementContentAsString();
                        break;

                    case "wp:category_description":
                        category.Description = categoryReader.ReadElementContentAsString();
                        break;

                    default:
                        categoryReader.Read();
                        break;
                    }
                }
                else
                {
                    categoryReader.Read();
                }
                if (categoryReader.Name == "wp:category" && categoryReader.NodeType == XmlNodeType.EndElement)
                {
                    // reached end node of category
                    break;
                }
            }

            return(category);
        }
        private void ConsumeImport()
        {
            XmlReaderSettings settings = new XmlReaderSettings
            {
                IgnoreWhitespace = true
            };

            using XmlReader reader = XmlReader.Create(fileToImport, settings);
            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                    case "title":
                        blogName = reader.ReadElementContentAsString();
                        break;

                    case "description":
                        blogDescription = reader.ReadElementContentAsString();
                        break;

                    // TODO: refactor item, category and tag to remove repeated code
                    case "item":     // includes posts, pages, nav items and media
                        WordpressItem post = ParseItem(reader);
                        wordpressItems.Add(post);
                        break;

                    case "wp:category":
                        WordpressCategory category = ParseCategory(reader);
                        wordpressCategories.Add(category);
                        break;

                    case "wp:tag":
                        WordpressTag tag = ParseTag(reader);
                        wordpressTags.Add(tag);
                        break;

                    case "wp:author":
                    default:
                        //Console.WriteLine("Skipping node: {0}", reader.Name);
                        break;
                    }
                }
            }
        }