Pages

Thursday, June 30, 2011

Convert Flash to HTML5

The time is *now*! Obviously the technology has matured enough that tools that automate transition from content in browser plugins into native support. In this case Flash to HTML5. It is (still) in Labs.

http://swiffy.googlelabs.com/

Monday, June 27, 2011

What to do when a phone is lost?

As my brother lost his phone on his biking trip, it was a good trigger to investigate the options for protecting the data that is kept on the phones these days. These links relate only to Android:

More to come.

VS Plugins

There are a few cool Visual Studio 2010 plugins to assist working with HTML5:

  • Image Optimizer (link)
  • Web Standards Update for Microsoft Visual Studio 2010 SP1 (link)

 

Friday, June 24, 2011

Custom Table Mapping with Entity Framework (EF) 4.1

I used EF 4.1 Code-First feature to develop a quick prototype for a QA team recently. Now more functionality is being added to the web application (ASP.NET MVC 3) and I need to display data from log4net's Log table. For that purpose I have to hook up another database, create a model with repository, and a new Data Context. Here I will list a few findings regarding conventions. They really become convenient only when known and also when a workaround is available for non-standard situations.

To add another database to the project, I simply copied an existing Data Context class and changed it's name. The class looked like this:

 

    public class MySecondSystem : DbContext
    {

        public MySecondSystem()
        {
        }

        public DbSet<ESBStubMVC.Models.Log> Logs { getset; }

    }

 

The original context's name had "Context" suffix but I removed that. The convention for finding a connection string is that a Connection String with the same Name will be loaded from Web.Config. Since there was already a Connection String with name "MySecondSystem" used for other purposes, adjusting the class name was the quickest way to make it use the same connection string. However, adding providerName to the connectionString tag is required for Code-First to work:

 

providerName="System.Data.SqlClient"

 

Class Log represents existing log4net Log table:

 

    public class Log
    {
        public int Id { getset; }

        public DateTime Date { getset; }
        
        [StringLength(255, ErrorMessage = "The {0} must be at least {2} characters long.")]
        public string Thread { getset; }
        
        [StringLength(50, ErrorMessage = "The {0} must be at least {2} characters long.")]
        public string Level { getset; }
        
        [StringLength(255, ErrorMessage = "The {0} must be at least {2} characters long.")]
        public string Logger { getset; }
        
        [StringLength(4000, ErrorMessage = "The {0} must be at least {2} characters long.")]
        public string Message { getset; }
        
        [StringLength(2000, ErrorMessage = "The {0} must be at least {2} characters long.")]
        public string Exception { getset; }

    }

 

In the LogRepository, created by MvcScaffolding, I just changed the data context class since it had picked up an old, existing one:

 

    public class LogRepository : ILogModelRepository
    {
        MySecondSystem context = new MySecondSystem();

 

Now, to actually read from Log table, as opposed to Logs - plural is used by convention - I had to add a custom mapping. This is easy enough to set by overriding OnModelCreating:

 

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            // Custom mapping.
            modelBuilder.Entity<Log>().Map(c => c.ToTable("Log"));
        }

 

So, the final Data Context class looks like this:

 

    public class MySecondSystem : DbContext
    {

        public MySecondSystem()
        {
        }

        public DbSet<ESBStubMVC.Models.Log> Logs { getset; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            // Custom mapping.
            modelBuilder.Entity<Log>().Map(c => c.ToTable("Log"));
        }
    }

 

 

Wednesday, June 22, 2011

AppHarbor .NET Hosting and Mercurial

AppHarbor offers free .NET hosting for small projects, just what some people need in order to deploy their hobby application, low-traffic site, a prototype, or something along those lines and have it available "out there".

Out of the box, AppHarbor works with Git as the code versioning system and makes it really easy and convenient to deploy your site by just pushing the source code. While this could prompt Mercurial users to try fiddling with hg-git, there is a better way. Mercurial is supported by using BitBucket as the code hosting provider.

Check AppHarbor instructions on how to link everything together - here, while instructions on how to do it via hg-git are here.

Monday, June 20, 2011

Software Repositories

With the lack of a better term to describe this type of web sites, here is the list of software repositories that contain links to the latest versions of free software. FileHippo also has an application that will check your installed software and notify you if there are any new versions.

These sites allow easy download of the latest versions of software updates. Hopefully all the software manufacturers start using something similar to the distribution process for Google Chrome.

Friday, June 17, 2011

World Wide Telescope

Here is the link to the World Wide Telescope (I keep opening the site that sells telescopes, all the time):

www.worldwidetelescope.org

It used to be wwtelescope.com, which was a bit confusing.

A nice feature is the ability to share links to views. This, however sucks in Google Chrome because it is impossible to just copy the URL from the message that pops up, without taking a snapshot of it and running it through an OCR. :)

Crab Nebula

Friday, June 03, 2011

Resharper Keyboard Shortcut for Import Namespaces

After fiddling with Visual Studio setting, installing and reinstalling different Resharper nightly builds and stable builds, I just had a weird case where the keyboard shortcut combination for importing the namespaces disappeared.

In the settings, I could not find anything that even remotely resembled the setting I was looking for. After reinstalling the application again, it turns out that Alt+Enter combination is stored under

ReSharper_QuickFix

key. I'm posting it just in case it happens again. :)

Thursday, June 02, 2011