Saturday, November 21, 2009

How to keep track of what you learnt?


This is a nice article that resonated with the method that I use to learn. I use the notepad approach, I keep a diary/notepad and write what I learn and it serves dual purposes, as an index for my learnings (so that I can go back and quickly reference) and the act of writing it makes me retain it longer.

http://www.freestylemind.com/how-to-keep-track-of-what-youve-learnt/

Thursday, November 5, 2009

.NET - Serialization to XML and back - Saving/reading custom configuration files

XML serialization in the .net framework is a powerful and very useful technology, yet I wasn't too familiar with it, so I felt I should blog about it. One of the situation where I think it is very appropriate to use this is to create custom configurations and read/save/modify them for web (server) or desktop applications. Using the asp.net Cache class it is also possible to assign the serialized file as a cache dependency thereby re-read and re-hydrate the serialized object from the xml file. This is a perfect scenario for xml configuration files. The below links are references and the code is from "switch on the code c# xml serialization tutorial", link shown below.
STEP 1: Create a simple .net class (Plain old .NET object, PONO), for example:

public class Movie
{
  public string Name
  { get; set; }

  public int Rating
  { get; set; }

  public DateTime ReleaseDate
  { get; set; }
}


STEP 2: Serialize it to Xml using the XmlSerializer class:


static public void SerializeToXML(Movie movie)
{
  XmlSerializer serializer = new XmlSerializer(typeof(Movie));
  TextWriter textWriter = new StreamWriter(@"C:\movie.xml");
  serializer.Serialize(textWriter, movie);
  textWriter.Close();
}

It would produce an XML file, named movie.xml, as:
<?xml version="1.0" encoding="utf-8"?>
<Movie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Title>Starship Troopers</Title>
  <Rating>6.9</Rating>
  <ReleaseDate>1997-11-07T00:00:00</ReleaseDate>
</Movie>




STEP 3: Modify the Xml file and deserialize (update and re-hydrate) the .net object from the xml file:

static Movie DeserializeFromXML()
{
   XmlSerializer deserializer = new XmlSerializer(typeof(Movie));
   TextReader textReader = new StreamReader(@"C:\movie.xml");
   Movie movie = (Movie)deserializer.Deserialize(textReader);
   textReader.Close();

   return movie;
}


Wednesday, November 4, 2009

Flex: Export chart / graph or some other component to image (save as image)

This was a non trivial issue prior to Flex 3 - most people had approached this using a mix of client and server side technologies, even using javascript as well. But most of the solutions were not simple or elegant, this is where Flex3 came to the rescue with the ImageSnapshot class. Doug McCune created an interesting approach using javascript and serializing image bytes to the browser address bar, although not simple, it is creative and that dynamic chart is great.

Today it is a very simple thing to do. It is a two fold problem with a very easy implementation thanks to the awesome flex framework.Graham Odds wrote a great article on how to do this and I'm elaborating on his article.
  1. Save the UIComponent as an image (you can specify the image format) using the ImageSnapshot class
  2. Send the image to be saved to the user's computer (using the FileReference class from Flash 10)
All UIComponents in flex extend DisplayObject which can be exported to an image, e.g. png,, jpg, etc using the ImageSnapshot class. Currently there are two classes that can take BitMapData or ByteArray  and convert them to an image format, class that implement interface IImageEncoder allow this. The image encoders are: JPEGEncoder and PNGEncoder. Once it is exported to an image, the byte data can now be transferred to the user's computer and saved as a file.This is done using the FileReference class introduced in Flash 10.

Below is the code snippet to do this (source) :
 
/**
 * Attempts to save the chart to the user's file-system.
 */
private function saveChart():void
{
    var image:ImageSnapshot = ImageSnapshot.captureImage(myChart, 300, new PNGEncoder());
    var file:FileReference = new FileReference();
    file.save(image.data, "chart.png");
}

Saturday, October 31, 2009

Transform any flex component with resizing, dragging with handles

Try it out yourself:



This is called "Flex Object Handles" available from Marc Hughes. This project is available on google code and has excellent tutorials, documentation, forum activity and support. This library supports using a custom container for flex components to enable thme to be resizable, draggable, moveable  and provides handles etc.

Another example:

Wednesday, October 28, 2009

Interesting article on how a plane ticket can be free

In europe there are plane tickets that costs around $20. How is this possible?
The article below explains this.

Awesome cloud formation in the sky

This cloud formation really stuck in my mind invoking some crazy imaginations. What if we had huge tubes like these as conduits to space, or maybe a halo ring/conduit around our planet with a habitats in it. Pretty cool :)



Here's some more cool looking clouds:
* http://www.webdesignerdepot.com/2009/10/the-weirdest-clouds-that-youll-ever-see/
* http://www.wired.com/wiredscience/2009/09/clouds/

Thursday, October 22, 2009

How to trigger some javascript (client-interaction) the very first time the page is requested in an ESRI .NET web ADF based web application?


Since the esri .net web adf is based on asp.net ajax we can leverage the client application and page lifecycle to trigger activities in different phases of the lifecycle. 
The below illustrates what happens during first page load, partial page postback, and browser close/moving away:
 A. During first initial page request: (1st time the page is loaded or refreshed)
APP_init
APP_load
APP_page_Load 

Notes: The init event of the Application instance is raised only one time for the life of the page in the browser. It is not raised for subsequent asynchronous postbacks. During an initial request, no PageRequestManager events are raised.
B. During Asynchronous postback (aka partial page postback, ajax request using asp.net ajax)
PRM_init_request
PRM_begin_request
WRM_invoking_request
WRM_completedRequest
PRM_page_loading
PRM_page_loaded
APP_load
PRM_end_request 

C. During browser close or browsing away from the page:
PRM_init_request
APP_unload

Where
APP = Sys.Application object
PRM = Sys.WebForms.PageRequestmanager
WRM = Sys.Net.WebRequestManager


1)       1) Create a file and place it  as follows: YourWebApp/javascript/ocgis.js
//contents of file
if (typeof myns== 'undefined') { myns = {}; }
myns.didOnce = false
myns.initAppEventHandler = function(sender) {
                myns.loadAppEventHandler();
}

myns.loadAppEventHandler = function(sender) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
                if (!ocgis.didOnce) {
                    alert("TODO: initiate things and show panel using javascript....");
                    myns.didOnce = true;
                }
} 

2)       In the default.aspx page, Insert the below right before </body> , i.e. end of body tag
<script language="javascript" type="text/javascript" src="javascript/myns.js" ></script>
<script
language="javascript" type="text/javascript">
                Sys.Application.add_init(myns.initAppEventHandler);
                Sys.Application.add_load(myns.loadAppEventHandler);
</script>  


The diagram below does a great job of showing the events from the 3 main objects in a nice sequence diagram:

Tuesday, October 20, 2009

Cool web app client for SVN repository

I've been searching for an easy to use, web client for SVN repositories. I had come across svnwebclient from Polarion, and it seems very promising, useful, with lots of features e.g. compare, diff, changeset, etc., but it requires a Java Container. I'm familiar with Tomcat which is free, so I installed it on it but performance wasn't great and Tomcat was using nearly 40% of CPU on a quad core when it was busy. I didn't venture with Jetty since the docs are horrible. I played with WebLogic a while ago, but purchasing that is not an option now. I looked into glassfish from Sun, downloaded and installed it. The installation was smooth, it even has a very nice web management tool for the server. However, when i deployed svnwebclient it caused the server to be unresponsive and was using 350-450mb of memory, so again performance was bad, so I abandoned that route.
"glassfish v3 preview" docs: http://docs.sun.com/app/docs/doc/820-7689/aboaa?a=view

Screenshots of svnwebclient  from Polarion:
Online Subversion file comparison screenshot
Compare SVN Files

Subversion repository browser screenshot
Subversion repository browser


This made me look at other web clients running on other frameworks, and so I found websvn, which runs on php. I tried installing it on my personal windows vista home premium x64 OS and found it was surprisingly easy to install. However, I was really frustrated with windows vista, absolutely horrible for doing any sys admin type of work, e.g. "run as" context menu has been removed, remote desktop has been removed, all menus, shortcuts, control panels have been re-arranged and so many more issues with it, which is another story.

Here's the installation instructions for websvn on a windows box (in my case IIS 6):

1) Go to http://php.iis.net/ and click on the install to initiate the "Web Platform Installer" program, which will download a ~15mb file to set up php on IIS 6/7. Below is the actual download location:
http://windows.php.net/downloads/releases/php-5.2.11-nts-Win32-VC6-x86.msi 

2) that program should setup the IIS mapping for .php extension. which should be mapped to the fastcgi extension, in my case it was located at c:\program files (x86)\PHP\php-cgi.exe.

3) Now simply copy and paste the contents of the websvn web app into an IIS virtual directory and convert that directory to an IIS app

4) finally, copy the file c:\inetput\wwwroot\websvn\include\distconfig.php and paste it as config.php. Read thru the contents of that file and change the necessary parameters to reference your SVN service

That's it.

Links for PHP on IIS 6 or 7:

Saturday, October 17, 2009

Internet, network, traffic analysis statistics for web apps in html, asp.net, flex, jsf etc.

Often we would like to analyze the flow of traffic to an application we build, so I thought I'd put a small list of tools to use. Most of these tools are fairly easy to setup and there are lots of info on the web, so I won't go into a detailed discussion on how to use them.

The tools are divided into 2 groups:

  1. Traffic analysis online services that require no installation by you. Does require you to embed some javascript code into your application to send signals to the monitoring service. Some services also have flex libraries (google analytics) that can be used directly from actionscript.
  2. Log parsing programs that require installation on your web server which will go through the logs created by IIS, apache, tomcat etc webservers to analyze traffic. Does not require any modification to the individual web apps. Will monitor all level of traffic (pages, resources, web apps, domains etc.) Will only monitor entire traffic to the configured servers.
Some example tools:
  1. Google Analytics : free, easy to setup. Requires js code to be embedded in each of your pages that you want to monitor.
    1. create google account
    2. register to use their service (free)
    3. create a new site profile
      1. can be created for both internet sites or intranet/secure sites as well
    4. add the generated js code to your site (after all page elements have loaded, just before the close of the tag)
    5. it takes up to 24 hours to register and show activation
  2. StatCounter : free easy to use. Requires js code to be embedded in each of your pages that you want to monitor. 
  3. SmarterStats from SmarterTools:
    1. requires installation
    2. commercial product but free for one web app
    3. works by parsing web server logs
    4. no modification to the web app or individual pages required
    5. web based sophisticated GUI for generating reports, charts, maps and advanced analysis
    6. my experience: it is really cool, easy to use, install and configure. but the only pro is that the free version is limited to one web app.
  4. AWStats  - free advanced statistics tool
    1. requires installation
    2. free GNU GPL
    3. for advanced users 
    4. complicated installation (requires perl, command line)
    5. complicated usage, command line (no UI) 
      1. run perl scripts from command line to generate reports/charts/maps etc. in html
    6. log parser

Google search keywords: 
* more like awstatshttp://www.google.com/search?hl=en&q=related:awstats.sourceforge.net/




* more tools like statcounterhttp://www.google.com/search?hl=en&q=related:www.statcounter.com/

  • GoStats.com
  • http://www.sitemeter.com
  • www.freestatscounter.com
  • www.shinystat.com
  • extremetracking.com
  • easycounter.com
  • www.addfreestats.com


Direct Connect to ArcGIS ArcSDE through a firewall

Direct Connect (DC) is now the ESRI recommended connection method to connect to an ArcSDE database running on SQL Server 2000/2005/2008, Oracle etc databases. This is recommended for various reasons concerning efficiency, performance, memory and scalability. As opposed to 'Application connect', direct connect does not spawn a process (giosrvr) on the ArcSDE server and does not require the arcsde (giomgr) services to be listening on designated ports for geodatabases. Not only that, but DC (running on SQL Server) requires only one port to communicate to all geodatabases inside ArcSDE - the sql server port, usually 1433. So if there's a firewall between the ArcSDE server and ArcGIS server/desktop, then opening port 1433 would suffice. One more great reason to use DC.

To add even more, ArcGIS 9.3, 9.3.1 and 9.2 SP5 can backward connect to 9/9.1/9.2 running on most databases.The following rules are used to govern how connections between different versions of ArcGIS clients and geodatabases operate:
  • Current releases of ArcGIS clients can connect to and use previous releases of the geodatabase. For example, an ArcGIS 9.1 client can connect to and use an ArcGIS 9 geodatabase.
You should be aware of the following, though:
    • If the ArcGIS client is using a direct connection to an ArcSDE 9.2 or prior geodatabase, connections cannot be made from the newer client to the older geodatabase. For example, an ArcGIS 9.2 client cannot make a direct connection to an ArcSDE 9.1 geodatabase.
    • Functionality specific to the current release is not available when connecting to a previous release of the geodatabase. For example, if you connect from an ArcGIS 9.1 client to an ArcGIS 9 personal geodatabase, you will only have access to functionality available at ArcGIS 9.
  • Previous releases of ArcGIS clients cannot connect to and use geodatabases created with later versions of ArcGIS. For example, an ArcGIS 9.1 client cannot connect to and use an ArcGIS 9.2 geodatabase.
The exceptions to this rule are as follows:
    • ArcGIS 9.2 Service Pack 5 (SP5) can open and edit a 9.3 geodatabase. Be aware, though, that functionality specific to the current geodatabase release is not available when connecting from a previous release of the client application.
    • ArcGIS 9 can open and edit a 9.1 geodatabase.




Client release
Personal geodatabase release
File geodatabase release
ArcSDE geodatabase using a direct connection
ArcSDE geodatabase using an ArcSDE service connection
8.3
8.3
NA
8.3
8.3
9
9, 9.1
NA
9
9, 9.1
9.1
9, 9.1
NA
9.1
9, 9.1
9.2
9, 9.1, 9.2
9.2
9.2
9, 9.1, 9.2
9.2 SP5
9, 9.1, 9.2, 9.3
9.2, 9.3
9.2, 9.3
9, 9.1, 9.2, 9.3
9.3
9, 9.1, 9.2, 9.3, 9.3.1
9.2, 9.3, 9.3.1
9.3, 9.3.1
If client has pre-9.3 geodatabase direct connect files* installed, can connect to 9, 9.1, and 9.2

9, 9.1, 9.2, 9.3, 9.3.1
9.3.1
9, 9.1, 9.2, 9.3, 9.3.1
9.2, 9.3, 9.3.1
9.3, 9.3.1
If client has pre-9.3 geodatabase direct connect files* installed, can connect to 9, 9.1, and 9.2

9, 9.1, 9.2, 9.3, 9.3.1

Sources:


How to create a floating window (dialog, panel) in the ESRI Sample flexviewer?

How to create a floating window (dialog, panel) in the flexviewer?

There are many scenarios when you'd like to have a new window open from an action triggered from inside a widget or the InfoPopup. This is one way to do it.
1) Create you custom component, e.g. TitleWindow, Panel, or create a draggable panel
2) Add properties/methods to that component
3) Use PopupManager to create/re-use that component to show information from the widget


//Widget Code
private var myPopup:MyCustomComponent=null;

private function onButtonClick(infoData:Object):void {
 if (this.myPopup) {
    PopupManager.centerPopup(myPopup);
    PopupManager.bringToFront(myPopup); 
 } else {
    this.myPopup = new MyCustomComponent();
    PopupManager.addPopup(myPopup, this, false);
    PopupManager.centerPopup(myPopup);
    PopupManager.bringToFront(myPopup); 
 }
 //change properties of myPopup
 myPopup.title = "Details for " + infoData.title;
 myPopup.featureId = infoData.featureId;
 myPopup.fetchFeatureDetails();
}

Sunday, October 11, 2009

How to prevent certain file types from being served by IIS


How to prevent certain types of files from being served by the server (IIS)?


1)       In web.config, under the httpHandlers section (which is under system.web section, add the below:
<add verb="*" path="*.blah" type="System.Web.HttpForbiddenHandler"/>
2)       Using the IIS managment console, add a new application extension mapping for *.blah
a.        Go to IIS control panel
b.       Expand the webiste, go to the desired web app using the IIS mngment console, e.g. it may be located at c:\inetpub\wwwroot\MyWebApp1
c.        Go to the properties of that webiste
d.       Go to the "Directory" tab
e.       Click the "configuration" button, this should open up a new dialog window
f.         Copy the executable path (dll) for the .aspx mapping, usually located at:
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
g.        Click on "add" button to add new type of mapping for our file type, e.g. *.blah
h.       Paste the dll location for the aspnet engine(handles aspx pages)
i.         type ".blah" (without the quotes) in the extension text area (this can be replace with any file extension eg: js/html/PDF)
j.         while still in the "add/edit application extension mapping" window click the "limit to" radio button and type "GET,HEAD,POST,DEBUG"
k.        ensure that the "script engine" radio button is selected but not the "verify the file exists" radio button