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").fileUpload({
uploader: "/Content/swf/uploader.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.

Tuesday, September 2, 2008

Google Chrome

Well Google Chrome beta is OUT!!!

Check out some the screen shots of the different features.

Javascript Console


View Source


Options Dialog box's






Find
The cool thing you don't get from this screen shot, is that while you are typing the highlight jumps through the page looking for the key word.


Element Inspector
You can right-click any element and see the html behind it.
In the Element Inspector box it has a handy tree path of elements at the bottom where the right-clicked element lives. This function is in a lot of HTML editors, like Microsoft Expression.


Search Highlighted text
If you highlight a piece of text and right click it the pop-up menu will give you an option to search for the text. Right now my search provider is Google but it will use what ever you set your search provider too.


Incognito Window


Task Manager
If you don't think Google is using this browser as its interface into the Google OS.
Just look under the developer menu for "Task Manager". It breaks out how much resources each page is taking up and if its causing the tab to lock up. Its even got a "Stats for nerds" link that shows you even more info about each web page. Like what process ID its running on and breaks down the the memory into how much private,shared and virtual memory your using. It even shows the memory foot print of Chrome and every other major browser.....NICE!!



The weird thing I noticed is that it installs its self not under the "C:\Program Files" folder but under "C:\Documents and Settings\[USER NAME]\Local Settings\Application Data\Google\Chrome\Application\chrome.exe"

Not surprisingly GMail and iGoogle load really fast!!

When you go to Google's Toolbar page. It recognizes the browser as a pre-Firefox 2.0 browser. I guess its not supported yet or maybe they are planning on baking in the toolbar functions.

Final thoughts
I'd say for a first beta, this browser is very stable and FAST!!
The one thing I have a complaint about, and this complaint I actually have with every browser. Is that the fonts, links & other html elements don't render as nicely as in IE. IE always seems a little softer on the viewers eyes.
I'm looking forward to see what kind of Google services they start hooking into it.

Update


Happy Easter
For you non-programmers, there's an Easter egg, too: type "about:internets" into the Omnibox.

Other "about:" features
• about:memory shows how much memory the browser--and any other Web browser--is using. Conveniently for Web developers, it also shows how much each Web site in a browser tab is using.

• about:stats shows a wide range of internal measurements such as the time taken to initialize Chrome, load Gears, or perform various operations while running JavaScript programs with Chrome's V8 engine. The page also carries the amusing note, "Shhh! This page is secret!"

• about:histogram into Chrome's address bar shows many performance details.

• about:network tracks the detailed network activity of using a Web site.

• about:version shows details of what version of Chrome is running, along with the user-agent text that the browser reports when identifying itself to Web sites. Why "Mozilla" is in this string is a mystery to me, though perhaps it has to do with the way Chrome can use Firefox plug-ins; why "Mozilla" is apparently in the iPhone's user-agent text is even more a mystery.

• about:histograms graphs various performance measurements such as the time taken to autocomplete text users type into the browser.

• about:crash crashes the active browser tab.

Monday, July 28, 2008

2008 San Diego Comic Con

This is the first year I went to the International Comic Con and it was amazing and claustrophobic. They had some really cool sessions about the new season of HEROES & LOST. I also got to see the pilot for a new show called FRINGE by J.J. Abrams. Its kinda like a X-Files meets CSI. The pilot was very good...can't wait to see more. Plus they had some kick ass movie previews of X-Men Origins: Wolverine, Terminator: Salvation (which by the way is shaping up to be a really good movie on how John Conner becomes the leader of the resistance) & The Watchmen.

The Comic-Con offered a little bit for everyone. They had ANIMA, Movie & Show previews, Video Games. How To Sessions on the entertainment industry like, breaking into game development, becoming a custom designer for shows and movies & portfolio reviews by the big guys at Marvel, DC and many others. In the booth section you had the WB, Marvel, DC, XBOX, Playstaion, artists and of course comic book sellers. They also had great panels with Matthew Fox and the writers from LOST, Kevin Smith, Frank Miller, director and stars from Terminator Salvation and ton of other guests.

Not everything was great. The amount of people that were their was astonishing...125,000 people attended! That's like the amount of people in an average city squeezed into one building. You felt like cattle...Mooooo!! Also if you really wanted to see a certain session, be prepared to get there early and get used to waiting in lines.

Overall though it was a great experience and something any scfi or comic book nerd should experience at least once.

Here are some pictures from the Con...