Thursday, December 22, 2011

ASP.NET MVC 3: How to update EdmMetadata ModelHash when manually adding a field to a database

Having developed web applications for 8 years now, I've gotten very used to adding fields to existing web applications. It is not an everyday thing. Maybe not even a every month thing. But it is definitely a every major release thing. With that in mind, Microsoft's MVC 3 seems a bit incomplete in what they are recommending you do every time you need to add a field to a existing MVC web application.

Option 1: Microsoft's suggested solution? Add a few lines of code that will automatically drop the table, re-create it, then seed it through an Initializer class if it detects that the schema has changed. This may be fine for development, but since most people actually looking to do this is working on a production web applications, this is a bad idea even to propose as one of the ways to add a field to your web application. And you must be extra careful when implementing this on a simple table. Imagine you or someone updated the schema of a table that has a lot of valuable data, but you just want to update a few tables with a few rows of data in it and you could easily seed it. You turn this feature on and that valuable data vanishes without a trace for that customer.

Option 2: If you try to search for the solution, the number one recommended solution is to disable checking of changes to the schema. This isn't a bad suggestion. Just turn the whole darn thing off. You and maybe a handful of people are care about schema changes anyway. Why have this elaborate schema checking system in place anyway? The answer is that the customers have compliance requirements, and they are required that their web application meets those requirements. And a common one is that they be notified of schema changes to their database.

Better Solution: What MVC does is that it runs a consistency check by hashing the schema definition. And they don't provide a well documented way to update this hash value. What they should do is let the user put the database in a learning or training mode. So that if the schema changes, it will update the stored hash value to the new value. Then when you are done adding the field, you can switch off he learning mode so that it throws up the normal server error when someone has maliciously (or unknowingly) changed the schema without alerting the right people. So this is my solution to make all that happen:

Step 1: Open Global.asax.cs in your MVC web application.
Step 2: Add these lines to the top of the file:
using myMvcProjectName.Models;
using System.Data.SqlClient;

Step 3: Add these lines to the main class for your MVC web application (the class is probably named MvcApplication).
private myDBContext db = new myDBContext();
public void Update_EdmMetadata_ModelHash()
string newHash = System.Data.Entity.Infrastructure.EdmMetadata.TryGetModelHash(db);

SqlConnection sqlConn = new SqlConnection(myConnectionString);
SqlCommand sqlComm = new SqlCommand("UPDATE EdmMetadata SET ModelHash = '" + newHash + "'", sqlConn);

Step 4: Add this line to the top of Application_Start, to run the new function to turn on "learning" mode. Just comment it out when you are done:

Italic = change these values accordingly.

Monday, December 12, 2011

The reason why the Galaxy Nexus has been delayed

The real reason? Billions of dollars of potential revenue for the foreseeable future with NFC money transactions. What Google wants to do is thin-out your wallet by getting rid of all your plastic, but in a good way. I certainly would prefer not to carry around the debit cards, credit cards, club membership cards, and clothing line cards if I didn't have to. There might have been some appeal in the past, maybe 10 years ago, to carry around as much plastic as possible. But that time is long gone as it has become a nuisance to carry the right card to the destination you are heading to. Instead, Google is predicting that swiping cards will be a distant memory in just a few short years with NFC chips that is built into newer phones. Instead of using a plastic card, you will just have a digital copy of your card on your phone, and all you will have to do is touch the smartphone to the credit card receiver. The amount of cards you can carry will be limitless, and you don't have to carry anything extra in your pocket. A real win for the consumer.

Under our noses, Google has positioned themselves to be the first successful and soon the only NFC payment service people will want to use. Even though NFC payment services have been in existence for a while, these companies are still struggling to gain any market share or convince consumers to start using NFC instead of plastic. Google, on the other hand, has smoothly made our Google Checkout accounts able to accept NFC payments (renamed it as Google Wallet), and is about to enable the NFC capabilities into android devices that we already own and carry with us all the time. And this is happening at the right at a time when the adoption of NFC payment devices at retail locations is exploding or about to explode. Well played Google. They are poised to take a percentage from every one of our credit card transactions in the future. They are one move away from saying "checkmate." And us, as consumers, are about to love Google for enabling this service.

But who is holding up the show? Verizon. And understandably so. Verizon would rather not have Google Wallet pre-installed on the Galaxy Nexus, and instead would rather have their own NFC payment app installed, and want any other NFC payment app blocked from making it on the device. So this is the real reason the Galaxy Nexus, already stocked at retail locations, is not being sold at the moment. This landmark decision is so big that Verizon is willing to lose many customers daily to AT&T as AT&T is turning on their LTE networks like gangbusters at major metropolitan areas on a daily basis.

The way I see it, Verizon is fighting a losing battle.
A) People don't like using included apps provided by the carrier, aka "bloatware". They are usually not refined, and better 3rd party solutions exist. It has become a reflex to uninstall bloatware as soon as a new phone is turned on.
B) Even if by a slim chance Verizon gets everything they ask for, gets Google to agree to remove Google Wallet, and block any other NFC apps from accessing the NFC chip, it can easily be circumvented by rooting. To add to that, what is going to stop Google from wanting users from rooting their device so that they can get Google Wallet onto their devices? Google will be on the side of the consumers, not Verizon.
C) A low level root protection could be enabled on the Galaxy Nexus and if it actually worked and held, there would be a backlash of biblical proportions by tech review blogs that it would be the worst decision Verizon can make that all the money they spent to get exclusive licensing of the Galaxy Nexus and the first one to have ICS, will be negated, maybe lost due to the impact on sales.

In conclusion, as much as Google has become "big brother", I trust Google a billion times more with the integrity of my payment transactions. Speak to anyone who has dealt with Verizon's hidden charges, erroneous charges, cancellation charges (even after you've fulfilled your contract). The way they handle themselves in your face is criminal. Basically, you are likely to get some erroneous charges when you first sign up for their service. You call, and the person that answers your phone call is already pissed off at you before you even start speaking. Then after a long heated argument on why you shouldn't be charged for something you didn't order and would never use, they make it sound like they are forgiving you by removing those charges. Then when you get your bill, you realize it is still high because they are charging you $15-$25 of hidden fees and taxes. You call them about it, and they say they have no reason to control that because it is a tax by the government. Federal, state, and local. No other carriers do this as they pay these fees which is included in your service fees. Then say after 2 years, you're done with their contract, you decide to cancel. They send you a mystery bill. When you call them on why you are getting charged for service you no longer are using, they once again are pissed off before you even start speaking. Then they ask to go talk to the manager. And they come back and say that they are giving you a break and that the manager has agreed to reduce your bill to half the amount as a favor. This is a bill you shouldn't even be paying. Then the only option of paying your bill is over the phone. And guess what, Verizon charges $5 for phone payments. This is how they run their business. It works for them because a lot of businesses like using Verizon as their carrier and businesses are unwilling to go through this kind of hassle. They instead just pay. Do you want a company Verizon acting as the bridge for everyone of your transactions in the future? Absolutely not. I trust Google more.

Saturday, December 10, 2011

Play KROQ on your Android

Wow, this took me a while. I think I spent about 3 hours total on how to get this to work properly.

The most obvious solution would be to look up KROQ a radio app, like TuneIn Radio on the Android Market and you will see that it says it is restricted by the content owner. Which wasn't a shocker. So I assumed that whoever owns the content, CBS, probably provides their own apps. So back on the android market, I google KROQ and find 2 apps. and Yahoo Music Radio. Long story short, it seems like KROQ's stream has some DRM on them. And the and Yahoo Music Radio doesn't know how to decode them! Ha! Pretty hilarious! It just plays garbled music. On top of that, even if it one day is updated so that it knew how to decode it's own stream, it would play it at very low quality. Worse than AM quality. In a nutshell, it is just fail after fail on all levels. Go to these apps, and you just see 1 star review after another. Don't they want people to listen to their station? I don't get it.

A quick solution is to go to on your android browser, and then it will play a nice high quality stream. The player on the page is flash based, but it is no problem for Android devices. The problem is when the phone's screen turns off, your browser goes to sleep. A wasteful solution is to make sure the browser keep the phone awake. Unfortunately, the screen is the most power hungry thing on your android. A tough price to pay for listening to radio. And even if you can plug yourself in to a power source, keeping your AMOLED screen on when you really don't need it is basically wasting the life of the beautiful screen. You wan't your screen to keep nice and bright for 2+ years right?

I was able to find a low quality stream on a forum. But how can I play it? The best solution was to find something like a shoutcast client that keeps the audio stream open when the phone goes to sleep. I found an app called XiiaLive Lite. There wasn't an obvious place to put my own streams in at first. Searching for KROQ didn't yield any results. But the feature is there under favorites. Now that I had KROQ playing on my phone with the screen turned off, I was still disappointed with the quality. Just finding this one low quality stream was no easy task and took quite a while to dig through google. But the interesting thing was the low quality stream link pointed to something called streamtheworld. That sounded interesting. I googled "streamtheworld kroq", and jackpot.

Just add this to XiiaLive:

Looking at the stream information, it looked like it is going to be a very reliable source as well as there are about 20 backup streams that it can failover to. Now I have a high quality audio stream of KROQ playing on the android device when the screen is asleep. I imagine that streamtheworld tries to offer streams of any radio station. Now all this could be avoided if the app worked the first time, and it allowed high quality streams. Hopefully that will be an option in the future. A note about WINAMP player that also plays shoutcast streams. It probably will not play the stream above because the WINAMP player is not capable at the moment to play high quality AAC streams.

For some reason, when I kill the app, then go back, it won't start up the AAC stream above. If I play the low quality stream first:
Then switch to the high quality stream:
Then it starts playing the HD stream again. Strange. Best to have both of these favorites in there in XiiaLive.