Wednesday, November 26, 2008

Infragistics.Documents versus ActiveReports

PDF document had to be rendered from an application. We used to use ActiveReports for PDF reports, but have experienced difficulties when maintaining them. I gave a try to Infragistics.Documents library. It looked nice, but a lot of coding would be required. I think one could prepare some set of classes that would allow fast creation of documents, but it would take some time we did not have. I had to admit, that it is much faster to create the document in ActiveReports, using the visual designer.
Perhaps this is just another prove of the rule "the less code you write the better".

Thursday, November 13, 2008

Good bye floppy disks

I did a big tidy up at home recently and found a bunch of floppy disks. My wife were interested in two of them. I coppied their content to an USB disk (yes, I still can access the computer having a floppy drive) and I guess I will never use floppy disks again.

Rest in peace, floppy disks!

Thursday, November 6, 2008

VisualStudio 2008 dead and alive

My VisualStudio 2008 stopped from runnning. After started, it reported several problems with loading of its parts and then crashed. Well, I wanted to repair the installation, but the installation program did not start, even. Because of that, I could neither uninstall the VisualStudio. Fortunately, I found the article on stackoverflow that helped me uninstall the VisualStudio.

I guess the problem was caused by uninstall of DataDynamics ActiveReports. Did anyone out there experience similar problem?

Wednesday, October 1, 2008

Boxing and arrays

There is one more catch with boxing (see also my former post Boxing and explicit conversions). Consider the code

public struct X
{
   public string Value { get; set; }
}

public void Fun()
{
   X x1 = new X { Value="original string 1" };
   X x2 = new X { Value="original string 2" };
   X[] array = new X[] { x1, x2 };

   array[0].Value = "modified string";
   //! x1 is not changed
}


I am occasionally amazed that x1 has "original string 1" on the line marked '!' although array[0] reads "modified string". Hell yes, that is because of boxing again. If X was classx1 would be changed, too.

Boxing and explicit conversions

Imagine you are writing a method that will process a number. You need to accept object as an argument.*) You know that you will accept integers. You have considered the usage of int and long, and you have chosen long since int can be safely converted to long. So you prepare something like

void ProcessNumber(object o)
{
   long number = (long)o; //!
   //do something with number
}


You test your method, and — surprise — you receive System.InvalidCastException on the line marked '!' when calling ProcessNumber(1). The problem is that boxing is involved, and the argument is not longer just int.

You can cast a boxed value only if it is of the very same type!

If it is not certain that you will receive single type in all calls, you had better use the appropriate method of the System.Convert class.

*) Consider accessing of properties via reflection.

Thursday, April 10, 2008

Quotation of the Day

"If you do serious Oracle Development, you will be clueless sooner or later." source

Tuesday, April 1, 2008

Edit .csproj file in Visual Studio

I bet everyone had the need to view or edit the content of .csproj file. I used to use notepad to do that. Accidentally I've discovered that it is possible to do so directly in Visual Studio. First you have to unload the project. You can use the context menu on the project in Solution Explorer to do so. Then this context menu changes so that it contains the item "Edit .csproj", by clicking which you can access and edit the content of .csproj file. Don't forget to "Reload Project" after you are finished.

Changing the size of paper in ActiveReports

I wanted to change the size of paper to A4. Thus I set the report's property PageSettings.PaperKind to System.Drawing.Printing.PaperKind.A4. The report designer reflected the change, but quite surprisingly I received the error when running the report:

Printer does not support A4 papersize. Please use PaperKind.Custom in your PageSettings or specify a papersize supported by the current printer

So I used PaperKind.Custom even though my printer supports A4 very well and specified the dimensions of A4 manually. What was my surprise when Adobe Acrobat Reader (viewer) still used the size of Letter! I searched ActiveReports' Support Forums and managed to find the idea of the solution: Document.Printer.PrinterName must be set to an empty string, after that you may specify both PageSettings.PaperKind and Document.Printer.PaperKind arbitrarily; the latter is esential for viewer.

Monday, March 31, 2008

Domain-Driven Design, the Book

I'm really looking forward to the Domain-Driven Design book. I've read the preface and part of chapter 1 so far and this book really seems worth reading.

Tuesday, February 12, 2008

Limited Formatting in Bind

You can specify not only what property you are binding to, but also the format that should be used. Example:
<asp:TextBox Text='<% Bind("SomeProperty", "{0:N2}") %>' />
to get number with two decimal digits.

The problem is that the format is applied in one-way manner. When the number is loaded, it is formatted perfectly. But the very same number (without editing) can be stored no more. (It depends on culture. I have discovered this when using non-us decimal separators.)

WebNumericEdit and Nullable<decimal>

I was binding Infragistics WebNumericEdit to a Nullable<decimal>. I had to set DataMode of control to NumericDataMode.Decimal. I set Nullable property to true since the value may be missing. (That is also the reason why we store the value as Nullable<decimal>.) It seemed working, but then I noticed that 0 is propagated to data instead of null. So it seems that Nullable<decimal> is not directly supported by WebNumericEdit.

After the short brainstorming, the decision was made to try to override the way how data are provided. Finally, this was sufficient to do:


public class WebNullableNumericEdit
: WebNumericEdit
{
public override object Value
{
get
{
return (this.Nullable &&
this.Text.Equals(this.NullText)) ?
null : base.Value;
}
set { base.Value = value; }
}
}

Wednesday, January 30, 2008

Overlapping Validation Groups and Duplication of Validators

I was solving the following problem: There are two buttons (B1 and B2) on a form and two fields (F1 and F2). B1 should trigger the validation of F1, while B2 makes both F1 and F2 validated.

The concept of validation groups as introduced in .NET 2.0 is well prepared for two logically independent forms of one page, but is quite not ready for above described situations (that are not so rare I think).

I rejected the idea of triggering the validation manually on button click. I wanted to follow the common pattern of validation as much as possible. I'm afraid you cannot share validators among several validation groups nor you can attach several validation groups to a single button. (The latter would be much preferred.) I introduced two validation groups, and there is a duplication of validators for F1 in order to make them included in both validation groups. This duplication is pretty systematic (only ValidationGroup property varies) and recognisable at first sight, but still it is a pitty to have it there.

Tuesday, January 29, 2008

The Effectiveness of Test-first Approach to Programming

National Research Council of Canada published a paper titled "The Effectiveness of Test-first Approach to Programming", in which the test-first approach leads to higher productivity. Read more comments on the paper on InfoQ. The co-author offers that quality is also better when using test-first approach, although his research showed more consistent quality results only.

Friday, January 4, 2008

Unexpected exceptions in .NET

You can throw any exception you like from any place of your code in C#. That is quite OK. The problem is that the caller may receive any type of exception. One cannot be sure with .NET framework either. Although there is MSDN documentation on what exceptions can be thrown from what methods, you may receive unexpected expections. For example XmlDocument.Load promises to throw XmlException on parsing error, but if you use validating XmlReader, the XmlSchemaValidationException can be thrown.


I like Java throws clause. You just discover all possible types of exceptions by compiling. With that knowledge, you may handle them or explicitly mark them to be passed to your callers. Thus you won't be surprised in run time (possibly on production system).