One thing I’ve learned today: Learning new technologies via samples results in Frankencode

I was asked to develop an internal tool that would manage the advertisements we would display in our application. My requirements were simple: I needed to provide the user the ability to view the list of existing ads, create an ad by uploading an image along with the ad metadata, update and ad or delete an ad. Since our customers would never see this application, I went on a limb and chose a technology I’d never tried and knew nothing about: .Net Web Api. I figured I’d adapt one of the many excellent examples I found on the web so that it would serve my purpose. How difficult could it be?

I wrote the service component first and left the ad management user interface till last and for that, I chose a simple product catalog sample application that used jQuery and Knockout.js, two more technologies I had no previous experience with. Again, I knew there were lots of code snippets available on the web for those libraries so, armed with a decent search engine and StackOverflow, how could I go wrong?

The product catalog sample provided me with code for a basic grid and a set of detail fields. The user would enter the row id in an edit field and click a button to fill the detail fields with the data for that particular ad. An Update and a Delete button at the bottom of the page would update or delete the selected ad. This wasn’t quite what I had in mind but it was a close approximation. I figured adding a delete button to the appropriate row in the grid and providing the ability to click a row to populate the detail fields would be simple to implement once I had the basic functionality working.

I looked for examples of image uploading and found several, all with their quirks and limitations. Figuring out which limitations I could live with and which I couldn’t took some time. I really wanted to be able to upload an image and its associated metadata (name, width and height) all in a single POST request but most of the samples either dealt with uploading just the file or uploading a whole slew of files…but no other data. I tried all sorts of file upload methods with various degrees of success before settling on one that used a strict HTML page with a form tag and a submit button. Have I mentioned I’d never dealt with uploading files over HTTP POST requests before?

Frankencode monster

Once I got the file upload working (though I’m now working on the functionality that will inform the user whether the upload succeeded), I stepped back and took a cold hard look at my application. What I saw was a Frankenstein-type application. The samples I combined were never meant to go together. I know I’m not validating my fields in an even remotely optimal manner. I’ve tried to hide the delete button for images that are still referenced by an ad and therefore can’t be deleted but haven’t figured it out yet. It should be a simple matter of making the delete button’s visibility conditional upon whether the image is referenced by an ad but my condition always evaluates to true so I still have to do a bit more work on the project.

Have I learned something? A resounding yes! I can now claim to know some jQuery, a bit of Knockout.JS and something of .Net Web APIs. However, I’m lacking a lot of the very basic knowledge that I would have gained if I’d picked up a book about any of these topics and read the first few chapters. I liken it to trying to learn C# by trying out async samples. You might eventually understand how the async functionality works but without an understanding of basic C# constructs, you won’t be able to extend those samples without creating a monster and without looking for yet another sample to base your next bit of code on.

But I have to admit it’s been a lot of fun! 😉

OneThing I’ve Learned Today: Windows 8 tidbits

Just this past week, I upgraded from Windows 7 (32-bits because my desktop is ancient) to Windows 8. The upgrade went very smoothly which gave me some good vibes about this new operating system.

It’s only been a few days so I’m still getting used to the new Start Menu and the way Metro-style applications work but so far I’ve enjoyed the experience though I’ve had tCharms baro change a few of my habits.

 

Charms bar with two monitors

I have two monitors but I don’t always turn them both on so bringing my mouse to the top or bottom right-hand corner of my screen without having it navigate to the second screen requires more precision than I’m willing to exercise. The solution? Shortcuts! The Windows key + C will bring up the Charms bar quickly and effortlessly.

Sleep

Rather than shutting down my computer when I’m not using it, I normally use Start Menuthe “Sleep” power option. In Windows 8, this option can be found on the Charms bar / Settings / Power / Sleep. It can also be reached via Ctrl + Alt + Del / Power / Sleep. Downright inconvenient if you ask me. The solution? Create a tile for the Start Menu. I called mine “Sleep” and placed it as lowest and rightmost tile of the menu though you can place yours anywhere. On the picture here, it’s the one with a royal blue background and a blank page for the image.

In Windows Explorer, I navigated to:

C:\Users\***username***\AppData\Roaming\Microsoft\Windows\Start Menu\Programs

Here, I created a shortcut by right-mouse clicking and selecting New Shortcut. A Create Shortcut dialog appears. Here, I gave it the following command line:

C:\Windows\System32\rundll32.exe powrprof.dll,SetSuspendState

Then I clicked Next, called it “Sleep” and clicked Finish.

In my case, I needed to perform one more step. I needed to disable hibernation on my computer. To do so, I followed the instructions found here.

Over the next few days or weeks, I’ll try to post about more useful tidbits as I find them. If you’ve found this information useful, leave me a comment! :-)

 

One Thing I’ve Learned Today: Joining the community is hard work!

Blogs have been around for a long time now and until recently, I was convinced I had missed the boat. So many people were publishing excellent content on flashy and often well-designed web pages, how could I hope to compete?

 

I regularly read various technical blogs but lately, I’ve started to feel like I’m on the outside of a fascinating community looking in. It took several invitations like this one before I gathered my courage and took the plunge.

So here I am, a newbie in a world of pros. Tonight, I figured out basic things like how to change the theme on my WordPress out-of-the-box blog page. I added the RSS feed and social media (the few I’m connected to) icons though I’m not convinced I like them yet. I’d much prefer if they stayed put. I also created a new Facebook page to go with the blog. I now feel more connected but utterly flummoxed at how many hours it took me to research and learn about everything so I could configure things almost just right.

So now that I’ve finally made a step towards joining the “community”, will it accept me? Will it think what I have to offer is good enough? Is it sufficient to create a blog and regularly write to it? Is it truly a case of “if you build it, they will come”?

Somehow, I suspect that joining the community is likely more a journey than a destination and that the hard work is yet to come… 😉

One Thing I’ve Learned Today: MVC Custom HtmlHelper

This week, I’ve spent some time learning MVC and one of the things I was trying to do was to display an image given the path to an image file. Using an <img /> tag in a Razor view seemed crude and less than optimal. That’s when I started watching the MVC PluralSight course offered for free here.

I wanted to be able to use

 @Html.Image(item.ImageUrl, item.Name)

 

Unfortunately, no such thing exists out of the box. However, making this work is surprisingly straight-forward:

Create a custom HtmlHelper class.

using System.Web.Mvc;

namespace MvcApplication1.Infrastructure
{
	public static class HtmlHelpers
	{
		public static MvcHtmlString Image(this HtmlHelper helper,
			string src, string altText)
		{
			var builder = new TagBuilder("img");
			builder.MergeAttribute("src", src);
			builder.MergeAttribute("alt", altText);
			return MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing));
		}
	}
}

Now, all I need to do is add a using statement to my view and add my Image tag where needed:

@using MyProject.Infrastructure
 ... blah blah blah...
 @Html.Image(item.ImageUrl, item.Name)


Quick, simple, and elegant. And if this custom HtmlHelper class is used in more than one view, you may want to forego the adding of the using statement in the view and instead, modify the Views\Web.config file and add the namespace to the list of namespaces defined for razor.

 

One thing I’ve learned today: The MCSD certification is back!

Many years ago, I earned my Microsoft Certified Solution Developer (MCSD) certification passing exams on such technologies as Microsoft Foundation Classes (MFC) which I used a lot and VisualBasic 4.0 which I never actually coded in. Lucky for me, I earned this certification before Microsoft realized that certifications aught to expire. This means I can still proudly claim my MCSD status high and low, regardless of how obsolete those technologies are today.

That was then, and this is now. Microsoft now has a new MCSD certification aimed at developing Metro-style apps (HTML5 or C# are the two streams offered) and one for web applications (covering HTML5, MVC, Azure and web services in its single stream).

Methinks I’ll have to try for a second MCSD certification… 😉

At least one thing I’ve learned today…

In the hopes of keeping up with the ever-changing world of software design and development, as well as any other area of life, I’m going to try an experiment: I’m going to attempt to post at least one thing I’ve learned each day on this blog. Hopefully, this will slow down my inevitable obsolescence.

So today’s pearl of wisdom was a bit of a ah-ha moment for me. Since I started working in the software domain, immediately after graduating from a program that claimed to have prepared me for it, I’ve felt overwhelmed by the speed of change. Programming languages mutate, tools and libraries multiply, methodologies come and go, and the only constant is that what I thought I knew yesterday is only barely good enough today and won’t cut it for tomorrow.

I listened to Scott Hanselman’s Hanselminutes podcast with Iris Classon and heard Iris mention that men tend to celebrate new knowledge whereas women tend to lament the extent of the what is yet to be learned. That’s me to a T.

Well, starting today, I’m going to celebrate my successes each day! Feel free to join me!