DCSIMG
December 2007 - Posts - Just code - Tamir Khason

December 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/how-to-disable-exchange-security-policy-for-windows-mobile-devices/]


Direct Push pushes email into your Windows Mobile device and it's good. However it pushes you security policy as well, that sometimes make you unable to set password that you want and sometimes, lock your device after one minute of inactivity. How to disable this useful feature? How to cancel autolock feature of your WM machine, connected to Microsoft Exchange server?

As everything in WM, you should patch registry, but what to patch? Well, it's simple

  • Enable/Disable the Exchange security policy - HKLM\Security\Policies\00001023: 0 = Enabled; 1 = Disabled
  • Inactivity time
    • HKLM\Comm\Security\Policy\LASSD\AE\{50C13377-C66D-400C-889E-C316FC4AB374}\AEFrequencyType: 0 = No inactivity time; 1 = Activity time enable
    • HKLM\Comm\Security\Policy\LASSD\AE\{50C13377-C66D-400C-889E-C316FC4AB374}\AEFrequencyValue: number of minutes before timeout
  • Password strength
    • Minimum number of characters: HKLM\Comm\Security\Policy\LASSD\LAP\lap_pw\MinimumPasswordLength
    • Password complexity: HKLM\Comm\Security\Policy\LASSD\LAP\lap_pw\PasswordComplexity: 0 = Require Alphanumeric; 1 = Require numeric (PIN); 2 = No restriction
  • Wipe settings
    • Number of failed attempts before all your information will go: HKLM\Comm\Security\Policy\LASSD\DeviceWipeThreshold: -1 = disabled; other failed attempts
    • Number of failed attempts before displaying codeoword: HKLM\Comm\Security\Policy\LASSD\CodewordFrequency: number of failed attempts

Well, that all. After you'll fix it, just go to Lock settings in your device manager and you'll be able to unmark and change whatever you want. I hate, when program denies me from doing anything in my device.

If you are not feeling comfortable with changing registry settings, I create simple program, that do it instead of you. You can download and use it for free, but notice, I'm not responsible if it will brick your device (this is system hack)

image

Download Exchange Police Patch >>

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/learning-marathon-december-23-29/]


Do you want to know WPF, Silverlight or it's architecture or appliance and you are in Israel next week? If so, please keep reading. Next week (Dec 23-29) it's going to be a lot of workshops, courses and other learning attractions, related to those technologies.

  • 24-Dec [4:00PM-8:00PM] - Architects user's group "Architects Forum Meeting - User Experience - Architecture and Technologies Dillemas" in Microsoft Israel (2, haPnina str, Ra'anana). The place to discuss with me + light dinner
  • 25-Dec [9:30AM-4:30PM] - "WPF training for designers" in Sela college (14, Baruch Hirsh str., Bnei Brak). If you are designer and want to stop getting rejects from developers, you should attend. You'll learn how to use efficiently Microsoft Expression tools and begin to designing real applications. What's in agenda?
    • What is UX? (Developers are strange nation)
    • Expression Design (It’s not Adobe)
    • Expression Blend (We do not need those strange designers)
    • Windows Experience (Visual Studio is old and bad tool)
    • Hands On Labs (Let’s make it work)
  • 26-Dec [8:30AM-1:30PM] - "Microsoft technologies appliance in C2 and military systems" in Microsoft Israel (2, haPnina str, Ra'anana). You'll hear about real world real time and near real time applications, command and control systems, and using WPF, Silverlight, Windows Server and .NET technologies to build them. If you are working in military industry - you have to attend. Lunch and dinner included.
    • Modern C&C systems, using new technologies (me)
    • mCore as C2 framework (Eli Arlozorov)
    • Israel Navy as C2 and WPF successful case study (Lior Rozner)
  • 27-Dec [9:30AM-4:30PM] - "Silverlight training for designers" in Sela college (14, Baruch Hirsh str., Bnei Brak). If you are designer and want to start writing Silverlight applications, you should attend. One day session to start work in Silverlight, by using Microsoft Expression suite. Agenda
    • How to start project (developers understand nothing)
    • Prepare assets (make developers not interrupt you)
    • Expression Blend how to (if I know Adobe, I already know it)
    • Make it moving (Adobe Flash is my friend)
    • Make it play (You are producer)
    • Fundamentals (make you understand developers)
    • How to finish project (developers understand nothing)

Not bad, ah? You should register @ Microsoft [send me an email if you have registration problem] to attend any of those events (it's free, if there are places). See you there and have a good weekend.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/changes-of-zip-codes-in-israel-is-for-large-amount-of-mails-dont-worry/]


Ohad wrote about changes in ZIP codes in Israel from 5 to 7 digits. I checked this issue with Israel Postal authority and it's valid for only large amounts of postage (more, then 3000 items a time). More, then this, old 5 digit zips will also work, however, client, using old zips will not receive any discount. So, don't worry and prepare yourself for large new projects within your large clients :)

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/anonymous-types-sharing-or-why-its-still-sucks/]


Did you try to cast anonymous types (vars)? You are. However, you never was able to pass var from one method to another. Why is it? Cos, anonymous type got known in context of current method only. Well, we always can cast one anonymous type into other. How? By using Extension methods. Let's make small repro. In one method, you have following structure

var myVar = new[] {
               new {Name = "Pit", Kind = "Alien},
               new {Name = "John", Kind = "Predator"},
               new {Name = "Fred", Kind = "Human"}
           };

In other method, you have other variable

var theirVar = new[] {
                new {Name = "Kent", Kind = "Alien"},
                new {Name = "Rob", Kind = "Predator"},
                new {Name = "Bill", Kind = "Human"}
            };

Cool. Now you can cast myVar easily into object or object array, and transfer it into other method. Then, cast theirVar into another object or object array and cast myVar into theirVar, right? Why not to use extension to make your live easier (tnx to AlexJ)?

public static class Extender
   {
       public static T Cast<T>(this object obj, T what)
       {
           return (T)obj;
       }
   }

Now, it's very cool part. Change theirVar assignment to following:

var theirVar = myVar.Cast(new[] {
               new {Name = "Kent", Kind = "Alien"},
               new {Name = "Rob", Kind = "Predator"},
               new {Name = "Bill", Kind = "Human"}
           });

You got theirVar type of myVar type. Isn't it cool? You even can enumerate through those objects, by using strong types

foreach (var q in theirVar)
            {
                Console.WriteLine("{0}-{1}", q.Name, q.Kind);
            }

Well, as always, I have a goat for you. Let's change myType as following

var myVar = new[] {
               new {Name = "Pit", Kind = "Alien", Goat = "bee"},
               new {Name = "John", Kind = "Predator", Goat = "mee"},
               new {Name = "Fred", Kind = "Human", Goat = "eee"}
           };

And we will not tell to theirType developer about what type Goat member is. So, we let him write

var theirVar = myVar.Cast(new[] {
                new {Name = "Kent", Kind = "Alien", Goat = 1},
                new {Name = "Rob", Kind = "Predator", Goat = 2},
                new {Name = "Bill", Kind = "Human", Goat = 3}
            });

Eaht! Will it works? Sure, if exceptions will be handled. Actually, you'll get

Unable to cast object of type '<>f__AnonymousType0`3[System.String,System.String,System.String][]' to type '<>f__AnonymousType0`3[System.String,System.String,System.Int32][]'.

Extremely informative exception (if you know what <>f__AnonymousType0 is). Isn't it? Don't use anonymous types. It's bad behavior! 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/tafiti-goes-open-source-well-actually-shared-source-under-ms-pl/]


All those, how want to implement data visualization in Silverlight (as Tafiti does), can look into this CodePlex project and use it for your own. Notice, you can download, modify and, even, resell this code, due to fact, that it's under MS-PL shared source licence. Well done, Live team.

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/messed-with-silverlight-video-player-skin-generated-by-encoder-see-how-to-customize-it/]


Have you ever try to create your own video player skin, by customizing one, generated by Microsoft Expression Media? If you not really familiar with Silverlight development, it's rather hard to do. Microsoft recognizes it and recently released special document about Silverlight Media Player skin customization. It's very useful for you, if you do not want to begin learn Silverlight internal, however, you want to create your own player skin fast. Here it is (direct link). You'll need BasePlayer.js debug version as well, so download it here.

image

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


Are you asking for case studies of LOB (line-of-business) application, written in Silverlight? Nothing simpler. Here is the result of the partnership between Microsoft and Infusion. Another great Penza and Airport type RIA (rich-internet-application)

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/wpf-for-developers-from-dev-academy-2-recordings/]


If you was unable to attend Developers Academy 2 and still want to see sessions there, you are more, then welcome to do it. Here link to the recording of my session. And here is the presentation. The quality of the recording is awful, as well as whole hosting site quality. It seemed like "Gisha Hadasha" has no QA and particle employed student to make sites. However, if you still want to see the screencasts of the sessions, go there.

image

See screencast "WPF for developers (or optimizing your WPF application)" >>

[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-see-hebrew-in-windows-mobile-device-baltic/]


Official answer - you can not. Unofficial - take tahoma and tahoma bold from your computer (in /Windows/Fonts) and put it into Windows/Fonts directory of your WM6  device. You'll see hebrew in most of applications. However, it will be הכופה תירבע. So, who tell, that Haaretz are old fashioned because they are still using  Hebrew-Logical?

Better, then nothing. If you want full Hebrew support, you should buy localization for WM6 (this one [Eyron's extender] for example).

image

<EOM>

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/flickering-in-wpf-itemscontrol-no-way/]


Remember WinForms GDI+ days, when we have to enable DoubleBuffering to prevent flickering of fast changing elements in the application screen? Do you think, that we already after it with WPF? Not exactly. Today, I'll explain how you can force 100% hardware rendered stuff to flicker in your WPF application and how to prevent it.

Let's start. I want to draw fast large amount of primitives in the screen. Let's say Rectangles. My source is underlying collection of Rect and I have one ItemsControl, bounded to the collection to visualize them.

<ItemsControl ItemsSource="{Binding}" Name="control">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.Background>
                    <SolidColorBrush Color="Gray"/>
                </ItemsControl.Background>
  </ItemsControl>

I also created DataTemplate, that uses TranslateTransform to set the rectangle positions (remember my Dev Academy performance session?)

<DataTemplate x:Key="theirTemplate">
            <Rectangle Fill="Red" Width="{Binding Path=Width}" Height="{Binding Path=Height}">
                <Rectangle.RenderTransform>
                    <TranslateTransform X="{Binding Path=X}" Y="{Binding Path=Y}"/>
                </Rectangle.RenderTransform>
            </Rectangle>
        </DataTemplate>

Now I'll add method to fill the ObservableCollection and force my ItemsControl to show them

ObjectDataProvider obp = Resources["boo"] as ObjectDataProvider;
           Boo b = (Boo)obp.Data;
           b.Clear();
           for (int i = 0; i < 100; i++)
           {
               Rect r = new Rect();
               r.Width = this.Width / 5;
               r.Height = this.Width / 5;
               r.X = (double)rnd.Next((int)this.Width);
               r.Y = (double)rnd.Next((int)this.Height);

               b.Add(r);
           }

So far, so good. Running this stuff, you'll notice red ghost rectangle in the left top corner of items control. It appears and disappears. What's the hell is it?

This is rendering order. First it creates visual, then draws it and only after it uses transformation to move it. Should not it be before rendering? Probably it is, how it is not working this way today.

So how to solve this problem? Just create your own rectangle, that works as required.

It is FrameworkElement (the simplest class, that can be used within DataTemplate).

public class myRectange : FrameworkElement
    {}

How, let's create brushes and pens (do not forget to freeze them to increase performance)

Pen p;
        SolidColorBrush b;

void rebuildBrushes()
        {
            b = new SolidColorBrush(this.Fill);
            p = new Pen(b,2);
            b.Freeze();
            p.Freeze();
        }

Draw Rectangle on Render event

protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.DrawRectangle(b, p, new Rect(0,0,Width,Height));
        }

And change transformations and color, before rendering

protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);
            if (e.Property == XProperty | e.Property == YProperty)
            {
                RenderTransform = new TranslateTransform(X, Y);
            }
            else if (e.Property == FillProperty)
            {
                rebuildBrushes();
                InvalidateVisual();
            }
        }

We done. Now, our "ghost rectangle" disappears. Don't forget to change DataTemplate

<DataTemplate x:Key="myTemplate">
            <l:myRectange Width="{Binding Path=Width}" Height="{Binding Path=Height}" X="{Binding Path=X}" Y="{Binding Path=Y}" Fill="Red"/>
        </DataTemplate>

Have a nice day.

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/hanukkah-is-almost-over/]


Well, very smart Jew sells special made sufganiot (Hanukkah Jelly Doughnuts). Delicious!

image

via Ben Tamblyn

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/feeling-alone-without-x-mass-tree-on-hanukkah-here-is-a-song-for-you/]


Adam Sandler performed Hanukkah song on Comedy Central. As for me, I do not know what to do. To laugh or to cry. Here the beginning

Put on your yalmulka, here comes hanukkah
Its so much fun-akkah to celebrate hanukkah,
Hanukkah is the festival of lights,
Instead of one day of presents, we have eight crazy nights.
When you feel like the only kid in town without a x-mas tree, heres a list of
People who are jewish, just like you and me:
David lee roth lights the menorrah,
So do james caan, kirk douglas, and the late dinah shore-ah
Guess who eats together at the karnickey deli,
Bowzer from sha-na-na, and arthur fonzerrelli.
Paul newmans half jewish; goldie hawns half too,
Put them together--what a fine lookin jew!

[This blog was migrated. You will not be able to comment here.
The new URL of this post is http://khason.net/blog/a-couple-of-updates-mega-update-post/]


Today, only updates

Yahoo finally releases Yahoo! Messenger for Vista - this was one of very first prototypes, shown in Mix last year. I did not install it, however, here a couple of review Erik Burke, Tim Sneath and Ryan Stewart. As for me, they lost "wow effect" last year

image Microsoft Expression Blend 2 - December Preview. What's new? VS2008 integration, inheritance, no SL2.0 support (strange, maybe, because of breaking changes toward near beta)

 

 

 

Vista SP1 RC1 available for MSDN subscribers (via Nick Whites). Nothing special, 40 minutes of installation, profile information loss and performance fixes

 

Office 2007 SP1 is expected to ship 10-December week. This time it is not RC or Beta, but final product (via Mary Jo Foley). Great work.

 

Windows XP SP3 is very close to RC1, but nothing about public beta yet.

 

Starting today, you can configure Messenger presence.  Some cool features become available (via Angus Logan). Here is how.

 

PDC 2008 (canceled last year) will be on October 27-30 in LA (hello, Peter). It promised to be great event about the company's emerging services platform efforts, .NET, Windows and Mobile technologies.

 

imageA little about mobile devices, while waiting for my new mega-device (more information soon): Dell is about to enter mobile phone industry in 2008, Opera compiled their browser for Brew platform (hello, Pelephone), while Google create their mobile version for IPhone.  Windows Mobile 6.1 is going to be cool. Here screenshorts. Meanwhile, you can update your Mobile Office to version 6.1 for free or your Nokia (N-series) with Internet Radio application. As for me, 8 hours speak time and 30 days standby, quad-band. Those are features, that you need from your handy.

 

Well, that's it for now. Have a nice weekend.

 

Now I have a question for you. What do you think, about such format of posts? Should ?I go on with it or continue to write post-per-event?

 

Thank you

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


Recently, Microsoft released Volta. This is kind of framework, that using .NET to emit client side JS code. Something very similar, was released in ASP.NET AJAX 1.0. So, now, you can access your anchor element in HTML DOM by using following expression

string val = Document.GetById<A>("myHref").Value;

Instead of using following expression in current JS

var val - document.getElementById("myHref").Value;

Pretty cool, however, while web development trying to escape variable types, client side development trying to get into it. Isn't is nonsense?

BTW, this concept already incorporated by Google and other web "prototype" service providers.

Other possible appliance of such framework is ability to work with typed and generic methods, revealed by Silverlight.

image

Download and try Volta >>

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


What's wrong with following code:

class aaa : DependencyObject { }

class bbb : DependencyObject
    {
        static readonly bbb b = new bbb();
        public static bbb GetMe { get { return b; } }

        public static readonly DependencyProperty MyPropertyProperty =
            DependencyProperty.Register("MyProperty", typeof(aaa), typeof(bbb), new UIPropertyMetadata(default(aaa)));

        private bbb()
        {
            MyProperty = new aaa();
        }
        public aaa MyProperty
        {
            get { return (aaa)GetValue(MyPropertyProperty); }
            set { SetValue(MyPropertyProperty, value); }
        }
    }

Nothing special, One DependencyObject, that implement singleton pattern. You should call GetMe to create and get an instance and then use it.

Well, this code throws "Value cannot be null. Parameter name: dp" exception. Why this happens? Why class aaa can not be null? It can - it dependency object!

How to fix it? Just move registration of DependencyPropery above initialization of static bbb to solve it. Like this

class aaa : DependencyObject { }

class bbb : DependencyObject
    {
        public static readonly DependencyProperty MyPropertyProperty =
            DependencyProperty.Register("MyProperty", typeof(aaa), typeof(bbb), new UIPropertyMetadata(default(aaa)));

        static readonly bbb b = new bbb();
        public static bbb GetMe { get { return b; } }

        private bbb()
        {
            MyProperty = new aaa();
        }
        public aaa MyProperty
        {
            get { return (aaa)GetValue(MyPropertyProperty); }
            set { SetValue(MyPropertyProperty, value); }
        }
    }

Why this happens? Well, even compiled, WPF initializes static classes by using it's order in code. Don't believe me? Open ILDasm for evidences.

Conclusion - I think, it should be reported as bug, however, from the other hand, it makes sense. You choose what's right and what's wrong.

Great thank to Kael and Matthew for helping me to debug it.

More Posts Next page »