Posts

Uploading files with Froala in ASP.Net MVC

Froala was very straightforward to get up and running. Their documentation is pretty good but lacks an English version of the server integration for image/file uploads. Ignoring the paste, here's a view of the simple upload of images/files. I have added a parameter to the method called location which lets me have the editor save files to different places depending on where the editor is. [HttpPost] [Route( "content/uploadfile" )] public ActionResult UploadFile( string location, HttpPostedFileBase file) { string fileName; try { // resourceService handles resizing image and saving to Azure blob storage. fileName = resourceService.AddFileInLocation(location, file); } catch (Exception ex) { return Json2( new { error = ex.Message }); } // /resources/ proxies requests to assets var data = new { link = ( "/resources/" + location + "/" + fileName).ToLower() }; return Json2(d...

What you see is what you get - enter Froala

When needing to add a bit of WYSIWYG into a web application I've always gone with the stalwart TinyMCE. It does the job, it's configurable with regards to what you allow in your elements and generally users use it without too much trouble. We just had a few issues that were annoying with TinyMCE so we went on a hunt for a new editor to use in its place. A colleague recommended Froala  as he had recently evaluated it for another project. We use angular extensively (and had to write a directive for TinyMCE integration) so I was expecting to have to do the same for Froala. Not so! They already have a directive for angular available on GitHub . It took approximately 5 minutes to go from TinyMCE to basic Froala. It took another day or so to get all the functionality we wanted - that includes creating APIs for image and file upload. Things I really like about Froala: Good documentation It seems to produce better html than TinyMCE did (fewer random <p> tags!) Pastin...

5 Lessons from failure

Today I messed up. I'm a strong believer in sharing experiences of failure. If no one talks about the times they make mistakes, we're going to be doomed to repeat the same errors over and over again. So, here goes... Today I made a big mistake in a production application that resulted in 15 minutes of frantic database scripting and partial service interruption. I'm going to share what I did wrong, in part so that I focus on what I can do better next time but also because I don't want other people to make the same mistakes. Here's what happened. In our application we have some entities which use a natural key rather than a database generated primary key. This can make life easier when querying as you reduce the number of joins but still have referential integrity (with the cost of a bit of denormalisation). In the past, the whole DAL was hand coded SQL so it saved a considerable amount of developer time; we now use an ORM so we really don't care about the ...

Azure worker roles and recurring tasks

Image
In our application we have multiple web front ends communicating with one or more worker roles. This allows our worker roles to take the brunt of expensive operations. For example, some (very infrequent) actions require up to about 500 emails being sent (via Amazon SES). Before Azure (BA), we did everything on the web server - it wasn't common but sometimes users reported over a minute from clicking the button to the result being displayed. Our move to using workers responding to queue messages has massively sped this sort of thing up. Most actions on the worker are triggered by queue messages but we do have several things that just need to happen at set intervals (we use blob leases to prevent multiple workers doing the same thing). While implementing the "ExclusiveJobHost" and "BlobLease" classes, I noticed a common pattern that I ended up pulling out: public class RecurringAction { private ManualResetEvent exitSignal = new ManualResetEvent( false ...

Validating partition and row keys in Azure Table Storage

Microsoft Azure Table storage is a very flexible No-Sql store for structured data. Each entity in the table is uniquely identified by a partition key and a row key. A good choice of these is beyond the scope of this post. However, it can be useful to check that entity you want to add to the table has valid partition and row keys. Here's a simple class that encapsulates those rules: /// <summary> /// Encapsulates knowledge about valid values for keys in Microsoft Azure table storage. /// </summary> /// <remarks> /// Rules are found here http://msdn.microsoft.com/library/azure/dd179338.aspx /// </remarks> internal static class KeyValidator { /// <summary> /// Determines whether the specified key is valid. /// </summary> /// <param name="keyValue">The key.</param> /// <param name="errors">Any errors in the value supplied.</param> /// <returns><c>tru...

Issue tracking nirvana

Like most developers I've experimented with lots of different ways of managing bugs, feature requests, architectural notes and documentation. I always start a new project determined to use a really air tight system for logging bugs and feature requests. I also try to create a central, accessible store for documentation which is searchable and easy for everyone to use. You know what? It never worked. I used a desktop "help desk" style system that logged absolutely everything but had no simple overview so figuring out what status a ticket was in involved opening it and reading through the history. Discussions were often via email and the help desk system wasn't updated. I'd get so fed up with spending 30 minutes setting up a ticket in the system that I'd resort to "todo" lists scattered over my desk. I eventually moved on to OneNote and finally Trello for my own time management although the department was officially using the desktop app. I moved...

Strong passwords.... Or not

I absolutely hate password "strength" plugins - they're almost always terrible. I use a password manager so all my passwords are generated according to the rules of the website I'm on to be as strong as the site will allow (within reason). So I was on NPower trying to register, it told me up to 20 chars, mixed case and at least one number. I got my password manager to generate me a 20 character mixed case password with numbers. I forgot to tick the box for special characters. The results for strength of password were alarming:  . @InfoSecInsanity nearly chose a bad password for @npowerhq but thanks to the PW strength test "Strong" now #FAIL pic.twitter.com/aLyCU184Q6 — Robert Head (@RobHead89) August 29, 2014 So 20 random chars is the same strength as "Orange1"? Add a space to the end (or any special character) and it's suddenly stronger? Who writes these things anyway? Validating the strength of a password is really bloody ...