Showing posts with label Visual Studio 2010. Show all posts
Showing posts with label Visual Studio 2010. Show all posts

Wednesday, March 10, 2010

A useful post for Telerik Users?

Well I found out, that these Telerik WinControls are boon and bane. I like theme because I do a lot of great design stuff via XML and Themes. And if you know what you’re doing these controls really perform. But I ran into a System.StackoverflowException and I found the documentation on that specific error very helpful. So thx anyway Microsoft. If I wouldn’t knew it anyway - what caused that error - I guess I would be lost. Take a moment, before they change the documentation on this error, I make a screenshot.

image

I like the explanation part.

image

Saying: A StackOverflowException occurs when the Stack overflows. Yes, who’d a thunk? Or WTF? So guys what happened here?

Well looks like the beloved Telerik.RadComboBox had a little event handling problem calling the Data Source. Since it's a bindingproblem within the RadControl there is no way for me changing that. Since the Data comes from a Service i also had no chance to edit that. Anyway debugging that is not easy. Found a cool article on this topic. Where? Yes, at stackoverflow.com! Since I have a modular software and want to fill the items of the comboBox by a public data Method and some parts at the control itself, it turns out the question: “How can I do that?”

So first I make sure evrything works fine when the controls are called. And check if the data source is null. In my example I want to bind the German tax authorities to that Combobox.

  private void InitMyComboBox()
 {
   ...
   if (comboBoxTaxAuthority.DataSource == null)
       comboBoxTaxAuthority.DataSource =
                            Logic.GetTaxAuthorities();
   ...
 }

“Logic” is a Mapper which points me as you might think to a static implementation of a Singleton which loads that data from a service.

Next step is to implement the ItemDataBound event.

private void ComboBoxTaxAuthorityItemDataBound(object sender, ItemDataBoundEventArgs e)
{
   var item = e.DataBoundItem as RadComboBoxItem;
   if (item != null)
   {
     var x = e.DataItem as TaxAuthority;
     if (x!=null)
     {
       item.Value = x;
       item.Text = x.Name;
       item.DescriptionText = "Finanzamt " + x.Name;
       item.Image = Properties.Resources.authorities;
       item.TextImageRelation =
                     TextImageRelation.ImageBeforeText;
      }
    }
}

So what this does, it casts the DataBoundItem which I get from the method to a RadComboBoxItem so that I can manipulate it at design time and set the things how they should be displayed. in the next step I set the properties. For example I want to set the Text and Value of the new item to it’s inner DataBoundItem properties. And then I can set the Image from the Resource file to appear in the ComboBox. The last thing to do is to set the Image Text relation of the object. So this is the way how I solved the problem with the databinding and image from a resource file. Doing it by hand however is not the fastest way but i get rid of that stupid exception. It would take much longer to show the code which caused that error. Because the hole class is about 150.000 Lines of code. To cut the edges I just wanna mention 2 things. First: Don’t program Event Driven. The idea of event driven development is totally wrong when you interact with nearly any sort of communication or data interaction. Think about the latency between “Event is fired” and “the whole Data is loaded and send to the control”. You can call that Message Driven. So thinking "message driven" instead of "event driven" helps you understanding how the system works. Get rid of the PEBKAC (problem exist between keyboard and chair) So disable your controls while waiting for the Message! The result looks like that:

image

So i just have to do the Error Providers and the localization stuff, and yes the Description Text should be reviewed.

Wednesday, February 10, 2010

Language Integrated Query (Linq) Session @ HM

Ok, seems like i always get the talks nobody else want to have. Mh, what can i say about Linq? Well i tend to tell the people how things work. But explaining how they build Linq is a hell of hack. Yes i can tell them about “computable functions” or let’s define better “higher-order functions”. WTF? So where to start? Functional Programming? Or maybe the Lambda calculus? Well i don’t think so. And reading the the Paper? “Can Programming Be Liberated from the von Neumann Style? A Functional Style and Its Algebra of Programs” written by John Backus at the IBM Research Laboratory, San Jose. Is this the start for my Session?

I often come to the conclusion people don’t want to know anything. Like in the movie “The Island” where McCord says: “Just cause people wanna eat the burger doesn't mean they wanna meet the cow.” And talking to students @ University of Applied Sciences Munich is always a pleasure. Give them a ball, and let them run with it. You’ll be amazed by the things they will come back with.

So, decided - i show the Technology and explain it step by step. Perhaps they will surprise me again.

So showing how to work with Linq, you can find so many solutions …

  • Perhaps you start with reading?

Linq start Webpage @ Microsoft
Thank you Charlie, again!

  • Or maybe you want to check out some Webcasts?

MSDN Webcast: Introduction to Microsoft .NET Language Integrated Query
and even more Linq Webcasts …

  • i for myself prefer the code:

So one step could be Open Visual Studio –> Help –> Samples –> local Sample folder –> CSahrpSamples.zip –> Linq Samples
or direct via C:\Program Files\Microsoft Visual Studio 10.0\Samples\1033

another way of learning by code start here … CodeProject … or look closer to Charlie’s Blog.

And yes, there are Books to:

Introducing Microsoft LINQ
byPaolo Pialorsi and Marco Russo
Microsoft Press 2007 (240 pages)
ISBN:9780735623910

Save the money, give it to me. :-) The book is not as good as his title promises. Since it’s the only one i read about this topic, i can’t tell much about others.

So i finally mixed up this things with an early preview of Anders Hejlsberg and came to this solution.

The Presentation stuff:

Luca Bolognese introduces Linq always by saying developers != plumper's. What that means is, like any other O/R Mapper Linq to SQL is doing the Mapping of SQL data - Types to you’re development data – Types. Well i prefer to introduce Linq by first of all telling the folks about Duck typing.

duck     

What you can do with Duck typing is you can use a shorter way to define your variables. Instead of using something like

   1:  int i = 10;

you can do the same thing by typing

   1:  var i = 10;

Ok, that however doesn’t means that it is a non strictly typed variable. Since the compiler understands that 10 is a integer value. Where is the duck? Well the duck means – it smells like a duck, it looks like a duck, it even acts like a duck ==> so it must be a duck.

Sine 10 is obviously a integer value C# knows that and using the best fitting data type which is int. Well you may argue: “Where is the benefit?”. There are 2 profits of Duck typing. The first one is easy to explain. Think of declaring a variable of a class or .net Type like 

System.Security.Cryptography.ManifestSignatureInformationCollection collection = new ManifestSignatureInformationCollection();

ok, don’t you think that this is a very long way telling the compiler what you mean. A shorter way would be:

var collection = new ManifestSignatureInformationCollection();

I personally like that profit. Using the var when you declare a string, int, … i personally don’t like that way. It makes the code a little bit harder to understand. Because i don’t see it on the first look, what the code is trying to tell me. I have to think a second about it. Ok it’s just a second but it’s still a second.

The other benefit is by using Linq. You really don’t have to think about the result you get back from your query. Telling about queries it’s time to talk about Linq in general.

With Linq you be able to query against anything which implements IEnumerable. Since any Object and data type in dotnet is using this Interface you be able to query against it.

Another aspect on Linq is that you can query against wrappers for databases, XML files and a lot of other implantations.

Now comes the part to explain Lambda expressions and the query style. 1st against Objects, 2nd against the O/R Mapper and 3rd against XML.

Since this blog post already a bit long and i don’t want to bore you any further here are coming the links. Tada…

So here you can find the empty Demo Project.

And here you can find the solved Demo Project.

Last but at always not least, the presentation.

So one good suggestion i can give you, think twice before you use “Linq to SQL”. Don’t think twice if you use Datasets. I have the hunch that Datasets are the hypocrite of death (memory). RAM Footprints, Race conditions, bad performance … are just a view results of using Datasets. “Linq to SQL” instead is a O/R Mapper. It helps a lot and brings performance to your design time. But performance and persistence problems at runtime could occur. If you have a performance critic solution, don’t touch “Linq to SQL”. And using the Entity Framework which means ADO.net makes it worse. Do it by hand - is the only way. Use stored procedures and let the databases do the things they are made for. Yes you can use stored procedures and that stuff in Linq too. But how do you get rid of the caching, the overcharged objects and the heavy memory usage of “Linq to SQL”?         

Visual Studio – Tips & Tricks 2010 @ HM

Ok, i had this Session on 11th February 2010 @ University of Applied Sciences Munich. Since i do that session for many years now, it’s a bit freaky that every time i tell new things. But Visual Studio offers a bunch of tools and features you can use to improve and customize you’re environment the way you like.

Here are some links to other tracks and and a few other tips & tricks i didn’t show at all.

Karen Liu, Lead Program Manager Visual Studio IDE

Dirk Primps, Developer Evangelist

You can download my Presentation right here.

And also the full Demo’s i showed could be found here.

Last but not least the Poster.

Thanks to the speakers above.