preload
Apr 13

This post is about a simple application that I’ve created to get my hands on Silverlight 2. It is simple Digital Clock which shows local time using custom fonts and updates itself every second. My few observations that I would like to share with you:

Demo Application

  1. Custom Font Embedding in Silverlight
  2. Data Binding Modes and using INotifyPropertyChanged
  3. Using Dispatcher.BeginInvoke()

Before we start digging each of above topics lets first have a look at the application in running condition. I have named it SilverTimer.


Download: SilverTimer Source (C#/VS 2008)


Custom Font Embedding in Silverlight

I have used custom fonts (courtesy: DS-DIGI.TTF) in my SilverTimer application. These fonts are first downloaded automatically by the Silverlight Runtime. Here is excerpt showing how to embedd custom fonts -


FontFamily is comprise of this format – FONT_FILE#FONT_NAME. Having said that font file is “DS-DIGI.TTF” and the font named “DS-Digital” and are separated by‘#’. The real beauty is that we need not write any single line of code for downloading the font-file. Just keep DS-DIGI.TTF file “ClientBin” folder where the XAP file is located. One thing to note here is that before you use custom font you need to change the Build Action for your Font file to ‘Resource’ as shown below. This will make it as an assembly resource.

Digital_prop

This is all you have to do to use the custom fonts. If you wish to know more about custom font embedding, you can watch this great video tutorial by Tim Heuer

Data Binding Modes and using INotifyPropertyChanged

I’d like to discuss it in three basic Steps

  1. Specifying DataBinding Mode
  2. Set the DataContext
  3. Implement INotifyPropertyChanged interface to the business object

Silverlight supports binding of Business Object properties with the UI Controls. The data flow between these can be controlled by specify the Data Binding Mode between source and target. Here source is the Business Object and target is the UI control. Modes supported are -

OneWay” – Binds source and target and update target subsequently as the source gets updated. (source -> target)
TwoWay” – It keeps source and target in sync. Source is updated when a target changed and vice versa. (source <-> target)
OneTime” – As the name suggest, it updates target with the data and never updates when a source get updated.

In application, I’ve used ‘OneWay’ Binding Mode to update the Time in application. Below is the excerpt from Page.xaml -


Here we are talking about this bit  “Text=”{Binding CurrentTime, Mode=OneWay}”, You can see the Text property is bind to the CurrentTime property and the mode is defined as ‘OneWay’.

Now, we need to specify which Object this property is associated with. We have to set the DataContext of target control to the Business Object. It goes like this -

txtTimer.DataContext = objTimer;

Specifying the Mode doesn’t do the job we need some mechanism/event which tells the UI controls (TextBlock) to update itself when a property of business object changed. This can be achieved by implementing the INotifyPropertyChanged interface to the business object. The INotifyPropertyChanged interface is used to notify clients, typically binding clients, that a property value has changed. In this case Timer.cs is the business object that implemented this interface and should raise a PropertyChanged event when “CrrentTime” is changed. -

        public string CurrentTime
        {
            get
            {
                return currentTime;
            }
            set
            {
                currentTime = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this,new PropertyChangedEventArgs("CurrentTime"));
                }
            }
        }
  .. .. ..

Whenever the CurrentTime property changed it notify the clients and they will be updated accordingly. You can go through this excellent video tutorial by Jesse Liberty

Using Dispatcher.BeginInvoke()

Dispatcher.BeginInvoke is used to execute the delegate asynchronously. Dispatcher is associated with the thread which is UI thread in this case. Why we need to use this? Form controls should be accessed in a thread which they have been created. Doing otherwise may throw “Invalid Cross-thread access” exception.

So, as soon as “CurrentTime” property is changed, the binding controls will be notified which is trigger by the “PropertyChanged Event” of “INotifyPropertyChanged” interface. But as this happen in a new thread this cause “Invalid Cross-thread access” exception.

The key to resolve this error is to update the “CurrentTime” property using dispatcher which guarantees the code to be executed on UI thread.

         public void RunTimer(object oDispatch)
        {
            while (true)
            {
                // Making asynchronous call to update the Texblock using the UI Thread.
                ((Dispatcher)oDispatch).BeginInvoke(() =>
                   {
                       //Updating the property which inturn notify the clients to udpate.
                       this.CurrentTime = System.DateTime.Now.ToLongTimeString();
                   }
               );

                // New thread sleeps for one second.
                System.Threading.Thread.Sleep(1000);
            }
        }

I hope you may have find this information useful. I would like to hear your comments and queries on this.

Tagged with:
Apr 10

This is one of my favourite monologue in movie history by Alec Baldwin from the movie ‘Glengarry Glen Ross’.

In this scene, Alec Baldwin is confronting the employees of a tough Chicago real-estate office. Alec Baldwin plays a perfect Hitler in this performance.

The look on Jack Lemon’s face when Alec Baldwin pulls out the brass balls says it all.

Tagged with:
Apr 08

IBM Rational User Group

IBM is presenting Rational User Group Launh on 21st April, 2009 at Hotel Taj Mahal, Delhi. Here is the excerpt of the mail I received…

It is our pleasure to invite you to Rational User Group meeting in Delhi on 21st April, 2009.

You are cordially invited to attend the launch and join the community of Rational users in Delhi.

The Rational User group will provide a platform for discussions with like minded people, share best practices and have some fun while we are at it.

The agenda will cover latest topics from Rational Software.

Please mark your calendars for the 21st April, 2009 from 5.00p.m onwards at Taj Mahal.
Do join us for dinner thereafter.

Thank you and look forward to meeting with you.

Agenda Topics:

* What is Jazz and Change Management using Rational Team Concert
* Quality Driven Software Delivery through Rational Quality Manager
* Secure Web Applications using Rational AppScan

Date: 21st April, 2009

Venue: Taj Mahal, Delhi

Click here to register

Tagged with:
Apr 08

Microsoft has announced a new camera for aerial photography. It is a 92 megapixel camera that they used for Bird’s Eye view on Live Maps. Did you know that Microsoft makes camera?

Tagged with:
Apr 05

A really cool funny video on Youtube by Julian Smith.

Tagged with:
Apr 01

cyber-threat

1. Collaboration Tools

Tools that help people collaborate i.e. IM, IRC, Social Networking Sites, Video Conferencing, and White Boards. Users can expect to see a surge of attacks through collaboration tools, as membership continues to increase. These tools will help cyber criminals in stepping up to hit interactive social networking site with unsolicited e-mail and malicious links. Ignorance about clicking on an ‘interesting link’ will be exploited by the bad guys on internet.  The cases of identity theft, cyber-stalking, cyber-bullying and cyber-extortion are expected to rise. At the corporate level, this may give rise to increase data theft from corporate databases.

2. Virtualization

Now a day’s companies are using virtual environments to reduce cost, save space and to increase convenience for their employees. Virtualization includes running a platform (Linux) on a different platform (Windows). But virtualization makes the security more complicated as it introduces an extra layer that must be secured. Now we have to secure both Virtual machine and the physical machine.

3. BotNet

A bot planted on the machine, maintains a command and control mechanism to enable communication with its master. A large number of such bots under command of the same master becomes a “bot army“ that has considerable computing power to engage in a variety of malicious activities including data theft, DoS attacks, spam delivery, NDS spoofing , to name a few.

4. Cyber Warfare

The low cost associated with launching cyber attacks as compared to physical attacks, the likely deniability of crime committed on the internet and the lack of international cyber laws to resolve conflicts between nations, are the main reasons for many governments mentoring cyber warfare. The vulnerability in systems , user ignorance and overdependence on outsourcing agencies are likely to be the main reason for the success of cyber warfare. The cyber attacks that occurred between Russia and Georgia in 2008 are indicators for military cyber engagements in 2009 and beyond.

5. Phlashing attacks

The attacks on network devices (router, switches etc) and other hardware systems that rely on firmware to contain OS related problems are likely to increase. In this type of attacks, hackers upload nonauthentic firmware to devices under the guise of original firmware updates. However this malicious firmware provides a back door into a network or permanently disables the devices. This may result to completely denial-of-service attacks.

6. Wireless Risks

Wireless will continue to be a big threat in 2009. Insecure protocols, easy accessibility, lack of strong encryption and authentication and more importantly, user ignorance are the main reasons for the increase in wireless risk.

7. Threats due to Green Computing

Using computing resources efficiently is certainly a good thing. But extra care should be taken while recycling computer resources, for example it can expose your data to a stranger if you don’t ensure that the hard drives have been completely wiped.

8.  Cloud Computing

Cloud computing is a buzzword these days.  It is a style of computing in which resources are accessed as a service over Internet. In this technology all of your resources are kept in terminals that are placed somewhere else. But when your data is placed somewhere else you can’t ensure the security of your data from everyone else out there.

9. Insider Threat

The financial meltdown and resulting lay-offs may fuel employee discontent, to cause serious threat to corporate networks and data theft.

10. Risk for OS other than Windows

Linux is safer than Windows. Is it true?
The reason Linux enjoying this reputation is Linux is not much popular as Windows is. Major portion of desktop OS market is acquired by windows. But as the popularity of Linux will increase, attention of bad guys toward Linux will also increase. There will be more targeted attacks on Linux in coming years.

Tagged with:
Mar 31

gv

If you have an outstanding idea for a StartUp and worrying from where all the money required would flow in. DON’T WORRY.

World’s largest search engine Google is ready to help you with your startup. Under the management of Rich Miner and Bill Maris google announces Google Ventures. Google Venture is a effort to use google’s resources to encourage entrepreneurs and new companies.

For Entire Story visit www.google.com/ventures

Tagged with:
Mar 31

Asp.net configuration file, web.config (machine.config at server level)  applies to the directory in which it appears and all sub - directories. The configuration file hierarchy for a Asp.net site goes as shown below.

Asp.net Configuration File Hierarchy

Here is a link where you can read more about web.config inheritance. While settings are inherited from the higher level of configuration file, child configuration files are always permitted to override them. Inheritance downward is useful for applying a unique settings for all applications on server but in certain situation a higher config file may want to prevent inheritance in child applications. This can be achieved by using the <location> element as follows.

<location path="." inheritInChildApplications="false">
<system.web>
...
...
</system.web>
</location>

The above code can prevent inheriting the <system.web> element in this case, into the child web application. Please note that this piece of code should be placed in the parent’s web.config file.

Tagged with:
Mar 27

When I say “Fastest”, I mean fastest in anyway like a drag bike. So does guys from HostMySite.com. They said that they have created a World fastest server which is actually a customized fully electric Drag Bike that can go from 0 to really fast within 2 seconds. They are also hosting a contest on CodeProject.com.

World Fastest Server

World Fastest Server

See the evolution of this bike in this full album. Wendy and Matt have taken their fun interview at SXSW, checkout it here.

Tagged with:
Mar 22

Microsoft has released the final version of Internet Explorer 8 at MIX09. IE8 has many new features with it, like InPrivate Browsing, Web Slice, Compatibility View etc.
The feature I like the most is Web Slice

What is a Web Slice.
Web Slice is a new feature in IE8 which allows users to subscribe to a portion of a webpage. Web Slice behave just like RSS feeds for a portion of a webpage.  Web slice are based on hAtom Microformat and hSlice Microformat. Any developer can create a web slice in a existing webpage just by annotating HTML with class names for title, entry content and other properties.

How to create a Web Slice.
Here is a simple working example.
Note: Web Slice works only when page is served by a server.

WEB SLICE Example

WebSlice Title

this is the content that will appear in the preview window
10
Tagged with: