summaryrefslogtreecommitdiff
path: root/SpacesToDasBlog/trunk/src/app/SpacesToDasBlog.Console/DasBlogWriter.cs
blob: 369c89a845ae6c0b6c4b2166d0b6fbfacacf772f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using newtelligence.DasBlog.Runtime;

namespace SpacesToDasBlog.ConsoleUI {
	public class DasBlogWriter {
		#region Constructors

		public DasBlogWriter( )
			: this( BlogDataServiceFactory.GetService( AppDomain.CurrentDomain.BaseDirectory, null ), "Journal" ) {}

		public DasBlogWriter( string defaultCategory )
			: this( BlogDataServiceFactory.GetService( AppDomain.CurrentDomain.BaseDirectory, null ), defaultCategory ) {}

		public DasBlogWriter( IBlogDataService service, String category ) {
			_service = service;
			_category = category;
		}

		#endregion

		#region Public Methods

		public void Write( ISpacesEntry spacesEntry ) {
			Entry entry = new Entry( );
			entry.CreatedLocalTime = spacesEntry.DateCreated;
			entry.ModifiedLocalTime = spacesEntry.DateCreated;
			entry.Title =
				( spacesEntry.Title.Length > 0
				  	? spacesEntry.Title
				  	: spacesEntry.Body.Substring( 0, Math.Min( 20, spacesEntry.Body.Length ) ) );
			entry.Content = spacesEntry.Body.Replace( Environment.NewLine, "<br />" );
			entry.EntryId = spacesEntry.Id;

			if ( spacesEntry.Categories.Count > 0 ) {
				foreach ( string category in spacesEntry.Categories ) {
					entry.Categories += category + ";";
				}
			}
			else {
				entry.Categories = _category;
			}
			entry.Author = "Mo";
			_service.SaveEntry( entry );
		}

		#endregion

		#region Private Fields

		private readonly IBlogDataService _service;
		private readonly string _category;

		#endregion
	}
}