Silverlight 4 in Action

pbrown_cover150Silverlight 4 in Action (Manning, Pete Brown) – this is second book, which I read about Silverlight. First was Pro Silverlight 3 in C# (Apress, Matthew MacDonald), which helped me when I was need to very quickly know more about Silverlight after WPF. After reading Silverlight 4 in Action I think that this is best book about Silverlight. But maybe I should compare this book with Pro Business Applications with Silverlight.


I think that most of Silverlight and WPF developers know book’s author’s blog Pete Brown. Since 2009 author is Microsoft employee, since 2007 Silverlight became the main technology of development for him. You can think that Silverlight 4 in Action is second edition, because Manning has also Silverlight 2 in Action, which I didn’t read. But Silverlight 2 in Action has different authors than SL4 in Action. So talk about what’s new in Silverlight 4 in Action is no good, it is different book, written by another author. Looks like this is first book of Pete Brown, and it is written very good.


After buying paper book you will get also free e-book version (pdf), which you can read with Kindle device for example (only in album rotation). The book has about 800 pages, has 3 parts and 25 chapters. Read more…

The art of Unit Testing with Examples in .NET

osherove_coverFirst time when I familiarized with unit testing was 5 or 6 years ago. It was start of my developing career. I remember that somebody told me about code coverage. At that time I didn’t write any Unit tests. Guy, who was my team lead, told me “Do you see operator if with three conditions? You should check all of these conditions”. So, after that I had written some code, I should go to interface and try to invoke all code which I wrote from user interface. Nice? At current time I know little more about tests and unit testing. I have not participated in projects, designed by Test Driven Development (TDD). Basics of my knowledge are a spying code of my colleagues, some articles and screencasts. I had decide that I should know much more, and became a real professional of unit testing, this is why I had start to read book The art of Unit Testing with Examples in .NET. More than, in my current job place looks like I’m just one who writing unit tests for my code. I should show good examples of my tests. Read more…

Silverlight basics. Validation. Part 1. DataAnnotations & ValidatesOnExceptions

Silverlight 4 has some new ways for validate input values (some new approaches to implement validation in your application). First approach is DataAnnotation. In this case you should describe validation rules with attributes. Two other ways (both of them is came with Silverlight 4) – you should implement one of interfaces for your ViewModel: IDataErrorInfo or INotifyDataErrorInfo. I want to talk about all of these approaches, about pros and cons of using each of them. Goal of this article to get a best way to implement validation of input values in my and your applications. This part of article about DataAnnotations.


Read more…

Small sample of using Code Contracts

I had read about Code Contracts long time ago, but I didn’t see a reason to use contract instead of simple tests and argument’s check with Exception’s throws. Only now I’m trying to use them at real project. I didn’t see why I need to write:

Contract.Requires<ArgumentNullException>(argument == null); 

Instead of like I did it before:

if (argument == null) 

    throw new ArgumentNullException(“argument”)


Couple of weeks ago I had reinstall my Windows 7 on my laptop (I bought SSD for my laptop). After I install ReSharper with Visual Studio 2010 after run I accidental choosed “Go to the metadata” instead of like usual “Go to Object Explorer” by Ctrl and Mouse Click. So when I clicked on some class of System.xxx (basic classes of .NET) I looked at source code of these classes and found that they are using Code Contracts. I thought this is why I need to understand why I need to use contracts in my code, so I started to use them in some small applications and tried to find some interesting case. Read more…

Config Transformation Tool: Parameters support

Couple of weeks ago I wrote about my small utility Config Transformation Tool, which I wrote with base of web.config transformation task. In those moments I was thinking about opportunity to pass parameters to transform file, to tool can replaces parameters in transformation file with special values. Yesterday I resolved this issue. From now I use class Microsoft.Web.Publishing.Tasks.XmlTransformation which works with strings and XmlDocuments instead of files. I had two tasks: (a) I need method which will replace parameters on values, (b) I need method which will be parse command line and create dictionary of parameters. Read more…

Register hotkey in system for WPF application

Couple days ago I got a question about how to register hotkey in Windows for WPF application. I remembered that one year ago I was solving the same problem in WinForms application, I was registering hot keys for my application, it was Vista Keys Extender project. I knew that my project worked, so I suggested author of question to use code of my project to solve his problem. But as we learned later in WPF message handle mechanism different from WinForms. So I started to find solution for WPF application. I copied my old code from my old project and started to rewrite it step-by-step. Read more…

Wrox–Professional WCF 4–Windows Communication Foundation with .NET 4

0470563141Couple of weeks ago I got a paper copy of book Pablo Cibraro, Kurt Claeys, Fabio Cozzolino, Johann Grabner – Professional WCF 4: Windows Communication Foundation with .NET 4. This book has not a lot of pages, just about 400. Really, I don’t remember when I saw so thin book about some technology. But maybe this book has not a lot pages, but a lot of interesting themes.


First chapter is patterns and principles of SOA applications. This is the best chapter in this book. When I was reading this chapter I saw that authors have a lot experience of creating applications with Service-oriented architecture. Authors described all possible architecture principles, with which you can create SOA applications. And they did not limit themselves to the principles that are possible with WCF. I think that this chapter is “must read” for all developers, it is doesn’t matter what technologies you are using: php, java or .net. And this is good luck that Wrox published this chapter online: Design Principles and Patterns. It is about 30 pages, so read it right now.


Read more…

TSQL: Passing array/list/set to stored procedure (MS SQL Server)

Passing array/list/set to stored procedure is fairly common task when you are working with Databases. You can meet this when you want to filter some collection. Other case – it can be an import into database from extern sources. I will consider few solutions: creation of sql-query at server code, put set of parameters to sql stored procedure’s parameter with next variants: parameters separated by comma, bulk insert, and at last table-valued parameters (it is most interesting approach, which we can use from MS SQL Server 2008).

Ok, let’s suppose that we have list of items and we need to filter this items by categories (“TV”, “TV game device”, “DVD-player”) and by firms (“Firm 1”, “Firm2”, “Firm 3). It will look at database like this

So we need a query which will return us list of items from database. Also we need opportunity to filter these items by categories or by firms. We will filter them by identifiers. Ok, we know the mission. How we will solve it? Most easy way, used by junior developers – it is creating SQL-instruction with C# code, it can be like this

List<int> categories = new List<int>() { 1, 2, 3 };

 

StringBuilder sbSql = new StringBuilder();

sbSql.Append(

  @"

    select i.Name as ItemName, f.Name as FirmName, c.Name as CategoryName 

    from Item i

      inner join Firm f on i.FirmId = f.FirmId

      inner join Category c on i.CategoryId = c.CategoryId

    where c.CategoryId in (");

if (categories.Count > 0)

{

  for (int i = 0; i < categories.Count; i ++)

  {

    if (i != 0)

      sbSql.Append(",");

    sbSql.Append(categories[i]);

  }

}

else

{

  sbSql.Append("-1"); // It is for empty result when no one category selected

}

sbSql.Append(")");

 

string sqlQuery = sbSql.ToString();

 

DataTable table = new DataTable();

using (SqlConnection connection = new SqlConnection("Data Source=(local);Initial Catalog=TableParameters;Integrated Security=SSPI;"))

{

  connection.Open();

  using (SqlCommand command = new SqlCommand(sqlQuery, connection))

  {

    using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))

    {

      dataAdapter.Fill(table);

    }

  }

}

 

//TODO: Working with table


We will filter items only by categories. Just want to write less code. In the previous example first line is list of categories identifiers, chosen by user (user can select checkboxes). Problems of this solution are: a) sql-injections in some cases (user can change identifiers, which we get from web-form); b) not really good code support at feature when categories can be a really big set. One more problem – it will be hard to place this code to stored procedure (of course you can use exec statement at sql-server, but it will be not a good choice). So we can name this solution like “Solution #0”, because you can use it only if you are very lazy guy, or because this solution is very fast written.


Read more… (Solution #1. String – parameters separated by comma., Solution #2. BULK INSERT, Solution #3. Table-Valued Parameters (Database Engine))