Commit fad1802

mo khan <mo@mokhan.ca>
2007-06-11 01:26:57
import from svn trunk main
lib/newtelligence.DasBlog.Runtime.dll
Binary file
lib/newtelligence.DasBlog.Runtime.Proxies.dll
Binary file
lib/newtelligence.DasBlog.Util.dll
Binary file
src/app/BloggerToDasBlog.Console/Properties/AssemblyInfo.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Reflection;
+using System.Runtime.InteropServices;
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly : AssemblyTitle( "BloggerToDasBlog.Console" )]
+[assembly : AssemblyDescription( "" )]
+[assembly : AssemblyConfiguration( "" )]
+[assembly : AssemblyCompany( "" )]
+[assembly : AssemblyProduct( "BloggerToDasBlog.Console" )]
+[assembly : AssemblyCopyright( "Copyright ©  2007" )]
+[assembly : AssemblyTrademark( "" )]
+[assembly : AssemblyCulture( "" )]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly : ComVisible( false )]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly : Guid( "0d3f6143-1978-43f8-8340-e3eff891bb32" )]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+[assembly : AssemblyVersion( "1.0.0.0" )]
+[assembly : AssemblyFileVersion( "1.0.0.0" )]
+[assembly : CLSCompliant( true )]
\ No newline at end of file
src/app/BloggerToDasBlog.Console/bloggerBackupGenerator.template
@@ -0,0 +1,20 @@
+<bloggerEntries>
+	<Blogger>
+		<bi_entry>
+			<bi_url><![CDATA[<$BlogItemURL$>]]></bi_url>
+			<bi_title><![CDATA[<$BlogItemTitle$>]]></bi_title>
+			<bi_body><![CDATA[<$BlogItemBody$>]]></bi_body>
+			<bi_author><![CDATA[<$BlogItemAuthor$>]]></bi_author>
+			<bi_date><![CDATA[<$BlogItemDateTime$>]]></bi_date>
+			<BlogItemCommentsEnabled>
+				<BlogItemComments>
+					<bi_comments>
+						<bi_commentauthor><![CDATA[<$BlogCommentAuthor$>]]></bi_commentauthor>
+						<bi_commentdate><![CDATA[<$BlogCommentDateTime$>]]></bi_commentdate>
+						<bi_commentbody><![CDATA[<$BlogCommentBody$>]]></bi_commentbody>
+					</bi_comments>
+				</BlogItemComments>
+			</BlogItemCommentsEnabled>
+		</bi_entry>
+	</Blogger>
+</bloggerEntries>
\ No newline at end of file
src/app/BloggerToDasBlog.Console/BloggerComment.cs
@@ -0,0 +1,32 @@
+using System;
+
+namespace BloggerToDasBlog.Console {
+	public class BloggerComment : IBloggerComment {
+		public BloggerComment( ) {}
+
+		public BloggerComment( string author, DateTime date, string body ) {
+			_author = author;
+			_date = date;
+			_body = body;
+		}
+
+		public string Author {
+			get { return _author; }
+			set { _author = value; }
+		}
+
+		public DateTime Date {
+			get { return _date; }
+			set { _date = value; }
+		}
+
+		public string Body {
+			get { return _body; }
+			set { _body = value; }
+		}
+
+		private String _author;
+		private DateTime _date;
+		private String _body;
+	}
+}
\ No newline at end of file
src/app/BloggerToDasBlog.Console/BloggerCommentXmlElement.cs
@@ -0,0 +1,10 @@
+using System;
+
+namespace BloggerToDasBlog.Console {
+	public class BloggerCommentXmlElement {
+		public const String Root = "bi_comments";
+		public const String Author = "bi_commentauthor";
+		public const String Date = "bi_commentdate";
+		public const String Body = "bi_commentbody";
+	}
+}
\ No newline at end of file
src/app/BloggerToDasBlog.Console/BloggerEntry.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+
+namespace BloggerToDasBlog.Console {
+	public class BloggerEntry : IBloggerEntry {
+		public BloggerEntry( ) {
+			_comments = new List< IBloggerComment >( );
+		}
+
+		public BloggerEntry( Uri url, string title, string body, string author, DateTime date,
+		                     IList< IBloggerComment > comments ) {
+			_url = url;
+			_title = title;
+			_body = body;
+			_author = author;
+			_date = date;
+			_comments = comments;
+		}
+
+		public Uri Url {
+			get { return _url; }
+		}
+
+		public string Title {
+			get { return _title; }
+			set { _title = value; }
+		}
+
+		public string Body {
+			get { return _body; }
+			set { _body = value; }
+		}
+
+		public string Author {
+			get { return _author; }
+			set { _author = value; }
+		}
+
+		public DateTime Date {
+			get { return _date; }
+			set { _date = value; }
+		}
+
+		public IList< IBloggerComment > Comments {
+			get { return _comments; }
+		}
+
+		private Uri _url;
+		private String _title;
+		private String _body;
+		private String _author;
+		private DateTime _date;
+		private IList< IBloggerComment > _comments;
+	}
+}
\ No newline at end of file
src/app/BloggerToDasBlog.Console/BloggerEntryXmlElement.cs
@@ -0,0 +1,12 @@
+using System;
+
+namespace BloggerToDasBlog.Console {
+	public class BloggerEntryXmlElement {
+		public const String Root = "bi_entry";
+		public const String Url = "bi_url";
+		public const String Title = "bi_title";
+		public const String Body = "bi_body";
+		public const String Author = "bi_author";
+		public const String Date = "bi_date";
+	}
+}
\ No newline at end of file
src/app/BloggerToDasBlog.Console/BloggerReader.cs
@@ -0,0 +1,122 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Xml;
+
+namespace BloggerToDasBlog.Console {
+	public sealed class BloggerReader {
+		#region Constructors
+
+		private BloggerReader( ) {}
+
+		#endregion
+
+		#region Public Methods
+
+		public static IList< IBloggerEntry > Read( Uri filePath ) {
+			XmlDocument document = new XmlDocument( );
+			document.LoadXml( File.ReadAllText( filePath.LocalPath ) );
+
+			XmlNodeReader reader = new XmlNodeReader( document );
+			reader.MoveToContent( );
+
+			IList< IBloggerEntry > results = new List< IBloggerEntry >( );
+			if ( reader.Read( ) ) {
+				if ( reader.NodeType == XmlNodeType.Element ) {
+					if ( String.Compare( reader.LocalName, BloggerEntryXmlElement.Root, true, CultureInfo.InvariantCulture ) == 0 ) {
+						String entryNode;
+						while ( !String.IsNullOrEmpty( entryNode = reader.ReadOuterXml( ) ) ) {
+							IBloggerEntry entry = ParseSingle( entryNode );
+							if ( null != entry ) {
+								results.Add( entry );
+							}
+						}
+						return results;
+					}
+				}
+			}
+			return null;
+		}
+
+		#endregion
+
+		#region Private Methods
+
+		private static IBloggerEntry ParseSingle( String resultXmlRecord ) {
+			if ( String.IsNullOrEmpty( resultXmlRecord ) ) {
+				return null;
+			}
+			XmlDocument document = new XmlDocument( );
+			document.LoadXml( resultXmlRecord );
+			XmlNodeReader reader = new XmlNodeReader( document );
+
+			IBloggerEntry entry = new BloggerEntry( );
+			reader.MoveToContent( );
+			try {
+				while ( reader.Read( ) ) {
+					if ( reader.NodeType == XmlNodeType.Element ) {
+						switch ( reader.LocalName.ToLower( CultureInfo.InvariantCulture ) ) {
+							case BloggerEntryXmlElement.Title:
+								entry.Title = reader.ReadString( );
+								break;
+							case BloggerEntryXmlElement.Body:
+								entry.Body = reader.ReadString( );
+								break;
+							case BloggerEntryXmlElement.Author:
+								entry.Author = reader.ReadString( );
+								break;
+							case BloggerEntryXmlElement.Date:
+								DateTime dateTime;
+								entry.Date = DateTime.TryParse( reader.ReadString( ), out dateTime ) ? dateTime : DateTime.MinValue;
+								break;
+							case BloggerCommentXmlElement.Root:
+								String commentNode = reader.ReadOuterXml( );
+								if ( !String.IsNullOrEmpty( commentNode ) ) {
+									entry.Comments.Add( ParseComment( commentNode ) );
+								}
+								break;
+						}
+					}
+				}
+				return entry;
+			}
+			catch ( FormatException ) {
+				return null;
+			}
+		}
+
+		private static IBloggerComment ParseComment( string xml ) {
+			if ( String.IsNullOrEmpty( xml ) ) {
+				return null;
+			}
+
+			IBloggerComment comment = new BloggerComment( );
+			XmlDocument document = new XmlDocument( );
+			document.LoadXml( xml );
+			XmlNodeReader reader = new XmlNodeReader( document );
+			reader.MoveToContent( );
+
+			while ( reader.Read( ) ) {
+				if ( reader.NodeType == XmlNodeType.Element ) {
+					switch ( reader.LocalName ) {
+						case BloggerCommentXmlElement.Author:
+							comment.Author = reader.ReadString( );
+							break;
+						case BloggerCommentXmlElement.Date:
+							DateTime dateTime;
+							comment.Date = DateTime.TryParse( reader.ReadString( ), out dateTime ) ? dateTime : DateTime.MinValue;
+							break;
+
+						case BloggerCommentXmlElement.Body:
+							comment.Body = reader.ReadString( );
+							break;
+					}
+				}
+			}
+			return comment;
+		}
+
+		#endregion
+	}
+}
\ No newline at end of file
src/app/BloggerToDasBlog.Console/BloggerToDasBlog.Console.csproj
@@ -0,0 +1,67 @@
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.50727</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{271369C6-0CA5-47CC-B037-13C1B4462324}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>BloggerToDasBlog.Console</RootNamespace>
+    <AssemblyName>BloggerToDasBlog.Console</AssemblyName>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="newtelligence.DasBlog.Runtime, Version=1.9.6264.0, Culture=neutral">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\lib\newtelligence.DasBlog.Runtime.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="BloggerComment.cs" />
+    <Compile Include="BloggerCommentXmlElement.cs" />
+    <Compile Include="BloggerEntry.cs" />
+    <Compile Include="BloggerEntryXmlElement.cs" />
+    <Compile Include="BloggerReader.cs" />
+    <Compile Include="DasBlogWriter.cs" />
+    <Compile Include="IBloggerComment.cs" />
+    <Compile Include="IBloggerEntry.cs" />
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="mokhan.blogspot.com.xml">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="bloggerBackupGenerator.template" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file
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, "<br />" );
+			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
src/app/BloggerToDasBlog.Console/IBloggerComment.cs
@@ -0,0 +1,11 @@
+using System;
+
+namespace BloggerToDasBlog.Console {
+	public interface IBloggerComment {
+		string Author { get; set; }
+
+		DateTime Date { get; set; }
+
+		string Body { get; set; }
+	}
+}
\ No newline at end of file
src/app/BloggerToDasBlog.Console/IBloggerEntry.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+
+namespace BloggerToDasBlog.Console {
+	public interface IBloggerEntry {
+		Uri Url { get; }
+
+		string Title { get; set; }
+
+		string Body { get; set; }
+
+		string Author { get; set; }
+
+		DateTime Date { get; set; }
+
+		IList< IBloggerComment > Comments { get; }
+	}
+}
\ No newline at end of file
src/app/BloggerToDasBlog.Console/Program.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace BloggerToDasBlog.Console {
+	internal class Program {
+		private static void Main( ) {
+			IList< IBloggerEntry > bloggerEntries =
+				BloggerReader.Read( new Uri( Path.Combine( Environment.CurrentDirectory, "mokhan.blogspot.com.xml" ) ) );
+
+			foreach ( IBloggerEntry bloggerEntry in bloggerEntries ) {
+				new DasBlogWriter( ).Write( bloggerEntry );
+			}
+			System.Console.WriteLine( bloggerEntries );
+			System.Console.WriteLine( bloggerEntries.Count + " Entries have been created!" );
+			System.Console.ReadLine( );
+		}
+	}
+}
\ No newline at end of file
BloggerToDasBlog.Console.sln
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BloggerToDasBlog.Console", "src\app\BloggerToDasBlog.Console\BloggerToDasBlog.Console.csproj", "{271369C6-0CA5-47CC-B037-13C1B4462324}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{271369C6-0CA5-47CC-B037-13C1B4462324}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{271369C6-0CA5-47CC-B037-13C1B4462324}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{271369C6-0CA5-47CC-B037-13C1B4462324}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{271369C6-0CA5-47CC-B037-13C1B4462324}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal
build.bat
@@ -0,0 +1,3 @@
+@echo off
+cls
+Tools\nant-0.85\bin\NAnt.exe -buildfile:projectName.build %*
\ No newline at end of file
projectName.build
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<project name="BloggerToDasBlog" default="all">
+
+    <property name="debug" value="true" />
+	
+    <target name="all"
+            depends="clean, init, compile"
+            description="Clean, build" />
+
+    <target name="clean" description="remove all build products">
+        <delete dir="build"  if="${directory::exists('build')}" />
+    </target>	
+		
+    <target name="init">
+        <mkdir dir="build" />           
+    </target>	
+	
+    <target name="compile" 
+            depends="init"
+            description="compiles the application">
+        <csc target="library" output="build\${project::get-name()}.dll" debug="${debug}">
+            <sources>
+                <include name="src\app\**\*.cs" />
+                <exclude name="src\app\**\AssemblyInfo.cs" />
+            </sources>                        
+			<references>
+				<include name="lib\newtelligence.DasBlog.Runtime.dll" />
+			</references>						
+        </csc>        
+    </target>		
+	
+</project>
\ No newline at end of file