Chrome dev tools dark theme

After seeing Iris Classon post about how to style Chrome Dev Tools, I knew I needed to give it a try.

I love Visual Studio dark theme, and having the same in Chrome is a joy for my eyes. So I’ve done it, and I’m happy.

chrome-dev-tools-dark-theme

Install:

  • Add the extension Zero Dark Matrix from Chrome Web store
  • Enable the Developer experiments (chrome://flags > Enable Developer Tools experiments) and click “Relaunch Now” at the bottom
  • Go to developer tools settings > Experiments > and tick Allow custom UI themes.

Thanks Iris for the tip.

 

Add Validation rules with FluentValidation

One scenario we have in almost all applications where requires user inputs, are validation rules. We have lot of different ways to implement validation (both server and client sides), and one of these ways is using a library called FluentValidation, where it uses lambda expressions to build all validation rules.

To integrate it, we can get the package from Nuget and add it to our project:

nuget

This will add FluentValidation references.

For this example, we’ll use a simple model such as:

public class Person
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Address { get; set; }
    public int Age { get; set; }
}

Now, to create our validator, we need to have a class who inherits from AbstractValidator<T>, where T in this case will the Person.

using FluentValidation;
using FluentValidationExample.Models;
namespace FluentValidationExample.Validators
{
    public class PersonValidator : AbstractValidator<Person>
    {
    }
}

Having our class created, we can now define the rules to validate a Person entity in the validator class constructor. For this example, I’ll add two rules, one to validate if the first name is not empty and other to make sure we have a age greater than 18.

public PersonValidator()
{
    RuleFor(d => d.FirstName)
        .NotEmpty()
        .WithMessage("First name cannot be empty");

    RuleFor(d => d.Age)
        .Must(AgeMustBeGreaterThan18)
        .WithMessage("Age must be greater than 18");
}

private bool AgeMustBeGreaterThan18(int age)
{
    return age > 18;
}

FluentValidation already includes some built-in validations, so for our first validation we can use the NotEmpty() method. For the second validation, we’ve created a new method who verifies the Age property value and makes sure is greater than 18. If not, it will throw an error.
In this case, the validator will go through all rules and will send the result back with any errors, but we can decide to stop on the first failure.

public PersonValidator()
{
    RuleFor(d => d.FirstName)
        .Cascade(CascadeMode.StopOnFirstFailure)
        .NotEmpty()
        .WithMessage("First name cannot be empty");

    RuleFor(d => d.Age)
        .Must(AgeMustBeGreaterThan18)
        .WithMessage("Age must be greater than 18");
}

private bool AgeMustBeGreaterThan18(int age)
{
    return age > 18;
}

Having the validator created, we now need to call it when we want to validate all rules for the Person model, check if there are any errors, and display (and log) those to the user.

static void Main(string[] args)
{
    var person = new Person
    {
        FirstName = "",
        LastName = "Salgado",
        Age = 17, // I wish
        Address = "London, UK"
    };

    var validator = new PersonValidator();

    var validationResult = validator.Validate(person);

    if (!validationResult.IsValid)
    {
        validationResult.Errors.ToList().ForEach(p => Console.WriteLine(p.ErrorMessage));
    }

    Console.Read();
}

I’m not defining the FirstName and i’ve set the age as 17 to force both rules to fail, so the output will be both error messages:

console_output

This is just a example of how we can add FluentValidation to a project, but much more advanced validations can be done, so I recommend you to read the documentation and follow the examples available in the project page.

 

Using Visual Studio 2013 with TFS and Git repositories on same project

With Visual Studio 2013 is a nightmare to keep a git repository but having TFS as a source control plugin activated when we load the solution. Every time we open the solution, by default Visual Studio will select the Git provider and ignore completely TFS (oh, irony…)

To solve that, I had to move out the .git folder to an external folder and point the git dir to the actual source code folder.

So an example is:

C:\Git\ (where I have my different .git repositories per project stored)
-- C:\Git\ProjectOne\.git
-- C:\Git\ProjectTwo\.git
C:\Code (where I have all projects source code)
-- C:\Code\ProjectOne\.git (this is a file, not a folder anymore)
-- C:\Code\ProjectTwo\.git (this is a file, not a folder anymore)

So, this .git file has to be generated as:

$ echo "gitdir: /git/ProjectOne/.git" > .git

After doing this, you can open Visual Studio and TFS will be selected by default. You still be able to run a “git status” or any git command as you always did before.

 

dotnetConf – 25th and 26th of June 2014

Channel9 is hosting on the 25th and 26th of June the dotnetConf.

dotnetConf is a free, online conference for helping developers create desktop, mobile, web, and cloud-based applications using the .NET Framework.

There are great sessions planned so is totally worth it to watch. Go to dotnetConf and register, it takes just a few seconds.

 

Visual Studio 2012 Update 4

It’s now available the update 4 for Visual Studio 2012.

Download: http://www.microsoft.com/en-us/download/details.aspx?id=39305

ISO image: http://go.microsoft.com/fwlink/?LinkId=327544

 

Visual Studio 2013 Launch

Yesterday was another great day for .NET Developers and really nice news from the best IDE (feel free to disagree), Visual Studio 2013.

Please find some useful links below:

VS Online “Monaco”

http://weblogs.asp.net/jgalloway/archive/2013/11/13/a-quick-look-at-the-new-visual-studio-online-quot-monaco-quot-code-editor.aspx

http://gunnarpeipman.com/2013/11/first-look-at-visual-studio-online-monaco/

http://blogs.msdn.com/b/somasegar/archive/2013/11/13/visual-studio-2013-launch-announcing-visual-studio-online.aspx

http://www.visualstudio.com/en-us/news/2013-nov-13-vso

PCL and .NET NuGet Libraries are now enabled for Xamarin – http://blogs.msdn.com/b/dotnet/archive/2013/11/13/pcl-and-net-nuget-libraries-are-now-enabled-for-xamarin.aspx

VS Launch videos – http://channel9.msdn.com/Events/Visual-Studio/Launch-2013

 

9th Issue of DNC Magazine

dnc-nov-13

Its available the 9th issue of DNC Magazine for download. Lot of nice articles are included such as “ASP.NET MVC 5 – Authentication Filters”, “Software is not a building”, “The new Hub Control in Windows 8.1” and much more.

DNC Magazine – 9th Issue

 

Alert users when they have lost internet connectivity with Offline.js

To alert users when they’ve lost internet connectivity, we can use a really tiny library (only 3kb) called Offline.js.

So, what is Offline.js?

Offline.js is a library to automatically alert your users when they’ve lost internet connectivity, like Gmail.
It captures AJAX requests which were made while the connection was down, and remakes them when it’s back up, so your app reacts perfectly.

It is really straightforward to add implement this on our web applications.

1. Download Offline.js
2. Download a theme. For that, choose yours here.
3. Add the JS and CSS files to your pages.
4. Add a div to be used to display the notification (see full code for an example)

Live Demo

Ahh, and if you want to allow users to play Snake while they don’t have connection, just change the option “game” to true 🙂

Full code:

 

29

And thats it… one more year to celebrate 🙂
29

 

Navigate between modules on DotNetNuke

On DotNetNuke, each folder inside DesktopModules are considered Modules (and they can’t communicate directly between each others).

Imagine you have:

Module1

  • View.ascx
  • Stuff.ascx (this is a module definition only accessible by ControlKey)

If you need to open Stuff.ascx from View.ascx, you can achieve this easily using Globals.Navigate() and specifying the ControlKey, because you have the TabID and ModuleID of the current Module.

But, when we want to do the same but in different Modules (folders) is more complicate.

So if you have something like:

Module1

  • View.ascx (assume this has a aspx page associated)
  • Stuff.ascx (this is a module definition only accessible by ControlKey)

Module2

  • OtherStuff.ascx (assume this has a aspx page associated)
  • MoreStuff.ascx (this is a module definition only accessible by ControlKey)

And you want on View.ascx or Stuff.ascx (Module1) to go to MoreStuff.ascx (Module2), we need to get the TabID, ModuleID (of Module2), and the controlKey.

We have the ControlKey, because we can specify that in DNN (Extensions Manager or DNN manifest file for compiled modules), but the TabID and ModuleID are dynamic, so is different per DNN website.

So, to be able to navigate across different modules, we need to find the TabID and ModuleID related to the module we want to access.

This code would help to do that: