Where did the build configuration manager go?

by Mikael Henriksson 30. August 2009 15:55

I just had a strange problem with Visual Studio I could not debug my Unit Tests. It just kept running in release mode no matter what I tried and the Build Configuration Manager was completely gone from the context menu of the solution and no build configuration in the project settings either.

Funny thing to run into at 4am… NOT! Well the solution is quite easy:

  1. Click on “Tools” in the menu bar
  2. Select Options
  3. Navigate to “Projects and Solutions”
  4. Make sure the checkbox “Show advanced build configurations” is checked

Now everything is back to normal though I have no friggin idea why it was missing to start with….

Tags:

Visual Studio

Synchronizing web sites with Web Deployment Tool

by Mikael Henriksson 26. August 2009 14:43

First of all we set up a DFS (Distributed File System) because having to copy the website files from Team City to two or three servers is a pain in the a**. Now we only copy the files to one server and it is synchronized with the others but hey what if you need to change something in the IIS manager? Well then there is the Web Deployment Tool. First install it then use it.

The following script should be run from server01 to synchronize the changes to server02. It does not take a backup of server02’s current configuration. It also does not create any application pools (have not figured that one out yet). First open a command prompt as administrator (otherwise it will give you a nice explanation about why). Second: in command prompt, navigate to “C:\Program Files\IIS\Microsoft Web Deploy” and then run the following two commands.

msdeploy -verb:getDependencies -source:apphostconfig="www.domain.com"
msdeploy -verb:sync -source:apphostconfig="www.domain.com" -dest:apphostconfig="www.domain.com",computername=server02 -whatif > msdeploysync.log

Forgot to mention the www.domain.com is actually the name of the website in IIS manager. The first line is to make a configuration out of dependencies. The second line executes this config against the server of your choice (-computername)

Tags: , ,

Windows Server | IIS | ASP.NET

ASP.NET Dynamic Data and the resource can not be found in IIS 7

by Mikael Henriksson 20. August 2009 22:50

It’s so silly but not enough people have written about it :) I kept getting a strange error while moving a Dynamic Data Entities application from IIS 6 to IIS 7. It said –“The resource ‘/TemplatePage/List.aspx’ can not be found”. I knew of course it had something to do with IIS7 finding what to add to the web.config was a different story.

Found it here: http://blogs.msdn.com/scothu/archive/2008/06/23/how-to-add-dynamic-data-to-an-existing-web-site.aspx

In the <system.webServer>/<modules> section add the following:

<remove name="UrlRoutingModule" /> 
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
In the <system.webServer>/<handlers> section add the following:
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

Tags:

Dynamic Data

Fluent Inheritance and Table-Per-Class – version 1.0.1

by Mikael Henriksson 13. August 2009 22:02

In this post I showed an old way of doing this. The new way would look like this:

public class PersonMap : ClassMap<Person>
{
  public PersonMap()
  {
    Table("person");

    Id(x => x.Id, "person_id");
    Map(x => x.FirstName, "person_first_name");
    Map(x => x.LastName, "person_last_name");
    Map(x => x.CreatedAt, "created_at");
  }
}
public class ContactMap : SubclassMap<Contact>
{
  public ContactMap()
  {
    Table("contact");

    Map(x => x.Email, "contact_email");
    Map(x => x.Phone, "contact_phone");
    Map(x => x.Mobile, "contact_mobile");

          Component(x => x.Address, c =>
                                      {
                                          c.Map(x => x.StreetOne, "address_street_one");
                                          c.Map(x => x.StreetTwo, "address_street_two");
                                          c.Map(x => x.Zip, "address_zip");
                                          c.Map(x => x.City, "address_city");
                                          c.Map(x => x.Country, "address_country");
                                      });
    References(x => x.ContactType)
      .LazyLoad()
      .Cascade.All()
      .Column("contact_type_id");
  }
}

Tags:

Fluent NHibernate

How to store XmlDocument as Xml in Sql Server 2005 using NHibernate

by Mikael Henriksson 13. August 2009 20:39

First of all I just want to state that I have no idea what I am doing but by the looks of things it is working… :) I found a ICustomType that I was almost happy with except that it stored the XmlDocument as varchar(4000). I’ll add that code at the end because it is 100 something lines. Let’s start with how difficult this was… NOT but maybe I just got lucky. Just using my XmlType class it didn’t work. Complained about System.Xml.XmlDocument could not be found when I tried mapping it so I had a look in the NHibernate source code and quickly I was able to find MsSql2005Dialect.cs and SqlTypeFactory.cs and two spots where I could potentially add code to make it work. I started with the dialect and since 2008 dialect inherits from 2005 it also inherits the xml type:

RegisterColumnType(DbType.Xml, "XML");

And then of course in SqlTypeFactory:
public static readonly SqlType Xml = new SqlType(DbType.Xml);

Now all that should be needed is to add that the column of your choice is of a custom type:
Map(x => x.ContactData, "contact_data").CustomType(typeof(XmlType));

Then a neat little class that inherits from SqlType. The last two classes could reside in
public class SqlXmlType : SqlType
{
    public SqlXmlType()
        : base(DbType.Xml)
    {
    }
}

And lastly the class that does the work:

using System;
using System.Data;
using System.Data.Common;
using System.Xml;
using global::NHibernate.SqlTypes;
using global::NHibernate.UserTypes;

public class XmlType : IUserType
{
    public new bool Equals(object x, object y)
    {
        if (x == null || y == null)
            return false;

        var xdoc_x = (XmlDocument)x;
        var xdoc_y = (XmlDocument)y;
        return xdoc_y.OuterXml == xdoc_x.OuterXml;
    }

    public int GetHashCode(object x)
    {
        return x.GetHashCode();
    }


    public object NullSafeGet(IDataReader rs, string[] names, object owner)
    {
        if (names.Length != 1)
            throw new InvalidOperationException("names array has more than one element. can't handle this!");

        var document = new XmlDocument();

        var val = rs[names[0]] as string;

        if (val != null)
        {
            document.LoadXml(val);
            return document;
        }

        return null;
    }

    public void NullSafeSet(IDbCommand cmd, object value, int index)
    {
        var parameter = (DbParameter)cmd.Parameters[index];

        if (value == null)
        {
            parameter.Value = DBNull.Value;
            return;
        }

        parameter.Value = ((XmlDocument)value).OuterXml;
    }

    public object DeepCopy(object value)
    {

        var toCopy = value as XmlDocument;

        if (toCopy == null)
            return null;

        var copy = new XmlDocument();
        copy.LoadXml(toCopy.OuterXml);
        return copy;
    }

    public object Replace(object original, object target, object owner)
    {
        throw new NotImplementedException();
    }

    public object Assemble(object cached, object owner)
    {
        var str = cached as string;
        if (str != null)
        {
            var doc = new XmlDocument();
            doc.LoadXml(str);
            return doc;
        }
        else
        {
            return null;
        }

    }

    public object Disassemble(object value)
    {
        var val = value as XmlDocument;
        if (val != null)
        {
            return val.OuterXml;
        }
        else
        {
            return null;
        }
    }

    public SqlType[] SqlTypes
    {
        get
        {
            return new SqlType[] { new SqlXmlType() };
        }
    }

    public Type ReturnedType
    {
        get { return typeof(XmlDocument); }
    }

    public bool IsMutable
    {
        get { return true; }
    }
}

I created a patch for this in jira and I found the original file here.

Tags:

NHibernate