Skip to main content

Posts

Showing posts from 2013

MVVM light and Model Validation

I have been using the MVVM light toolkit for a project recently. It is a great toolkit but is missing a couple things and Laurent Bugnion does a good job trying to cover those holes. One of the things the toolkit does not support is Validation. The good news is there is a great CodePlex project out there call Fluent Validation that makes this pretty easy to add and really powerful. My objective was to add validation to my model so I could call “IsValid” on the model itself (similar to the MVC attribute approach). Fluent Validation has you create a new class file that holds you validation rules for a given model. This is the approach I took to enable each model to have an “IsValid” property and a “Errors” property that returns the validation errors. First I setup my ValidationFactory: public class ValidatorFactory : FluentValidation.ValidatorFactoryBase { public override FluentValidation.IValidator CreateInstance(Type validatorType) { return SimpleIoc.Default.G

Visual Studio Code Review

I have finally been able to work with Visual Studio and TFS code reviews. There were a couple thing that threw me off I wanted to write about. If you want a good quick overview of what this is check out the Channel9 video “Using Code Review to Improve Quality.” There are a few things to note about this feature no one calls out easily: 1- You must have TFS to enable this 2- You must have at least Visual Studio 2012 premium If you have those two things you can start doing code reviews this way. It is a great feature I think. Sadly it will be under utilized by a lot of development shops for a few reason. First, I think few will understand this feature is there and even if they do fewer will spend the time to defined their processes for it. Second I think a lot of development shops have only a professional license, don’t use TFS as their back, or if they do, they don’t work to use its full capability and just use it as source control. With all that said if you are using it or thinking

Web API – Pass multiple simple parameters on a POST/PUT

I have been working a lot lately on Web API (v1). For the most part I really like but there is one thing I found out that I really hate. Web API (v1) does not let you POST multiple simple type parameters. Here are the links I found that let me get through this. WebAPI Multiple Put/Post parameters Passing multiple simple POST Values to ASP.NET Web API This was a little tricky to find and most people think Web API cannot do this. Which I by default it cannot be this extension has worked great for me. So I wanted to make sure I could find it again and make it a little easier for others to maybe find it.

Calculate Screen Size in Inches based on height and width in millimeters

This will be short and simple but some math that hopefully will be helpful. I have been doing a lot of mobile device detection work as of late. Recently I was about to get the physical width and height of a device in millimeters. This was great but what I really needed was the diagonal screen size in inches. Here is the math for it. - Get the width in inches : width in millimeters times 0.0393700787 - Get the height in inches :  height in millimeters times 0.0393700787 - Combined value of both to the power of 2 : width in inches ^2 + height in inches^2 - Get the square root which should be the diagonal screen size : Combined value square root That is it. You can see it working on my test site

Web API, JSON, AJAX, CORS, Chrome 500 error and Authentication–Oh My!

I have been working on a project that is using .Net 4.0 and MVC 4 with Web API. Web API is great and provides a lot of great functionality easily. We have needed to call our Web API from another domain though which introduces Cross Origin Resource Sharing (CORS) issues. Web API in 4.0 does not really support this so it has been causes us issues, you can configure IIS to work with it pretty easily.. In later version it will support it better. See the following links: Web API VS 2013 (.Net 4.5 and later) http://aspnetwebstack.codeplex.com/ Enabling Cross-Origin Requests in ASP.NET Web API ASP.NET Web API: CORS support and Attribute Based Routing Improvements However, if you are using 4.0 that is not much help to you. We have had to push through a few issues on this front. If you are testing with IE8 you will not see them as it does not care about CORS issues. If it is working in IE but not working in Chrome or FireFox here are some issues we have been working through:   Some calls

Clearing Indexes on Sitecore Content Delivery Servers

For anyone that is building a website on Sitecore you have probably come across this issue. In even a basic production deployment of Sitecore you have a content management box and a content delivery box. When content is updated on the management servers you want your content delivery box’s indexes to be updated. Some people think you need to create your own custom process to move content management indexes out to the content delivery services. They think this because the content management box detects the indexes needs to be updated and runs the process to update its indexes, but there is nothing on the content delivery boxes to do this. Well this is just not true. To be honest if it was true Sitecore would have a serious short coming if they expected this process to be created manually every time by everyone. Alex Shyba has written a great post with additional details on how all this works. Of course there is also the Sitecore docs you can reference. The fact is the web.config fil

Sitecore Azure – Getting up and running

I am a fan of Windows Azure and Sitecore so I figured it was time to see what Sitecore for Azure was all about. The post is just about first impressions and lessons learned while getting started. There are a few must haves if you are going to work with Sitecore Azure. First you have to get a license file. This is a manual process where you have to email Sitecore with your Sitecore license info and your Azure subscription info (assuming your provisioning your Azure environments yourself). This takes about 24 hours to get the environment file back. Secondly make sure you have the version of the Azure SDK they note in the documentation. In my case it was version 1.7 (documentation gives you a link as well). I figured this was a soft requirement so I just downloaded the latest Azure SDK (1.7 was 2 version behind) however, this did not work and caused deployments to error out (it also gives you an “environment file not found error” in the Sitecore Azure screen). Once you have all that and

Create Web Forms for Marketers Custom Save Action and Edit Screen

I was recently working on a project where I needed to create a custom save action to add to my Web Forms for Marketers module.  I needed a custom save action to push the data to salesforce and I also needed a custom edit screen so the author could setup some configuration values the action needed. Here are the details of what I did starting with the save action. Save Action The first thing you need to do is create a new class that inherits the “ISaveAction” interface (Sitecore.Form.Submit.ISaveAction) and implement the Execute method.   public class SalesforceSaveAction : ISaveAction { public string FormKey { get; set; } public string FieldsToSend { get; set; }   void ISaveAction.Execute(ID formid, AdaptedResultList fields, params object [] data) { // Code to execute here } } That is really all you need. Now it all becomes about custom code and configuration.  To configure the save action to show up you need to go to Modules –> WFM –> Sett