You do have a backup (plan), don't you?

by mgreuel 5. May 2011 15:00

Everybody has probably read a dozen times about how important backups are and how much you are screwed if you don't have a backup (or a wrong/old/incomplete one). So it should be save to assume that at least every IT-Pro makes regular backups.

That was what I thought when a co-worker of mine had a HDD crash some weeks ago. I said to him "You're an IT-Pro so you do have a backup, don't you?" His answer was simple: "Yes, but ..."

This little "but" got me thinking about my own backups. OK, all source code (and important docs) are checked in. It's unlikely that the VC server, its backup and clients crush, so it's save enough, for me. But the rest? The weekly, manual backup on an external HDD didn't seem too save when thinking about it. And what about my servers? Damn, I wanted to created a backup plan for the databases and files ... some month before.

After a few thoughts it was obviously not a good plan, so I started planning. The first step was to make a list of data I wanted to backup and then to decide how to back it up. But that list was just too heterogeneous for a single backup plan. I decided to group the data into categories, depending on importance and size (You can't backup all you VMs in real-time with revisions) and came up with the following:

Local Data

Level 1 (Important Documents, E-Books, Portable Apps)

  • "Real-time" backup/sync using SugarSync
  • When at home: "Real-time" backup to NAS (Synology ds211j with 2TB Raid1)

Level 2 (Documents, Pictures, Videos, Drivers)

  • "Real-time" backup to NAS

Level 3 (Virtual Machines, Software, Games)

  • Weekly, manual update on external HDD

Server Data (Databases, Files)

  • Daily, automated backup to NAS (over FTP)

I feel a lot better now and really hope I do so rightly. 

Tags:

General

ASP.NET MVC 3 Tools Update Setup fails with fatal error (0x80070643)

by mgreuel 13. April 2011 16:29

Today I tried to install the ASP.NET MVC 3 Tools Update. The Installation always failed with a fatal error(0x80070643). The log file sent me to the ASP.NET Webpages.msi logfile which had the wonderful error message

There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor

The Eventlog had even some additional but equally useless information:

Application: WebConfigCA.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentException
Stack:
   at System.Web.Configuration.VirtualDirectoryMapping..ctor(System.Web.VirtualPath, System.String, Boolean, System.String)
   at System.Web.Configuration.VirtualDirectoryMapping..ctor(System.String, Boolean)

After some digging I found a KB Article describing the same error during the installation of MVC 3 or WebPages and the first suggested workaround helped:

Remove the trailing backslash from the following registry keys:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\4.0.30319.0\Path
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\ASP.NET\4.0.30319.0\Path

 

I guess someone at Microsoft missed the Path.Combine method ;)

Tags:

General

Working jQuery UI Theme Switcher Widget without hotlinking

by mgreuel 12. April 2011 13:18

Since the jQuery disabled hotlinking, the default implementation of the Theme Switcher Widget doesn't work anymore. To get it running on your webspace, you need to download the js and images and change alle the links. That seemed to cumbersome for lazy dev, so I asked google for another solution. Surpringsingly, I did not found much, but there was one blog entry which picked up the idea. Although it hat some errors and was still hotlinking the css files, I could reuse it with some changes.

The attached zip file contains the js file and all necessary images. You can set the baseUrl, path to the images and the CDN which should be used in the settings, e.g.

 

cssPrefix : "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/themes/", 
imgPrefix : baseUrl + "Images/Themeroller/theme_90_", 
imageLocation : baseUrl + "Images/Themeroller/",

 

themeswitcher.zip (163.96 kb)

Tags: , ,

General

Loosing the Comparer when (De-)Serializing a Dictionary with the DataContractSerializer

by mgreuel 20. March 2011 11:44

I came across an interesting bug when working with a dictionary. I had a class using a dictionary as internal storage which should always ignore the casing of key when access the dictionary, Similar to the following code:

[Serializable]
public class TestContainer
{
    private readonly string id;
    private readonly Dictionary<string, string> dictionary;

    public TestContainer(string id)
    {
        this.id = id;
        this.dictionary = 
            new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
    }

    public string GetValue(string key)
    {
        return this.dictionary[key];
    }
        
    public void AddValue(string key, string value)
    {
        this.dictionary.Add(key, value);
    }
}

There were unit tests checking all possible scenarios to make sure the values were always retrieved correctly (at least I thought so). The container was serialized and saved to a database by one application and deserialized by another application. The following sample has the same effect:

DataContractSerializer serializer = 
    new DataContractSerializer(typeof(TestContainer));
using (MemoryStream memoryStream = new MemoryStream())
{
    serializer.WriteObject(memoryStream, testcontainer);
    memoryStream.Position = 0;

    deserializedTestContainer = 
        (TestContainer)serializer.ReadObject(memoryStream);
}

Everything seemed to work just fine, until I encountered a bug where a value in the dictionary couldn't be found. I looked at the serialized xml (which was quite a pain being several MB big) and debugged to find the missing value. When I found the value in the dictionary I was really surprised and couldn't explain it. Then I realized the casing of the key wasn't consistent and began to wonder whether I had missed a scenario in my unit tests. But everything seemed to be covered and all tests passed. While inspecting the dictionary object I discovered that the dictionary's comparer was a GenericEqualityComparer. That means the (de-)serialization ignores the comparer of a dictionary and resets it to the default. To fix the issue, the [OnDeserialized] attribute can be used:

[OnDeserialized]
private void OnDeserialized(StreamingContext context)
{
    this.dictionary = new Dictionary<string, string>(
        this.dictionary, StringComparer.OrdinalIgnoreCase);
}

Tags:

General

Creating a themeable jQuery UI menu

by mgreuel 16. March 2011 12:12

Because I'm not very good at designing I decided to base the style of the new version of MediaCommMVC completely on jQuery UI themes.

I started with the menu and was quite sure I would find a ready to use menu which offers a second level flyout and supports jQuery themes. But none of the hundreds of menu example I found supported jQuery UI themes (maybe I just missed it?). There is a menu() function in jQuery UI 1.8 which belongs to the autocomplete widget. But it's style doesn't really fit in the overall color schemes of the themes. There is also

Not really being interested in creating a menu widget from the scratch I looked at the jQuery UI samples to find components I could reuse. Putting aside the flyout behavior, the buttonset seemed like a good choice regarding the theme support. The first level menu can be created with just a few radiobuttons and a single jQuery call:

<script type="text/javascript">
	$(function () {
		$("#mainNav").buttonset();
	});
</script>
<nav id="mainNav">
	<input type="radio" id="radio1" name="menu" />
       <label for="radio1">Menu Item 1</label>        
	<input type="radio" id="radio2" name="menu" />
        <label for="radio2">Menu Item 2</label>  
	<input type="radio" id="radio3" name="menu" />
        <label for="radio3">Menu Item 3</label>
</nav>

To add a level 2 flyout menu, I wrapped a menu item in a div and included nested radio buttons:

<div class="menu-item">
    <input type="radio" id="radio2" name="menu" />
    <label for="radio2">Menu Item 2</label>
    <div class="hover-menu">
        <div class="menu-item">
            <input type="radio" id="radio2Sub1" name="subMenu2" />
            <label for="radio2Sub1">sub menu item 1</label>
        </div>
        <div class="menu-item">
            <input type="radio" id="radio2Sub2" name="subMenu2" />
            <label for="radio2Sub2">sub menu item 2</label>
        </div>
    </div>
</div>

The following css code makes the submenu visible on hover:

#mainNav .menu-item { display: inline; }

#mainNav .menu-item .hover-menu { display: none; }

#mainNav .menu-item:hover .hover-menu
{
    display: block;
    position: absolute;
    left: 0;
    top: 28px;
}

#mainNav .menu-item:hover { position: relative; }

 

The result may look like this:

 

You can see the demo here (including the jQuery UI themeroller) or download the attached sample.

jQueryUIThemesMenu.zip (1.31 kb)

Tags: ,

General