.NET Framework 3.5 - Part 2: What's new in it?
- http://dotnetwithme.blogspot.com/2007/05/what-new-in-net-35.html
- http://msdn2.microsoft.com/en-us/library/bb332048(VS.90).aspx
- http://blogs.msdn.com/tims/archive/2007/07/27/what-s-new-in-wpf-3-5-here-s-fifteen-cool-features.aspx
There is a lot of new language features in 3.5, most important to highlight for this series is LINQ. Moving along to the more shiny information there is significant work put into integration of AJAX, WPF (XBabs support in Firefox, can work with cookies now), WCF (more WS* support, general syndication support, special model for web development, and Silverlight. WCF + WF and WCF + AJAX now play very well together (lots of support for each other now). There is also support for new cryptography stuff (nice), peer to peer development. Interesting WinForms now supports the same model as ASP.NET for authentication.
.NET Framework 3.5 - Part 1: Where you can find it?
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages
BTW one nice feature of using this version, is that you have all 60Mb already downloaded. So when you launch it, and it says you need to download a bunch of data - well you give it a second cause it doesn't.
RegularExpressionValidator Designer Will Die
Working with Microsoft software is often a ride of highs and lows. Highs caused by a tiny feature which changes your life. These tiny features are the spark of genius from some lowly dev in Redmond which makes the magic happen (my favorite is the fact you can copy and paste the MSCRM license code into the installer and fills in all the blocks at once, not just the first block like other installers. Office 2007 has a similar good idea).
However there is the other side, the lows of the idiot. The people think about problems so much they forget how the rest of the world works/sees there item and thus makes it work in odd ways (MSCRM team bastardizing relationships in 3.0 to build certain things. Thankfully fixed in 4.0).
Today though I met another one of these issues, the RegularExpressionValidator in ASP.NET. You give it a RegEx to validate against and guess what it validates against that. Good, expected, normal. Here's the issue, leave the field blank or put only spaces in the field and BOOM! No validation! The workaround, and it is a workaround since this is supposedly by-design, is two validators per field (RegEx and Required!). I mean for heaven sake this is retarded. There is no reason why it should be like that, and if there is WHY OH WHY is there no property to make it work logically/illogically.
Let it be said that if I find you, Mr RegularExpressionValidator Designer Guy/Girl, you will pain for the torture you have caused me to go back through every field in my app and add another validator!
Looking Good
Through my experiences with software development a lot of time how good (polished) a software looks is almost as important as if it works well. It seems easier to get people to grant an extension on that deadline if the software looks good. A key point for any development on Windows (and in my main area Microsoft CRM) is icons. Be them for tool bars, menus, start menus or (in MSCRM) entities and ISV.Config changes good icons are a must.
To date I've collected around 11000 and sometimes never have the right one but it's a good collection to have and build from. I do share these with my coworkers but a lot of the time they ask me where I get them from so I have decided to share some of the places I got them from.
This is all inspired by the great set of 105 icons released today Sekkyumu so the first item is hers, but these are in no real order. If I can think of anything special about the site I will put it in but some places I just found some icons there. All these sites have free icons available and most also have paid for icons. I do recommend supporting these guys by buying (or getting your customers) to buy icons from them if you use them alot.
- Developper Icons by Sekkyumu - DeviantArt is also a great place in general to search.
- IconKits - These guys have some great free ones and there is a points system (each month you get a point and if you recommend someone you get points) which enables access to more icons.
- Evraldo.com
- GlyphLab - I got exposed to these guys when they bundled their icons with Delphi 2005, which still beats the pants off of the ones that ship with Visual Studio.
- FastIcon
- Icon Experience
- FamFamFam - Of all the icons I have their Silk ones (and there is over a thousand in the set) have graced more MSCRM deployments than any others.
FindControl and Master Pages
FindControl Basics
First off a primer on FindControl taken from the MSDN help: Searches the current naming container for a server control with the specified id parameter. Example: The following example defines a Button1_Click event handler. When invoked, this handler uses the FindControl method to locate a control with an ID property of TextBox2 on the containing page. If the control is found, its parent is determined using the Parent property and the parent control's ID is written to the page. If TextBox2 is not found, "Control Not Found" is written to the page.
private void Button1_Click(object sender, EventArgs MyEventArgs)
{
// Find control on page.
Control myControl1 = FindControl("TextBox2");
if(myControl1!=null)
{
// Get control's parent.
Control myControl2 = myControl1.Parent;
Response.Write("Parent of the text box is : " + myControl2.ID);
}
else
{
Response.Write("Control not found");
}
}
Searching Master Page content using FindControl
You could build a recursive find control method which searches master pages and content pages control internally looping through each control and checking the ID, but then you would need to also build one which takes logic for the offset overloaded version. Sounds like too much work, and I guess MS thought so too since it was never designed this way. Example 2: If you wanted to search the master page for a control you could do the following:
this.Master.FindControl("ControlID")
This will find any control in the master page which happens to have the ID "ControlID". This control can be a sub control of another control. Whats going on here? Well to understand, I downloaded the famous Reflector and searched Microsoft's Framework for this.
protected virtual Control FindControl(string id, int pathOffset)
{
string str;
this.EnsureChildControls();
if (!this.flags[0x80])
{
Control namingContainer = this.NamingContainer;
if (namingContainer != null)
{
return namingContainer.FindControl(id, pathOffset);
}
There is more to it and you can read it here (You'll need Reflector 5 or higher installed for that to work).
The important thing to note is the recursion being done there!!! Thus we do not need to worry about it.
There is a problem though, this searches the master page only. How do we get to the content page?
Example 3:
If you wanted to search for a control in the content page. Assuming our Content Place Holder ID is named "Content" you can then put that in FindControl followed by either $ or : and then the control you want to find.
this.Master.FindControl("Content$ControlID")
OR
this.Master.FindControl("Content:ControlID")
There you go, now you can find any control (nested or otherwise) on any content page :)Dynamically working with Enum's
Basics Of Enum
Example 1
In this example First would be equal to 1, Second to 2 and Third to 3.
public enum Demo { First, Second, Third }
Example 2
In this example First is equal to 1, Second to 222 and Third by 986.
public enum Demo { First = 1, Second = 222, Third = 986 }
Example 3
What’s nice is that if you just want to change the start position then you can define that only, so in this example First is 10, Second is 11 and Third is 12.
public enum Demo { First = 10, Second, Third }
Example 4
Even better is the ability to decorate the enum with the "flag" attribute, set the numbers (Raymond Chen explained why this is not done automatically) and use it as bitflags. Note the integer values are in traditional flag values with None set to 0 and All set to the combined value.
[Flags] public enum Demo { None = 0, First = 1, Second = 2, Third = 4, All = 7 }
Example 5
So how do we use those flags? The code below will output:
First, Third
The code is:
static void Main(string[] args) { Demo Enum = Demo.First | Demo.Third; Console.WriteLine(Enum); }
Dynamically Using Flag with Enums
So here we are basics out of the way, and now on to the fun. I continue to use the definition in example 4 above.
Example 6
First I will show how to add a value to the enum variable. What I do is start off by defining the enum to none (0 value) then using the OR concat (|=) symbol I add each enum. This code will output:
Second, Third
The code is:
static void Main(string[] args) { Demo Enum = Demo.None; Enum |= Demo.Second; Enum |= Demo.Third; Console.WriteLine(Enum); }
Example 7
In this last example I will show how to remove an value from the enum variable. I start off by defining all (integer value of 7) and then I use the AND concat (&=) symbol and prefix the enum value with tilde (~). This code will output:
First, Third
The code is
static void Main(string[] args) { Demo Enum = Demo.All; Enum &= ~Demo.Second; Console.WriteLine(Enum); }
Microsoft is pushing open source
Before I begin let me clarify a few points so you are aware of the context of this post.
1) I currently work for a Microsoft Gold Partner, been contracted to Microsoft (through my employer) and spoken at TechEd.
2) Before that I worked for company which used almost solely open source software and developed software for that. I also did work with the Shuttleworth foundation at the linux days event.
So I have been on both sides of the fence, now on to the content...
Go anywhere near Slashdot and mention Microsoft and you will get atleast a few zealots who complain about it's attitude/actions to FOSS (Free and Open Source Software).
Well I am not going into the free part, since until I can live without money making everything free doesn't help and there is many people in the traditional OSS community which do make money (RedHat, Novell, many linux contributors etc...) so I guess I am not alone in this view.
But many people bring up the open source side, which makes less sense to me. Microsoft does have this shared source thingy which is some special license for special people, but that doesn't fit with true OSS where anyone can access it so I'm not including it. Microsoft has Port25 (there public front for their internal open source lab) which has some interesting information, but not really pushing OSS. There are also a few "sponsored" projects on SourceForge and the now defunct CodePlex. Neither of these push OSS as part of major projects. So while benefical aren't big enough.
So what is it that doesn't make sense to me? Simple, the .Net framework is completely open source. All of the .Net assemblies are in source code (IL) all the time and thanks to reflection can be transformed into a convient language of choice of the viewer. Since .Net is the big push from Microsoft the new core of their systems will be open source. This can be seen currently with their applications built on top of it, like Microsoft CRM which has all their assemblies in .Net and can all be opened and viewed. Microsoft CCF is even further advanced with it including some applications in .Net (like the admin console) but the bulk is available in direct source code. BTW Neither are obfuscated in anyway, so there is no attempt to close this source.
Agreed that the core big money makers (Windows, Office etc...) are still closed source, but how much of that is legacy versus how much is based on the choice of language tool (C++ Win32 vs Dot Net) and how much of that is specific plans to close off the source I can not say and no one outside the core executive at Microsoft could say, but the argument that Microsoft doesn't get it, is just wrong. They get it and probebly more than most of the zealots mentioned earlier since they have figured out to use it strategically.
Set classes in BCL
Mark Seemann has started a vote for the introduction of sets into the BCL. Funny enough I have not thought about them since the Delphi days and got on using generics in .Net and some extra items tacked on the top, but now that Mark has brought it up I can think of dozens of places in code this would have been useful. For more details on this view Mark's post or if somehow I have convinced you you can go and vote directly.