DCSIMG
November 2007 - Posts - Just code - Tamir Khason

November 2007 - Posts

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/vs2008-rtm-is-available-for-msdn-subscribers/]


After long wait, Visual Studio 2008 (code name Orcas) become available for MSDN subscribers. Download it now >>

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/how-to-make-your-code-completely-unreadable-with-net-35/]


With the time we got our developers less and less professional by enhancing programing languages and using easier code syntax. However, while we are trying to make things better, we discovered that things are going bad. Let's see following code sample

delegate string BringBeerDelegate(int amount);

static void Main(string[] args)
        {
            Console.WriteLine("Bringing beer using anonymous delegates");
            AskBarmenAboutBeer(2);

        }

static void AskBarmenAboutBeer(int amount)
        {
            BringBeerDelegate bringBeer = new BringBeerDelegate(BringBeer);

            Console.WriteLine("You got {0}", bringBeer.Invoke(amount));
            BringAnotherBeer(bringBeer, amount+1);
        }

static string BringBeer(int amount)
        {
            return string.Format("{0} beers",amount);
        }

static void BringAnotherBeer(BringBeerDelegate firstPint, int newAmount)
       {
           string res = firstPint(newAmount);
           Console.WriteLine("You got another {0}",res.ToString());
       }

It pretty clear what this code is doing. It creates new delegate named BringBeerDelegate, that actually formats string. Then it invokes the delegate. After it the delegate transferred into BringAnotherBeer method and invokes there. This way it works in .NET 1.1 So far, so good. Let's use anonymous delegate, introduced in .NET 2.0 instead on using method to invoke it. Now, we'll add another method, that creates and invokes the anonymous delegate BringBeerDelegate.

static void AskBarmenAnonymouslyAboutBeer(int amount)
        {
            BringBeerDelegate bringBeer = delegate(int am) { return string.Format("{0} beers", am); };

            Console.WriteLine("You got {0}", bringBeer.Invoke(amount));
            BringAnotherBeer(bringBeer, amount + 1);
        }

Now, calling AskBarmenAnonymouslyAboutBeer with number of pints we want, we'll create and invoke the anonymous delegate. The code less readable (as for me), but never mind, we saved a couple of code lines.

Now, let's write following:

BringBeerDelegate bringBeer = am => string.Format("{0} beers", am);
BringAnotherBeer(bringBeer, ++amount);

What the hell all those => are doing? This is anonymous delegate BringBeerDelegate defined by lambda¹ expression.

small lyrics: ¹Lambda (uppercase Λ, lowercase λ) - the 11th letter of the Greek alphabet. In the system of Greek numerals it has a value of 30. Letters that arose from Lambda include the Roman L and the Cyrillic letter El (Л, л).
Lambda expressions provide a more concise, functional syntax for writing anonymous methods.

Is it really more concise and functional syntax? What do you think, following code doing?

Func<int,string> firstTime = (int am) => { return string.Format("{0} beers", am); };

Func<T..> is generic delegate type for lambdas. That's piece of cake, isn't it? Let's see you to predict what following code will output...

BringBeerDelegate bringBeer = am => string.Format("{0} beers", am);
Func<int, BringBeerDelegate, string> bringBeerFunc = (int am, BringBeerDelegate beer) => { return beer(am); };
Func<int, Func<int, BringBeerDelegate, string>, string> lastTime = (int am, Func<int, BringBeerDelegate, string> func) => { return func(am, bringBeer); };

The other awful thing in new .NET 3.5 is anonymous types. So, great news, VB programmers, there is new king in the village. His name is VAR. Following previous code section, following make our life even more complicated.

var whatBeer = bringBeer;

//At least, either compiler and interpreter knows, that whatBeer variable is of BringBeerDelegate type

image

Happy and very unreadable coding, my friends.

Source code for this article.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/just-released-microsoft-visual-simulation-api/]


Do you know Microsoft Flight Simulator (X) game? Want to incorporate it's features in your development? Let me introduce you Microsoft ESP. Now, you have visual simulation platform, that might bring realistic visual environment without a lot of development affords. 

Now, connect it with Virtual Earth (with it's new geophysical API) and you have your own .... {censored}. You know, what I mean and can hear it here. Sky is not limit anymore :)

image

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/70-552-should-be-removed-or-at-least-changed/]


About two weeks ago, I'm failed on 70-552 (UPGRADE: MCAD Skills to MCPD Windows Developer by Using the Microsoft .NET Framework). I'm FAILED. Just flaked it off, stumble on it, loooooose! I even was unable to imagine, that I can fail any MCP exam? So, I investigate why it happened (*** does not happen, we make it happens)

  • I found, that I ever, never used (aint even think of using) build it unit test framework from VS, 'cos it's really SUX!
  • I do not think, that I ever though to "Test the identified component based on the requirements", 'cos first of all I should understand what client need and what other systems he has. Only then I can begin of thinking about "components"
  • I do not want to "Design a new exception handling technique", 'cos we either can use error handling design patters or incorporate existing exception handling best-practices, used by clients.
  • I do not want to "Decide which configuration attributes to store", 'cos we need them all and if you found, that you should not store some attributes, you can just void them
  • I do not think, that I should "Evaluate the test environment specification" or "Evaluate the performance testing strategy" or, even "Evaluate the stress testing strategy", 'cos we have really good external companies, that does it professionally. I have to write good code, while keeping performance in my mind. I definitely should not test the application performance with Windows Task Manager - this is very bad behavior. So, "Identify performance spikes" and "Track logon times" is not my job!
  • I'm unable to "Evaluate the impact of the bug and the associated cost and timeline for fixing the bug", 'cos if you are only developer in the company, you'll fix it. If not, you should know all developers involved.
  • If you are going to "Track bugs that result from customer activity", you should do only this task. I think any of you, who ever did it, know, that we're, developers, trying to explain the customer, that we never have bugs. All those behaviors are kindly expected.
  • If you are not aware about security and want your customer to report "suspicious activity" with your application installer, you, probably, should know how to "Identify scripting requirements for deployment. Considerations include database scripting". As for me, I do not!

So, by summarizing those points, I'll retake the exam, by writing whatever they want me to write, however, I'm very sure, that this exam should be removed from developers certification, if we do not want our developers to become even worth, than they are.

For conclusion about you, as developers. Try to answer following question (from this examination). Later, I'll tell you what the right and "right" answer for this one.

You are developing application, which includes several components:

  • 3rd party webservice
  • External API, developed in other company
  • Core component, developed in your company
  • MSSQL database in your company
  • External component, that using external API

What two components you advice to test in integration tests.

Good luck.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/developer-academy-ii-registration-is-over/]


Today, I checked the registration status of Developer Academy II event and found, that the registration is over. After 5 days the event becomes overbooked. From one hand, it's really cool, from the other, I believe, that there are more people, who were not able to register (due different reasons) and now they can not attend.

See you there at DEV411 "WPF For Developers -  Lessons learn from last year (Or Optimizing Your WPF Application)" 2:45 PM - 4:00 PM at Arbel hall.

Thank you for attending.

devopen2

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/diy-how-to-replace-your-dell-latitude-d820-keyboard-for-only-1399/]


  Well, after my fight against Dell Israel and Omnitech, I decided to replace my keyboard my self. The keyboard was ordered via official Dell US website for only $13.99 (inc. P&P)

DSC06586

It took about a week to arrive and now I'm ready to start replacement process.

DSC06587

You'll need two wrenches like those.

DSC06605

First of all, you should shut down your computer and remove it's battery

DSC06588

 

DSC06589

Next, by using plastic scribe or small wrench remove front hinge cover.

DSC06590

DSC06591

DSC06592

After the hinge removed, you'll get an access to three screws in the top side of the keyboard and small plug. Unplug it.

DSC06593

 

DSC06594

Then remove screws.

DSC06595

DSC06596

After the screws removed, rotate your laptop by 90 degrees and pull the keyboard forward up to remove it.

DSC06597

Turn the keyboard upside down. You discover the plug, that connects the keyboard. Unplug it by pulling it up.

DSC06598

DSC06599

And remove the old keyboard. Now replace the old with new one and plug it back.

DSC06600

Put the new keyboard to it's place and push it down from the upper side and both right and left side to secure it in place. Do it gently to avoid scratches.

DSC06601

Replace all three screws and upper plug.

DSC06602

Put the hinge cover back by pushing it gently

DSC06603

And you done.

DSC06604

 

You just save $121.01. Not bad does not it? Thank you, local thieves, and know, who spares the bad, injures the good. However, here in Israel, an open door may tempt a saint.

Be good men and have a nice weekend.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/to-liorz-with-love/]


As promised, famous T-shirts have been printed. Here it comes

Picture 2

I can not judge the creativity of Lior, Ori and Gil, but I begin to produce such t-shirts. They are available in black and white in any size (M,L,XL and XXL) for 50 NIS (~12.5$) + postal costs (if you'll take it yourself nothing should be paid). If you want your own blog (or any other address) add another 5 NIS.

If you have (or have a connection to) print house and can make it cheaper - you're more, then welcome to help us with those t-shirts.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/number-only-textbox/]


There are a lot of cases, you have to validate, that user inputs numbers only into TextBox. Someone things, that it's bad behavior to prevent user from typing well-known bad characters. I think, it's good. Let's take an example of form, you have to enter Social ID. Do you really think, that user expects the form tell him: "Hey, you, it's 9 digits only. You typed 'Z', which is not digit. Don't do it anymore...". I think, that the good behavior is when user types Z in text area for social id, nothing should happens. But, anyhow, it's up to you to decide.

Today, I want to explain how to build TextBox, that accepts only numbers in WPF.

In WinForms world, we used to handle KeyDown or KeyPressed event to get character and check whether it number. In WPF world, there are a lot of ways to input anything, that text (for example Voice recognition or handwriting. More then this, in WPF (device independent) world we can not be sure, that when you press key with 2 and @ in your keyboard without Shift pressed, you meant "2". Thus KeyDown or, even PreviewKeyDown event will not bring you salvation. We should handle input text without relation to input device. For this purpose, we have TextInput and PreviewTextInput event. Let's handle it

public class NumberTextBox:TextBox
    {

        protected override void OnPreviewTextInput(System.Windows.Input.TextCompositionEventArgs e)
        {
            e.Handled = !AreAllValidNumericChars(e.Text);
            base.OnPreviewTextInput(e);
        }

     }

Pretty cool, ah? What's about validation itself? "5" is definitely number, but what about "٥" ? Well, it's five in Arabic and it's number too. Is '½' is number? Sure, it's a half, but is it digit? No! This why we should use Char.IsDigit method, rather then Char.IsNumber which is not limited to radix 10 digits. The same behavior,   you'll get using Char.GetUnicodeCategory method to compare to UnicodeCategory.DecimalDigitNumber, but in this case, it will be current culture oriented.

Well. now we know if the input it decimal, what's about 1,000.00 numbers? The simplest way is to check whether the char is '.'{0x2e} or ',' {0x2c} and mark it as valid, however, what's about 1'00''00 or 100° which is absolutely valid numbers? NumberFormatInfo.CurrentInfo is your best friend in this case. You can always check my Globalization statements by using this handy program.

Now, when we sure, that everything is ok, we can write the test method

bool AreAllValidNumericChars(string str)
        {
            bool ret = true;
            if (str == System.Globalization.NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator |
                str == System.Globalization.NumberFormatInfo.CurrentInfo.CurrencyGroupSeparator |
                str == System.Globalization.NumberFormatInfo.CurrentInfo.CurrencySymbol |
                str == System.Globalization.NumberFormatInfo.CurrentInfo.NegativeSign |
                str == System.Globalization.NumberFormatInfo.CurrentInfo.NegativeInfinitySymbol |
                str == System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator |
                str == System.Globalization.NumberFormatInfo.CurrentInfo.NumberGroupSeparator |
                str == System.Globalization.NumberFormatInfo.CurrentInfo.PercentDecimalSeparator |
                str == System.Globalization.NumberFormatInfo.CurrentInfo.PercentGroupSeparator |
                str == System.Globalization.NumberFormatInfo.CurrentInfo.PercentSymbol |
                str == System.Globalization.NumberFormatInfo.CurrentInfo.PerMilleSymbol |
                str == System.Globalization.NumberFormatInfo.CurrentInfo.PositiveInfinitySymbol |
                str == System.Globalization.NumberFormatInfo.CurrentInfo.PositiveSign)
                return ret;

            int l = str.Length;
            for (int i = 0; i < l; i++)
            {
                char ch = str[i];
                ret &= Char.IsDigit(ch);
            }

            return ret;
        }

The only thing we should do is handle drag and drop and paste whole text into the textbox. That's all folks. If you want to know how to handle and validate D&D and paste, let me know.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/call-for-action-register-microsoft-developer-academy-2-this-is-not-about-crm/]


Shahar and Guy announced about open registration to 1032359731 (Microsoft Developer Academy 2). Please notice, it is not "תתחיל להכיר את הלקוחות שלך מקרוב - כנס CRM לארגונים תעשיה ביצוא", it's Developer Academy. So, sign up and attend at hall E at 2:45 PM - 4:00 PM for "WPF For Developers -  Lessons learn from last year (Or Optimizing Your WPF Application)" . Know, it's only 2.5 weeks from now - prepare your questions and bring your problems with you.

Developer Academy

It will take place in Airport city (near Ben-Gurion airport) at Avenue convention center, northern Kfar Truman on road 453. Here the map. Be sure to be there.

image

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/your-potential-their-t-shirts/]


Back to the Live event yesterday, I recalled old joke, prepared by me for Lior (Microsoft MARCOM) after Blogference, but never sent him. Today, using Microsoft Live Services, I can collaborate this image with him, while wearing Microsoft's T-shirt with slogan "The Jewish people are Live".

image

I'll probably, print this slogan (about T-shirts, not about Jewish people) one day on white T-shirt for my own...

I even prepaired images suitable for printing on material (TIFF, 300 dpi, black and white background). Download it, if you want to print such T-shirt for your own (or for me :) )

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/visual-studio-windows-live-tools-november-ctp/]


For all those, who want to incorporate Windows Live into their applications, new Windows Live Tools from Visual Studio will be great place to begin. Download November CTP on Microsoft Connect.

via LiveSide

Windows Live Tools

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/windows-live-messenger-web-api/]


A couple of hours after Windows Live has been announced, you can chat with me directly from my (or your) blog. Enter and see the left side for Windows Live Messenger Web Control.

Want too? That's simple. First, allow others to see your presence. Then choose the control to use. Now (for those, who are using CS) add it into News section or other place in your blog (Spaces for sure).

image

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/new-branded-yournamelivecom-is-available/]


After a long wait, Microsoft Live is officially available. So, if you are in USA, you already can register new @LIVE.COM email address and have a new fresh start

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/release-dates-visual-studio-2008-net-framework-35-and-microsoft-sync-framework/]


Great news: VS2008 RTM and the final version of .NET framework 3.5 will be available by the end of this month (November). That's what was committed by Soma today at TectEd in Barcelona. This is really cool and means, that RC version is almost similar to RTM.

The other great news, is that there is new product "Microsoft Sync Framework" - a synchronization platform, that works with Live services and Popfly will be available aside this package. \

So what is "Sync Framework"?

· The first CTP of the Microsoft Sync Framework demonstrates Microsoft’s ongoing investments in synchronization and builds on the synchronization functionality available in Visual Studio 20008. With Visual Studio 2008 developers can rapidly take advantage of offline synchronization capabilities to sync-enable applications and services easily with rich designer support. 

· The Microsoft Sync Framework extends the support featured in Visual Studio 2008 to also include offline and peer-to-peer collaboration using any protocol for any data type, and any data store.

· This is part of Microsoft’s long term commitment to providing synchronization for partners and ISVs who can embed the Sync Framework into their applications easily to create rich sync-enabled ecosystems that allow any type of data to follow their customers wherever they go

What is Popfly Explorer?

· Web developers and Popfly users need an easy way to add Silverlight gadgets built in Popfly to their Web pages, as well as publish HTML Web pages directly to Popfly

· To enable this kind of easy customization, Microsoft today announced that Popfly Explorer will provide deeper integration into Visual Web Developer Express. Now developers can now design Web pages using HTML, CSS, JavaScript and publish those pages directly to Popfly (server-side code is not supported)

· The Visual Studio/Visual Web Developer 2008 integration makes it easy to add Popfly mashups built in Silverlight to your Web page. Making your personal Web site look cool just got a lot easier

Have a nice day and be good people.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/poster-of-net-framework-35-namespaces/]


Many thanks to Paul Andrew, Kit George and Brad Abrams for creation of this useful wall poster for your convenience. Read Brad's and Paul's posts about it. Download the full size PDF version.

More Posts « Previous page - Next page »