Permalink
Browse files

Check number of files created

Fix Empty directory bug
Fix missing file argument bug
  • Loading branch information...
1 parent e089020 commit a01720f6cad2486ab85374f8ca124122113a49f6 @MichaelPereira committed Mar 28, 2012
@@ -42,7 +42,7 @@ public void Import()
{
int termId = int.Parse(matchRelationship.Groups["termId"].Value);
int postId = int.Parse(matchRelationship.Groups["postId"].Value);
-
+
// Check if the term is already in the list
if (terms.ContainsKey(termId))
{
@@ -52,7 +52,7 @@ public void Import()
{
terms.Add(termId, new Relationship()
{
- postIds = new List<int> {postId}
+ postIds = new List<int> { postId }
});
}
continue;
@@ -62,7 +62,7 @@ public void Import()
if (matchType.Success)
{
int termId = int.Parse(matchType.Groups["termId"].Value);
-
+
// Set the type for termId element in the list
if (terms.ContainsKey(termId))
{
@@ -120,10 +120,13 @@ public void Import()
Relationship term = terms[key];
foreach (int postId in term.postIds)
{
- if (term.termType == termTypeEnum.category)
- postList[postId].Categories.Add(term.termName);
- else if (term.termType == termTypeEnum.tag)
- postList[postId].Tags.Add(term.termName);
+ if (postList.Contains(postId))
+ {
+ if (term.termType == termTypeEnum.category)
+ postList[postId].Categories.Add(term.termName);
+ else if (term.termType == termTypeEnum.tag)
+ postList[postId].Tags.Add(term.termName);
+ }
}
}
@@ -149,6 +152,9 @@ private void ImportPost(WordpressPost p)
var yamlHeader = string.Format("---\r\n{0}---\r\n\r\n", header.ToYaml());
var postContent = yamlHeader + p.Content; //todo would be nice to convert to proper md
var fileName = string.Format(@"_posts\{0}-{1}.md", p.Published.ToString("yyyy-MM-dd"), p.PostName.Replace(' ', '-')); //not sure about post name
+
+ if (!Directory.Exists("_posts"))
+ Directory.CreateDirectory("_posts");
fileSystem.File.WriteAllText(Path.Combine(pathToSite, fileName), postContent);
}
@@ -46,7 +46,7 @@ public void Posts_Are_Imported()
Assert.True(fileSystem.File.Exists(BaseSite + "_posts\\2010-09-28-about.md"));
Assert.True(fileSystem.File.Exists(BaseSite + "_posts\\2010-12-07-recyclez-votre-vieux-pc-avec-jolicloud-1-1.md"));
-
+ Assert.True(fileSystem.AllPaths.Count() == 3);
var postContentAbout = fileSystem.File.ReadAllText(BaseSite + "_posts\\2010-09-28-about.md");
var headerAbout = postContentAbout.YamlHeader();
@@ -1,55 +1,64 @@
-using System;
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Linq;
using System.ComponentModel.Composition;
-using System.IO;
+using System.IO;
using System.IO.Abstractions;
using Pretzel.Logic.Commands;
-using Pretzel.Logic.Extensions;
-using Pretzel.Logic.Import;
-
-namespace Pretzel.Commands
-{
- [PartCreationPolicy(CreationPolicy.Shared)]
- [CommandInfo(CommandName = "import")]
- class ImportCommand : ICommand
- {
- readonly static List<string> Importers = new List<string>(new[] { "wordpress", "blogger" });
+using Pretzel.Logic.Extensions;
+using Pretzel.Logic.Import;
+
+namespace Pretzel.Commands
+{
+ [PartCreationPolicy(CreationPolicy.Shared)]
+ [CommandInfo(CommandName = "import")]
+ class ImportCommand : ICommand
+ {
+ readonly static List<string> Importers = new List<string>(new[] { "wordpress", "blogger", "wordpressSql" });
#pragma warning disable 649
[Import] IFileSystem fileSystem;
[Import] CommandParameters parameters;
#pragma warning restore 649
- public void Execute(IEnumerable<string> arguments)
- {
+ public void Execute(IEnumerable<string> arguments)
+ {
Tracing.Info("import - import posts from external source");
- parameters.Parse(arguments);
-
- if (!Importers.Any(e => String.Equals(e, parameters.ImportType, StringComparison.InvariantCultureIgnoreCase)))
+ parameters.Parse(arguments);
+
+ if (!Importers.Any(e => String.Equals(e, parameters.ImportType, StringComparison.InvariantCultureIgnoreCase)))
{
- Tracing.Info(String.Format("Requested import type not found: {0}", parameters.ImportType));
- return;
+ Tracing.Error(String.Format("Requested import type not found: {0}", parameters.ImportType));
+ return;
}
- if (string.Equals("wordpress", parameters.ImportType, StringComparison.InvariantCultureIgnoreCase))
+ if (string.Equals("wordpress", parameters.ImportType, StringComparison.InvariantCultureIgnoreCase))
{
- var wordpressImporter = new WordpressImport(fileSystem, parameters.Path, parameters.ImportPath);
- wordpressImporter.Import();
+ var wordpressImporter = new WordpressImport(fileSystem, parameters.Path, parameters.ImportPath);
+ wordpressImporter.Import();
}
else if (string.Equals("blogger", parameters.ImportType, StringComparison.InvariantCultureIgnoreCase))
{
var bloggerImporter = new BloggerImport(fileSystem, parameters.Path, parameters.ImportPath);
bloggerImporter.Import();
- }
-
- Tracing.Info("Import complete");
- }
-
- public void WriteHelp(TextWriter writer)
+ }
+ else if (string.Equals("wordpressSql", parameters.ImportType, StringComparison.InvariantCultureIgnoreCase))
+ {
+ if (String.IsNullOrEmpty(parameters.ImportPath))
+ {
+ Tracing.Error("Null or empty file name");
+ return;
+ }
+ var wordpressImporter = new WordpressImportSql(fileSystem, parameters.Path, parameters.ImportPath);
+ wordpressImporter.Import();
+ }
+ Tracing.Info("Import complete");
+ }
+
+ public void WriteHelp(TextWriter writer)
{
- parameters.WriteOptions(writer, "-i", "-f");
- }
- }
-}
+ parameters.WriteOptions(writer, "-i", "-f");
+ }
+ }
+}

0 comments on commit a01720f

Please sign in to comment.