using Dojo Inheritance to inherit the map in ArcGIS JavaScript API

I am using ArcGIS JavaScript API to build a map based application.
The usual code to create a map, and set its extent is as follows:


var ext = new esri.geometry.Extent({ "xmin": -8869000, "ymin": 5689000, "xmax": -7303000, "ymax": 6639000, "spatialReference": { "wkid": 102100 } }); var popup = new esri.dijit.Popup(null, dojo.create("div")); app.map = new esri.Map("map", { "extent": ext, "infoWindow": popup, "slider": false }); var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"); app.map.addLayer(basemap);

The above code will create a map , and set its extent to Quebec city, in Canada.

For me, I had a huge script that I wanted to refactor and make it look better.
One idea was to take out the code that set the extent and layers to Quebec, and have the code in its own class. And will be cool to inherit that class from esri.map.
So, I will have a class "quebecMap", which when I create it , will create esri.map, with extent and layers match Quebec map.
So the code was like that
dojo.declare("quebecMap", esri.Map, {
   constructor: function (divId) {
       this.extent = new esri.geometry.Extent({
            "xmin": -8869000,
            "ymin": 5689000,
            "xmax": -7303000,
            "ymax": 6639000,
            "spatialReference": {
                "wkid": 102100
            }
        });
        
        this.infoWindow = new esri.dijit.Popup(null, dojo.create("div"));
        this.slider = false;
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer");
        this.addLayer(basemap);
   } 
});


The above code defined a class called "quebecMap" , which will create esri.map that setup to show Quebec data.
Then to use it, just write the following code:


var mapObject = new quebecMap("mapDiv");
/* where mapDiv is the html DIV's id that will contains the map */

cool, isn't it?

Dojo: the underrated gem

In my current project, I am working with ESRI's ArcGIS JavaScript API
The first thing you notice, that the JavaScript API was built with Dojo framework.

And the immediate question, why they chose Dojo, and not JQuery?
JQuery is more popular.
But after I started learning Dojo, I was impressed.
Dojo is not only DOM-query and manipulation.
It is expanded to be more. and if you work with one of its extension dojo.data, you will find that dojo.data is a simple MVC framework for building JavaScript application.
I found it more difficult than JQuery, but it worth the fight to learn.

To all Javascript developers

If you didn't work with Aptana, then leave everything you are doing and go and grab it

Installing Windows 8 on VHD

Wow!!
I had a wonderful experience installing Windows 8 on VHD today on my machine.
I followed the perfect guide from Scott Hanselman on how to install Windows 8 on Virtual Hard Drive.

The feature of Virtual Hard Drive in windows 7, and the notion that you can create a bootable windows OS from it, is something beyond amazing, and it is astonishing.

It is so amazing, because you can build a whole machine, that contains the OS, and add many other applications, while keeping all that software stored in just one file in the parent operating system.

I know it might look like a virtual machine, but it is better, because the new OS runs without the parent operating system, and actually there is no parent operating system.

It runs "naturally" on the machine accessing all its devices.

It is like dual booting, but better, and it is like a virtual machine but better.

It combines the good part of virtual machine, and the good part of dual booting.

excerpting from Scott Hanselman post

Virtualization vs. Dual booting:

Multiboot:

  • Good performance (runs natively on the machine, no extra abstraction layers)
  • Good hardware integration (everything that is built into or attached to the machine is visible to the running OS)
  • Clunky setup (different boot loaders overwriting each other, partitions cannot easily be resized or moved around)

Virtualisation

  • Very flexible (only takes up as much hard disk space as the solution requires)
  • Can run virtually any Operating System
  • Non-Optimal performance (running piggyback off another Operating System, consuming resource in both)
  • Marginal hardware integration (all major system components are virtual only; depending on the virtualisation solution, SOME components might be surfaced inside the virtual machine)

So, the boot from VHD will have to pros of both, avoiding the cons of both

And if you don't like the new OS, just delete the file.
Isn't that the magic itself?

The different Visual Studio Command Line tools

After installing Visual studio, you will have many different command line tools.
Each one will run different start-up script to set the environment variables that are essential for the build.
I learned something useful about them, after I chose the wrong command line to do the build.

I was running MSBuild project today from the command line to build a project, and I kept getting this error:

error MSB4126: The specified solution configuration "Debug|X64" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU")

I debugged the build process by making the "Verbosity" level to "d[etails]", and I was sure that the "Configuration" property of the build was Debug.
Then it must be the platform.
In order to know what platform is being used, I switched the "Verbosity" level  to "diag[nostic]", and I found that the Platform variable was "X64"

Then, I figured out that when I opened the Visual Studio command line, I opened the one which titled "Visual Studio x64 Command Prompt".

Gettings all tables with their primary keys in SQL Server

I had to write a SQL to get all the tables with their primary keys separated by commas.
So I thought I will share this
This query will select tables inside a specific schema, which is specified in the where clause ('anyschema')

WITH Ranked ( TABLE_ID, TABLE_NAME, rnk, COLUMN_NAME ) 
AS ( SELECT TABLE_ID,TABLE_NAME,
ROW_NUMBER() OVER( PARTITION BY TABLE_ID ORDER BY TABLE_ID ),
CAST( COLUMN_NAME AS VARCHAR(8000) )
FROM 
(SELECT     ST.object_id AS TABLE_ID, ST.name AS TABLE_NAME, SC.object_id AS COLUMN_ID, SC.name AS COLUMN_NAME
FROM         sys.key_constraints AS SKC INNER JOIN
sys.tables AS ST ON ST.object_id = SKC.parent_object_id INNER JOIN
sys.schemas AS SS ON SS.schema_id = ST.schema_id INNER JOIN
sys.index_columns AS SIC ON SIC.object_id = ST.object_id AND SIC.index_id = SKC.unique_index_id INNER JOIN
sys.columns AS SC ON SC.object_id = ST.object_id AND SC.column_id = SIC.column_id INNER JOIN
sys.types AS STY ON SC.user_type_id = STY.user_type_id
WHERE     (SS.name = 'anyschema'))a
),
AnchorRanked ( TABLE_ID, TABLE_NAME, rnk, COLUMN_NAME ) 
AS ( SELECT TABLE_ID, TABLE_NAME, rnk, COLUMN_NAME
FROM Ranked
WHERE rnk = 1 ),
RecurRanked ( TABLE_ID, TABLE_NAME, rnk, COLUMN_NAME )
AS ( SELECT TABLE_ID, TABLE_NAME, rnk, COLUMN_NAME
FROM AnchorRanked
UNION ALL
SELECT Ranked.TABLE_ID, Ranked.TABLE_NAME, Ranked.rnk,
RecurRanked.COLUMN_NAME + ', ' + Ranked.COLUMN_NAME
FROM Ranked
INNER JOIN RecurRanked
ON Ranked.TABLE_ID = RecurRanked.TABLE_ID
AND Ranked.rnk = RecurRanked.rnk + 1 )
SELECT TABLE_NAME, MAX( COLUMN_NAME )
FROM RecurRanked
GROUP BY TABLE_NAME;

SQL Server express connection and the firewall

I was struggling today to connect to an instance of SQL-Server express from a remote machine.
I did every steps that Microsoft mentioned, and didn't have luck
1 - I enabled TCP protocol, and Named pipe protocol.
2 - I checked the checkbox of "Allow remote connection to this server"
3 - I started SQL Browser
and no luck.
Then I thought it is a firewall
I added SQL server application "sqlservr.exe" to the exception list of the firewall, and still no luck.
Then, I started to read about what the browser service is doing.
I added the SQL browser service application to the exception list of the firewall, and voila, it worked.

So, what I learned is , the browser service is an application that will listen to any connection request on any port.
When you connect to SQL server, you don't specify a port.
and the Browser will listen to any request on any port, and route it to the Sql server Service.
If you want to connect on a specific port, and you add that port into your connection string, then you don't need the Browser service running.