ASP.NET MVC Plugins

Dec
05
2008

One of the last things I posted here was how I was toying with flexible content and template solutions in ASP.NET MVC. For that project, we're going forward with the solution that emerged from that experimentation and I'm excited to see how it turns out. 

Along the way, an interesting question about how to create what are essentially plugins for the MVC framework. Basically, if what you're building is an MVC app that will be deployed in dozens, hundreds or thousands of independent implementations, it becomes obvious pretty quickly that you need most of the pieces of the application to be modular so they can added/removed/overridden at least to a minimal level.

I've come up with what I think is a workable solution, which is pretty much just gathering up some of the other ideas already out there into a quick-n-dirty working prototype. The basic idea is this:

Put an encapsulated set of model classes (or none if you depend on central model classes), controller classes and a set of views into its own DLL. The views (using the default WebForms view engine, they're aspx files) go in as resources.

Pull that DLL into your MVC application and the MVC stack inside your "plugin" will work just like if those bits had been a "natural" part of the base MVC application. In fact actually creating the pieces from inside the main app and then moving them over to their own project is the quickest way I found to actually create the bits for the plugins.

When the question came up, I vaguely remembered seeing a question on StackOverflow about how to put views into an assembly/DLL. That question along with one on VirtualPathProviders provided most of the kernel of what I needed.

So, on to how to actually do this.
Read the rest of this entry »

Sit on Your Butt and Watch Movies Day

Oct
01
2008

Creative Commons Licensephoto credit: Usonian

A few years back (I can't really remember exactly when), my lovely wife looked at the calendar, and, seeing my birthday a week ahead, asked me what I wanted to do for the day. That wasn't the first year she'd asked that question. However, it was the first where I came up with anything other than a shrug an "I don't know".

When she asked that time, I stopped and gave it some thought. A few moments later, an answer tumbled out of my mouth, "What I really want to do is spend the day sitting on my butt and watching movies, with the laptop in front of me".

Once said, I realized that it was really exactly what I did want to spend my birthday doing. Holidays all celebrate something. Birthdays are celebrations of specific individuals and the things they enjoy. For lots of people, that celebration involves large groups of people, noise, loud music and a great deal more activity than I have ever really enjoyed.

I do, however, really enjoy chilling out and watching movies in my home theater, while messing around online and writing code for my own purposes. Thus was born the first Sit On Your Butt and Watch Movies Day.

The first one turned out to be an amazingly great day, humble though the activities may be. I chose movies entirely based on what *I* felt like watching, had a couple of tasty meals, and thoroughly enjoyed myself.

After that, when people asked me how I spent my birthday or how I was going to spend an upcoming one, I would relay my new tradition. What surprised me is just how many people seemed to stop for a second, think about it and say, "You know, that's a really good idea.".

Clearly, this day has an appeal for lots of people and every year, more and more people join in. However, I have been asked for what the "rules" are. Given how I didn't exactly start this as some sort of grand vision, I have pretty much just made on-the-spot rulings on people's questions.

My birthday is coming up this coming Sunday, and I figure I might as well share a more "structured" version of the holiday for those who want to join in on the laid back fun. Since the main day is on the weekend this year, things are wide open if you'd like to join in.

Suggestions on this list are welcome and those that strike my fancy will be included in next year's revised definition.

Your Guide to Sit On Your Butt and Watch Movies Day

  1. Sit On Your Butt and Watch Movies Day is a laid back holiday. Where any rule would cause you stress or discomfort, the rule should be deleted.
  2. Sit On Your Butt and Watch Movies Day is celebrated on October 5th (J Wynia's birthday), your birthday or the birthday of someone nearby.
  3. If those days are inconvenient, choose the nearest weekend day.
  4. There is no limit to the number of celebrations in a calendar year.
  5. Whenever possible, the day should be without work, either employment or house-related.
  6. The number of movies to be watched must be at least 2, ideally 5-8 and limited only by your definition of "day".
  7. The primary celebrant shall be the holder of the remote control and, should an all-in-one universal remote not be available, the holder of all of the remotes for the duration of the celebration.
  8. The movies to be watched must be either personal favorites or movies you haven't seen before. Any movie which might inspire a "meh" should be left in the DVD stack until later. There are to be no compromises or sacrificial choices for the sake of others in the room.
  9. Any movie which causes the celebrant to think to him/herself, "Why am I still watching this?" should be ejected immediately and the next movie on deck begun. Letters to the producer/director/lead actors about how they ruined your own personal holiday are entirely optional, but should wait until the next day.
  10. Because the movies can't be paused while you visit the bathroom or get snacks at a theater, Sit On Your Butt and Watch Movies Day is best celebrated in a home theater.
  11. There should be a comfortable seating arrangement, temperature adjustment and lighting levels. Suggested configurations tend toward dimmed lights, slightly cool temperatures and an overstuffed recliner or sofa. Seating choices which allow the feet and heart to be on the same level are optimal.
  12. There shall be no talking during the movies. Or, if the celebrant is one who is prone to talking during movies, there shall be little silence. Whatever. Either way, recitation of catch phrases and favorite lines along with the actors are welcome, but should only begin when the celebrant starts it.
  13. The snacks must be many and diverse, covering all of the snack groups: salty, sweet and savory.
  14. The meals should be delivered or otherwise easily obtained during short intermissions.
  15. The celebrant's beverage of choice must flow freely. While the official beverage of Sit On Your Butt and Watch Movies Day is Coke Zero, that should in no way influence the beverage choice.
  16. In case the snacks and meals may prove to exceed the digestion capacity of the celebrant, antacids and/or Pepto Bismol must be readily accessible.
  17. To provide the best movie roster, the movies should be planned in advance, saving particularly desired movies just for the day.
  18. Showering or communicating anything more sophisticated than grunting is entirely optional.
  19. Finally, should the nearest celebration be too far away to be bearable, emergency celebrations can be declared at any time. It's *somebody's* birthday.

This year's stack of DVD's looks like this, with a couple of slots still open:

  • Iron Man
  • Run Fatboy Run
  • Leatherheads
  • The Forbidden Kingdom

Dynamic Font Replacement: sIFR, FLIR and More

Aug
22
2008
numeral types
Creative Commons License photo credit: threedots

A couple of weeks ago, Antonio Lupetti shared a list of 10 "handwritten" fonts that he uses in his design projects. He also does a brilliant job of integrating that stuff into the diagrams in his posts, which is why I paid attention when he put out a list (just take a look at his archives and you'll see what I mean).

As I was looking at those fonts and downloading them, I was thinking about sIFR, which I've mentioned before. It's a way to replace text in web pages with Flash on the fly, using fonts that aren't on a user's computer. I've wanted to include that on this site and on several others for quite a while.
Read the rest of this entry »

Writing My Own Travel Agent in C#

Jul
30
2008

Yesterday, Garrick was describing the difference between a "search result" and "find". His short answer was:

Search Results Listings say, 'The answer might be here'. Find says, 'Here you are, get on with your day.'”

That distinction is something that has always struck me as irritating about using every travel site I've ever seen (later discussion revealed that, ironically, this distinction is talked about obsessively at Orbitz). That irritation is because every search I've made started out as something that doesn't fit in their search boxes: "Find me a cheap coach flight and a hotel near the conference center in Austin, TX for SXSW", "I'd like to go to San Francisco for a long weekend some time this fall; is there a way to do that for under $500?" or "Which one of these cities and which weekend will be cheapest in October for a 5 day weekend?".

Those aren't questions which naturally get answered by a search results page. You don't get to pose those questions to travel sites. What you are asked on every one of them is to choose specific dates and, in many cases, both airports. The sites don't even so much as hold on to the fact that 99% of my travel is based out of Minneapolis/St. Paul International Airport.

Rather, I get a constant flow of emails from the travel engines telling me about great deals to Miami/Las Vegas/New York for $89. Of course, if you are flying out of Minneapolis, that deal suddenly becomes $327 instead.

There is a place you could and can ask those questions and get your "find" satisfied. Travel agents pick up the phone, listen to just such a question and call you back later in the day with the results of your find. Unfortunately, they also are professionals who need to make a living. That means they're not entirely thrilled to, for instance, check daily for weeks at a time for a very specific set of criteria for a vacation I may take if the deal is good enough.

That does, however, smell of the kind of thing that I like sling a bit of code to solve. And, it's something I've wanted to solve for a very long time. Every couple of months, I go looking for a way to write code that searches for flights and hotels and have always come up empty.

Then, this weekend, I did it again and ran across the Kayak API, which looks like what I've been looking for all along. The API allows 1000 searches per day, per developer key. While that wouldn't let me create much of a public service or commercial application, it's a really roomy number if you're looking to do lots of permutations for your own travel needs.

Personally, I'd like to do things like have a list of cities I've never been to and have software grind away on it, finding a good deal for a "fall long weekend" or a "week-long summer vacation", etc. for one of those locations. Similarly, I'd like to be able to say, "I've got $300. Is there somewhere I can go and get a hotel for a 3 day weekend that's on my list?".

Software can easily handle digging through the tedious crap like seeing whether leaving on Thursday and coming back on Sunday is cheaper or more expensive than leaving on Friday and coming back on Monday. As a person, trying those combinations on the existing search results-oriented sites is tedious. Tedious is what software does best.

Before I start dreaming too big for what might be possible, I threw together a quick POC app to see how easy it might be to search and grab results. I created a really basic class library for doing the actual searches and a tiny console app to try out a single search.

I have to say, I like what I see and think that there are some real possibilities for coding up my own travel agent with Kayak.

The sample, half-finished POC code is available in PDF form if you want to look at it. It's got gaping holes all over (hard-coded, read-only properties, unused properties, concatenated strings, etc), but shows the basic idea for how to hit the service. This doesn't do anything to take advantage of any of the polling cycle that the API documentation describes, so the results are incomplete.

However, it proved what I wanted from the POC. I'm now pretty sure that I'll be able to get what I want out of that API. If you're interested in travel and writing software, it might be worth a look for you as well.

HTML as Page Layout Language

Dec
28
2007

Off and on over the last 6-8 months, I've been working on a project that needs PDF as its final output format. The plan has been to use DocBook and the toolchain attached to it. However, that's been more frustrating than it first looked when it comes to integrating into the whole system I'm designing.

Then, earlier today, someone posted a link to this YouTube video, which demo's the functionality of the Prince engine. That revealed a system for really nice page layout using HTML and CSS (with CSS3 handling the page breaks and other stuff like it was designed to, making Prince the only implementation of CSS3 out there that works as far as I know).

Given how my project is web-based, being able to just keep it all HTML from end to end and still get really nice PDF's out the other end would be a huge benefit. And, given how this project will be commercial and how much time I've already spent trying to do all of the conversions back and forth, even the steep pricetag for a server license will likely be a net bargain.

Fortunately, the version that puts a little logo in the top, right corner of the PDF (only for display, not printing) is free for development/personal use. So, I messed around with that a bit tonight and got a feel for it. There are versions for pretty much all of the platforms (Windows, Mac, Linux, BSD, etc.) and integration with code for automatic generation is fairly easy.

Really basic conversion using C# only took 3 lines of code. I just grabbed the normal Windows version, also downloaded the DLL and added that DLL to a basic console app.

Then, these 3 lines work to dump out a PDF of the page in question. I just threw together a quick HTML document to test with a few H1, paragraphs, etc.

IPrince pr = new Prince(@"C:\Program Files\Prince\Engine\bin\prince.exe");
pr.AddStyleSheet(@"C:\Program Files\Prince\Engine\style\xhtml.css");
pr.Convert("demo.html", "demo.pdf");

Pretty easy startup as far as I'm concerned. The video is worth watching, despite being somewhat irritating to watch. Like many presentations to a room full of geeks, there's quite a bit of not seeing the forest for the trees. Lots of people shooting it down by saying, "this is would be REALLY great if it supported my one pet feature" kind of stuff. They got a bit hung up on those little nit-picking details and I wonder how much of their presentation ended up left out as a result.

Based on what I've seen so far, I definitely think it's worth tinkering with a bit more and doing the math on that license fee as part of my project budget.

« Older Entries  

J Wynia

For better or worse, I'm the guy who runs things here. I'm a web consultant, software developer, writer and geek from Minneapolis, MN. This site is a fairly wide cross-section of the things I'm interested in and enjoy writing about.

Oh, and if you happen to be looking for hosting for your Subversion repositories or just web hosting in general, take a look at Dreamhost. It's what I use for Subversion and your signup helps me out.

Feeds and Links


www.flickr.com
This is a Flickr badge showing public photos from J Wynia. Make your own badge here.

Search


Pages

Archives

Computers Blog Directory
© 2003-2009 J Wynia. All original content is licensed under the terms of the Creative Commons Attribution license unless otherwise noted. Content from other sources is licensed under its original terms.