May 28, 2009

History erased in the most cruel manner in China

Uighurs represent a minority islamic community in China with life as simple and ancient as their ancestors. The city has houses that are hundreds of years old. With the Chinese government stating the risk of impending earthquake catastrophe, has initiated complete demolition of the entire city of Kashgar and rebuilding modern structures. The government can relocate them tomore safer structures, but should preserve the old city as a heritage center instead of demolishing it. The NY times article presents more detailed picture of the situation. 


Here is the audio presentation about the same.
http://www.nytimes.com/interactive/2009/05/28/world/asia/20090528-kashgar-audioss/index.html

May 9, 2009

See what happens when you put off or stop caring about…

  • Checking your email every ten minutes.
  • Having everything finished on your to do list.
  • Having an immaculately clean house.
  • Trying to please everyone.
  • Seeking praise and popularity.


May 6, 2009

composite application guidance framework - building modular systems

Loading modules based on rules. This allows you to only load modules that are applicable for a specific role. An application might retrieve from a service the list of modules to load.

Loading modules from different locations. A Windows Presentation Foundation (WPF) application might retrieve modules from the Web, from the file system and/or from a database. A Silverlight application might load modules from different XAP files. However, most of the time, the modules come from one location; for example, there is a specific folder that contains the modules or they are in the same XAP file.

guidelines for developing a modular system:
- should be opaque to the rest of the system and initialized through a well known interface
- modules should not directly reference one another or the application that loaded them
- should use loosely coupled techniques such as shared services to communicate to each other or to the application that loaded them instead of communicating directly
- modules should not be responsible for managing dependencies. should be managed externally through dependency injection
- should not rely on static methods, which inhibits testability
- modules should support being added and removed from the system in a pluggable fashion

design a modular system:
- define module's responsibilities
- module to have distinct set of responsibilities
- each module consists of its own presentation layer, business layer and resource access layer

communication patterns between modules:
- loosely coupled events: publish and subscribe to events for communciation between modules. pattern works when the number of events required to fulfill a task is small. otherwise, overheads happen due to wait time for the event triggers.
- shared services: a class that can be accessed through a common interface. a shared assembly containing common functions such as authentication, logging, configuration is an example.
- shared resources: modules can communicate indirectly through a database or web service instead of communication directly

team development using modules:
- infrastructure team: cross module interfaces and functionality such as logging, authentication
- ui team: shell and visual components design
- operations team: managing deployment of modules

UI composition:
views from multiple modules have to be displayed at run time in specific locations within an application's UI
developer defines layout with named locations within which the views will be displayed at run time
layout can evolve independently wihtout affecting the modules that are adding views to the layout
shell of the application defines the layout at the highest level
the module that defines the view and the view being displayed doesn't have knowledge of how it be displayed in the named location

view discovery approach for composite ui design:
modules can register views against a particular location
when that location is displayed at run time, the registered view will be automatically created and displayed
modules register views with the registry
parent view queries the registry for views registered with a particular location
displays views in the named location control
after the application is loaded, the composite view is notified to handle the placement of views that are added to the registry
composiste application library defines a standard registry called RegionViewRegistry to register views for named locations

view injection approach to composite ui design:
views are programmatically added or removed from a named location by the modules that manage them
application contains a registry of named locations
module can lookup locations in the registry and programmatically inject views into it
the locations adhere to a common interface to inject views
composiste application libarary defines a standard registry called RegionManager and an interface called IRegion for view injection

--> when to use view discovery versus view injection, see the UI Composition technical concept.


May 4, 2009

way to get my silverlight application talking to the COM port on my local computer

There's no access to computer resources, but you can communicate with sockets. So it's possible to have your users install an application which listens on a port and communicates with a COM port. You can do this by opening a socket connection from your Silverlight control to a local socket which intern have the COM port access

Use a XBAP (Browser Deployed WPF) that requests some extra permissions. Would live inside the browser, but only run on Windows machines with .NET 3.0 / 3.5 installed

Write an ActiveX control that talks to the local device and expose an API. Then use JavaScript to consume this API and interact with the JavaScript code from Silverlight. This would give you a in-browser application, but your users would have to install an additional device  ActiveX component.

SL and Javascript two way connectivity sample:
http://blogs.msdn.com/salvapatuel/archive/2008/05/01/build-interaction-between-javascript-and-silverlight-2.aspx

Calling ActiveX from Javascript
http://www.coderanch.com/t/121777/HTML-JavaScript/Editing-Excel-Sheet-using-javascript

Sample code to connect SL, Javascript and ActiveX
SL Mainpage.xaml:
<UserControl x:Class="JavascriptTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" Height="300"
             Name="Xaml1">
    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel>
        <TextBox Name="NameTxt" Width="500" Height="20"></TextBox>
        <Button Name="NameBtn" Content="Send to JS"></Button>
        </StackPanel>
    </Grid>
</UserControl>

SL Mainpage.xaml.cs:
namespace JavascriptTest
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            NameBtn.Click += new RoutedEventHandler(NameBtn_Click);
            HtmlPage.RegisterScriptableObject("navObj", this);
        }

        void NameBtn_Click(object sender, RoutedEventArgs e)
        {
            HtmlPage.Window.Invoke("ExecuteAnimation", NameTxt.Text);
        }

        [ScriptableMember()]
        public void SendMessage(string state)
        {
            MessageBox.Show("Message reached SL");
        }
    }
}

test.html:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>JavascriptTest</title>
    <script type="text/javascript">
        function ExecuteAnimation(params) {
            loadexcel(params);
            alert("Hello, World");
        }
        function load() {
            var ctrl = $get("Silverlight1");
            ctrl.Content.navObj.SendMessage('Hello');
        }
        function loadexcel(params) {
            var ExcelSheet;
            ExcelSheet = new ActiveXObject("Excel.Application");
            ExcelSheet.Workbooks.Open(params);
            //ExcelSheet.Visible = true;
            // Place some text in the first cell of the sheet.
            ExcelSheet.ActiveSheet.Cells(1, 1).Value = "This is column A, row 1";
            // Save the sheet.
            ExcelSheet.SaveAs("C:\\TEST.XLS");
            // Close Excel with the Quit method on the Application object.
            ExcelSheet.Quit();
            // Release the object variable.
            ExcelSheet = "";
        }
        </script>
    <style type="text/css">
    html, body {
        height: 100%;
        overflow: auto;
    }
    body {
        padding: 0;
        margin: 0;
    }
    </style>
</head>
<body >
    <form id="form1" runat="server" style="height:100%;">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div  style="height:90%;">
            <asp:Silverlight ID="Silverlight1" runat="server" Source="~/ClientBin/JavascriptTest.xap" MinimumVersion="3.0.40307.0" Width="100%" Height="100%" />
        </div>
        <input type="submit" onclick="load()" />
        <input type="submit" onclick="loadexcel()" />
    </form>
   
</body>
</html>