Firefox 3 certificate & bug

26 06 2008

I’m one of the millions of people who downloaded Firefox 3.0 some days ago. Here is my certificate!

image

Unfortunately TippingPoint ZDI notified Mozilla of a vulnerability in Firefox that impacts versions 2.x and 3.0 has mention here.  This issue is currently under investigation.  To protect Firefox users, the details of the issue will remain closed until a patch is made available.  There is no public exploit, the details are private, and so the current risk to users is minimal.

We look forward for a patch!

Technorati Tag:




WPF Document Outline: Visual Studio 2008 vs. Blend

18 06 2008

In these days I’m developing a new WPF application using VS2008 and Expression Blend.

As you can see Expression Blend has a very strong support for all graphical aspects of UI

image image

I think today you can’t develop a WPF application without using together Expression Blend and Visual Studio 2008





When WPF Databinding change the way you write code

21 05 2008

In these days I’m developing my first real production project with WPF and one of main different with Windows Form is Databinding. In WPF, databinding is very powerfull and sometimes allow you to write markup code that replace procedural code normaly used in Windows Form.

For example in this little piece of code I have written today use Databinding & Converter

image

in order to change StatusBar Visiblity when IsChecked property change on Checkbox

image image

The syntax is very compact and it’s very powerfull doing this things whit XAML markup but I’m wondering how to test this behaviour.

I thing in another post I will cover this topic.

 

Technorati Tag: ,,




The Machine is Us/ing Us

18 05 2008

Are we using the machine or the machine is using us ? Very cool video!

 

Technorati Tag:




Convert XmlDocument to DataTable using LinqToXml

3 05 2008

I found this solution to import in my database an XML file received from an external legacy system via a POP3 server. I used an open source library to get the XML file on my hard disk. Now I need to bulk insert this information into a remote server where I can access only using MSSQL protocol so I dediced to use SqlBulkCopy class. In order to use this class I need to transfor the XML document into a DataTable.

This a sample of my XML file:

<sales>
<pos code=”000000″ index=”0000000003″>
<year value=”2007″>
<month value=”04″>
<day value=”02″>
<tipo code=”L”>
<row code=”002039055″ qty=”1″ price=”7.290″ />
<row code=”002309045″ qty=”134″ price=”2.390″ />
<row code=”002427274″ qty=”21″ price=”6.500″ />
<row code=”003366150″ qty=”1″ price=”4.600″ />
<row code=”003785045″ qty=”0.1″ price=”6.940″ />
</tipo>
<tipo code=”V”>
<row code=”002039055″ qty=”21″ price=”7.290″ />
<row code=”003366150″ qty=”87″ price=”4.600″ />
</tipo>
</day>
</month>
</year>
</pos>
</sales>

and this the code
XElement xElement = XElement.Load("test.xml");
var elements = from f in xElement.Descendants(”riga”)
select new
{
Code = f.Attribute(”code”).Value,
Quantity = f.Attribute(”qty”).Value,
Price = f.Attribute(”price”).Value,
Type = f.Parent.Attribute(”code”).Value,
Day = f.Parent.Parent.Attribute(”value”).Value,
Month = f.Parent.Parent.Parent.Attribute(”value”).Value,
Year = f.Parent.Parent.Parent.Parent.Attribute(”value”).Value,
} ;

Now you can build you DataTable using the common syntax

DataTable dataTable = new DataTable("dbo.Vendite");
dataTable.Columns.Add(”data”, typeof(DateTime));
//others columns

and the you can add rows using a foreach loop

foreach (var element in elements)
{
DataRow dataRow = dataTable.NewRow();
dataRow["data"] = element.Date;
//others columns
dataTable.Rows.Add(dataRow);
}

now I can use SqlBulkCopy to insert data in the server locate inside LAN.





Optimise Rhino.Mocks tests using a base class

27 04 2008

It’s usual my team to use ModelViewPresenter pattern and than use Rhino.Mocks to test Presenter without concrete View and Model. Rhino.Mock is a great tool but its usage can be quite booring as it requires some repeated code for each test. Here a sample:

    public class Presenter
    {
        public Presenter(IView view, IModel model)
        {
            model.Loaded += delegate { throw new NotImplementedException(); };
        }
    }

    public interface IModel
    {
        event EventHandler Loaded;
    }

    public interface IView
    {
    }

I want to test that during constructor Presenter subscribe model Loaded event. So I need to write this unit test using Rhino.Mocks:

[TestFixture]
public class ClassicMockingSample
{
    private IView _view;
    private IModel _model;
    private MockRepository _repository;

    [SetUp]
    public void SetUp()
    {
        _repository = new MockRepository();
        _view = _repository.Stub<IView>();
        _model = _repository.CreateMock<IModel>();
    }

    [Test]
    public void Ctor_Always_SubscribeModelEvents()
    {

        using (_repository.Record())
        {
            Expect.Call(delegate { _model.Loaded += null; })
                .Constraints(Is.NotNull());
        }
        using (_repository.Playback())
        {
            new Presenter(_view, _model);
        }
    }
}

Looking at NBehave framework I discover a usefull class SpecBase that hides the codes needed to create MockRepository repository and give you more readable code.
Here the same test as shown before but refactored using SpecBase class

[Context]
public class NBehaveLikeMockingSample : SpecBase
{
    private IModel model;
    private IView view;

    protected override void Before_each_spec()
    {
        model = Mock<IModel>();
        view = Stub<IView>();
    }

    [Specification]
    public void Ctor_Always_SubscribeModelEvents()
    {
        using (RecordExpectedBehavior)
        {
            Expect.Call(delegate { model.Loaded += null; })
                .Constraints(Is.NotNull());
        }
        using (PlaybackBehavior)
        {
            new Presenter(view, model);
        }
    }
}

As you can see there is nothing magic here.
It’ just a more readable unit test. Context and Specification attribute are alias of MbUnit attribute

using Context = MbUnit.Framework.TestFixtureAttribute;
using Specification = MbUnit.Framework.TestAttribute;

As I don’t need all the NBehave framework for the moment I decided to copy the class SpecBase inside my UnitTest Assembly after removing the AutoMocking feature.The code it’s here:

public class SpecBase
{
    private MockRepository _mocks;

    protected IDisposable RecordExpectedBehavior
    {
        get { return _mocks.Record(); }
    }

    protected IDisposable PlaybackBehavior
    {
        get { return _mocks.Playback(); }
    }

    [SetUp]
    public void MainSetup()
    {
        _mocks = new MockRepository();
        Before_each_spec();
    }

    [TearDown]
    public void MainTeardown()
    {
        After_each_spec();
    }

    protected virtual void Before_each_spec()
    {

    }

    protected virtual void After_each_spec()
    {
    }

    protected TType Mock<TType>()
    {
        return _mocks.DynamicMock<TType>();
    }

    protected TType Mock<TType>(object[] prams)
    {
        return _mocks.DynamicMock<TType>(prams);
    }

    protected TType Partial<TType>()
        where TType : class
    {
        return _mocks.PartialMock<TType>();
    }

    protected TType Stub<TType>()
    {
        return _mocks.Stub<TType>();
    }

    protected void Verify(object mock)
    {
        _mocks.Verify(mock);
    }

    protected void VerifyAll()
    {
        _mocks.VerifyAll();
    }

    protected void Spec_not_implemented()
    {
        Assert.Ignore(“Spec not implemented”);
    }
}
Technorati Tag: ,,




Simplicity: What We Can Learn About Usability

24 04 2008

Speech less:

Technorati Tag: ,





My ALT.NET code

23 04 2008




TortoiseSVN global ignore pattern for Visual Studio solution

13 04 2008

Many times I saw collegue and customers put wrong files under the source control for example bin and obj folders or  *.user and *.suo files.

Sometimes ago I discover a great feature of TortoiseSVN called ignore list.

 TortoiseSVN

As shown above you can manage it in TortoiseSVN settings’. Currently I’m using this list.

*bin *obj RECYCLER Bin *.user *.suo

Technorati Tag: ,





Tech-ed 2007: my experience

9 04 2008

In November 2007 I had the opportunity to spend 1 week in Barcelona to attend the Microsoft TechEd 2007. During this week I got a lot of information about the current and new products released by Microsoft Corp. in these days.

One week is not enough to understand which are all the benefits of this experience as all but now, after some months, I feel how this experience was important for my working career and the software I’m developing today. TechEd was the best place I’ve ever been to speak about ways of doing software with MS technologies. Another great chance to improve my skills come from the DVD that contains record of all the sessions of TechEd. In fact every attendee received this DVD that has inside the whole kwon-out of this great week.

In the past years I had the opportunity to attend only at conferences held in Italy. This means that during the past years I usually travel to Milan (where MS has his local offices)  5 or 6 times for 1 days to keep me up to date. Now that I have been to TechEd I don’t need this because I already known the subjects of these meetings. To be honest, I kwon more because the session level of the TechEd is higher that the meeting held in Italy.

The most importanti thing is that I’m going to return to Barcelona next November.