Continuous Integration in .NET book MEAP update

January 21, 2010 on 6:11 pm | In DotNet | No Comments

image There are two new chapters available at Manning MEAP site. The third one about build process automation (with MSBuild) and the forth one about choosing the right CI server (covering CCNet, TeamCity and TFS 2010).

And wow the book is third on this weeks bestselling early access titles. Juhu!

Speaking about continuous integration

January 16, 2010 on 7:09 pm | In Continuous Integration, DotNet | No Comments

image I will be speaking on Wednesday (20.01.2010) in Krakow, Poland at the Karkow .NET Developers Group meeting. The session is about Continuous Integration in .NET. So if you like hear what I have to say about CI meet me at ABB ISDC, Pałac Pugetow, ul. Starowislna 13, Krakow at 18:30. I believe the attendance is free but registration is required. See you in Krakow!

Selenium RC and FitNesse as a service on Windows Server 2008

November 7, 2009 on 10:19 pm | In Windows, Continuous Integration, DotNet | No Comments

If you are working in a team or running a continuous integration process the most comfortable way to run tools like Selenum RC Server or FitNesse is to install them as a windows service. I was doing this earlier on my old Windows Server 2003 by issuing the  instsrv.exe (to install a service) on srvany.exe (to run anything) - both from Windows Resource Kit. I had to edit the registry to provide what exactly do I wanted to run (java –jar selenium-server.jar or java –jar fitnesse.jar).

But there is no Windows Resource Kit for 2008. You might use the sc.exe and get the old srvany.exe (with compatibility issues according to Microsoft itself). It would work but why bother when there is a Non-Sucking Service Manager! All you have to do to install a service with this tool is to download it, issue a

nssm.exe install SeleniumRC

and edit this dialog box:

image

Click Install service and you are done. Selenium RC Server is installed. All you have to do is to start it. Voila!

How to make CruiseControl.NET accept SSL certificate under Windows Server 2008?

October 24, 2009 on 11:44 pm | In Windows, Continuous Integration, DotNet | No Comments

If you are running CruiseControl.NET under the Local System account and your SVN server certificate was issued by yourself (or by VisualSVN Server) you will quickly run into trouble. Normally if you run any command on your repository you will get this information:

C:\Program Files\svn\bin>svn log https://your_server/svn/your_repository/trunk –username username –password password
Error validating server certificate for ‘https://your_server:443′:
- The certificate is not issued by a trusted authority. Use the
fingerprint to validate the certificate manually!
- The certificate hostname does not match.
Certificate information:
- Hostname: your_server
- Valid: from Sat, 26 Sep 2009 17:24:27 GMT until Tue, 24 Sep 2019 17:24:27 GMT

- Issuer: your_server
- Fingerprint: 24:8e:f6:ba:c7:a6:3f:69:32:c0:21:92:64:44:62:fe:2c:bb:b4:69
(R)eject, accept (t)emporarily or accept (p)ermanently?

If you accept you will not be bothered again. But CCNet works as a Windows Service. There is no one to make the decision. How to deal with this issue. Well earlier it was easy enough. You had to use one of the security holes and start cmd.exe in interactive mode wit at command (look here for more details). But with Windows Server 2008 it is not possible you will simply get this:

C:\Users\Administrator>time
The current time is: 23:31:11.59
Enter the new time:

C:\Users\Administrator>at 22:32 /interactive cmd.exe
Warning: Due to security enhancements, this task will run at the time
expected but not interactively.
Use schtasks.exe utility if interactive task is required (’schtasks /?’
for details).
Added a new job with job ID = 1

How to deal with this. There is very easy solution. Set the CruiseContril.NET service “Allow to interact with desktop” flag (Start –> Control Panel –> Administrative Tools –> Services –CruiseControl.NET) like this

image

Restart the service and wait a while for this windows to appear:

image

Select show me the message.

Voila! You have command line as Local System user available. You can now issue the

C:\Program Files\svn\bin>svn log https://your_server/svn/your_repository/trunk –username username –password password
command and accept the SSL certificate permanently.

Local Service User Accepting SSL SVN certificate fir CruiseControl.NET server

From this time on you CCNet server will not have any problems with accessing your secured repository.

Buy Continuous Integration in .NET book

October 19, 2009 on 7:52 am | In Continuous Integration, Books, DotNet | 2 Comments

Continuous Integration in .NET book cover

The Continuous Integration in .NET book is available as an early access edition from MEAP. For those of you that are not familiar with MEAP it stands for Manning Early Access Program and it is the place where you can download a free chapter and buy the whole book printed or as an ebook before it gets published. You will get continuously chapter after chapter successively as they will be written.

Get Oracle stored procedure object output in NHibernate

September 5, 2009 on 5:24 pm | In Oracle, DotNet | No Comments

I’ve wasted view hours on this so I think I share in case you have a similar problem.

We are working with Oracle Database and .NET project using NHibernate as a object-relation mapper. We have a function in Oracle that returns an Oracle Object. Objects in Oracle are user defined types. They are defined like this:

CREATE OR REPLACE TYPE Foo as object(
Value1 number,
Value2 date,
Value3 varchar(10)
);

And now Oracle Function with signature like this:

CREATE OR REPLACE FUNCTION Bar (id int)
return Foo pipelined

This function returns a Foo object and gets the id key from a table VT (some table). The 3 values from Foo object should extend an NHibernate VT object. So I want to have 3 new properties in the NHibernate entity.

Sound easy? Well it wasn’t for me. At first how to get the values? You can get an instance of IDBConnection down from NHibernate context and fight your way with ordinary ADO.NET (which is not so easy for functions with user defined return values – at least I don’t know how to do this). But you can use a TABLE() function of Oracle. You can issue this SQL select statement:

select * from Table(Bar(1))

It will return a result set as a table you can select from. Cool stuff! But to use it you have to know it exists ;)

Ok, now the easy part. I though. I define a property in NHibernate with a formula attribute and I will map this on a property in my class. Something like this:

<property
  name=Value1type=Int64formula=“(select Value1 from Table(Bar(id)))>
</property>

Not so easy! If you do this you will get the Oracle exception. NHibernate thinks that Value1 from your formula is a part of NHibernate object and gives it a suffix. It is transformed to something like that:

select _vt0.Value1 from Table(Bar(4711))

_vt0 being the object alias. It is obviously not the case. There is no Value1 field physically in the database. There is a custom made property with SQL formula in NHibernate. As you can se the id was translated to actual key in the table.

The general rule for the formula attribute is everything tat NHibernate does not understand is send direct to database as is. The trick was to make NHibernate think it does not understands the statement completely.

The answer is to enclose Value1 with quotation marks. To achieve this you will have to use the XML escape marks. Just like this:

    <property
      name=Value1type=Int64formula=(select Value1from Table(Bar(id)))>

A lot of tiny puzzles to put together. But it works!

Next big thing – continuous integration book

August 14, 2009 on 9:39 pm | In Continuous Integration, Books, DotNet | 3 Comments

image I’m going to write a book about Continuous Integration in .NET for the Manning Publications. I’m sure I don’t have to tell you how exited am I. I will join the noble team of Manning authors like John Skeet, Ayende Rahien or Roy Osherove. I’ll keep you posted about the progress. In the mean time let me give you some history.

I’ve once written an article for Software Developers Journal about Continuous Integration in .NET. It was very well received. I always thought I have a lot more to say in this topic. The idea to write a book came while speaking with my good friend hsd (well I have more and more to thank you for :). I’ve tried to propose the book to a polish publisher Helion. Very fortunately for me they said there is not enough place on the polish marketplace to get enough sell (I’ve blogged about this in polish). I presume they know better. I’ve already buried the idea about the book when I saw the ASP.NET MVC 1.0 Quickly book from Packt Publication. It was written by a guy from Belgium (Maarten Balliauw). I’ve read his blog and I realized has not native English speaker. “If he can, why not to try myself?” I thought and written a short proposal for Packt. They were interested! I’ve worked on the proposal with the Acquisition Editor and I’ve shortly after that I’ve got the information that the book was “committed”. I was very, very happy until something went wrong at Packt (the went scared by a download stats of one of the tools I wanted to write about). The book was “uncommitted” and we didn’t sign the agreement. I don’t throw my hands up! I thought if they are interested probably someone else will be too. I’ve send view more proposals to other publishers and the Manning appeared. In the mean time Packt turned to be after all interested in me writing the book. The Acquisition Editor at Packt Publishing was a great guy. I’m sure it would be great to write a book for them but it was to late. Manning found me a co-writer Craig Berntson. Someone that speaks English a lot better than I and has a know how in continuous integration. The way the Manning deals with his authors seems very provisional and I’ve very glad to get this opportunity.

So be aware. The best Continuous Integration in .NET book comes sooner than you expected!

ASP.NET MVC custom binder for currency

June 24, 2009 on 8:05 am | In ASP.NET MVC, DotNet | 1 Comment

I can imagine that’s quite common problem. You have a double (or better decimal) value that you want to show formatted as a currency field. Lets assume we are storing the price data in an object like this:

public class TestModel
{
    public double NumberField
    {
        get;
        set;
    }

    public double CurrencyField
    {
        get;
        set;
    }
}

The MVC view is strongly typed with this TestModel. And the view model value is formatted like this:

<%=Html.TextBox(“NumberField”, Model.NumberField)%>

<%=Html.TextBox(“CurrencyField”, Model.CurrencyField.ToString(“c”))%>

If you set the current culture to German-Swiss, for example in (base)controller like that:

protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
    base.Initialize(requestContext);

    string culture = “de-CH”;

    CultureInfo ci = CultureInfo.GetCultureInfo(culture);

    Thread.CurrentThread.CurrentCulture = ci;
    Thread.CurrentThread.CurrentUICulture = ci;
}

Done so we will get a text boxes looking like this:

image

What will happen if you use a default binder to get this value? The default binder will try to parse the string as a double value and get an ModelState error. The string does not represent a double value.

To deal with this issue we have to write our own model binder. This can be done by implementing the IModelBinder. But I don’t want to reimplement this how DefaultModelBinder reads other values than my currency doubles. So I though I will set a special attribute to the “special” properties. Something like this:

[AttributeUsage(AttributeTargets.Property)]
public class CurrencyAttribute : Attribute
{
}

And my object:

public class TestModel
{
    public double NumberField
    {
        get;
        set;
    }

    [Currency]
    public double CurrencyField
    {
        get;
        set;
    }
}

And now we can overload the DefaultModelBinder and implement our TestModelBinder like this:

public class TestModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext,
            ModelBindingContext bindingContext)
        {
            object bindingObject = base.BindModel(controllerContext,
                bindingContext);

            foreach (System.Reflection.PropertyInfo propInfo
                in bindingObject.GetType().GetProperties())
            {
                object[] attributes =
                    propInfo.GetCustomAttributes(typeof(CurrencyAttribute), false);

                foreach (object attribute in attributes)
                {
                    CurrencyAttribute currAtt = attribute as CurrencyAttribute;

                    if (currAtt != null)
                    {
                        bindingContext.ModelState[propInfo.Name].Errors.Clear();

                        string attempted =
                            bindingContext.ValueProvider[propInfo.Name].AttemptedValue;
                        CultureInfo ci =
                            bindingContext.ValueProvider[propInfo.Name].Culture;

                        propInfo.SetValue(
                            bindingObject,
                            double.Parse(attempted, NumberStyles.Currency, ci),
                            null);

                    }
                }
            }

            return bindingObject;
        }
    }

And now we have to set the attribute to our object to tell MVC that it has to use your binder.

[ModelBinder(typeof(TestModelBinder))]
public class TestModel
{
    public double NumberField
    {
        get;
        set;
    }

    [Currency]
    public double CurrencyField
    {
        get;
        set;
    }
}

Done! Although there are a view issues with this solution (if you are using Entity Framework you cannot set custom attributes, and in the binder above you will have to implement checking if the field is present on the view), but you get the general idea!

Easiest way to have 2 submit button in one html form

June 12, 2009 on 4:41 pm | In JavaScript, DHTML, DotNet | No Comments

Here is the easiest way to have two (or more) submit buttons in one html form and to make them “do” something else. It is very helpful if you are planning to implement a toolbar like behavior. Example is from ASP.NET MVC but it does not matter. Since it uses JavaScript to dynamically change the action attribute of a form tag, it can be used everywhere. Here it is:

    <h2><%= Html.Encode(ViewData[“Message”]) %></h2>

    <script language=”javascript” type=”text/javascript”>
        function ChangeFormAction(sender, url) {
            sender.form.action = url;
        }
    </script>

    <form method=”post”>
        <input id=”text” name=”text” type=”text” value=”Hello from Action” />
        <br />
        <input type=”submit” value=”Go to action 1″
            onclick=”ChangeFormAction(this, ‘/Home/Action1′)” />
        <input type=”submit” value=”Go to action 2″
            onclick=”ChangeFormAction(this, ‘/Home/Action2′)” />
    </form>

And the actions that responds to this form are here:

public class HomeController : Controller
{
    public ActionResult Action1(string text)
    {
        ViewData[“Message”] = text + “1″;

        return View(“Index”);
    }

    public ActionResult Action2(string text)
    {
        ViewData[“Message”] = text + “2″;

        return View(“Index”);
    }
}
Nice!

Keep your lib folder up to date

February 9, 2009 on 10:22 pm | In NUnit, SVN, DotNet | No Comments

I’m keeping all the 3rd party assemblies that I use in my .NET projects in a separate library folder called lib. It is a part of my Subversion repository. In most of my project it is placed in linked repository (with svn:externals property). It lets my check out the whole project on any machine I like and it compiles right away.

But be aware! In such scenario (and, well… in any other scenario as well) you have to keep your lib up to date. Take a look at this nasty bug. I was using the NUnit version 2.4.6.0

Take a look at this test method:

[NUnit.Framework.Test]
public void Test()
{
    System.Text.ASCIIEncoding ASCIIEncoding = new System.Text.ASCIIEncoding();

    string str1 = “abc”;

    byte[] array = ASCIIEncoding.GetBytes(str1.ToCharArray());

    System.Array.Resize<byte>(ref array, 10);

    string str2 = ASCIIEncoding.GetString(array);

    NUnit.Framework.Assert.AreEqual(str1, str2);
}

What would you expect?

image

Fail! Isn’t it?

No! 1 passed, 0 failed, 0 skipped, took 0,54 seconds.

Even NUnit hast bugs to! I’ve updated to the newest version and it works as a charm! So keep you lib folder up to date!

Next Page »

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^