March 22-25th 2010 ESRI Developer Summit

Friday, March 12 2010         No Comments


In 2 weeks the ESRI Developer Summit will start in Palm Springs, if you haven’t register, there is still time.

clip_image001

 

Created for Developers
by Developers

Prepare for tomorrow's challenges at the ESRI Developer Summit (DevSummit). It's the place to be for developers interested in using spatial technology in their applications.

Bring your toughest questions for the ESRI engineers and hear insightful user presentations given by your peers. Register today

Hope I’ll see you there.

Cheers

Al

Read more....

Comparing LINQ to SQL vs the classic SqlCommand

Sunday, March 07 2010         3 Comments


When you are coming from using SqlCommand and SqlConnection is difficult to move to another library for your database needs. For those people still in the limbo to make the decision to move to another DAL, here is a comparison to help you see the light or to move away for ever.

 

How to do a select query using SqlCommand:

   1: SqlConnection myConnection = new SqlConnection(@"Data Source=PROG-3407\SQLEXPRESS;Initial Catalog=Demo;Integrated Security=True;Pooling=False");
   2:  
   3:             string sQuery = "SELECT * FROM Table1";
   4:  
   5:             SqlCommand myCommand = new SqlCommand(sQuery);
   6:             myCommand.Connection = myConnection;
   7:  
   8:             myConnection.Open();
   9:  
  10:             SqlDataReader dataReader = myCommand.ExecuteReader();
  11:  
  12:             while (dataReader.Read() == true)
  13:             {                
  14:                 string sID = dataReader[0].ToString();
  15:                 string sName = dataReader[1].ToString();
  16:                 string sCity = dataReader[2].ToString();
  17:  
  18:                 MyData dat = new MyData()
  19:                 {
  20:                     ID = Int32.Parse(sID),
  21:                     Name = sName,
  22:                     City = sCity
  23:                 };
  24:                 myDataCollection.Add(dat);                
  25:             }
  26:  
  27:             GridView1.DataSource = myDataCollection;
  28:             GridView1.DataBind();
  29:  
  30:             dataReader.Close();
  31:             myConnection.Close();

And now a select query in LINQ to SQL

 

   1: Table1DataContext dataContext = new Table1DataContext();
   2:                        
   3:            var all = from p in dataContext.Table1s orderby p.City select p;
   4:            
   5:            GridView1.DataSource = all;
   6:            GridView1.DataBind();

Pretty short isn’t it?, the select statement is inline with a little help from intellisense.

 

Insert in SqlCommand

   1: using (SqlConnection myConnection = new SqlConnection(@"Data Source=PROG-3407\SQLEXPRESS;Initial Catalog=Demo;Integrated Security=True;Pooling=False"))
   2:             {                
   3:                 string sQuery = "INSERT INTO Table1 (Name,City) values(@Name,@City)";
   4:  
   5:                 SqlCommand myCommand = new SqlCommand(sQuery);
   6:                 myCommand.Connection = myConnection;
   7:  
   8:                 myConnection.Open();
   9:                                 
  10:                 myCommand.Parameters.AddWithValue("@Name", TextBoxName.Text);
  11:                 myCommand.Parameters.AddWithValue("@City", TextBoxCity.Text);
  12:  
  13:                 myCommand.ExecuteNonQuery();
  14:             }

 

Insert in LINQ in SQL

   1: Table1DataContext dataContext = new Table1DataContext();
   2:  
   3:             Table1 row = new Table1()
   4:             {
   5:                 City = TextBoxCity.Text,
   6:                 Name = TextBoxName.Text
   7:             };
   8:  
   9:             dataContext.Table1s.InsertOnSubmit(row);
  10:             dataContext.SubmitChanges();

 

Hope this helps

Cheers

Al

Read more....

The new Microsoft SQL Server Compact Edition 3.5 in Visual Studio 2010 RC without Geometry Types.

Tuesday, March 02 2010         No Comments


With the goodies coming with Visual Studio 2010 a new type of SQL Database comes out to make it easier to deploy application and simplify the way to consume your data.

This is a huge improvement from Microsoft to improve hosting and deployment of your web applications that requires a database.

For years a database like that has been very needed, some file based that can be run with low trust on a web hosting environment, something better than SQL Express. Some other databases came out, like VistaDB. Something that can be deployed just by using an FTP client.

You only need to right click –> Add New Item and select SQL Server Compact Edition Database, a wizard will let you create a model as well for the database.

image

Issue: These version of SEL Server Compact Edition does not support Geometry types like SQL 2008 versions. After creating the database, I tried to add a geometry type and I could not find it on the dropdown.

image

I better note that I don’t know if in the geometry and geography types will be supported in release version of the SQL Server Compact Edition, seems difficult if the release candidate does not.

This is a huge problem for people that uses those kinds of types in their database to migrate. In my modest opinion new releases of SQL Server should always be backwards compatible.

Is LINQ to SQL Geometry fixed in Visual Studio 2010?

Seems like Microsoft if moving away from the Geometry and Geography types, I thought that .NET 4 will be supporting LINQ to SQL with Geometry and Geography types. However adding a SQL 2008 Database and creating a LINQ to SQL Class won’t be able to read the geometry type field on the database.

Cheers

Al

Read more....

Difference between ASP.NET Sessions, Application variables and Cache objects.

Monday, March 01 2010         2 Comments


When developers start with ASP.NET Web Forms the question I always get is; where is the best place to store user information, the application variable, the session state, cookies, database or the cache objects?

This is not an easy answer there are so many variables and options. In a nutshell Session state can make a big difference depending there that session state is also stored, depending on so many factors, how many servers you going to need? how many users you need to support?

Please find the code below to test for yourself how Session, Application and Cache variables work.

In the previous post, you can see how Cache has a callback when the object gets remove from memory.

The difference from an Application variable and Cache is mainly that you can assign the time the Cache variable will be stored in memory.

The main difference between Cache, Application and Sessions is the later is isolated by user, so every user has their own pool of Session variables to use, Session variable gets destroyed after Session timeout.

   1: public class MyCacheInfo
   2:         {
   3:             public string Url
   4:             {
   5:                 get;
   6:                 set;
   7:             }
   8:             public object MyValue
   9:             {
  10:                 get;
  11:                 set;
  12:             }
  13:         }
  14:  
  15:  
  16:         static string _myObject = "MyObject";
  17:         static CacheItemRemovedCallback onRemove = new CacheItemRemovedCallback(RemoveCallback);
  18:  
  19:         public static void RemoveCallback(string k, Object v, CacheItemRemovedReason r)
  20:         {
  21:             MyCacheInfo info = v as MyCacheInfo;
  22:  
  23:             WebClient net = new WebClient();
  24:             net.DownloadData(info.Url.Replace("?Al=1","") + "?Al=1");
  25:            
  26:         }
  27:  
  28:         protected void Page_Load(object sender, EventArgs e)
  29:         {
  30:             if (Request.Params["Al"] != null)
  31:             {
  32:                 DateTime dtExpiration = DateTime.UtcNow.AddSeconds(10);
  33:  
  34:                 MyCacheInfo info = new MyCacheInfo()
  35:                 {
  36:                     MyValue = DateTime.Now,
  37:                     Url = HttpContext.Current.Request.Url.OriginalString
  38:                 };
  39:                 Cache.Add(_myObject,
  40:                       info,
  41:                       null,
  42:                       dtExpiration,
  43:                       System.Web.Caching.Cache.NoSlidingExpiration,
  44:                       System.Web.Caching.CacheItemPriority.High,
  45:                       onRemove);
  46:             }
  47:         }
  48:  
  49:         
  50:         protected void Button1_Click(object sender, EventArgs e)
  51:         {
  52:             // Add everything here
  53:             Session[_myObject] = TextBoxSession.Text;
  54:             Application[_myObject] = TextBoxApplication.Text;
  55:  
  56:  
  57:             MyCacheInfo info = new MyCacheInfo()
  58:             {
  59:                 MyValue = TextBoxCache.Text,
  60:                 Url = HttpContext.Current.Request.Url.OriginalString
  61:             };
  62:  
  63:             DateTime dtExpiration = DateTime.UtcNow.AddSeconds(10);
  64:             Cache.Add(_myObject,
  65:                        TextBoxCache.Text,
  66:                        null,
  67:                        dtExpiration,
  68:                        System.Web.Caching.Cache.NoSlidingExpiration,
  69:                        System.Web.Caching.CacheItemPriority.High,
  70:                        onRemove);
  71:            
  72:         }
  73:  
  74:  
  75:  
  76:         protected void Button2_Click(object sender, EventArgs e)
  77:         {
  78:             //Retrive
  79:             if (Session[_myObject] != null)
  80:                 LabelSession.Text = Session[_myObject].ToString();
  81:             else
  82:                 LabelSession.Text = "No Session";
  83:  
  84:             if (Application[_myObject] != null)
  85:                 LabelApplication.Text = Application[_myObject].ToString();
  86:             else
  87:                 LabelApplication.Text = "No Application";
  88:  
  89:             if (Cache[_myObject] != null)
  90:                 LabelCache.Text = Cache[_myObject].ToString();
  91:             else
  92:                 LabelCache.Text = "No Cache";
  93:         }
  94:  
  95:     }
Hope this helps

Cheers

Al

Read more....

The Orchard Project as my new blog engine.

Sunday, February 21 2010         8 Comments


 

Orchard is an open source CMS web application that will allow you to create any website, page based or blog. We have been seeing many CMS in the market lately, this is a Microsoft open source solution that is intended be part of the Codeplex foundation.

Orchard have been build using ASP.NET MVC instead of ASP.NET Web forms, no a surprise there when Microsoft has been pushing their open source MVC as the way to create ASP.NET applications. 

You can find the Orchard Project here.

The features coming out in Orchard.

Even that now the Orchard Project is still very young, I can see potential, all the features they are going to add overlaps with the area of DNN, Word press and Graffiti.

I have been running Graffiti CMS for many years and I was looking in moving to Word press for the reach features, the main problem is that Word press runs in pho and mySQL. That blog engine has been growing in adopters by the masses leaving behind other blog engines in .NET. Is that why Microsoft created the Orchard project?

However if Orchard Project moves at the speed they have been moving, I can see running my blog soon with Orchard, leaving behind the fateful Graffiti CMS that now that became open source I feel I’ll be jumping ships before they can release the expected 2.0 version.

My experience downloading the source code for Orchard on February 18th.

Its important to note the date on a open source solution as the changes are happening everyday.

First screen just after compiling it and running the Orchard web app you’ll find that will ask you the customization of the CMS. All the configuration happens on the web application, you do not have to make any changes to the web.config.

image

Allow you to decide at start up about what database you want to store the application data. Your options are SQL Lite, SQL Server or SQL Express.

image 

The results looks like a new ASP.NET MVC simple application. I’m sure the first thing you want to do is to change the theme.

image

Problem changing themes in the latest release. Some images are still missing in the theme, I believe they are fixing that problem right now, so most probably that is being resolve when you read this post.

image 

Adding a new blog instead of pages, so in Orchard, you can just add pages to the engine or blogs. The Orchard theme looks really good.

image

Do not delete the Home page that comes in Orchard, you should be able to do it, but looks like your app won’t work at all if you do that.

Workaround, create a new page before deleting the home page and make it the main page.

So what is Orchard project missing? Well right now, many things really, still the project is pretty young and looks like there are many wished features that need to be added. The foundation has been set.

I don’t recommend to start using it just now for anything customer facing, great tool to download and learn the insides and outs or to learn ASP.NET MVC.

List of Things that there are a must for me.

  • A mobile theme; I would like to specify the theme when an iPhone, blackberry or other mobile device reads my blog.
  • Set Orchard on blog mode so I can personalize the Home page to show my blog posts.
  • Widgets; a way to add widgets and if I want write widgets to display on my blog.
  • Import and Export from other blog engines easily.

Cheers

Al

Read more....

Making your ASP.NET application work as a service.

Wednesday, February 17 2010         2 Comments


Now this post by the title already says is controversial or a hack, I take the second one, what that means is I’m recommending not to use the code in the post as anything plan to go close to production, this is just a little fun with code.

Most of the time, in ASP.NET you find yourself that when designing an application, you need to think about a Windows Service to complete a task without any user interaction. In the ASP.NET architecture, the user loads a page and code behind get executed, then results from the code will be display to the user. Now when the application needs to, for example, download the twitter public timeline, you cannot expect that you’ll have so many users to execute server side methods to do just that. When nobody is making requests, your ASP.NET application is not doing anything, how to make it do something?

So there is an state object in .NET called the Cache class. That class has a great delegate to expire the content stored in that object.

   1: public class MyDateTime
   2:     {
   3:         public DateTime datetime
   4:         { get; set; }
   5:  
   6:         public HttpContext context
   7:         { get; set; }
   8:     }
   9:  
  10:     public class MyCache
  11:     {
  12:         static List<MyDateTime> datetimeList = null;
  13:         static string cacheName = "test";
  14:         static CacheItemRemovedCallback onRemove = null;
  15:  
  16:         public static void InsertNewCache(HttpContext context, List<MyDateTime> oldDatetimeList)
  17:         {
  18:             // First time create the collection, otherwise retrive it.
  19:             if (oldDatetimeList != null)
  20:             {
  21:                 datetimeList = oldDatetimeList;
  22:             }
  23:             else if (context.Cache[cacheName] == null)
  24:                 datetimeList = new List<MyDateTime>();
  25:             else
  26:                 return;
  27:             
  28:             MyDateTime myItem = new MyDateTime()
  29:             {
  30:                 datetime = DateTime.Now,
  31:                 context = context
  32:             };
  33:  
  34:             datetimeList.Add(myItem);
  35:  
  36:             onRemove = new CacheItemRemovedCallback(RemovedCallback);
  37:  
  38:             DateTime dtExpiration = DateTime.UtcNow.AddSeconds(10);
  39:             
  40:             context.Cache.Add(cacheName,
  41:                                     datetimeList,
  42:                                     null,
  43:                                     dtExpiration,
  44:                                     System.Web.Caching.Cache.NoSlidingExpiration,
  45:                                     System.Web.Caching.CacheItemPriority.High,
  46:                                     onRemove);
  47:         }
  48:  
  49:         public static void RemovedCallback(String k, Object v, CacheItemRemovedReason r)
  50:         {
  51:             List<MyDateTime> retrievedCache = v as List<MyDateTime>;
  52:             InsertNewCache(retrievedCache[retrievedCache.Count-1].context, retrievedCache);
  53:         }
  54:     }

 

Create a webpage to call once to start the process.

   1: public partial class _Default : System.Web.UI.Page
   2:     {
   3:         protected void Page_Load(object sender, EventArgs e)
   4:         {
   5:             if (Cache["test"] != null)
   6:             {
   7:                 List<MyDateTime> dtList = Cache["test"] as List<MyDateTime>;
   8:                 foreach (MyDateTime dt in dtList)
   9:                 {
  10:                     Response.Write(dt.datetime.ToString() + "<BR/>");
  11:                 }
  12:             }
  13:             else
  14:             {
  15:                 MyCache.InsertNewCache(HttpContext.Current, null);
  16:             }
  17:         }
  18:     }

 

The results:

1:12:48 PM
1:13:00 PM
1:13:11 PM
1:13:40 PM
1:13:52 PM
1:14:15 PM
1:14:28 PM

Disclaimer: This is horrible code, this is to proof a concept, not to go live with anything to production with something like that, I just want to show, how the Cache object calls itself without a HttpContext and can run as long as IIS does not unload the Application Pool. As you can see the time is pretty variable, so there isn’t a warranty of the time span.

Now to keep IIS from unloading your application, you could on the CallBack event make a request to the application from within the application, not that will completely avoid that problem, yet will delay it.

Cheers

Al

Read more....

Arrived to the Microsoft MVP Summit

Tuesday, February 16 2010         No Comments


 

Once again back to Seattle for the MVP Summit, this year is a pretty exciting one with all released they had. A few blurry pictures from the first day.

iq8g[1] 

John Papa and Tim Heuer

Me and Toby Richards, I actually look scare, just bad camera man ;-)

7ue[1]

At the end, great experience, tomorrow we are going to the campus to meet the product developers.

See you all tomorrow.

Cheers

Al

Read more....

Silverlight Map Stats 2.0 released

Saturday, February 13 2010         1 Comment


Finally this weekend I had time to work in the Map Stats to bring it to an useful tool.  It was overdue in a face lift.

MapStats is a simple script that when added to your website or blog, provides you with a Silverlight Map Control with the status and location of the people hitting your website by time.

I used ESRI technology and base maps. You can download the ArcGIS API for Microsoft Silverlight/WPF version 1.1 here.

 

image

  • Changed the map to Web Mercator Auxiliary 102100 to consume a great ArcGIS Online map
  • Added better symbology with a color ramp and animation
  • Added a slider when open full screen to see different times.
  • Upgraded to ESRI SDK for Silverlight 1.1.
  • Added a legend.

image

With the slider you can see the history of the requests, by default shows you all request of the last 3 days.

How to add MapStats to your website?

Just add the script below to your website you can change the Width and Height to fit anywhere in your website.

<script type="text/javascript" src="http://mapstats.net/Stats.ashx?Width=300&Height=200"></script>

 

You’ll be able to see the map and will start gathering information of the users hitting your page, by IP address will find the location and show them on the map.

How do I check the top websites with the Map installed?

You can check the website MapStats.NET for the number or geocoded IPs collected on your website.

If you press the button to see the Full Screen you then can interact with the map and see the tooltips as well as the legend. Being able to see the history of the requests to your website is very useful by just sliding the bar. If you want to see it running, just look to your right and down as you read this post, you’ll find the map, click the button to open it full screen and browse around.

Ok, I need ideas and feedback of where to go from here.

Cheers

Al

None of my opinions reflects opinions or views by my employer nor Microsoft. This is just my personal blog that is provided "AS IS" with no warranties and confer no rights. The postings on this site are my own and don’t necessarily represent ESRI’s positions, strategies or opinions.

Read more....

Creating a Server Object Extension for ArcGIS Server 9.3.1

Wednesday, February 10 2010         No Comments


This fantastic walkthrough is for developers who need to build and deploy a server object extension for use in server applications. It describes the process of extending the MapServer to provide methods for performing a specific type of spatial analysis on the features in one layer of the map.  The scenario consists of four parts:

  • Developing the server object extension
  • Developing the ArcCatalog and ArcGIS Server Manager administration property pages for the server object extension
  • Registering the custom server object extension  
  • Developing a client application to work the server object extension

Read the whole complete tutorial here:

http://resources.esri.com/help/9.3/arcgisserver/adf/dotnet/developer/scenarios/extend_svr_object.htm

If you are thinking in extending ArcGIS Server, this is the best documentation I found that got me running.

You can actually get the sample here.

Even if the link says 9.3 it works in 9.3.1.

Cheers

Al

Related links.

Extending a ArcGIS Server geocoder.

Creating a Map Service Browser

How to keep yourself interested as a developer.

Wednesday, February 10 2010         1 Comment


 

I can only speak for myself in this one, I have seen other people master the balancing world of development without much ado, in my case, is being a lifetime of learning the way that works for me, hopefully my few tips can help you out or amused you to know that I’m still struggling in that battle.

The biggest problem for any developer is that is consumed by the project that works at every single time, developers like to put all their energy to deliver a complete solution using the framework and tools setup to accomplish that task. Saying that, is difficult to come up for air to see what’s around. The biggest sign you have that problem is that after working in a huge project, you realize how many things you have been missing.

Looks like every project always comes with a hard deadline, never seen any project without it, just finding the way to find any other time is an impossible mission.

In previous years I have been consumed by technology and getting that project to completion, now I find myself organizing myself better on the task at hand, being able to break down the tasks to small manageable pieces that will give me a better overview of the complete solution as well as the project deadline. I personally try to have more than one project at the same time, allows me to switch gears and pull myself out of not being consume by the project.

If you can, try to work in project with different tools and technologies, so if you have a ASP.NET project, try to get a dynamic language project consuming other kind of data. Will allow you to completely force you to think differently and not to confuse them. I have mistake before to different ASP.NET projects in C#!

Something really hard to do is to leave a task not completed, I wouldn’t recommend to add time schedules, I would stay on the task until is being completed before changing projects, that will allow you to start with a clean sheet. Not finishing a task for the lack of time, or because you are pushed to move to another project, will cause you distractions. Some developers get agitated when they don’t have the time to fix a bug or something is not working the way they would like.

Overextending yourself is normally what has happen to me, I never say no to a project really, when I get the chance to sit it out or dance, I always dance, probably my advice to myself should be, I need to learn when sitting that one out is the right choice.

I personally use the Windows 7 post notes that you can create for all my tasks, so I can always see them in the desktop, every single task will be added as a new note, I’ll reorganize them in the desktop by priority. Before Windows 7 notes I use actual post-its.

All and all, I keep myself interested by multiple projects, scheduling those are the hardest part, and in the overall schedule of work, family and my time for my pet projects is probably the hardest schedule of all. I guess at that point becomes priorities instead of scheduling. I wonder why I never finish any of my pet projects.

How do you keep your sanity as a developer when not all work is a workflow? I would like to hear from you and what do you use to organize yourself.

Cheers

Al