DCSIMG

 Subscribe in a reader

November 2008 - Posts - Guy kolbis

November 2008 - Posts

Google Maps offers a satellite view or a street-level view of tons of locations around the world. You can look up landmarks like the Pyramids of Egypt or the Great Wall of China, as well as more personal places, like your ex’s house.

However, for all of the places that Google Maps allows you to see, there are some that are off-limits, actually there are 51 "Prohibited" places.

Check out the list here.

I really enjoy reading point 23:

"Iran: Late in 2007, an Iranian businessman tried to download Google Earth and got a message that said, "Thanks for your interest, but the product that you're trying to download is not available in your country."

Cool!

kick it on DotNetKicks.com

Intro

So, the idea behind this post is to show you guys, how to disable the click event of a .NET button, but first thing first and lets start with a little review of the Control class.

Every Button in .NET eventually inherits from a base class Control. The Control class has a virtual method defined:

protected virtual void WndProc(ref Message m);
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

This method is basically a the location we hook up to windows notifications. There are a lot of types for window notifications, for example:

  • WM_SIZING - The WM_SIZING message is sent to a window that the user is resizing. By processing this message, an application can monitor the size and position of the drag rectangle and, if needed, change its size or position.
  • WM_MOVE - The WM_MOVE message is sent after a window has been moved.
  • WM_CLOSE - The WM_CLOSE message is sent as a signal that a window or an application should terminate.

You can find the complete list of notification here.

The Message Struct

All the notifications are received in the WndProc method using a message struct:

 
    public struct Message
    {
        public static bool operator !=(Message a, Message b);
        public static bool operator ==(Message a, Message b);
        public IntPtr HWnd { get; set; }
        public IntPtr LParam { get; set; }
        public int Msg { get; set; }
        public IntPtr WParam { get; set; }
        public static Message Create(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam);
        public override bool Equals(object o);
        public override int GetHashCode();
 
        public object GetLParam(Type cls);
        public override string ToString();
    } 

One important thing to notice is the :

public int Msg { get; set; }
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

This is id number of the message (notification). So basically when we get a new message we can investigate the Msg and understand what type of notification it is. Every notification can be converted to int, thus we can compare the Msg with a notification and add or replace the default behavior for a given notification. Later on in our example we will replace the default click event...

Lets take a look at the Control's WndProc implementation:

protected virtual void WndProc(ref Message m)
{
    if ((this.controlStyle & ControlStyles.EnableNotifyMessage) == ControlStyles.EnableNotifyMessage)
    {
        this.OnNotifyMessage(m);
    }
    switch (m.Msg)
    {
        case 1:
            this.WmCreate(ref m);
            return;
 
        case 2:
            this.WmDestroy(ref m);
            return;
 
        case 3:
            this.WmMove(ref m);
            return;
 
        case 7:
            this.WmSetFocus(ref m);
            return;
 
        case 8:
            this.WmKillFocus(ref m);
            return;
 
        case 15:
            if (!this.GetStyle(ControlStyles.UserPaint))
            {
                this.DefWndProc(ref m);
                return;
            }
            this.WmPaint(ref m);
            return;
 
            }
       //And so on....
    }
}
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

As you can see, the WndProc method is build on a long switch statement, where on each case there is a different handler.

Disable The Left Click Event

In order to do that we need to follow this steps:

  1. Create a class that inherits from button control.
  2. Override the WndProc method.
  3. Check if the notifucation we get within the message is the user clicked event and if so ignore this message.

Simple, right?

One thing that we must first know is the message id for left mouse click:

public const int WM_LBUTTONDOWN = 0x0201;

Now, lets see the entire class:

public class IgnoreClickButton : Button
{
    public const int WM_LBUTTONDOWN = 0x0201;
 
    public IgnoreClickButton()
    {
        
    }
 
    protected override void WndProc(ref Message m)
    {
        if (m.Msg == (int)WM_LBUTTONDOWN)
        {
            return;
        }
 
        base.WndProc(ref m);
    }
}

That is it. Now, every time that a left click occur, we will ignore it. Cool, ahhh?

 

On my previous post I have asked a question:

"Would you test a private method?"

I got a good response from Chad Myers and would like to share it with you all:

"Microsoft's opinion is in favor of testing private methods. In fact, they seem to encourage it with Private Accessors and various How To articles on MSDN.

I wouldn't say that this is just my opinion (not to test private methods), it is generally a common-held opinion in the unit testing and, specifically, TDD circles. I won't take credit for this thought, but I will say that I do hold this opinion (e.g "Do not test private methods").

I have written several large-scale enterprise apps and have not ever needed to test a private method.  I'm saying this to brag or anything, I'm saying it to prove a point that it IS possible and SHOULD be a virtue worth striving for.

Having said all this, I am not prepared to say that testing private methods is ALWAYS wrong, but it's "ALMOST ALWAYS" wrong. There may be a few circumstances where it is beneficial or worth the risk of brittle tests to do this.

This is why I called it a code "stench".  It's worse than a smell, but it's not universally BAD."

Now, about internal methods he said:

"I feel mostly the same about this one, but it's not quite as dangerous as private methods, so I would tone down a the warning a little.  Generally, I manage to find a way to not have any internal methods also.

Internal methods usually denote direct coupling between concrete classes versus coupling through abstractions (public interfaces).  This creates a more brittle framework and prevents client code from overriding functionality if it needs to.

By using the Dependency Inversion Principle and Interface Segregation Principle, along with an IoC container, I seem to never need the 'internal' keyword and very rarely need the 'private' keyword, let alone tests for the same."

Thanks you Chad Myers.

You can read his post the responses here.

My Opinion

I tend to accept Chad Myers opinion, however I do not agree with the statement:

"Do not test private methods".

I think you should try to avoid testing them, but there are cases that you just have no choice (I have proven it to myself... :)).

Try This...

As a practice, try when you design your code, to set the all methods as public. If you feel you need a private method, try and redesign your code to use another class that exposes that method as public.

You should see that most of the time it is possible however there are cases where you will use private methods.

kick it on DotNetKicks.com

The Problem

We use TFS as an ALM tool in order to manage the entire development cycle.

So far simple enough. The problem occurred wen I tried to attach a file to the work item. Here is what I got:

image

The Solution

Go to the TFS Server.

Open the Internet Explorer, type the following address:

http://<tfsserver>:8080/WorkItemTracking/v1.0/ConfigurationSettingsService.asmx?op=SetMaxAttachmentSize

where <tfsserver> represents the name of the Team Foundation Server.

This web service will enable us to change the limit of the file that we attach to a work item.

1

Enter the maximum attachment size in bytes, and then click Invoke.

NOTE: The maximum attachment size is 2 gigabytes:

2 

 

That is it, I hope it helps.

I have read a really good white paper from Microsoft that talks about Requirements Management using VSTS. I encourage you all to read it:

Requirements Management with Visual Studio Team System White Paper

image

Why should you read it?

I will give you five (good) reasons to read it:

  1. It is only 30 pages with a lot of pictures.
  2. You will understand what a requirement is.
  3. You will understand requirements life cycle.
  4. The roadmap of requirement lifecycle in future versions of TFS.
  5. Some tips & tricks.
kick it on DotNetKicks.com

After reading Chad Myers post on Do not test private methods, I started thinking...

I have always tested private, internal and public methods using one of the unit testing frameworks: NUnit, MBUnit, .NET Unit Testing Framework and others. Was I wrong?

What do you think?

Some Background...

I have a customer that uses Microsoft Load Test and Web Test tools in order to validate the performance for his web application. Web Tests and Load Tests get executed against each and every new build. A new build is published to a the web server (either an IIS or Tomcat) under the application name + the build number, for example:

"rcm41020"

So, the application name is rcm and the build is 41020.

The Problem

For each web test that we execute we need to change in the URL the application name:

image

in this screen shot I have marked the name of the application that we need to change.

Now, consider that we must replace the name of the application on each web test. Unfortunately, we do not have a tool that can help us do that and we have to go through all the web test manually and change it.

The Manual Solution

Ok, so I accepted the fact that I need to use a manual operations to complete the change. Still I would like to share with you my solution that might save you some time and anger...

1. Add a context parameter to you web test and name it ApplicationName. Set the name you want in the property grid, for example:

image

2. Open the web test with an XML editor:

3

3. Use the Find & Replace to replace all the privious application name with the context parameter you have added, such as ApplicationName. Please note that in order to bind to the context parameter, you need to add {{ApplicationName}}.

4

4. Open the design view and verify that you can now see the updated web test:

image 

That is it. Hope this helps!

Question: would you like to see an add-in that helps you with that?

Earlier this year, Microsoft announced that it would make the .NET Framework source code available to developers for debugging support. Here are some links that will help you getting started:

Enjoy!

kick it on DotNetKicks.com

I encountered a nice article by Eric White that explains how to debug Linq queries.

Sum it up for me, please

Basically, lets say that you have this complex query:

var uniqueWords = text
    .Split(' ', '.', ',')
    .Where(i => i != "")
    .Select(i => i.ToLower())
    .GroupBy(i => i)
    .OrderByDescending(i => i.Count())
    .Select(i => new { Word = i.Key, Count = i.Count() })
    .Take(10);

And, lets say you want to debug it, here is a trick that can help you do that:

var uniqueWords = text
    .Split(' ', '.', ',')
    .Where(i => i != "")
    .Select(i => i.ToLower())
    .GroupBy(i => i)
    .Select(z =>
    {
        return z;
    })
    .OrderByDescending(i => i.Count())
    .Select(i => new { Word = i.Key, Count = i.Count() })
    .Take(10);

You should note that a "select" statement had been added to the query and now it is possible to add a breakpoint at the return statement and examine the return value that are yield by the group by method.

Let me read more

Eric White posted about this in the following post. So, if you want to see some print screens and more info you can read the full article here.

One of my customers asked me a simple question:

Customer: "Say Guy, what is the different between const and readonly fields?

Guy: "Well, the differences are...ohmmm..."

I had to go to the drawing board on try to remember the differences. I thought I'd share the results:

Constants

Here is what I found out about constants:

  • Static by default (but you cannot write "static const").
  • Value is evaluated at compile time, thus it must have compilation-time value ("A"+"B" is OK, method calls is not OK).
  • Cannot be changed at runtime.
  • Can be used in attributes.
  • Are copied into every assembly that uses them (a local copy of values).
  • Could be declared within functions.

Readonly

Here is what I found about readonly:

  • Can be either instance-level or static.
  • Can be initialized in declaration or by code in the constructor, thus are evaluated when instance is created.
  • Can hold a complex object by using the "new" keyword at initialization.
  • Cannot hold enumerations.
  • Must have set value by the time constructor exits.

Conclusion

The main difference between const and readonly is that a readonly member can be initialized at runtime, in a constructor as well being able to be initialized as they are declared.

NOTE: constants and readonly fields are considered to be concurrency safe.

Followed Tamir's post on Windows Vista 100% working Keygen, where he explain why Vista Keygen is not hoax and it works, I encountered a pyrate video, which should confirm that it work:

Take a look at this video here.

טוב, אני בדרך כלל לא נוהג לכתוב פוסטים בעיברית, אך הפעם הנושא מחייב אותי.

אני מניח שעכשיו בערך כל מדינת ישראל מכירה את האתר החדש של קשת:

image_thumb  Mako

ובכן, גם אני התוודאתי אליו בתקופה האחרונה, היות וקשה מאוד במדינה שלנו להעביר יום מבלי לשמוע משהו מבית האח הגדול או יציאה חדשה של אדון בובליל.

גם אני ככל מדינת ישראל כנראה, נהנה לצפות בתקצירים ובתוכניות של האח הגדול אבל לפעמים קורה שאני מפספס... לשמחתי השידורים מפורסמים גם ברשת ולאחרונה הועלו לאתר החדש מה קו.

לפני שאני אמשיך רק אומר כי אין בכוונתי לפגוע באף אחד מהאנשים שעמלו קשות בהרמת האתר ובפרט:

טל שחר

http://blogs.microsoft.co.il/blogs/talshahar/archive/2008/10/23/mako-is-live.aspx

לא פעם מצאתי את עצמי פותח את האתר ונאבק בו בכדי לצפות בפרק של האח הגדול. בהתחלה חשבתי שזה אני הבעיה, שחיבור הרשת שלי לא מהיר מספיק, שהדפדפן עושה בעיות, אבל...מסתבר שזה לא המקרה.

מה קו סובל מתסמונת בעיות ביצועים חמורה!

זוהי דוגמה קלסית למערכת שלא עברה בדיקות עומסים וביצועים בצורה ראוייה לפני שעלתה לאויר. אני מתפלה איך עד עכשיו השרתים שלהם מחזיקים מעמד...להערכתי, האתר עלה מוקדם מידי לאויר, לא?

למען האמת, נכון לעכשיו ויתרתי על התענוג להשתמש באתר הזה ועברתי להשתשמש באתר המעריצים של האח הגדול ששם אני יכול לצפות בנחת בשידורים חוזרים.

So, what are the most frequently development mistakes?

Well, Construx recently submitted a list of classic mistakes and then conducted a survey to assess the prevalence and impact of these mistakes.

NOTE: This survey is based on Steve McConnell book Rapid Development.

Mistakes That are Most Frequently Reported to Occur Almost Always or Often

  1. Overly optimistic schedules
  2. Unrealistic expectations
  3. Excessive multi-tasking
  4. Shortchanged quality assurance
  5. Noisy, crowded offices
  6. Feature creep
  7. Wishful thinking
  8. Insufficient risk management
  9. Confusing estimates with targets
  10. Omitting necessary tasks from estimates

Mistakes That are Least Frequently Reported to Occur Almost Always or Often

  1. Switching tools in mid-project
  2. Lack of automated source control
  3. Research-oriented development
  4. Premature or too frequent convergence
  5. Overestimating savings from tools/methods
  6. Push me, pull me negotiation
  7. Silver-bullet syndrome
  8. Subcontractor failure
  9. Letting a team go dark
  10. Uncontrolled problem employees

Mistakes That are Most Frequently Reported to Produce Catastrophic or Serious Consequences When They Occur

  1. Unrealistic expectations
  2. Weak personnel
  3. Overly optimistic schedules
  4. Wishful thinking
  5. Shortchanged quality assurance
  6. Inadequate design
  7. Lack of project sponsorship
  8. Confusing estimates with targets
  9. Excessive multi-tasking
  10. Lack of user involvement

You can get the complete white paper here.

kick it on DotNetKicks.com

Thought you might like it:

the Jerry Seinfeld and Bill Gates Ad.

kolbis כתב בתאריך Friday, November 21, 2008 6:14 AM
תגים:

Tracking the visitor actions is a common issue for web applications. You want to get statistics such as:

  • How many users logged on to your application?
  • What is the time duration they spent in each page?
  • What pages they are visiting?
  • etc.

Mads Kristensen posted a nice solution using HttpModule to that issue.

You can read more here.

I am hoping to load test this solution and get the sense of capabilities in production environment.

Question: How does Google Analytics do it?

kolbis כתב בתאריך Thursday, November 20, 2008 6:22 AM
תגים:,
More Posts Next page »