So, what happens after you press publish on our newest and coolest blog post?

basically, we all know it.
But in the current edition of Wired there is a really cool article about that. with a even better flash poster to move around. really worth a look, readers!

thanks to Matthew Hurst for pointing me to this. (I love your blog!)

And that's exactly what I really like about web 2.0.
Everything get's connected. in a smart way.

with no comments
Filed under:

Just now, an Email arrived here from Steve himself (it was send to the Executive Newsletter from Microsoft) introducing the Launch of Vista, Office 2007 and Exchange 2007.

In there, he points out that "We still rely too much on paper documents to share ideas" and that "During the next decade, the world's information will be digitized."

Sounds pretty much like the that was created in an Article of the Business Week in 1975.

So, back to the Mail.
Also there are some common "mistakes" in there, what people like Michael Arrington would never write in an press paper, like, that Exchange and Sharepoint 2007 will "revolutionize the way people work in teams" or to call them "groundbreaking products"

 

Let's grab some facts about the Mail:

.)"Windows powers 845 million computers"
.)"Office is used by more than 450 million people"
.)"We spend an average of 14.5 hours per week reading and answering email"
.)"the time we spend looking for and analyzing information costs companies $28,000 per employee per year"
.) And that this has Doubled in the last 5 Years
.) more than 5 million Beta Downloads of the 3 products where done
.) "Industry analysts expect that in 2007 alone, these products will generate more than $250 billion in revenue for our partners."
.) "During the coming year, we'll introduce new innovations such as unified communications including voice over Internet protocol (VoIP)" <-- eh, do they mean to "invent" VoIP next year? did I miss here something?


Also, he writes that they focused on 4 Aeras:
Simplifying how people work together
Finding information and improving business insight
Helping to protect and manage content
Increasing security and reducing IT costs

 

That was in short the Information in that mail.
Seems like an Marketing mail for CEO's and Decision Makers to buy these Products. Nice to read. Thanks Steve.

 

the Email can be read online.
http://www.microsoft.com/mscorp/execmail/2006/11-30businessvalue.mspx

 

with no comments
Filed under: ,

We Installed an Local Team Foundation Server here to test some Stuff with It. Local means, that it runs under Local Accounts, but the Windows Server itself is in the Domain.

First of all, I wanted to say, that the Installation of It is really not easy. Before you install It, open the Help and use the Installation Guidelines step by step. you really need it.

 

The Symptom

While you are installing, you read more than once, that when you run that Stuff as a Local User, you have some limitations. But basically not, what limitations are there.
What you experience afterwards is, that you cannot add any Domain User to Groups, and Domain Users that are in Windows Groups cannot be resolved. so no Domain User can log on into the Team Foundation Server.

 

The Problem

So, the TFS runs under an Local User. thereof, the TFS cannot access the Active Directory of the Domain, and cannot do anything to Resolve an User. The User gets just a Message, that he is not allowed to access the TFS Server, or when you want to add an AD User, it throws an error that it cannot resolve the User.

 

The Structure of Identity in TFS

The TFS has a Mixed Identity Structure. It has its own Group/Group Member Structure in the Database. As a Group Member you can add Windows Users and Groups as well as other TFS groups. 

The Data is stored in the Tables
   TfsIntegration.dbo.tbl_gss_groups
   TfsIntegration.dbo.tbl_gss_group_membership

And has an pretty easy Structure. The group_membership is self explaining. It just uses the SID's of an Group and it's Member.
In the groups Table, the special_type tells the System more or less what the Group is about.
  0 = Default Group
  1 = Administrative Group (Server or Project)
  2 = Service Applications (the Identities under that TFS and its Tools runs)
  3 = Everyone Group. Here is only the Group for any User that has access to the System (Team Foundation Valid Users)
  4 = Licensees Group. dunno what this does.
The PID is the Project ID. If the Group does not belong to an Project, its 0

 

The commandline Tool "tfssecurity"

in the Tools Folder of the TFS (e.g. C:\Program Files\Microsoft Visual Studio 2005 Team Foundation Server\Tools) there's a Tool called TfsSecurity. With This, you get the detailed Messages, what Fails when you have an Error. Also this Tool gives you best possibilities to modify the Security directly. I really recommend that over direct modifying of the Tables.
To get the Info's of an specific User, just type
          tfssecurity /server:<servername> /imx <user>
the User can be either the Domain User "domain\username", the SID, or the LDAP path.
In our Case the Tool tells us in Detail, that it cannot resolve the Domain User. that happens because the TFS runs under a Local User that has no access to the Domain.

 

The TFS Webservices

TFS itself is not an Program that runs on that machine. Its an very intelligent Webservice and some SQL Tasks.
So it is pretty easy to manipulate the Stuff. And what we need to Solve our Problem is pretty easy. Another User that is allowed to look up in the AD.
That can be done thru the "TFS AppPool" in the IIS Application pools.
Change it to the Local System Account (it warns you about that, but click okay) and now you can add Domain Accounts.

The Drawback here is, that you cannot leave the AppPool with the System account. Basically you only need this for the "Services" Webservice and you can create another AppPool for the Rest, but you ran sometimes into Problems. and one of the not so nice features is, that you often don't get the right error Message. So I don't recommend to leave the AppPool with the Local System.

 

The Solution

There is a Possibility to use Domain Users in an Local TFS. The Problem in Authenticating is, that the Server cannot look up the User. But if the User is directly inside the Database Tables (group_member), the Server does not have to look up for the User and the Authentication succeed.
To test that, simply put an Domain User in the Membership Table of the Group "Team Foundation Administrators". Now, you can log on into the TFS Server.

 

Step By Step

But how to do that practically for a bunch of Users?
We combine both of the Ideas.

  1. Change the Identity of the AppPool to Local System (TFS AppPool)
  2. Open Visual Studio and Log into the TFS with an Admin Account.
  3. Create a new Group for your Users
  4. Add all Users that should have access to the Server (no Groups. only single Users, so they get looked up an cached)
  5. When finished, change the AppPool back to the Local User

The only drawback from this Solution is, that while you are adding Users, the TFS is practically useless. And also you have to add each new User manually. But for evaluation of an TFS this is pretty nice, since you can just do that on an Test Machine.

 

Links

Some links about TFS
MSDN TFS Documentation : http://msdn2.Microsoft.com/en-us/library/ms181232.aspx
Rob Caron's Blog : http://blogs.msdn.com/robcaron/
TeamFoundationServer.org : http://teamfoundationserver.org/web/default.aspx

Maybe Rob can tell us, why the team foundation server really needs an domain user, beside of lookup users.

 

with no comments
Filed under:

Yesterday I refactored one of our projects and needed to go thru many of the files. and as always, when I see some strange stuff, I cannot leave it and have to correct them (damn perfectionism). so here are the common strange stuff, that should have never made it into the code.
If you have questions to one or the other, just post a comment and I'll explain it a little bit deeper. I'm always happy about response.

 

Don’t access Indexer of Objects more often than needed.

These Indexers are the Request.Querystring[“blahblah”] stuff.
That rule is first of all depending, on what the Indexer does and how large the Collection is. Bigger Collection means longer time to find your entry. 
Basically when you access it in one code block more than 2 times, its better to create an local one.
Be aware, that this is some sort of caching (the value of the variable don't get updated), so its preferred to do this in local code blocks and not in classes with longer lifetime.

Benefits:
+ Faster : since indexers have to go thru the collection on every access.
+ Better Readable : there's less code, an local Variables describe the Data in it better (most times...).
+ Less errors : you can check once if the data in the local variable is okay. (ever saw Application.Items["blah"].ToString()? what's if this item is not present in the Collection?)
+ Threadsave : Your local value don't get changed in your codeblock.

 

Use string.IsNullOrEmpty and int.TryParse

These are one of the most often checks and you see the same checks in very different ways. It's not easy, when you get an Object, or access these Indexers, to verify that its filled and have the right Type.

Instead of:
        object myObj;
        int myInt = 0;
        try
        {
            myInt = int.Parse(myObj.ToString());

        } catch {}

use:
        object myObj;
        string myString = myObj as string;
        int myInt = 0;
        int.TryParse(myString, out myInt);

the Integer gets filled, if its possible or left Zero.

For the Strings there are many possible checks.
The best is
        string myString;
        if(!string.IsNullOrEmpty(myString))
            //do something when string is filled;

That's Equal to
        if(myString != null && myString.Length > 0)
            //do something when string is filled;

To verify the Length is the best possible Way, because here are no Memory comparing needed since there is no other String involved.

Use the using Statements

When you use namespaces more than once in an class, try to use the using statements. you can also assign it also to an Shortname (like using ctrl = System.Web.UI.WebControls).

+ Better namespace refactoring : we renamed some namespaces due to rebranding and it was a Pain in the Ass to merge the Stuff with other Branches because the changes of the others had the old Namespaces.
+ Better readability : due to less code. depends on the good chosen names of the classes
- Double chosen Class Names : some Classes have the same name, and so the vs does not know, what class to use, when both Namespaces are in the using Region

 

Don’t cast too often

First, don't use the "is" keyword when you cast it afterwards.

        object myObj;
        string myString;
        if (myObj is string)
            myString = myObj as string; // same as myString  = (string)myObj

Here the Framework has to make the casting 2 times. once for the is, and once for the real Conversion. Better do it directly and verify if it's not null. (only possible with reference Types).

        object myObj;
        string myString = myObj as string;
        if (myString != null)
            //do stuff

Also, when you know that there is an specific Type in an Collection, cast it directly. I often see that with Integers in an object Collection. Its pretty the same code like the one I used to show int.TryParse().

Flatten Conditional

Like suggested in the Framework Design Guidelines, this make the code much easier to read and complex Code easier to understand.
Basically, it says, don't use too much nested if's.
Instead of
        if (true)
        {
            foreach (object var in collection_to_loop)
            {
                if (true)
                {
                    //do something
                }
            }
        }

Use
        if (false)
            return;

        foreach (object var in collection_to_loop)
        {
            if (false)
                continue;

            //do something
        }

 

Don't Log exceptions twice

This is not an Rule for every Project. At my current Project we are the only one who uses it, and have done a pretty nice logging Structure. But as I read the logs, I often see the same Messages multiple Times with different Information. That's hard to get the complete overview of what happened. So, when you are returning an Exception, don't log it also. but fill the Exception with as much Information as possible.

 

Use The Comment Task List feature

In Visual Studio there is a pretty cool Feature, that if you start a Comment with "//TODO:", a Pointer to that Line is added in the Error List Messages on compile Time. So you can find easily Tasks that you have just defined in the Code itself.
I would suggest, that if you have a bigger Team, also add your Name in the Comment, so everyone knows who created that. You can also add more Tokens that the vs should watch for (Tools->Options->Environment->Task List).

Make Shared Code

If you feel, that you write the same Code over and over (like converting an Object from an ObjectCollection to a Type and verify, if it contains Data), make a shared Method out of it. normally its easy to find an good place. if not, I would suggest to make an "I dunno where to put that" Namespace (often like Utils.Misc or so) and give It there a good description. You can refactor that with someone else later.

 

Stick to your Architecture

When you defined, that you want to use an 3-tier Architecture, then do that so. As longer a Project exists, as more Violations of such Stuff are done. If you are really in that hurry that you cannot stick to your Architecture (I think that's never the case...) than mark that Code as an Task for refactoring with an todo Comment.

 

so, that's pretty all for now. I know, there are many more tips out there. but no time to write them all.

 

with 3 comment(s)
Filed under:

There it is. I Shout it out. Now we really started working on the long awaiting next release.

What is RoyalTS?

For those, who doesn't know it. RoyalTS is an manager for Remote Desktop connection. in the current version only supporting the RDP protocol. completely coded in C# and open source.

What are the features for the next Release?

The next release is completely done from scratch. so there is plenty of work to do. here are the main features we plan currently:

  • Nested folder Hierarchy : the folder structure is complete up to you
  • More Protocols : so you are not limited to administer only windows machines any more
  • Plugin interface : you can write your own protocol implementation and integrate it. we also plan to have something like a "verified Plugin list" so you don't get some suspicious plugins
  • Keychain : credential management. secured/encrypted with your local user. none other can use your stored passwords
  • XML file Format : all configurations are written in XML. edit as you like.
  • Tasks : simple commandline tasks you can execute for one or more machines. pretty like in MoM
  • Pre Connect requirements : e.g. dial VPN before connect.

This is our Main Feature List, that you all can expect in the final version.

There are many, many more ideas on our wishlist. depending on time and complexity of each, we'll implement them sooner or later.


The Team

Basically all of the code4ward members are working on this Project.
7 People that meet each month and review the Process. so we think we are pretty sure to have a consequent proceeding in finishing the program.

I also want to say, that I'm really glad to be in that project and that its a great team. nevertheless, this is an fun project, and so we don't have the time that companies have for their projects.

When do I get my Hands on the next Release? what is the current Status?

We delayed the Timeline definition to our next meeting. since there were some more prototyping and evaluation in specific parts needed.
But, we have some of the program already coded and currently working on the basics. Architectural stuff and what you always need. (file handling and so on).

Currently the next planned release is Alpha.
This should be something like the version 1 redone with the architecture of 2 but missing the most of the features. so you can start using this version, but don't have real enhancements there. like the RDP Plugin will be directly in the core assemblies and no public Plugin interface. I really would like to have it done till the end of the year, but it seems to be January, when we can release it.
An more detailed Roadmap will be available after the next meeting.


What happened with 1.5?

That release is dropped. we tried to implement some of the really needed stuff that can also be reused with the v2 version branch, but there were too much incompatibilities, so we directly started with v2 and added this "alpha" release, that should be something like the 1.5 with a cool new base.

How can I Contribute? What's with my Ideas?

First of all, many of the Ideas come from people that are using it. Thanks for all of your suggestions. They are great.

If you have more, I would first suggest, posting them to our code4ward Forums. here we can keep track on all the wishes.

The Project itself is Hosted on .
there you see directly how the process is ongoing.

If you want to contribute to the project or have an direct talk, the best thing is to write it into our forums and we'll contact you.

What's Next?

We'll keep working on it. I try to post about the status about every month. or when we do some cool features explain them directly here (maybe after the alpha release)

 

Special Thanks to Stefan, for the Guidance of our Team and the Project.

p.s: we know, what the codename means, and choose it because of that... this is a big, big release...

with no comments
Filed under:

So, time has come, that I also post my A-list.
I just put them together because some of my colleagues wanted to have an starter list. overall I subscribed now to more than 200 feeds.

 

First of all, we have some linklisters. They post only links to other feeds.
Jason Haley  is really an essential information. think at least 1/4rd of my feeds are subscribed after one of his posts

A Continuous Learner's Weblog has also an good linklist.

Software designers

These people post about how to make better software most of the time.
So most posts are not directly code, but helps you with your PC time.

Scott Hanselman  Definitive one of the best sources for developers. His tool lists are the best out there.

ScottGu's Blog Always good tips for .net developers. great code.

Sam Gentile  Also a good read. Like all of the codebetter.com guys. If you want to search for more, go to their startpage and look at the blogs of the others.

James Shore Successful Software Often criticized and sometimes different to what all others are thinking, but often really good articles.

Newsfeeds

Neowin.net  Everyone should know Neowin… they have also 2 other feeds (software & games). always great news source

Engadget Much to read, but their content is so good written.

Videos

Channel 9: The Videos The MS videos from inside. Always very interesting, if you have time to watch. I know there's also on10.net and others. but I like more the really technical videos.

There are also pretty good MS automatic feeds out there. I subscribed to all .net 2.0 kb articles that comes out. But they are most times not interesting.

Geek Stuff

Solution Watch Presents new companies with new ideas. so web 2.0 stuff

TechCrunch The best web company review page out there. With more than 120k subscribers

Website Updates

What's new for Writer Plugin rss feed for Windows Live Writer plugins

CodeProject c# Everyone knows codeproject. Always an good source. But be aware, when you use code, check their license.

Dotnet & co

Programmer feeds

Coding Horror Has deactivated his images in feeds... , but has good content

If broken it is, fix it you should Tess makes debugging at Microsoft. Best articles for hardcore memory debugging

Dotnet BCL team Team blog of the BCL team (the core language team) always good tips for performance

Chris Donnan : Programming - Brooklyn Style I really like his articles. But they are most times not really .net related

Rico Mariani's Performance Tidbits One of the best .net performance blogs. And always has also the explanation why it is so

.NET slave Much code. Most times not the best solution, but always nice solutions for common problems

Greg Young Another codebetter guy. I like his Contests.

Infinities Loop Asp.net stuff. Reveals some of the mystic behind .net

Nicholas Allen's Indigo Blog Always good to keep up to date what's with indigo (wcf). But hardcore code, if you are not familiar with the framework

Signs on the Sand XML Stuff

Clemens Vasters: Enterprise Development and Alien Abductions Most about the WinFx.

K. Scott Allen Odd To Code. Good code examples

Oliver Sturm's weblog Also good content for .net. his electric editing visual studio plugin is a must. one of the developers at DevExpress (I love your tools)

Smart Software Nice info about software development

Rick Strahl's Weblog Another blog with much code

MS Business

Blogs that blog about business stuff, mostly Microsoft.

Ray Ozzie The Technology chief himself. would be nice, to have more posts from him.

Mini-Microsoft Some anti Microsoft thoughts from one inside. Sometimes a little crazy stuff and pessimistic.

Scobleizer The guy who created channel9. But has left Microsoft. Blogs a little bit too often. Had better times… :-)

msgoodies Always nice info about MS.

The Old New Thing The guy, that really knows, why something was done this way. Also wants 100% backcompatibility (maybe you got some of the discussions about that….)

BlueScreenOfDeath's Blog Hmm.. always nice beta info. But site seems to be offline… bad…

Microsoft team blogs

Jensen Harris: An Office User Interface Blog The definite office07 info blog

Microsoft Research Downloads All new downloads from MS Research. Every time cool tools

live.com blog What goes on at Live.com

Microsoft Research Publications All Publications. Sometimes hard to read, but as always good ideas.

MrDave's (David Yack) Blog! Team Foundation server guy. Many useful things about it.

Mobile

MobileCrunch All about new companies dedicated to mobile. part of TechCrunch

UberPhones Every new handset is listed here… was long time a fan of MobileMentalism. but since they don't send their pictures any more to feed readers...

W3C Mobile Web Best Practices Working Group Best practices for mobiles. Just released as a draft, so always good to have more info's.

bluepulseblog About the platform bluepulse. Program once, run on many handset. That’s their idea. Have also posts about general mobile topics.

Other Feeds

10,000 Monkeys - Harnessing The Power of Typing Monkeys I like his posts. Sometimes crazy.

Russell Beattie Notebook Very sad, that he stopped posting. Was a very good blog. (not included in the list)

Attached I have 2 feed lists. the small and the big one. also at the small one, there are some that are not mentioned here...

 Hope you enjoy the list.

 

Update:

Heh, forgotten to add the opml feeds....

Short OPML feed

Complete OPML feed
Also Accessable thru my opml.org page

 

Technorati tags: , , , ,
with 4 comment(s)
Filed under:

 

Is it so hard, to make rss readers?
I cannot find any reader, that has all my features implemented. most of them lacks of some of the "core" features.

What I really need is:

1) river of news (oldest first optional)

2) good reading pane, fast display of posts

3) folder with options (mark all read,....)

4) and direct tagging of feeds and posts

5) searching in tagged stuff.

6) rating of feeds with more than just a checkbox

 

and the most readers fail on the last 2. some also on point 3.

none implement point 6.

Currently I'm using . its pretty cool done. good interface (3pane) and has tagging for posts, smart feeds (posts by keyword. also an cool feature). missing only the 6th feature. browser based.

wanted to try . since it has also pretty much of my points. but the UI has really some bugs, where you cannot read posts... bad....

the third, that I really hope that they implement the direct tagging support is . that is a Mozilla based browser with social additions. and there all of the favorites can be stored in . also the rss posts and therefore tagged. the only bad thing is, that you have to open after "starring" to the fav folder and add the feeds. no direct access.

I', pretty near of making my own rss reader. but I cannot even use an good web rss reader as my store, since they don't have enough features there. maybe using an normal web based rss reader as store and using del.icio.us as my fav store. huh. that will be much work.

 

with 3 comment(s)
Filed under:

Hey,

im sitting here at the basta. its halftime.

The Basta Conference 2006 in Mainz is a german speaking 4 day event for .net and Visual studio. with pretty interessting speakers like Dino Esposito or Jason Zander.

As the keynote we heared from Jason many things about, what comes in the next time from Microsoft. so an overview of .net 3.0 and the Atlas and so on. a good overview and introducing in all the stuff and why it was done.
and... he showed us a really cool demo. as allways with the coolest features you can have currently.
it was an calcuclator, that he programmed from the IronPython console. thats something i also use for my next presentation...

The first Session was about Team System. and all about the features it has. pretty cool. will save some of my work i think. will start using it right after i come back. currently the most of them i cover with other products. but let´s give the "fully intregrated" once an try...

Then we met some really cool guys (Mark Miller and Oliver Sturm) from DevExpress and talked about some nice additions to their Refactor! it and dxCore product. and they are really smart, because they dont put them on their wish list, they even IMPLEMENTED this directly while we stand next to them in a simple version into their Visual studio AddIn. isn't that a cool feature. now i not only have my additions, i also know how to add one of them, if i want one. thank you.

Next, i got some introducing about MDA, a Model Driven Architecture. cool idea and stuff here. good to know that stuff. I'll implement that in one of my later projects.

After the Lunch, we talked with some guys about testing. specially speed tests. there are some guys of "Speed Test Pro". that looks really cool. nice featureset, really easy implementation, good reports. they bring a new version the next weeks. looking foreward for that. (with the new version, the trace file is written directly to disk. not to the memory...)

After a little bit sitting in the sun, we looked foreward for dino's session. That was really cool. He really give us the feeling, how it is to program with Ajax. a great Speaker. and was very interresting.
The coolest feature i see in Atlas?
That you have clientside also an DataSource (like the DataSet) and the Visualization can have Filters like the Dataview and is automatically updated, when you add, remove, change something in the source. isn't that a cool feature?
i just start programming now...

So, a short wrapup?
Nothing of "Cool new stuff, that you comes in a year"
All Sessions are to start programming now. (.net 3.0, team system, Atlas, Ajax, SOA)
nearly no Vista (just jason has it on his machine and it had an black screen once^^)
Many SOA solutions
Much stuff for managing your live nebst programming. but no standard there.
Really nice people to talk with.
Great food.
The Wlan connection is not the best here (seems they run out of ip adresses in their pool)
Bad, i missed the session about .net on the xBox

 So, thats all for now. i write the second part on thursday, after the conference.
If you have questions, want more infos an a specific part or session just ask me.

Brenton House posted about an Interesting Interview Question.

its  pretty easy.

selected = selected++;

what comes out?

 

on the first view, you would say something+1. but that's not right.

The most people use this with some while stuff.

int something = 0; while(something < 10) { //do something something++; }

here it is easy. it'll do the while 10 times.

But the base idea is a little bit different. this is done that you don't need to write an extra line for the counter.

int something = 0; while(something++ <= 10) { //do something }

so. the something is automatically incremented with the ++. no need for an extra line....
but, does this now 10 iterations or 11? what is returned in the 10th iteration?

The answer is, there are 2 of this ++ features you can use.

// returns something and increment something afterwards something++; // increment something bevore, and the returns the result ++something;

so. now it is clear. there would be 11 iterations, because at the 10th, 10 is returned, and 11 is stored afterwards.

and that's exactly what happens in the question.

selected = selected++;

here, at the right side, selected is returned, and then incremented. and after that, selected is stored on the left side. so the answer is, the original value is stored. not the incremented.

selected = ++selected;

Here, it would happen what you normally expect. the incremented value would be stored.

little tricky, hah?

with 1 comment(s)
Filed under:

eh, oh. someone who uses anonymous methods? aren't they so bad? why should someone use them?

here, I cry it out. I LOVE them. they are great.

first, what are these Anonymous Methods?
Anonymous Method is a new feature of the .net 2.0. with them, you can create an inline method, without having to name them. here's an short example:

 

// Create a handler for a click event
button1.Click += delegate(System.Object o, System.EventArgs e)
{ System.Windows.Forms.MessageBox.Show(
"Click!"); };

So, seems to be easy. but why most people say, they are bad is, because the usability of code drops. these Methods are not listed anywhere nor can be reused. so it seems they are just for the guys, that program "quick and dirty"

BUT, they have one feature, that makes them really cool and useful in some conditions. and this feature is also one of the things, you really should be aware of, if you using them.
These methods are sharing the context of the Hosting Method. yes. you can access any of the private variables of the method where you created it.

Hmm.. sounds a little crappy.
Where to benefit from it?
Let me show you an example of the most common once.
We want to use any feature and improvement of .net 2.0. so we use a generic Collection for our items.

 

public class MyListSearcher {
private List<string> myList = new List<string>();

public MyListSearcher() {
myList.Add(
"foo");
myList.Add(
"bar");
}

}

Now, we want to make a public function, that has an char as Parameter and returns the first entry, where the char is contained. if none, it returns string.Empty. oh, yea. this is easy. lets make an foreach...
NO. the List have some pretty cool functions, that are much faster than an foreach. like the List.Find method.

 

public string GetStringContainingChar(char c)
{
return myList.Find(new Predicate<string>(???));
}

This method accepts an Delegate, that is called for every item in the List, until it returns true, then this Item is returned.  beside of making the process faster, its also much cleaner to read the code.

The easiest would be, making a new Method and store the character in the current class, so the Method can access it, and use it.

 

private char savedChar;

public string GetStringContainingChar(char c) {
savedChar
= c;
return myList.Find(new Predicate<string>(stringContainsChar));
}

private bool stringContainsChar(string s) {
return (s.IndexOf(savedChar) != -1);
}

That's working. and enough for a single thread. but what, if there can be multiple calls at the same time? then this solution does not fit anymore. the easiest workaround is, create a short class, that holds you your value.

 

public string GetStringContainingChar(char c) {
SearchHelper helper
= new SearchHelper(c);
return myList.Find(new Predicate<string>(helper.StringContainsChar));
}

private class SearchHelper
{
private char c;

public SearchHelper(char c)
{
this.c = c;
}

public bool StringContainsChar(string s)
{
return (s.IndexOf(c) != -1);
}
}

Now, this is also Multithreading save. the implementing Method is pretty short. but we have such damn Helpers, that noone likes. let's see, how we can get rid of this all with an Anonymous Method.

 

public string GetStringContainingChar(char c) {
// using Anonymous Method
return myList.Find(delegate(string s) {
return (s.IndexOf(c) != -1);
});
}

Is that short. The delegate can use all private variables of the hosting Method. so also its Parameters (but no out or ref parameters). I prefer always to make a comment before, so when someone comes thru it, he knows, what is used here (there are not much people outside using this). there is no faster and shorter solution than this.

What to think of:
These Anonymous Methods share the context. so the context has to be alive as long as the Method is referenced. so if you add an Method for example to an Event of classB, then your Method and class is in memory until classB drops out. could be a possible memory problem

You have to think of as if the Method itself is the hosting class for the Delegate. and if you are modifying variables of the Method, you can run into an Multithreading problem again, if the delegate is called parallel. here's a demo:

internal static class staticTest {
public delegate void TestDelegate(string text);

public static TestDelegate Tester;

public static void InitTest() {
int count = 0;
string myString = "init";

Tester
= delegate(string text) {
Write(
string.Format("Bevore: int {0}: string {1}", count, myString));
count
++;
myString
= text;
Write(
string.Format("After: int {0}: string {1}", count, myString));
};

}

public static void RunTest() {

InitTest();
Write(
"Test Initiated");
Tester(
"test one");
Tester(
"test two");
}

}

so, on every call of the Tester delegate, the count is risen and the text is changed. the output is like

Test Initiated

Bevore: int 0: string init
After: int 1: string test one

Bevore: int 1: string test one
After: int 2: string test two

 

So, we see, there are really some useful stuff, what you can do with these. if you have some other ideas, where they would be great, let me know, and i post them here.

 

Some Q&A

Why is this working in Multithreading, when i reuse the class instance? isn't that then the same context?
No, the context of the Method itself is different on every call. just the context of the class is the same. so the Parameter c is not shared.

 

Update: added my demo project 

Just read the post from Karl Seguin, that he now starts to learn TDD.

That’s an task, that I cannot follow. TDD is nothing you have to learn long time… neither it is a big change to your Development Process.

These post will describe, how to easy start with TDD, without the heavy stuff of all that “be agile, do your tests for everything”,.. and so on. If you are new to that, you don’t need to jump in the middle of the hot soup. Start slurping from the colder side…if you just want an short summary, read the conclusio at the bottom.

Test Driven Development just means, that you write test first, program later.

But this is done, when you write a single test, that just checks for example that the Response of your command line program is 0 (so executed with no error). Yep. Maybe that is nothing that helps you that much, or test the real important stuff of your program. But that’s basically an TDD.

So, why is everyone speaking of extensive unit tests and TDD?

Yep, nearly everywhere where you read about unit testing is speaking of TDD and write an unit test for all things you have. And this is also TDD, if you write this before. But its an more extended version. I speak in that case of Extensive Whitebox testing (EWT) e.g. TDEWT (test driven EWT, Since you can also write the tests afterwards).

White Box & Black Box testing

these differences are easy. Black box testing is, when you treat your Program as an Black (unknown) box, and make the tests as you were an normal user of your product (clicking thru the website, testing your Webservice, running your program). White box testing is, if you need to know your class structure to do the tests. (testing one of your components, mock up objects and so on). You can also treat it as Blackbox testing if you just testing the public API of your Component.

There’s a really nice Post about Black and White Boxes from Tyner BlainSoftware Testing Series: Black Box vs White Box Testing

How easy is it to start TDD?

so, you’re new to TDD, and someone say, you should/have/want to do it. How to start?

That’s really easy. For someone new to TDD and with their own Project (if your project already have some unit tests, you should maybe go on with them…) I would recommend to make some Black Box testing. Since they are much easier (most times e.g. in the beginning) and also more useful for the short time. To write good Unit tests, you need some experience writing them. Else you have to change them too often, since your test context has changed (added some parameters etc…) The first of these is simply, if it’s working (e.g. if your program starts, if it execute without error, if you can request your webpage without error,..) There are also some frameworks outside for these testing’s. And when you write such an test, before you write your program, it’s already TDD. If you just develop an component for your company, you can also start with make one test, that test the main process of that. It’s pretty the same.

That’s all?

eh, no. not really. You cannot ran now to your chef and say “We now implemented the latest trend and have changed our Development Process to TDD”. This is just the first step to start, and the basic thinking of TDD. Test first, develop later. That you stay just with one test, that make just the easiest test is allowed, but not the way it will be usefull to your development. and this is what we want to get from that. Not just that we can say, we have that.

What’s next?

Write more tests. I prefer much more that you think of, what is your important part and start there making blackbox tests, and not come from the other side. Especially when you implement that in an existing environment (so no TDD). Get slowly into Unit testing, think of useful abstraction, and definition of your components to the tests, and that all API’s could be changed in the future.

But all say, we need 100% Code coverage. This is far away from that…

the nearly 100% coverage is an double bladed knife. Yep, if you make some mistakes in implementing changes, you’ll get an error right after you tested it. But nearly all wanted changes you do, needs also changes in the unit tests. And that takes time.

I recently read some statistics about companies, implementing an nearly 100% code coverage, and they have 60% of their code written in unit tests and use nearly the half of the time implementing and maintain that.

I know, that there can be business critical applications, that are not allowed to fail anywhere. So here I see the request for 100% coverage. But for the normal program, or for an team that is just starting with TDD, I don’t think, that this is feasible. You put so much work in there, with not that much reward. It’s much more useful to write tests, that check your primary business and go deeper and deeper with time. So you have a pretty fast reward on small work for your testing. No one would start with making an Picasso at the first try. You start with some easy painting and learning.

Conclusio

Start with one test after the other. Think of what will be useful and your most important test (most time Blackbox testing). There’s no need to have an extreme high code coverage in the first implementation. The important part is, that it helps you fast, and identifying some big mistakes fast, and not when you tell your test team to make an “full tested ok”-test

A note to the geeks

“yey, what the hell you writing here? You are so an idiot”. Okay, maybe I’ll exaggerate that. But I’ll know, some of you thinking that is bullshit. But see it from the small guy. Some of your managers telling you “hey, the geeks say, use TDD. So do that now.”. or you heard about it yourself and want to implement it for the next projects. The most times in the normal programmer live there is no place to make from one day to the other 50% of the time unit tests (and definitely more time in the beginning when you learn it). Give them an easy, fast start in doing so, and the acceptance of it will be much faster and wider. I Appreciate critics, and will answer them. Or maybe write an followup.

p.s: this post is published with Word 2007. pretty cool

with 1 comment(s)
Filed under:

Wohoo...

The ultimative Football Screen for Geeks. watch the WM in an ASCII Stream.

just type in your command window "telnet diego.ascii-wm.net 2006" and press enter.

Freaking cool stuff. if you want to know more about that austrian students project, go to their website at www.ascii-wm.net


                                   _ajjaa                           
                                  _Q???4Qf                          
               _,...,_            ) a/]QQb                          
             .'@/~~~\@'.              jQQba                         
            //~~\___/~~\\          _, .?QQ#[ _                      
           |@\__/@@@\__/@|         ]m _.7   "asLaas_a/              
           |@/  \@@@/  \@|        , ,\J#L -!4Wba                    
           \\__/~~~\__//       [aL[    \    \jmm     jP             
             '.@\___/@.'  ,b#'"[     \jmmmmm    _P.              
               `"""""`        a##'      "4P#mmm#   _ya              
                             _P          !4####m  ?]aa/             
                            /'        aaJ#U###m#   4QP'             
                           '         aa,/4!44! '                    
                       jf         _'jQQQQyb7b /                     
                       '.         '.QQQQ4QQPb  )?                   
                                    QQQ'QQP?'  jg/ f                
                                  _yQP']QQb aa                      
                                a#W?'..QQQQ?)?   ?'                 
                               "##'  _jQQP'                         
                              .j?  [ jQQ'                           
                         aJ  jmaaX#L???                             
                         ? am'                                      
                       _QjQQQ/                                      
                       )QQQP?                                       
                        4QQQ/                                        

 

so, whats WMIC?
I think you know about WMI. the Windows Management Instrumentation is an System from Windows, where you can access the most of the properties of windows.
And WMIC? thats an Command line utility that comes with windows XP and up to query this stuff.

It's pretty amazing, how they managed to port code that needs plenty of lines in vbscript or c# into one line. cool.
I tried that tool for my IIS helper. did'nt work , but find some nice references about that tool.

First, try c:\> WMIC /?
here, you find a list of all commands.

a little bit more explained in the MSDN Documentation
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/setting_namespace_security_with_the_wmi_control.asp

If you have some time, watch the webcast about that tool
http://support.microsoft.com/servicedesks/webcasts/en/wc072402/wct072402.asp

Also theres a cool list of examples at Handler's Diary
http://isc.sans.org/diary.php?storyid=1229&rss


Thats pretty all of what you need to start. if you need help about how to configure security, remote machine and so on, refer to WMI.

and you want to know, what i tried?
C:\>wmic /TRACE:ON /NAMESPACE:\\root\MicrosoftIISv2 PATH IIsApplicationPool CALL Recycle
This should cycle thru all of the appPools and Recycle them. but it don't work. allways comes with an "The parameters provided for the method are not valid.". and i dunno why. so lets try other things.

with no comments
Filed under:

seems they have some problems. 

go, check der funny messages they posted for the downtime.

added an screenshot of the current page.

Update: is up again. currently no blog entry, what it was... :-(

Jon Galloway posted, that you should avoid using the iisreset since it does a complete restart of the iis.

i agree with him, also have some more points

  • it takes all sites offline for a short time
  • it takes very long sometimes
  • it devalidates the complete cache (on some changes its just nice to have the cached stuff from bevore)
  • it detaches the debuggers
  • it forces a recompile for the most dll in the web app.

I know, sometimes its needed. since you want a "clean" start of the app, or you have some strange stuff going on. but most times, its not needed.

so, we want a fast and easy way to do that.

If you ever look into the api of iis, you'll propably find 3 types.

  1. do the iisreset. sometimes you need it
  2. do an asp Reload
  3. Unload the App Pools (on win2k3)

the first is clear. run iisreset.exe.
The second one is the same as touching the we.config or global.asax. the FileWatcher there sets a flag in the iis, that on next request, it shuts the app down and starts it again. why not set the flag yourself?
The third one is just to unload the app pools from the ram. so they get startet again.

The Tool:

This is a simple .net 2.0 tool that i done for my division. i removed all extra features, so it just have the iis tools in it and some not needed code. it also has in my test version the possibility to do that remote. but have some bugs in it.
Also this tool is for win2k3. the app pool command will fail with an error message at winxp or 2k. and it needs .net 2.0. the app also works at vista, when you install the iis6 comptibility stuff.

The Features:
you get an small icon in the taskbar. right click on it, you have the 3 commands to execute.
after it has completed the command, it shows you the result. (e.g. how much app pools it unloaded. so you see, if it failed)

  • Reset IIS: does the iisreset exe thingie.
    • the Good:
      • does really restart the iis. so all is clean afterwards
    • the Bad:
      • as listed up there, many things
  • Unload AppPools: goes thru all the app pools and unloads them
    • the Good:
      • really unloads the App pools from memory. so also the inproc cache is cleared
    • the Bad:
      • takes sometimes long (specially when your code is waiting for timeouts)
      • clear the inproc cache
      • works always (except when the iis stops responding^^)
      • forces a recompile and reload of the dll's
  • Force IIS Asp Reload: Sets the flag, that you can also do by touching the web.config
    • the Good:
      • freaking fast (since just making an flag)
      • the dll's keep loaded in memory
      • the cache stays the same
      • keeps debugger attached (so you can also catch the appStart events) (yeh, somtimes it looses them, but thats seldom)
    • the Bad:
      • the action is done on next request. (not really bad, but you should know that. e.g. the appShutdown events are then fired)
      • the cache stays the same
      • wrong loaded stuff in cache, dll, ... are staying

now, its much easier for me to do that stuff. have some ideas for extension. if you also have some, just post them.
Also, this is really just an "because its actual" post of the tool. not a real version that should be wide distributed.

Hope that helps you.

with 1 comment(s)
Filed under: ,
More Posts Next page »