From fad18020a7a15f4afdf425d8f5f2b9467141f598 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sun, 10 Jun 2007 19:26:57 -0600 Subject: import from svn --- src/app/BloggerToDasBlog.Console/DasBlogWriter.cs | 63 +++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/app/BloggerToDasBlog.Console/DasBlogWriter.cs (limited to 'src/app/BloggerToDasBlog.Console/DasBlogWriter.cs') diff --git a/src/app/BloggerToDasBlog.Console/DasBlogWriter.cs b/src/app/BloggerToDasBlog.Console/DasBlogWriter.cs new file mode 100644 index 0000000..51435cc --- /dev/null +++ b/src/app/BloggerToDasBlog.Console/DasBlogWriter.cs @@ -0,0 +1,63 @@ +using System; +using newtelligence.DasBlog.Runtime; + +namespace BloggerToDasBlog.Console { + public class DasBlogWriter { + #region Constructors + + public DasBlogWriter( ) + : this( BlogDataServiceFactory.GetService( AppDomain.CurrentDomain.BaseDirectory, null ), "Journal" ) {} + + public DasBlogWriter( IBlogDataService service, String category ) { + _service = service; + _category = category; + } + + #endregion + + #region Public Methods + + public void Write( IBloggerEntry bloggerEntry ) { + Entry entry = new Entry( ); + entry.CreatedLocalTime = bloggerEntry.Date; + entry.ModifiedLocalTime = bloggerEntry.Date; + entry.Title = + ( bloggerEntry.Title.Length > 0 + ? bloggerEntry.Title + : bloggerEntry.Body.Substring( 0, Math.Min( 20, bloggerEntry.Body.Length ) ) ); + entry.Content = bloggerEntry.Body.Replace( Environment.NewLine, "
" ); + entry.EntryId = Guid.NewGuid( ).ToString( ); + entry.Categories = _category; + entry.Author = bloggerEntry.Author; + _service.SaveEntry( entry ); + if ( bloggerEntry.Comments.Count > 0 ) { + foreach ( IBloggerComment bloggerComment in bloggerEntry.Comments ) { + WriteComments( bloggerComment, entry.EntryId ); + } + } + } + + #endregion + + #region Private Methods + + private void WriteComments( IBloggerComment bloggerComment, String targetEntryId ) { + Comment comment = new Comment( ); + comment.CreatedLocalTime = bloggerComment.Date; + comment.ModifiedLocalTime = bloggerComment.Date; + comment.TargetEntryId = targetEntryId; + comment.Author = bloggerComment.Author; + comment.Content = bloggerComment.Body; + _service.AddComment( comment ); + } + + #endregion + + #region Private Fields + + private readonly IBlogDataService _service; + private readonly string _category; + + #endregion + } +} \ No newline at end of file -- cgit v1.2.3