Archive for April, 2012

Using jQGrid with ASP MVC controllers

April 24th, 2012

I have been toying around with making the JQuery Grid found over on this site http://www.trirand.com/blog/ work with a asp.net controller and I finally got it working after much trials and tribulations, all because of a couple of little gotchas I either didn’t see in the documentation or just overlooked.

Here is the javascript code that will load a jQgrid into your div on your page that uses a plain ActionResult method in a MVC controller that is tagged with the [HttpPost] attribute.

$("#list2").jqGrid({
                url: '/Product/GetProducts',
                datatype: "json",
                jsonReader : { repeatitems: false },
                mtype: 'POST',
                width: 550,
                colNames: ['Name'],
                colModel: [{ name: 'Name', width: 120, align: 'left', editable: true}],
                toppager: true,
                pager: $("#jqTablePager"),
                rowNum: 10,
                rowList: [5, 10, 20, 50],
                sortorder: "desc",
                viewrecords: true,
                multiselect: true
            });

Notice this line ‘jsonReader : { repeatitems: false }’, you seem to need that line if you don’t have an Id column in your data that you are mapping to a column, that was really killing me cause I was just trying to show a simple list of products with a Name property in there.

The other ‘gotcha’ that I had to do a lot of research to finally find out was the way that you have to wrap your JSON in order for the grid to display it correctly. I have included the code below that will return a correct set of JSON assuming you are using a List of some kind of object.

var jsonData = new
            {
                total = products.Count(),
                page = totalPages,
                records = products.Count(),
                rows = (
                    from p in products
                    select new {
                        p.Name
                    }
                ).ToArray()
            };

And then finally here is the HTML that will place the jQgrid and a paging mechanism right below it.

<table id="list2"></table>
<div id="jqTablePager" />

Still Hacked!

April 18th, 2012

In my ongoing effort to keep my word press blogs from being hacked and redirecting folks all over those interwebs, I have finally found something that can show you just what is effected in your word press blogs.  Just go to your Dashboard and then to your plugins and ‘Add New’ plugin and do a search for ‘Exploit Scanner’.   This little tool will do a complete scan of your sites php files and will give you a report of the ones that have the potential threat in them too, it also says it will scan your database, although I found I didn’t have any problems in mine.  I found that in my particular situation, the problem was in all the themes I have downloaded in the past, the code in most of those directories was still hacked.  I recommend before you run this file go look thru your wp-content directory and then down in your themes directory and delete any themes you may have in there, it will speed up this search and save you time in your effort to eradicate this problem from your site :).  I hope this helps somebody out there, I know this has been pretty frustrating for me and I guess the plus side to it is that I have learned how WordPress works and a little more about php on the side. I also recommend going to your dashboard and doing a re-install of your current word press install, it will re-enable a lot of things that may or may not work in your admin.

Getting image of GIS map

April 17th, 2012

Have you been racking your brain trying to get an image from your map and have just about given up?  I have went through several GIS libraries including OpenLayers, ThinkGEO and some others and finally came across SharpMap which is an open-source .net library that does geo-spatial imagery and it just so happens to have a very nice little Image export routine that does the job and does it simple, here is all the code you need to generate a map from SharpMap:

//code to create Lat and Lon points
var list = new List<KeyValuePair<double, double>>();
 samplePoints.ForEach(delegate(ScoutSample sample)
 {
      list.Add(new KeyValuePair<double, double>(Latitude,Longitude));
});

var layer = new VectorLayer("Field Layer", provider);
layer.Style.Fill = new SolidBrush(Color.Green);
layer.Style.Outline = Pens.Black;
layer.Style.EnableOutline = true;
            
var map = new SharpMap.Map(new Size(250, 250));

//code to add the points
foreach (var pt in points)
{
     //Add a single Point
     var geomColl = new Collection<Geometry>();
     var vLayer = new VectorLayer("GeometryLayer");
     var point = new SharpMap.Geometries.Point(pt.Key, pt.Value);
     geomColl.Add(point);
     vLayer.DataSource = new GeometryProvider(geomColl);
     map.Layers.Add(vLayer);
}

map.Layers.Add(layer);            
map.BackColor = Color.White;
map.ZoomToExtents();
var image = map.GetMap() as Bitmap;

Of course I am not showing you my provider at the moment, I am still fine-tuning the code and I will update this code at a later time, but this is just so easy, just instantiate the map and then call GetMap(), that is how it should be done. There isn’t any methods in OpenLayers that I could see and ThinkGeo has to have a control loaded before you can run the GetMap, which is garbage.

Need a good conference to go to?

April 17th, 2012

Are you tired of all these tech conferences where the focus is on the sponsors instead of the content?  I was so I started looking around to see what other conferences were available that focused on the content first and I came across the StrangeLoop conference in St. Louis.  You can visit this conference over at their website at http://www.thestrangeloop.com.  It’s usually in the fall and starts on a Sunday, at least the workshops start on a Sunday if I remember correctly.  I didn’t get to attend the workshops last year cause they sell out so fast, so you had better reserve your spot soon, as the conference sells out rather quickly, even with around 1000 attendees!!  The focus of the conference is web development but there is a rather large functional programming group there.  Coming from a .net background, I had a lot to learn, but I am learning more and more about the web dev world and how things work over in that space.  I highly recommend this conference if you are looking for something very different from the normal conferences.

A generic error occurred in GDI+.

April 13th, 2012

Are you getting this error when you try to save an Image to your disk somewhere?  I was getting this very “Generic” error when I was trying to write a Bitmap out to my hard drive using Windows 7.  I was just trying to write it to C:\temp\test.bmp and it was throwing this error up which didn’t tell me a thing.  It turns out that the error is masking the real error, which looks to be some kind of permissions error, so if you just change it to either save it to another drive or even another folder, this error should go away.  I hope this helps someone else out there struggling with this issue.

Keyboard stops responding in Visual Studio 2010 when editing js files.

April 9th, 2012

It appears that sometimes when I am editing a javascript file in Visual Studio 2010, the IDE will just stop responding to my keyboard.  Thinking it was my keyboard I tried unplugging and re plugging it back in to see if it is a USB issue and that doesn’t fix it.  I actually found a bug report to Microsoft located HERE to which there are no solutions provided, just a “We are planning on fixing this in the next version.  I will report below some of the things that I have done that have brought the keyboard back for me in case you run into this problem yourself.

1)  If I press Ctrl+Shift+Caps Lock+Tab all at once it seems to free it back up for me.
2)  CTRL+TAB either once or twice seems to do it as well.
3)  Sometimes, closing and re-opening the specific code window I’m working in fixes it.

I hope this fixes this issue for you should you happen to run into this problem.

Publishing apps to Windows Azure from Visual Studio 2010

April 5th, 2012

I have been tinkering around with Windows Azure using Visual Studio 2010 and I am finding that more and more of the articles you find on the internet are either outdated or just wrong. This is very well likely due to the fact that things have changed over the course of the last year or so with Windows Azure. Here is the steps I took to get my app actually published to Windows Azure, hope it helps.

I am not going to go into the creation of the app, just the publish part of it, there are tons of examples out there that go into details of how to create your app and there are several example apps you can download as well. You have to make sure you have a Windows Azure account of course to go through this tutorial I have here as well, again, pretty self-explanatory.

 

The first thing to do is open your project in Visual Studio 2010 and right click on your Azure Project and click on Publish:

The next step you will see a screen like this:

You will need to create a Certificate by dropping down the Credentials dropdown and then hitting “New”, that will bring up a screen like this:

You can make your certificate in this screen and then use the “Copy the full path” link there to get it copied to the clipboard and then you will also need to get your subscription ID from the Windows Azure portal, you can find that under “Hosted Services” under the right hand pane in the “Subscription ID” box.  When you get that created, you can click on ok and you are almost ready to publish your app to azure.

Before you click OK on the next screen, over in your Azure portal, you need to make sure to upload your certificate to Windows Azure so that your app will be authenticated with the server.  In the azure portal, locate the “Management Certificates” under “Hosted Services, Storage Accounts and CDN”, click on that and you will see something like this below.

Then just click on the “Add Certificate” button

and you will see a screen like this one:

Your subscription will have been chosen assuming you have already taken care of all of that before by signing up for azure, you then click on the Browse button and then paste in your directory, you will probably have to clear out the certificate key filename to allow you to open the directory to choose the file, then ok that and then ok this screen and you will have your app authorized for azure.

Finally you can go back to studio and click on your ok button to publish your app to azure, it does take a while and the progress of the publish will show up in the lower section of studio in the activity log.

Researching Windows Azure Apps

April 2nd, 2012

I am doing some research on writing applications on Windows Azure, or Microsoft’s new cloud based computing solution. I am finding that most of the “Tools and SDK links” they provide me were not the correct files that I needed to get my example projects to work correctly. Here is the link that I found that correctly gets the libraries installed that you need. http://www.microsoft.com/download/en/details.aspx?id=15658

You have to install both the VSCloudService.exe and the appropriate WindowsAzureSDK for your environment.