Wednesday, August 31, 2011

IBM DB2 .NET Data Provider 9.7

The IBM DB2 .NET Data Provider 9.7 has both the data provider for .NET 4.0 AND Add-in for Visual Studio 2010. But you need to install the FP4. I installed the original and upgraded to FP3a and then FP4, and it didn't work properly (can not see IBM driver in the list, testconn20 and testconn40 both are not working). So a clean install of FP4 is the most reliable way.
Another thing is the tools needs admin priviledges. If you don't run VS under admin or (most of) the tools under admin, they just disappear or report reason code 10.

Thursday, June 30, 2011

WeatherLive Windows Phone 7 application Privacy Policy

WeatherLive is a client application designed for displaying current weather forecast with Live Tile support on your Windows Phone. In order for providing weather information for you, we may need to access your location information as a convience feature. As such, we are providing the following privacy policy.
This Privacy Policy may be updated and you can receive information about updates through the web site or the service. The latest version of the privacy policy is available to you at http://laorient.blogspot.com/2011/06/weatherlive-windows-phone-7-application.html.

Information Collected

When you chose to enable location service for weather information, we collect the location of your phone and send it over the internet to get the weather information. If the application is in Trial mode, we may use this location information to deliver ads appropriate to your location. We only store the current location information for Live Tile support and not use it for other purposes. You can turn off the feature in the settings and still use the weather feature by entering the worldwide city and state.

Sunday, June 26, 2011

Tips encoding bytes for REST services (or any Uris)

Use Base64Url to encode any bytes as part of a url. It replaces the normal "/" and "+" with "-" and "_", makes it url safe.

Windows Azure: WebRole.cs is NOT running in the same process as the website

WebRole.cs is running in WaIISHost.exe in local dev, and website is in w3wp.exe. This causes code running in the WebRole.cs having no access to the website's in memory classes/code, thus several confusing issues:
1. If you initialized something in Run/OnStart, it is actually not effective for the website.
2. The code running in WebRole.cs can not access the web.config file, as it is not run as a website.
When I tried to start a Quartz.NET scheduler, such an architecture caused many mysterious behaviors and issues for me. E.g., the scheduled job has a EF object that can not get its connection string (because it is in the web.config). And trying to run a scheduled job code in the website ondemand can not access the main scheduler (because it is in another process!). After I moved the initialization code for the scheduler into the Global.asax.cs, everthing starts working.

Friday, June 24, 2011

Ad Idea: Information in one shot

A guy standing and saying "I don't value my phone as much as the other guy." Showing the other guy standing beside, head in shoulders, tapping crazy on his iPhone.
"I value myself more, though". Swooshing out a Windows Phone, click open, took a look, then tuck it in and walk away.
Big start screen with weather, stock, mail, calender live tiles for 5 seconds. Weather updated and stocks turn green from red, price go up. Overhead voice "This is how I get my information in one shot". Then phone screen turns off.
Tag line: "Information in one shot".

Thursday, June 23, 2011

LED Clock Windows Phone 7 app Privacy Policy

LED Clock is a client application designed for displaying and telling current time, weather and other information on your Windows Phone. In order for providing weather information for you, we may need to access your location information as a convience feature. As such, we are providing the following privacy policy.
This Privacy Policy may be updated and you can receive information about updates through the web site or the service. The latest version of the privacy policy is available to you at http://laorient.blogspot.com/2011/06/led-clock-windows-phone-7-app-privacy.html.

Information Collected

When you chose to enable location service for weather information, we collect the location of your phone and send it over the internet to get the weather information. If the application is in Trial mode, we may use this location information to deliver ads appropriate to your location. We do not store the location information or use it for other purposes. You can turn off the feature in the settings and still use the weather feature by entering the city and state.

Tuesday, June 7, 2011

How to escape invalid characters in XAML within a Markup Extension

Use %20 for a space and other XML Character Entities for the invalid characters, such as "{d:Design Data Source=/Sample%20Data/SampleData.xaml}" for the source path of "/Sample Data/SampleData.xaml".

In the case that you do NOT want to interpret "{" as the start of a Markup Extension, then put "{}" before it so it becomes "{}{". No need to do the same for the closing bracket "}".

Sunday, May 29, 2011

Windows Phone 7's limited Generic support

It finally occurred to me that I was delusional. :) Turns out that Windows Phone 7, which uses Compact .NET Framework, has limited support of Generic type reflection. Such that, when a Generic type is used in reflection, it mostly raises NotSupportedException for most of its methods.
The .NET Compact Framework provides limited reflection functionality for generic types and methods, sufficient for supporting C# and Visual Basic runtime and class library dependencies.
This causes hideous problems in places that relies on this behavior, and it could be in surprisingly many places.
However, Mango (Windows Phone 7.1) does seem to fix it.

Tuesday, May 24, 2011

When in doubt, redeploy (SSRS)

Got a really persistent and "consistent" error in deployed SSRS report, which is a fairly complex one with maps: rsUnknownDataSetParameter. Just can not figure out why it complains as everything is in there. So I took the advise of a webpage and redeployed the whole report site, and whola! it works. Guess sometimes SSRS just got confused by the versions and maybe I missed something when deploy... (But I double checked!?...)

Saturday, April 30, 2011

Several things that I always need in an application

Recently I have started on quite a few applications, and I found that reinventing the wheel has been a big part of the effort in them. They are all Data Binding applications in Silverlight/WPF. Several things that I found always needed in my applications:
1. Deep Clone: Definitely needed if you need a decent Undo/Redo capability in a Data Binding application.
2. Converters: Converters are a godsend in Silverlight/WPF application. If you are using Data Binding, which is the way to do a Silverlight/WPF app, then you have to use them. Out of the many converters that I did, these are my favorites:
a. Boolean To Visibility
b. Boolean To Brush
3. Implements INotifyPropertyChanged: This is also a given in a Data Binding application. One particular thing about my classes are that they may be from a Web Service (generated by SvcUtil) and you need to conform to the way SvcUtil choosen to implement the INotifyPropertyChanged.
4. Extend classes generated by the SvcUtil from Web Services: Mostly for direct use as the View Model. There are many traps and tricks when doing this. One of them is the inability to step through because of the stupid DebuggerStepThroughAttribute SvcUtil put on every class it generates.
5. Collection that is a union/combo of other collections: A view, so to speak, that merges contents from two or more ObservableCollections and show them as one. On top of that, I also need INotifyCollectionChanged events fired correctly on it when sub collections changed.
6. SetterValueBindingHelper: A great tool by Delay (David Anson) that solves the problem in Silverlight 2/3 (Can not set binding in Style setters).

Friday, April 22, 2011

Decent ways of converting a color from a string name to the Color class

//best, using Color's static method
Color red1 = Color.FromName("Red");
// using a ColorConverter
TypeConverter tc1 = TypeDescriptor.GetConverter(typeof(Color)); // ..or..
TypeConverter tc2 = new ColorConverter();
Color red2 = (Color)tc.ConvertFromString("Red");
// using Reflection on Color or Brush
Color red3 = (Color)typeof(Colors).GetProperty("Red").GetValue(null, null);
// in WPF you can use a BrushConverter
SolidColorBrush redBrush = (SolidColorBrush)new BrushConverter().ConvertFromString("Red");

http://stackoverflow.com/questions/372693/convert-string-to-brushes-brush-name-in-c

Saturday, March 26, 2011

Some CEO knows how to make headlines (but not by doing his job)

According to this CEO, .NET sucks!
What a news! Microsoft has become the new IBM, and open source is the new kid on the block!
I can see this cycle repeating several times now, from IBM to Digital, then to Apple, then to Microsoft, then to Open Source. This is just a natural evolution of the software industry, and it behaves more and more like fashion industry. Open Source is the new Black!
Despite headline grabbing capabilities, there may be some truth to his speech. The fact that few startups use Microsoft do pose a valid question, but the answer sure is not that .NET sucks. .NET is very much up-to-date and still runs at the front of innovation, introducing new things, especially LINQ (Rx and Parrallel LINQ are two of my favorites).
The main reason that .NET is not used widely by startups is: Microsoft costs. Given a choice, many would love to skip the license cost of several thousands and run for a free product, say Linux and MySQL. Language is not the problem here, cost is. However, many argue that the hidden cost of Open Source is not understood fully when these decisions are made. Also, it is kind of funny that you are willing to shell out at least $100k for someone (supposedly) good, but frown upon $5k of industrial strength software.
The main problem is talent. Any good talent, no matter what language is he/she working on, costs. And there are always bad Open Source programmers, as long as they got paid. A good measuring stick of a talent is that if the person does any (for free) sidejobs besides the main one.
During my whole profressional life, I have seen preciously few talents. But what languages do they use are definitely not one of the deciding factors!
Oh, and on top of that, a .NET programmer is better than a Ruby on Rails guy, according to him.

Thursday, March 24, 2011

Oldie but goodie: WSE for .NET framework 2.0

If you are still stuck in the .NET 2.0 world and want to use WS-Security, here is the rescue:
WSE 2.0

Something new again (Two-way SSL Certificate for Web Services)

1. The Intermediate Certificate should be in the Intermediate Store for IIS, otherwise it will not be able to verify the chain of certificates.
2. The certificate store should be for Local Computer, not Current User. And
3. If it doesn't work, delete all certs, restart IIS and do it all over again!

Wednesday, March 23, 2011

Something new (for me) everyday: Easy upsert in SQL Server Integration Services

See here. It also mentions the "Instead of" triggers that are (apparently) there since SQL Server 2000. I can see some magical use of these.

Thursday, February 24, 2011

script tag

This is something that outraged me when I ventured into the la-la land of javascript... :)
If you want to have a <script> tag in html, it can not be something like <script .../>, as any self-respecting tag can do (and a valid scenario when you have a "src" attribute). But rather, you need to have <script ...></script>. This is nuts!
And the reason is that it is not conforming to the xhtml standard as it requires (#PCDATA), thus can not be self-closed...
No matter who comes up with this has to be a nutjob.

atdmt.com and all its troubles

I got a mysterious problem on my Windows 2008 Server R2 machine that drove me crazy. And it doesn't show up on other machines that I have. Here is the problem: When I log into Hotmail, for every email that I click, I will get a popup dialog asking for credentials. And it won't go away unless: Either I click cancel, or if I enter some gabbage and click OK, it will popup again for a total of three times. And the whole thing starts all over again once I click another email. Add insult to the injury, this problem is with every browser that I try.
This behavior is very close to, actully the same as, the behavior for a NTLM enabled website. This makes it bizarre as no sane website would do this on the internet. I did a tone of googling on "hotmail atdmt" and various combinations. And the only result I got refers to the atdmt tracking cookie, which is not really related.
So I finally got fed up and decided that not able to view hotmail is a big deal for my development machine. :). And fired up fiddler on two machines to compare what is going on. And here is what I found:
1. The h.atdmt.com reference was redirected by h.live.com.
2. The h.atdmt.com returned 401 Unauthorized and ask for either "Negotiate" or "NTLM". Another funny part is that it is an IIS/7.5 with Sharepoint 14. (wink)
3. On the "good" machine, this same request will be actively rejected by the host. (wink again.)
4. And finally, the IP address of h.atdmt.com is "127.0.0.1", for both machines!
Everybody knows that "127.0.0.1" is the local host. And that's weird. I tried ping it and get the same result. There is no proxy on my machine so it must be happening from DNS server. But why?
Before I start to venture about the answer to the question, this phenomenome is explained well by the facts that:
a. I have a SharePoint 2010 installed on my local machine and it requires NTLM.
b. There is no webserver on the "good" machine.
So when a request is made to h.atdmt.com(127.0.0.1), the XP machine ("good" machine) rejected it immediately while the 2k8 server replies with 401 and indicates for NTLM (or Negotiate). And the clients faithfully ask for credentials every time!
What I guess the reason this is happening is: For some reason, the central IT people wants to block tracking done by atdmt.com. And what they choose to do is returning 127.0.0.1 when asked for atdmt.com, thus blocking it at DNS level. And unfortunately, hotmail has a love affair with atdmt and try to track every email click that way. And, because I am a developer and have a NTLM enabled website, I got hosed.
Once I got the problem identified, the solution is simple. I added h.atdmt.com to hosts file and gave it an address not in the network. And it works good after that. Thank God, there is peace in the world again...

Thursday, January 20, 2011

Frustration with idiotic .NET Generics

Do you know ObservableCollection(of Object) != ObservableCollection(of ClassA)? Of course you do. But what do you do when you have a generic collection class that you want to generalize (pardon the tone twister)? You need to do a little converter function. However, if .NET can say ObservableCollection(of ClassA) isa ObservableCollection(of Object), life will be a lot easier.
Another thing it will fix is the need to create a non-generic class as the parent type of the generic class in a class hierarchy (to ease the pain of multiple "isa" call in trying to assert the subclass' type). So you can say:
If typeof o Is GenericClass(of Object) Then
instead of
If typeof o Is GenericClassUselessParent Then
to simplify the class hierarchy.

One thing hard learnt regarding Dependency Properties

I was scratching my head like crazy on this one but could not figure it out. It turns out that: if you put a default value of reference type in the Register function of DependencyProperty, this vaue will be shared by ALL instances of the property and cause problems. For example, if you have a property of the type Collection, then all data added to that collection will "magically" show up in other instances too! This has bothered me for a long time and I finally found a good explaination at this web page.