![]() |
|
Spaces home John Liu .NET: Time for ...ProfileFriendsBlogMore ![]() | ![]() |
|
John Liu .NET: Time for Fun in .NETdotnet - silverlight/wpf - consulting - games
Sharing a little gem - ASP.NET Javascript String.formatWhen you are working with ASP.NET 2.0, Microsoft injects quite a bit of Javascript framework stuff. Most ASP.NET developers don't dive into these libraries and thus never know the gems that Microsoft has added in their Javascript framework. I'm just going to share a little gem today, Microsoft has implemented a full version of the String.format in Javascript - in the same style as the .NET counterpart. So in Javascript, you can do:
String.format( "{0:d}", new Date() ); or String.format( "{0:c}", 100 ); Do watch out these values are localized to your current culture - whether it's [en] or [en-us] or [en-au], these are set in your browser's settings. Have fun! jliu New MacBook to have glass trackpad (End of September)Source I've got to say the multi-touch glass screen on the iPhone is pretty neat - and I've seen the multi-tracking trackpad on the macbook. Tristan Kurniawan owns one. Couple of other guys in the office already have, or are getting their MacBooks soon and dual boots daily. Personally I'm still not convinced the MacBook is worth twice the cost of other notebooks such as offerings from Dell, Acer or Asus. A typical dual-core laptop with 4GB ram and readyboost should be able to handily out perform a MacBook any day. But anyway, with all the chatter about touch trackpads, here's my prediction for 2010:
Year 2010, Steve Jobs unveils the MacBook Super Touch Pro. There is no keyboard or trackpad for this MacBook, the touch keyboard functions as:
In other news, Microsoft complained that this was the same surface technology they've demo'ed 5 years ago in 2005 (but never worked out how to sell it properly). In yet more other news, Homer complains that he can no longer use the drinking bird to press the Y-key on his MacBook. Because the keyboard detects human touch only. jliu HTML map and area tags not working for FireFoxHere was an interesting problem, what was wrong with the following code, which works fine in IE but not in FireFox <map id="mymap"> <area ... /> <area ... /> </map> <img usemap="#mymap" ...>
It appears that FireFox doesn't understand the id attribute and the name attribute is required. According to W3C recommendations, http://www.w3.org/TR/REC-html40/struct/objects.html#adef-usemap the usemap attribute should match the name attribute of the map tag. Try this instead: <map id="mymap" name="mymap"> Customizing CSSLink and ScriptLink for public Sharepoint siteMSDN has quite a thorough topic on optimizing a Sharepoint Server for public facing site: http://msdn.microsoft.com/en-us/library/bb727371.aspx I would just like to add a few more points and share some thoughts on our experiences of customizing for performance in addition to this guide.
Good luck! The best way to learn to customizing Sharepoint for an ASP.NET guy - use ReflectorThis is probably the best best tip I'm going to share so far with regards to Sharepoint. Think of Sharepoint as a pre-built framework on top of ASP.NET, if you are working within the confines of the multitude of options Sharepoint gives you, then you need a big thick book on Sharepoint. If you are thinking about customizing Sharepoint, then you're beginning to face a problem I had. How does it all work, and perhaps more importantly, why does it just not work? You can resort to Google. In which case, I hope you find this blog. Or you can grab Reflector and peek inside the secrets of Microsoft.Sharepoint (WSS) and Microsoft.Sharepoint.Publishing (MOSS) assemblies. I'll share with some findings real soon. Tough to love Sharepoint Recently started doing some work on Sharepoint, it's really tough to love Sharepoint. At a glance, it seems that this is just a technology that's build on top of ASP.NET, so surely it's got all the goodness of ASP.NET + more build-in goodness. Actually, I'd almost say it's the opposite. It's got all the goodness of ASP.NET locked away where you can't easily use to customize your solution. So if you are after something out of the box with light modifications, Sharepoint is really your friend. As soon as you want heavy modifications, it feels like a complete road block. Still, it has some really great publishing features, which distinctively makes it very compelling for an enterprise to use and set up. I'll have more to say very soon. Where is the DataRepeater for Silverlight?I came across a really puzzling thing while playing with Silverlight tonight, try as I might, I couldn't find a DataRepeater style of control. Basically, this is what I wanted to do: <StackPanel x:Name="actions" Margin="10,0,10,5" Orientation="Horizontal" > <HyperLinkButton Content="{Binding ActionName}" Click="Action_Click" /> </StackPanel> And then bind these to an array of actions in the datacontext. Sadly, StackPanel doesn't support ItemTemplates, and looking around, it seems that the only controls that supports binding collections properly are ListBox and TabControl. The Grid control is purely for positioning. The ItemsControl (and the child class ListBox) supports ItemTemplate, but refuses to tile my hyperlinks one after another horizontally, until the width is full and it wraps around. Bummer. I've settled temporarily with adding the HyperLinkButtons in the codebehind inside a foreach loop. But not using databinding for this task makes me sad. I will get to the bottom of this.
Starting another journey, againI've finished one leg of my journey at Oakton www.oakton.com.au and have decided to return to my old company www.ssw.com.au to continue my consultant dream. The reasons are long and numerous, but I'd just say that the biggest factor is there was a really good situation for me and I grabbed it before the window of opportunity disappeared. In a sense I feel I've learned a lot in the three years I've spent wandering around in the wilderness, I've experienced:
But some things remains the same
(Thanks to Dinesh for fixing the rhyme on "flops" for me - second line) I leave my old colleagues with what I've always firmly believed consultants do
So with a happy fondness for all the great memories, I bid my old colleagues farewell for now. Your windows service started and stoppedThe name-of-your services on Local Computer started and stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service. I had fun with this one for a bit. Developing Windows Service is one of those "I rarely do this" activities. So when I got one of these errors when I start my service, immediately I switch into "Ah I must have forgotten something" mode.
I couldn't attach a debugger to the service given that it doesn't stay running. So that limited my options a bit. Turns out, the "informational message" was pretty misleading, I had the following in my event log. Service cannot be started. System.NullReferenceException: Object reference not set to an instance of an object. Oops. Fixed that error, and the service starts successfully. this.consulting.lifeBeing a consultant is:
--- Mark: When you charge a fortune Mark: The clients expect a miracle John: So we are "miracle workers" Mark: Pretty much --- Client: We have a situation here Client: One miracle worker may not be enough Client: We need a team of Moses, to part the Atlantic ocean, cause this thing is sinking pretty fast --- There are good consultants and great consultants.
--- A consultant (especially an expensive one) is a secret weapon used (usually by newly-appointed upper management) to wedge open layers of old office politics to introduce change. It is often excruciating for the consultant. A consultant has to preach new technology, methodologies and win converts. People do not like change. They will resist change. Sometimes they will threaten to leave, and blame it on the consultants. Ultimately, the company will realize the changes were for the better, but the consultant is never around by then to see the benefits come to fruition. --- A process takes an internal dev guy 5 days to do. Because he needs several permissions and find a time that's suitable for everyone involved to have a meeting. It usually takes an external consultant 2 hours to come to the same decision. Because an expensive consultant is too expensive to keep around for 5 days. Management will move mountains, switch appointment times, even *gasp* cut short their lunch break to make a meeting. Price tag is everything. Quick tip: Initialising Dictionary inlinevar dictionary = new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" }, { "key3", "value3" }, }; var list = new List<string> { "value1", "value2", "value3", }; You might notice that I like to leave the comma behind the last element in my inline initializers - this is actually unnecessary. But having it there means that I can copy/paste entire lines and move them around without worrying about missing comma right at the end. For example, this is valid code: var list = new List<string> { "value1", "value2", "value3" };But if I had to swap the order of the elements and end up with this code, this is not valid. var list = new List<string> { "value1", "value3" "value2", }; Generic EventArgs<T> implementation (but isn't really all that useful)public class EventArgs<T> : EventArgs { private T t; public EventArgs(T t) { this.t = t; } public T Value { get { return t; } set { t = value; } } } To use this class: public EventHandler<EventArgs<String>> Notification; protected void OnNotification(string message) { var handler = Notification; if (handler != null) { handler(this, new EventArgs<String>(message)); } } While this code is all nice and dandy, I wonder if it's all that useful. One of the things with custom event args is that they may grow over time, and this implementation doesn't support future scenarios that well. My colleague Dinesh mentioned that perhaps I'll end up going down the Func<> route, ie: EventArgs<T>, EventArgs<T, U>, EventArgs<T, U, V> Personally I think that's a bit challenging: If I had to add an future int property to my EventArgs<String>, changing the event to EventArgs<String, int> doesn't automatically fix the issue - as all my event hooks will now stop compiling, because EventArgs<String, int> doesn't imply it inherits from EventArgs<String> Anyway, nice looking bit of code but I'd say not greatly useful. A camera of the futureIn the future, when you take a picture of something, the camera generates a 3D scene of it and stores it in memory. Camera will need 2 lens to work out the distances and generate the 3D model. Camera will record and generate the textures that we can see. When looking at the scene from the angle that the picture was taken at, the resolution is as good as a flat-picture camera. Missing entry: setting DateTimeFormat.ShortDatePattern across the entire ASP.NET applicationThis entry is about a week overdue, nonetheless I shall post it now: In the global.asax, before page execute, do this: protected override void PrePageExecute(Page page) { // change short date pattern of the current culture short date pattern CultureInfo info = (CultureInfo)CultureInfo.CurrentCulture.Clone(); info.DateTimeFormat.ShortDatePattern = "dd MMM yyyy"; System.Threading.Thread.CurrentThread.CurrentCulture = info; base.PrePageExecute(page); } I'm using CompositeWeb.WebClientApplication here, if you are using vanilla ASP.NET, you can use a whole lot of different events such as BeginRequest. Take the current culture, clone it (because the current culture is read-only). Then set the short date pattern to something universal like "dd MMM yyyy"; This affects all instances where these are used: datetime.ToString("d"); This fixes issues for our application that is used by both American (MM/dd/yyyy) and Australian (dd/MM/yyyy) audiences. Ideally, the user would set the language setting in their browser to the appropriate locale (en-US or en-AU), but this is too hard to force upon our non-technical users and the risk of someone misreading a date is too high, so we've opted for the "dd MMM yyyy" format which everybody understands. jliu Updating from SilverLight 2 Beta 1 to Beta 2Cannot specify both Name and x:Name attributes
Update project references
That was all the changes I had to do. I think I escaped lightly this time. Oh the joy of playing with beta software. Modelling the system
Here's a nice pretty diagram of the various components of modelling a (any) world. In my case here, the world is a virtual world. You would noticed quickly:
One final work remains in this modelling exercise:
Inspiration strikes - RTS ChessChess is typically a turn-based game. You move, my move, your move again. I had this inspiration to make a RTS chess, how would it work?
We have Real-Time-Strategy Chess!
Do we really need that many controls in Silverlight?I was digesting Scott Gutherie's blog on Silverlight 2 Beta 2
It really made me wonder, do we really need that many different types of controls built-in with the default Silverlight installation? Beta 2 now has around about 30+ controls, and the only one that I've noticed is missing, is the combo-drop down list control. I'm guessing if they really plan to end up with so many controls, then perhaps they'll start by porting across all the various controls that currently WPF have and Silverlight doesn't. Edit: Oh and some sort of Menu control Lack of statistics for Windows spaces.live.comThe statistics capabilities for Windows Live wetted my appetite for better statistics reporting. Why on earth:
Anyway, the lack of statistics really is beginning to be a pain in the neck, makes me feel that no matter what I do, Windows Live spaces just doesn't support me to grow my blog, unlike other service providers like Blogger or WordPress. (Both of them easily integrates with Google Analytics). Which drives people back to use AdWords. Sure we hate all things Google ;-) Silverlight 2 Beta 2 coming really soonAll signs points to Silverlight 2 beta 2 coming within the week: The biggest news I can find:
Edit:
Doing a simple timeout page with WebClientApplication<%@ Application Language="C#" Inherits="Microsoft.Practices.CompositeWeb.WebClientApplication" %> <script Language="C#" RunAt="Server"> protected override void PrePageExecute(Page page) { // True when the current session was recreated with the current request if (Session.IsNewSession) { // redirect if the requested page is not Default or the Timeout page // or if the request method isn't GET if ((!(page is Retail.Web._Default) && !(page is Retail.Web.Errors.Timeout)) || Request.HttpMethod != "GET") { Response.Redirect("~/Errors/Timeout.aspx"); return; } } base.PrePageExecute(page); } This approach relies on the Session.IsNewSession property to tell us if the current session was created with the current request, with a bit of convenience support for the timeout/default pages. Nikhil has a more detailed solution: Detecting Session Timeout in ASP.NET 2.0 Web Applications if you want to differentiate between
vs
GMail getting slower and sloowweerrThere could literally be thousands of reasons for why GMail seems to be running slower and slower for me:
The thing is, it really shouldn't be "my problem" to work out what's wrong with GMail. As far as I'm concerned, other websites continue to work fine, and if I switch to the basic GMail view, it works fine too. So there must be something wrong with the standard version of GMail.
Which really got me to think about the whole connection between web and PC. I use GMail because:
I use an offline mail program (like Windows Live Mail) because:
You would think Microsoft should theoretically have an advantage with their desktop/web integration strategy, I'm just not sure why it hasn't been executed (or received favourably) yet. Laptop has three vertical lines nowLooks like my Dell Inspiron is really heading for the trash can. Dell customer care has got back to me with some model numbers that the out of warranty replacement covers, unfortunately the bad news for me, my LCD isn't one of those part numbers. Not sure where to go now:
Nikhil Kothari's behaviour framework for SilverLightNikhil here describes a mini behaviour framework for SilverLight, and then proceed to implement a DefaultCommit, AutoComplete and TextFilter behaviours that can be attached to the SilverLight textbox. Very cool.
|
|||||||||||||||||||||||||||||||
|
|