Monday, November 23, 2009

TweetGIS

I just wanted to talk about a little project I did early in the year for ESRI's 2009 Developer Summit's Dev Challenge contest. At the time people were just starting to understand what Twitter was and how to use it. So I thought it would be a really neat way to use Twitter as an editing status feed on parcel data. It would tweet when someone edited the attributes of a parcel and include a link to the parcel that was edited. It would also tweet when a new user was created and when one returned.

Since ESRI's Javascript framework doesn't support attribute editing I separated the data from the features. I put the attribute data inside Google Spreadsheets, which I found out does not have a record limit.

The project is made up of 2 apps. The front end which consist of html, jQuery and ESRI's JSAPI Framework. Then the server side piece which I used ASP.NET MVC, TweetSharp library and Google's Spreedsheet API.

The project came together really well and took 2 weeks of late nights.

Here is a presentation I did on it

Demo

Source Code

Thursday, August 27, 2009

ComicsInventory.com

I just wanted to share a little project I've been working on called ComicsInventory.com.

I have been a big fan of comic books for years and have over the years accumulated a very large collection. Sometime ago I decided to start organizing my collection and finding out how much each issue was worth. I looked around the net for a solution but found very over priced solutions or free solutions that had very bad interface designs or poorly written code. This gave me the opportunity to merge my love of comics with my love of code. Plus I figured I could use the site as a testing ground for anything new that comes out in the coding world ;-)

For my framework I decided to use (at the time) the beta of Asp.net MVC. I liked the freedom it gave you and its minimalistic design. It's faster, lighter and gets you back to html and http. No server controls or viewstate! But I've already talked about this before.

Since theres so many different ways to organize comics. I decided to build the site around a labeling system. This gave me the flexibility to assign multiple labels to comics and group them in different categories. A side benefit that came about was when I added the "total price" feature. This made it very convenient when getting values for all your spider-man comics. But also if some of those spider-man comics were CGC'd. I could create a CGC label and see how much all my CGC comics were worth.

Another big feature is the Image Viewer and Image Upload. This was tricky because I had to reliably upload an image, create 2 copies (1 large & 1 thumbnail) and upload those images to Amazon's S3 service. All in 1 step. I used the awesome flash plugin Uploadify to constrain the image sizes and handle the image upload to the site. I then used the .NET image classes to copy and resize the images. Instead of making my own Amazon S3 library I decided to use ThreeSharp. This library was fantastic and had an active discussion section.

Designing the interface and the look of the site was very important to me. I wanted the site to be very clear, easy to use, but also minimalistic. I spent time at 37signals, studying there site but also there philosophy on feature creep and really focusing in on what features are important to ship with first. It helped a lot with designing the Home page where I wanted to show what the site was about.

I learned a lot about the MVC architectural pattern, designing and using third party services to extend your site. But the best thing is I now have a place to inventory my comics and in the process created a service that others can benefit from.

Site Architecture

Core
  1. OS: Windows Server 2008
  2. Web: IIS 7.0
  3. Database: SQL Server 2008
  4. Language: C#

Dev Tools
  1. IDE: Visual Studio 2008 Team
  2. Framework: ASP.NET MVC
  3. Data Access helper: Microsoft Enterprise Library
  4. Browser Framework: jQuery
  5. Source Control: Subversion
  6. Subversion Client: AnkhSVN
  7. Compare Tool: WinMerge

Third party libraries
  1. Uploadify - flash plugin to handle uploads & constraints
  2. ThreeSharp - Amazon S3 library
  3. Json.NET - JSON Serializer/Deserializer
  4. Google Analytics - web site statistics
  5. UserVoice - feed back system

Tuesday, May 26, 2009

Using jQuery Plugin Uploadify with Asp.net MVC

Just started using this great jQuery plugin called Uploadify, that lets you upload multiple files to the server. It uses flash to queue the files and send them one by one to the server. Plus provides feedback and all other types of goodies. The implementation is pretty straight foward.

Just add this client side code.

<script type="text/javascript" src="/Content/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/Content/js/jquery.uploadify.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#fileInput").uploadify({
uploader: "/Content/swf/uploadify.swf",
script: "/UIImageViewer/Upload",
cancelImg: "/Content/imgs/cancel.png",
auto: true,
folder: "/uploads",
onError: function (a, b, c, d) {
if (d.status == 404)
alert("Could not find upload script. Use a path relative to: "+"<?= getcwd() ?>");
else if (d.type === "HTTP")
alert("error "+d.type+": "+d.status);
else if (d.type ==="File Size")
alert(c.name+" "+d.type+" Limit: "+Math.round(d.sizeLimit/1024)+"KB");
else
alert("error "+d.type+": "+d.text);
}
});
});
</script>
<body>
<input type="file" name="fileInput" id="fileInput" />
</body>


Then create a controller with a "Upload" action.
  public string Upload(HttpPostedFileBase FileData)
{
/*
*
* Do something with the FileData
*
*/
return "Upload OK!";
}


The tricky part, which drove me crazy, is that you need to use the "HttpPostedFileBase" class NOT the "HttpPostedFile" class. If you use the other class the script will return a "IO Error #2038" error message.

Saturday, March 28, 2009

2009 ESRI Developer Summit

ArcGIS 9.3.1 Server (ships after U.C.)
- New Optimized Map Service that is as fast as ArcIMS or sometimes faster.

- New Map publish toolbar in ArcMap that helps optimize mxds and rendering speeds, using the analyze tool. The analyze tool produces errors, warnings and messages to help you see what's slowing down your map service. It also creates a new optimized mxd file with a .msd extension, that is used for the new Optimized Map Service. During one of the sessions it took a map that rendered in 12sec and optimized it to .8 secs.

- New Silverlight API beta is released with some custom controls like automatic point clustering and rendering. The demos were really slick and fast. At one of the sessions someone asked what the limitations of the Silverlight API was. Art Haddad said he tested rendering 10,000 points with no problem. He says your bandwidth is now your bottleneck. For you JavaScript API folks out there, you know the pain and limitation of only showing 100 points before it brings your browser to a crawl. Also map rotation will be supported. I believe this will be ESRI's default web client.


ArcGIS 9.4 Desktop (ships late fall or early next year)
- New UI with dock able controls like Visual Studio

- Catalog has been added right into ArcMap

- Asynchronous geoprocessing (basically when running a toolbox tool it will not lock up your whole ArcMap session anymore)

- Side by side deployment (9.3.1 & 9.4 versions will be able to run on the same machine)

- High performance graphics

- Full python integration with script console

- Enhanced editing in 2D & 3D

- No support for IE6, VB6, VS2005, Oracle 9i, SQL2000, Win2000 & Win Server 2000

- VBA only available for legacy

- Python is now the default custom tool language

- New layers tab in ArcMap that groups the layers by there state. Groupings like Visible, Out of Scale Range, Hidden layers, and Selectable layers.

- New editing tools for ArcEngine that match the tools in ArcMap

- Search integration in all products

- New layer type called "Query layers" that limits displayed features using SQL syntax.


ArcGIS 9.4 Server (ships late fall or early next year)
- Web editing service provided in all web APIs.

- Support for native SQL, no ArcSDE required.

- Faster map tile retrieval.

- Query Layer support

- Access to standalone tables

- Improve map cache update workflow

- Full support for domains

- Support for native SQL



ArcGIS Explorer 900
- New feature lets you create presentations with fly over animations using your data. It also lets you import you PowerPoint slides.

- Virtual Earth data will be available.

- New ribbon interface and a custom settings file can be created to limit what tools are shown for custom user installs.



Other random items
ArcGIS Online (ships after 9.3.1) - Using your global account you can log in and share your data by uploading it. You can even create groups and secure them so that only certain people have access to the data. You can even create hosted maps from your uploaded data. No mention was said if this would be a free site or some type of paid service.

Layer Packages - These are basically compressed files that will include the layer symbology and data in one file. This will be used to upload data to the new ArcGIS Online.

Using Open Layers with the REST API - James Fee gave an interesting user session about modifying the open source project Open Layers to use the ArcGIS Server REST API. Right now it supports a subset of the REST API features but will support all functions possibly by Fall of '09.

ArcGIS Mobile 9.4 - Mobile will be supported on tablets and the SDK has been made easier for task based programs. The same program should work on handheld and tablet with no modification.


This year I would say the key jargon phrases for the summit are "Web Maps" and "Story". "Story" is taken from Microsoft and basically its a way to assign emotion to a product. It also describes the user experience. It was used in almost every session I went too. "Web Maps" is ESRIs way of saying "stop creating sites that mimic ArcMap on the web" and create more focused web map applications with the least amount of layers. I'm not really sure this is cost effective. Since most clients want to get the most bang for there buck and don't really want to pay you to create 5 focused sites when 1 light web gis viewer could do the same thing. I understand there shooting for the Google simple map app, but I don't believe in these financially
sensitive times that this makes sense.

Overall I think the Dev Summit was good and I'm really looking forward to playing with the Silverlight API and the Optimized Services.

Tuesday, February 3, 2009

Sending email in C# using GMail!



Here is some code I put together to send email using your Gmail account.
This can come in handy if you want your app to send notifications and you don't have access to an SMTP server.

Remember there is a limit that Gmail puts on mass emails. They will punish you if you go over it.

Gmail Sending Limits
In an effort to fight spam and prevent abuse, Google will temporarily disable your account if you send a message to more than 500 recipients or if you send a large number of undeliverable messages. If you use a POP or IMAP client (Microsoft Outlook or Apple Mail, e.g.), you may only send a message to 100 people at a time. Your account should be re-enabled within 24 hours.



Remember to set "DeliveryMethod = SmtpDeliveryMethod.Network". If this is not set then Gmail will come back with a "client was not authenticated" error.

Code
using System.Net.Mail;
using System.Net;

var fromAddress = new MailAddress("from@gmail.com", "From Name");
var toAddress = new MailAddress("to@yahoo.com", "To Name");
const string fromPassword = "password";
const string subject = "test";
const string body = "Hey now!!";

var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword),
Timeout = 20000
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}

Friday, January 23, 2009

Last nail in ArcIMS's coffin.



Well ESRI just released some news about ArcGIS 9.3.1.
What's Coming in ArcGIS 9.3.1?

Here is an item that caught my eye.
High-Performance Dynamic Map Publishing
New faster rendering engine
Outperforms equivalent ArcIMS services.
Produces significantly better-looking maps.
Shortens map caching time.
Quicker, smoother zoom and pan.


If this is true then ArcIMS is truly dead.
There are no more excuses left to not move to server.

Wednesday, January 7, 2009

Asp.net MVC & jQuery the new standard

Wow its been a while since I'v posted something. Been busy at work and settling into the new house, holidays and every other crazy thing that happens around this time of the year.

But what I really want to talk about is the new ASP.NET MVC & jQuery and how this will be the standard way of building sites on the ASP.NET framework. I know its a bold disclaimer, but I fully believe it after using both on a couple of projects and coming away thinking.... why wasn't it always this fun to build sites in Dot Net!

To begin with the MVC part stands for Model-View-Controller. This is a very old concept dating back to 1979 which was described by Trygve Reenskaug, then working on Smalltalk at Xerox PARC(..I'm always surprised at the amount of ground breaking technology that went on at Xerox back than.).
In MVC, the model represents the information (the data) of the application; the view corresponds to elements of the user interface such as text, checkbox items, and so forth; and the controller manages the communication of data and the business rules used to manipulate the data to and from the model.




You gain a lot by separating your website out like this. It makes it super easy to run Unit Tests against all 3 levels. You also lose the ViewState dead weight. No more limitation on just 1 form and the post back model goes right out the door. Now the down side is most server controls that use ViewState will not work. But MVC makes up for this with HtmlHelpers. Plus you get really nice looking REST like urls. Like so http://stackoverflow.com/questions/tagged/asp.net-mvc. Notice you don't see the ".aspx" ext or any extensions. You may think "who cares, so your url looks pretty". Yeah I thought the same thing also, but what makes this important is the url is self describing. It now has meaning and that meaning can be parsed and indexed by the all mighty GOOGLE search engine. You know what that means. Better search indexes, higher ranking and more eye balls finding your site!!

These nice urls are pointers to actions in your controller.
An action is basically a function waiting to be called by a url. And just like any function you can pass parameters to it and it can output data from it. This is huge because now not just your front end .aspx page have access to your logic, but so does anything that can communicate through http. This is what makes MVC such an easy fit for AJAX. You can call that action url right in Javascript and have it return some string information or better yet JSON objects.

This is where jQuery comes in handy.
jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.




jQuery makes javascript fun again. Like when you first discovered all the cool little floating boxs and color changing scripts you can do with it. You can even make it snow on your web site with Javascript. But than all the different browsers decided, they knew the best way to implement javascript. You had to add all that browser checking code mixed in with your logic and boiler plate code....ahhhhhhhhhhhh!!!. No wonder most people ran screaming and called javascript a toy language. jQuery takes care of all that and comes up with a genuis way of traversing the DOM using selectors.

jQuery selectors are a combination of CSS 1-3 & XPath. Essentially, the best parts from both of these query languages were taken, combined, and used to create the final jQuery expression language.


What really makes jQuery shine is the fact that its very extensible. There are 100s of plug-ins on the site. From form valadation plugin-ins, auto-complete controls with ajax to a full Grid control with built in search using local or remote data, column resizing and ording.

jQuery was so powerful that Microsoft decided to include it with its ASP.NET MVC Beta release.

Just imagine the possibilities. I know its a different way of thinking and building a site from a .NET view. But this is the way all major web platforms are built. Ruby on Rails, PHP, Java..etc. It makes sense for the web and makes development life a lot easier.

If you want some tutorials on some of the topics I talked about ScottGu's Blog has some really nice posts that get into the details of ASP.NET MVC.

jQuery's site has a lot of nice documentation on what jQuery is and how it works.