A fix for the Blog Engine Importer tool problem...?

by Paul Kohler 24. October 2008 14:03

The problem with the importer is more that it hides the real issue. An exception in the BlogImporter web service is caused when a DateTime.MinValue is mdoified for the timezone - so depending on your timezone you will get the error :)  This throws an unhandled exception resulting in a SOAP error and the blog importer client interprets this as a username/password issue.

IMHO (!) the easiest fix is...

Open up BlogEngine.NET\api\BlogImporter.asmx from the website.

Find the "AddPost" Method, duplicate (what in my build is) line 84 but assign to "post.DateModified = import.PostDate" or "post.DateModified = DateTime.Now". Updating it to the current time is possibly "more correct"... up to you...

Now you should be able to run the importer :-)

The code should look something like this:

    [SoapHeader("AuthenticationHeader")]
    [WebMethod]
    public string AddPost(ImportPost import, string previousUrl, bool removeDuplicate) {
        ...snip...

        Post post = new Post();
        post.Title = import.Title;
        post.Author = import.Author;
        post.DateCreated = import.PostDate;
        post.DateModified = import.PostDate; // or "DateTime.Now"
        post.Content = import.Content;
        post.Description = import.Description;
        post.IsPublished = import.Publish;
        ...snip... 
        post.Import();

        return post.Id.ToString();

    }

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

BlogEngine.NET

ASP.NET MVC Generator - First Cut

by Paul Kohler 16. October 2008 07:44

I’ll keep this brief, this is the kind of thing you are better off trying for yourself.

Rails and MVC Stuff

One of the things the rails guys enjoy with developing their sites is basic code generation (skeleton files) for models, controllers and views (and whatever else). This "ASP.NET MVC Generator" is a C# implementation of the same idea making use of the standard ASP.NET MVC templates that come with the framework (currently preview 5 the beta).

(Note that for now there is a minor issue around the VB generation because of the lack or namespaces etc...)

Generators

I implemented controller and view generators with a hybrid of the two I call a "controller set". The generator I like the best is the "Controller Set". This generator creates the controller with its actions and the relevant views for each action in the appropriate view area. For example, I have an MVC website (called mvc1) setup in "C:\DEV\MvcSample\". I copy the generator and its templates to the root of the project. I have not worried so much about a Model generator yet because most of us will probably go for LINQ to SQL or SubSonic etc. I plan on adding the Model soon (not that it's hard!) but it's geared more towards the NHibernate/Active Record style of persistence.

C:\DEV\MvcSample>dir
Directory of C:\DEV\MvcSample
15/10/2008  01:50 PM            26,112 AspNetMvcGenerator.exe
15/10/2008  04:42 PM    <DIR>          mvc1
15/10/2008  04:39 PM    <DIR>          MvcTemplates 

I type the following command, sets the root namespace of the code generator to "MVC1" and the base directory to "mvc1" (where the website is from this dir) and the writes out a settings file (called "mvcsettings.xml"). The settings file is loaded if present by default to save typing the namespace etc every time.

C:\DEV\MvcSample>AspNetMvcGenerator.exe /ns:MVC1 /basedir:mvc1 /ws
C:\DEV\MvcSample>dir
Directory of C:\DEV\MvcSample
15/10/2008  01:50 PM            26,112 AspNetMvcGenerator.exe
15/10/2008  04:42 PM    <DIR>          mvc1
15/10/2008  04:44 PM               631 mvcsettings.xml
15/10/2008  04:39 PM    <DIR>          MvcTemplates 

Let's check the contents of the settings file:

C:\DEV\MvcSample>type mvcsettings.xml

<?xml version="1.0" encoding="utf-8"?>

<SiteProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 

<BaseDirectory>mvc1</BaseDirectory>

  <Area />

  <AutoEventWireup>true</AutoEventWireup>

  <ContentTags />

  <Language>C#</Language>

  <LanguageExt>cs</LanguageExt>

  <SafeItemName />

  <ActionMethods />

  <RootNamespace>MVC1</RootNamespace>

  <MasterPage>~/Views/Shared/Site.Master</MasterPage>

  <ControllersPath>Controllers\</ControllersPath>

  <ViewsPath>Views\</ViewsPath>

  <BaseClassControllerName>Controller</BaseClassControllerName>

</SiteProperties>

These are the parameters that are used for substitution in the templates. You can make other changes etc if for example your views or controllers do not reside in the default locations.

For this example I am going to delete the Home controller and its view area (actually one thing I have not got around to doing yet is checking for existing files etc.) The solution looks like this before the code generation:

 

Boring! Now for the good stuff. Type the following command:

C:\DEV\MvcSample>AspNetMvcGenerator ControllerSet Home Index AboutUs Contact

Wrote: C:\DEV\MvcSample\mvc1\Controllers\HomeController.cs

Wrote: C:\DEV\MvcSample\mvc1\Views\Home\Index.aspx

Wrote: C:\DEV\MvcSample\mvc1\Views\Home\Index.aspx.cs

Wrote: C:\DEV\MvcSample\mvc1\Views\Home\Index.aspx.designer.cs

Wrote: C:\DEV\MvcSample\mvc1\Views\Home\AboutUs.aspx

Wrote: C:\DEV\MvcSample\mvc1\Views\Home\AboutUs.aspx.cs

Wrote: C:\DEV\MvcSample\mvc1\Views\Home\AboutUs.aspx.designer.cs

Wrote: C:\DEV\MvcSample\mvc1\Views\Home\Contact.aspx

Wrote: C:\DEV\MvcSample\mvc1\Views\Home\Contact.aspx.cs

Wrote: C:\DEV\MvcSample\mvc1\Views\Home\Contact.aspx.designer.cs

We just generated a "controller set" of files for a controller called "Home" and three actions, Index, AboutUs and Contact....

OK, now jump back into Visual Studio, show all files and include the new files.

 

Now we have a generated "controller set":

(Note that the menu code in the master page is out of wack. Menu items at this level are usually cross controller or make use of multiple master pages etc...)

Now how about another set of files. Try a members area, some actions could be index, list, search, inbox, send message.

C:\DEV\MvcSample>AspNetMvcGenerator.exe controllerset Members Index List Search Inbox SendMessage

Wrote: C:\DEV\MvcSample\mvc1\Controllers\MembersController.csWrote: C:\DEV\MvcSample\mvc1\Views\Members\Index.aspxWrote: C:\DEV\MvcSample\mvc1\Views\Members\Index.aspx.csWrote: C:\DEV\MvcSample\mvc1\Views\Members\Index.aspx.designer.csWrote: C:\DEV\MvcSample\mvc1\Views\Members\List.aspxWrote: C:\DEV\MvcSample\mvc1\Views\Members\List.aspx.csWrote: C:\DEV\MvcSample\mvc1\Views\Members\List.aspx.designer.csWrote: C:\DEV\MvcSample\mvc1\Views\Members\Search.aspxWrote: C:\DEV\MvcSample\mvc1\Views\Members\Search.aspx.csWrote: C:\DEV\MvcSample\mvc1\Views\Members\Search.aspx.designer.csWrote: C:\DEV\MvcSample\mvc1\Views\Members\Inbox.aspxWrote: C:\DEV\MvcSample\mvc1\Views\Members\Inbox.aspx.csWrote: C:\DEV\MvcSample\mvc1\Views\Members\Inbox.aspx.designer.csWrote: C:\DEV\MvcSample\mvc1\Views\Members\SendMessage.aspxWrote: C:\DEV\MvcSample\mvc1\Views\Members\SendMessage.aspx.csWrote: C:\DEV\MvcSample\mvc1\Views\Members\SendMessage.aspx.designer.cs

Again, show all files and include the new controller and view folder. You just got another huge kick-start :-)

The Templates

The main reason that the templates are copied along with the generator executable is that you will tend to tweak them for the individual project – especially the view ones. They are based directly off the standard VS.NET MVC Preview 5 templates. This is partly so that maintenance is easy (a good thing). The only one I added was the view page content (ViewContentPageContent.txt) and a token in the view page ($ContentTags$).

Note that I do need to include the VB stuff yet...

Other Enhancements

Firstly I'll get the VB issues sorted... 

One thing I would like to do is add some smarts for the actions – something like if the action is "List" then the controller will generate some basic LINQ against a model. The views could spit out a simple foreach loop or include a control etc. They are not a big priority though seeing as you can code them pretty quick anyway! It would only be if you were working on a real big site.

---

Anyway, let me know what you think, kick it, link it - whatever, all feedback is good!

kick it on DotNetKicks.com

AspNetMvcGenerator-bin.zip (12.86 kb) / AspNetMvcGenerator-source.zip (29.54 kb)

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

ASP.NET MVC Generator

An ASP.NET MVC Generator...

by Paul Kohler 12. October 2008 00:43

I am working on a "generator" for the MVC stuff Microsoft has come out with. It's a rails thing in case you hadn't seen it - basically a file set skeleton generator. Rather that using built in templates, you have a local set of templates (this is important) for an application and you type stuff like this via command line:

> generate Controller Home Index About Join Contact 

And a controller is created in the right spot with basic methods etc.

> generate View Home Index

...would give you an Index view in the Home folder under views etc. The ASP.NET implementation "requires" 3 files for a view which is a bit of a pain but hey....

Probably the main thing I really wanted to roll up was a "controller set", i.e. the first command creates the controller, it's methods and all associated views.

It's almost done :-)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET MVC Generator | General

What not to check into source control

by Paul Kohler 7. October 2008 22:56

What not to check into source control...

Debugger.Break();

Just don't!!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

General

Powered by BlogEngine.NET 1.4.5.10
Theme by Mads Kristensen