A Code Voyeur article demonstrating how to create an extensible repository base class using NoRM and MongoDB.
http://www.codevoyeur.com/Articles/20/A-NoRM-MongoDB-Repository-Base-Class.aspx
A Code Voyeur article demonstrating how to create an extensible repository base class using NoRM and MongoDB.
http://www.codevoyeur.com/Articles/20/A-NoRM-MongoDB-Repository-Base-Class.aspx
While most .NET developers who want to work with MongoDB focus on C# with NoRM and MongoDB-CSharp, there’s an alternative – IronPython and PyMongo.
PyMongo is the 10Gen developed Python driver for MongoDB. It’s actually pretty easy to get it working with IronPython. The steps are as follows:
That’s pretty much it. Python eggs are apparently incompatible with IronPython, so you can’t just drop the egg in site-packages. There may a way around that of which I’m unaware.
Finally open up ipy.exe and try:
IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.4927
Type "help", "copyright", "credits" or "license" for more information.
>>> from pymongo import *
>>> conn = Connection("localhost", 27017)
>>> db = conn.blog
>>> posts = db.posts
>>> posts.insert({"Title" : "On Using PyMongo with IronPython", "Author" : "John Zablocki"})
ObjectId('4bfee0c4af6bd912f4000000')
>>> posts.insert({"Title" : "On Installing PyMongo as a Service on Windows", "Author" : "John Zablocki"})
ObjectId('4bfee0e3af6bd912f4000001')
>>> posts.find({ "Author" : "John Zablocki"})
>>> posts.find({ "Author" : "John Zablocki"})[0]
{'Author': 'John Zablocki', '_id': ObjectId('4bfee0c4af6bd912f4000000'), 'Title'
: 'On Using PyMongo with IronPython'}
>>> posts.update({ "Author" : "John Zablocki"}, { "Author" : "John C. Zablocki"})
>>> posts.find()[0]
{'Author': 'John C. Zablocki', '_id': ObjectId('4bfee0c4af6bd912f4000000')}
I haven’t played with it too much yet, but the basic CRUD functionality all seems pretty solid.
I speak just enough Italian that I’m able to order a glass of Chianti and find my dog a toy in a Venetian marketplace. Nonetheless, I’ve been published in the Italian DEV magazine (which I think is pretty cool). DEV is a community-driven, non-profit magazine.
A few notes to save you some headaches while installing MongoDB as a service on Windows… It seems that it’s common to encounter the results below, so these are some things to remember.
Sat May 01 11:52:40 dbexit:
Sat May 01 11:52:40 shutdown: going to close listening sockets…
Sat May 01 11:52:40 shutdown: going to flush oplog…
Sat May 01 11:52:40 shutdown: going to close sockets…
Sat May 01 11:52:40 shutdown: waiting for fs preallocator…
Sat May 01 11:52:40 shutdown: closing all files…
Sat May 01 11:52:40 closeAllFiles() finished
Sat May 01 11:52:40 dbexit: really exiting now
More on MongoDB in a later post…
I’ve always been bothered by writing code like:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About() {
return View();
}
public ActionResult Terms() {
return View();
}
public ActionResult Privacy() {
return View();
}
public ActionResult About() {
return View();
}
}
So many methods doing the same thing and possibly scattered across many controllers… Sometimes inheritance works, but sometimes it’s not a possible solution. Castle’s Monorail has dynamic actions to address this problem. In this Code Voyeur article I demonstrate how to solve the problme in ASP.NET MVC.
A former co-worker once said to me that he hated Apple for its insistence on putting form ahead of function. After nearly two years of being a Mac and iPhone user I’m pretty certain I agree with his assessment. Most of my frustration with Apple has to do with its MobileMe service. In theory, it’s a great idea. MobileMe has email, contacts, calendar, picture galleries and a cloud storage all for $99 a year. If you own a Mac and an iPhone it’s a great (in theory) way to keep yourself organized.
Unfortunately, the web app is simply horrible for email. Really horrible. After a few conversations with Apple’s live chat, it’s obvious they just don’t care. Below are some excerpts from a recent conversation. I had explained to the support rep that it’s painfully slow to get into my inbox and that when I click reply, I often have to wait for a great deal of time for a new message window.
First suggestion (and the obvious one):
Javier C.: Go to the Edit menu and choose Empty Cache. Click Empty in the “Are you sure you want to empty the cache” dialog.Close any open Safari windows.
Javier C.: So let’s try to clear your cache. I listed some steps to clear your cache up above
Javier C.: You must make sure you close all windows that you have open in safari
That did nothing. And interesting that he presumed I was on Safari, even though I told him I was on Windows. I use Chrome.
Javier C.: What email application are you currently using for example outlook, thunder bird?
OK, I’m asking about a web app problem. Unclear…
Javier C.: It is showing that you have over 13,000 emails in one folder, and another 13,000 in a sent folder
Yup, I send a lot of email. Why should this be a problem I wondered…
Javier C.: What were probably going to have to do is archive the folders or delete some messages. Since there are so many messages in your folders your computer may act slow due to having so many messages in your folders. Over 5000 will cause your computer to act slow and you have 13,000 in one folder and another 13,000 in another
Uh, really? How does having thousands of emails on Apple’s server make my computer slow? When they’re in archive folders that I rarely click into? And again, on Apple’s servers…
Javier C.: What were looking for is something called outlook or outlook express, I really think this could help our situation.
ok…
Javier C.: If we setup Outlook then messages will download once instead of over and over when you open the browser.
Javier C.: It would help with the loading process in me.com we are just removing the messages off of the server.
I complained that I shouldn’t have to remove my email from the cloud. That’s why I use MobileMe after all…
Javier C.: The email will remain on the cloud
But he just told me to download it all to remove it from the server… So lost. I mentioned to him I thought it was crazy to suggest that too many messages on the server were causing problems with MobileMe’s web app. I mentioned that I have a Gmail account with 300k+ emails in the inbox. No delays with Gmail…
Javier C.: I completely understand where your coming from. Basically since there are over 20K emails in the webmail though, it is going to have a hard time processing that much data, as were are not an email only service such as gmail. Since we have over 6 services integrated with our online application, this is why the performance may be degraded. Currently at this time, the best option, would be to setup your MobileMe email in your email application such as Outlook, then once all of the emails are copied and downloaded there, create an archive of them on the computer that way they are no longer on the MobileMe server, and slowing down your optimal performance.
Wow, so he’s telling me that because MobileMe has other services, it’s OK for the web app for mail to suck.
So that’s Apple support. Impressive, no?
I’d pretty much completely written off Windows after the Vista debacle. I’ve spent the past year+ trying to become a Mac user. I have for the most part. I’m writing this post from the train on my Macbook.
Mac OS is a aesthetically pleasing. But it’s not without its faults. Programs hang. Gmail has killed Safari on multiple occasions. Finger gymnastics are required to perform simple tasks such as cycling through windows in an open application (Cmd + Shift + ~). For switching tabs in Safari you need to use Cmd + Shift + Arrow right or Left.
Spotlight is pretty spot on. I’ve tried numerous imitators (Launchy, SlickRun, etc.) on Windows. Most are good, but all fall short of the original. The lack of an Apply button is a nice subtlety on properties windows. But still in other areas, the Mac lacks. Renaming a folder requires a double click on the folder. A right click option is missed.
Mac hardware is shiny and polished. But its quality is at odds with the premium one pays to own one. My MacBook has developed an odd striping on the screen. The DVD drive sticks. I’ve known plenty of other people who swear by Apple’s Apple Care. I’m of the opinion the quality of a product shouldn’t be so in question that people are fans of an extended warranty.
I’ve also come to question the quality of my iPhone and will probably consider the Pre when my contract is up. The button on my iPhone lags. It often takes several presses to get the phone to wake or close email. It’s my second iPhone in just over a year. I know other people who have had iBricks.
MobileMe is also a terrible product, but a great idea. The web applications are sub-par. Email cannot be searched except for subject and sender (no body?!). MobileMe is slow and has iCal sharing – even on a family plan. But iDisk is really handy and the push email is more reliable than Yahoo!’s.
Perhaps it’s my frustration with AT&T that’s leading me to reconsider Windows. After all it was the iPhone that sold me on the MacBook. Not it’s the iPhone that’s making me consider the PC again. OK, it’s also the fact that I work with .NET – a platform that I still believe is the best of breed.
After two days on Windows 7 at work, I’m nearly sold. I think Microsoft finally got it. They’re beating Mac at the usability game by finding that sweet spot between power user and novice. A Mac is a great machine for the newbie who just wants to get pictures off of his or her camera. It’s a great machine for the Unix geek who eschews all things GUI. But for the user who is in between?
Windows 7 seems to let me be all three. The new keyboard shortcuts are great, especially when you have dual monitors. Jump lists and the new task bar are a fantastic way to manage your desktop. It’s fast. It’s clean. It’s Windows? The user access features have been paired down to just right. Search is drastically better than its unusable cousin on Vista.
If my experiences going forward are as they have been so far, my next laptop will probably be an HP again. If you have been considering a Mac, still do. But not unless you also try out Windows 7 first…
The CollabNet binaries for Subversion generally provide a simple means for setting up Subversion on a Windows box. The build includes Apache and the installer will get you up and running rather quickly. In the years since I’ve started using Subversion, I’ve always used Apache and therefore http as the svn protocol. Recently, I decided to avoid the extra steps involved with setting up Apache and SVN and opted instead for running the svnserve.exe as a Windows service. I’ve run into a few gotchas that I think are worth noting.
Subversion’s basic security simply stores plain text passwords. If you’re looking for a better means to protect user information, you need to use SASL. SASL allows you to create a binary users file, without plaintext passwords. SASL uses a config file, svn.conf that you store in a known path (where the SASL binaries live).
I first got svnserve.exe up and running by running it from the command line:
svnserve.exe -d -r c:\path\to\repos
Everything was working fine. So I decided to install svnserve as a Windows service. The strange thing is the CollabNet installer prompts to install the service into SCM. But even when checked, it didn’t. I tried to run the installer again to fix, upgrading from 1.4 to 1.5. The 1.5 installer changed the install path from C:\Program Files\CollabNet Subversion Server to C:\Program Files\CollabNet\Subversion Server (note the extra slash). I failed to notice this change and had parallel installations.
I googled around and found that svnserve.exe actually needs to be installed with sc (unclear on the MSI’s checkbox). So I ran:
sc create svnserve binPath="C:\Program Files..."
After some hair pulling and hand wringing, I realized that the options for sc require a space after the equals sign. There’s a vague help entry about it when you run sc, but it’s odd and subtle and will drive you crazy. The space in the Program Files path also requires some escaped quotes:
binPath="\"C:\Program Files\CollabNet Subversion Server\svnserve.exe\" --service -r: c:\repos"
Once I finally got the service installed, I was getting errors trying to start the service. I had inadvertently continued to use the old installed path “CollabNet Subversion Server” vs. “CollabNet\Subversion Server.” After I got the service running against the correct path, I started to get SASL errors.
I kept getting invalid user not found errors, though I clearly had a password file that was valid. There’s a SASL utility for checking the user list in the files. As an experiment, I stopped the service and ran the command line. It worked. I checked my SASL conf file.
pwcheck_method: auxprop auxprop_plugin: sasldb sasldb_path: passwordsdb.txt mech_list: DIGEST-MD5
It then occurred to me, that when svnserve.exe is running as a service, it wasn’t resolving sasldb_path to the correct path. I find this behavior odd, because I ran the command line from my users directory and not the CollabNet\Subversion Server directory. After that, everything was working as expected.
Another CodeVoyeur article on extending your ASP.NET MVC apps with IronPython.
http://www.codevoyeur.com/Articles/16/A-Simple-IronPython-ActionFilter-for-ASP.NET-MVC.aspx
My first experience with version control was VSS. I used it exclusively for SCM tasks until about three years ago when I started teaching at Fairfield U. I learned enough to teach the basics (through Subclipse) to college students who had never even coded before. Eventually, I was lured in further by its better checkout model and the oh-so-shiny TortoiseSVN. I signed up for an account at CVSDude and started hosting my personal projects there (great service). I’ve also migrated three companies with substantial codebases from VSS or SourceGear to Subversion. Along the way, I’ve wrestled with the various ways of structuring a repository. This post will describe what I’ve found to be useful…
There are lots of examples on how to layout your repository. Google around and you’ll find plenty of ideas. What I’ve not found in abundance is how to structure a typical repository within a corporate codebase. If you have only one product, it’s simple. But what about the more common case where a business has several related applications, with a few shared libraries. In this setting, there will be multiple web apps, services, console apps and scripts. But it all goes to support a single product.
For this example, I’ve tried (and seen many others try) the approach where each application has its own development branch. For example:
MyCommonLibrary/trunk MyWebApplication/trunk MyOtherWebApplication/trunk
One big problem with this approach is that branches that cut across applications are hard to manage. One logical branch has many physical branches. While there may be other limitations (excessive use of externals for dependencies) with this structure, this one was enough for me to move to a single branch tree. A single development trunk poses some challenges. The structure below is one I typically use and is the result of studying projects such as Spring.NET
trunk/
/build
/docs
/lib
/thirdparty
/legacy
/db
/migrations
/dml
/ddl
/src
/components
/tests
/webs
/tasks
/services
The structure should be pretty self explanitory, but I’ll describe it briefly.
While this structure won’t work for everyone, I’ve found it to be a good starting point. It provides some obvious benefits over the alternate structure I described above.