Apache Cordova and Visual Studio 2015 – To Do sample application

I want to explore Apache Cordova and the new tools available at Visual Studio 2015.

There is a sample application walkthrough we can use to practice Cordova with VS 2015, I selected the AngularJS version of the sample. You can also find the source code for the sample here Source Code Link.

The application keeps record of to do activities users enter. It stores the tasks in a local Html5 storage and, if you have access, in a Azure SQL server database using an Azure Mobile Service.

Had no issues following the walkthrough up to making it work with the local storage. The problem was when I tried to use Azure storage through the mobile service: the application simply didn’t  show any data neither saved it to the database.

It result that I had to configure the mobile service and add the table from it, so, I created another mobile service from Azure console, and followed the steps at the link Configure Mobile Service. Then, I went back to the code and set the Mobile Service API Key and the Url of the service at the service file azureStorage.js.

 

Running sample on Android VS 2015 emulator

Running sample on Android VS 2015 emulator

Cordova allows access to functionalities like geo location, camera, etc. while using JavaScript and AngularJS, TypeScript and other known web development frameworks.

I think there are good opportunities for taking advantage of all of these technologies so to quickly develop apps and avoid difficult to maintain mobile applications, developed in native to the device code.

I plan to keep improving on web development frameworks, specially JS, AngularJS and TypeScript. I’m sure we will find a good business use of them at my job at Zgura!

Cheers,

Danfer.

Learning AngularJS and use it with ASP.Net MVC – Controller on MVC view

I’ve been using book Build Single Page Application with ASP.Net MVC 5 and AngularJS.

On chapter 4, at Creating first angular controller, book’s code didn’t work in my case. I’m using Angular version 1.3.15.

I had to make following changes:

At _Layout.cshtml, identify the app:

<html ng-app=”myApp”>

At homeIndex.js (the file storing the angular controller definition):

//homeIndex.js

var app = angular.module(myApp, []);

app.controller(‘homeIndexController’, function ($scope) {

$scope.fname = “John”;

$scope.lname = “Doe”;

});

 

And at the view, from where the angular controller is supposed to be called, Index.cshtml:

@section scripts

{

<script src=”~/js/homeIndex.js”></script>

}

<div ng-app=”myApp” ng-controller=”homeIndexController”>

Fname:- {{fname}} <br />

Lname:- {{lname}}

</div>

Will write this comment at Amazon too. Either AngularJS has changed since the version author was using (he says it is 1.2.26 or there may be some errors on sample code at the book.

Cheers.

Planes para esta semana 18-22 de mayo 2015

Trabajar en 2 proyectos en Zgura (como siempre, estamos haciendo excelentes soluciones de software!). Asp.Net MVC, JS, WIF, Microsoft Azure y SQL Database.

Continuar estudiando Single Page Web App utilizando ASP.Net MVC 5, WEB API 2 y Angular JS. Building Single Page App With ASP.NET MVC 5 and Angular

Continuar leyendo the wright brothers david McCullough.

Saludos!

Custom attribute with WIF claims based authorization

WIF is Microsoft framework for building applications using token security services and claims. Claims are like attributes that describe the user. An example could be the claim Role with a value “Administrator”. Another example, claim Location, value “ManaguaOffice1”.

I can develop an application that can validate claims and act in consequence, like allowing access to some functionality based on Role or location claims.

You can find a nice explanation on the topic here: Introduction to claims based authentication in .Net

I’d like to share an implementation of claims based authorization. This is a solution we developed at a ASP.Net MVC 5 project that uses WIF and OWIN security. We needed to provide a simple way to set authorization for users to access application functionality based on their roles.

As the functionality users have access to is implemented using ASP.Net MVC controllers and controller’s action methods, we needed a custom attribute that could be applied to either controller or action level. We developed an alternative custom attribute, here the code:

//
//Enables custom claims based authorization.
//It uses role claim type.
//Role values get from Auth DB.
//

public class RoleAuthorizeAttribute : AuthorizeAttribute
{

private string[] claimValues;

public RoleAuthorizeAttribute(string allowedRoles)
{
claimValues = allowedRoles.Split(‘,’);

var userProfile = UserProfileRepository.Get(HttpContext.Current.User.Identity);
var identity = UserProfileRepository.AddClaimsRole(userProfile, HttpContext.Current.User.Identity);

}

public override void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
{

bool isInRole = false;

foreach (var str in claimValues)
{
//It can manages white spaces before and after the role name.

isInRole=HttpContext.Current.User.IsInRole(str.Trim());

if (isInRole) break; //break foreach as user is in one of the required roles.
}

if (isInRole)
{
base.OnAuthorization(filterContext);
}
else
{
base.HandleUnauthorizedRequest(filterContext);
}

}
}

This class inherits from AuthorizaAttribute class and overrides the onAuthorization action filter to allow to “inject” the custom attribute. It can work for more than one role. I’d implement it at the controller like below:

[HttpPost]
[RoleAuthorize("user, admin")]
public ActionResult MyAction(int id)
{
....

 

Cheers.

Access to Login ASP.Net Login control objects, code behind

This post is about Web Forms. We still have some legacy applications using that platform. Although our main direction is MVC, we still support them. Here a sample for the subject matter:

RequiredFieldValidator req1 = Login1.FindControl("Req1") as RequiredFieldValidator;

req1.ErrorMessage = "My text";

var text = CCContent.GetStringContent("MustRegisterPassword");

RequiredFieldValidator req2 = Login1.FindControl("Req2") as RequiredFieldValidator;

req2.ErrorMessage = text;

 

In the case of req2 assignment of variable text, I obtain that text from a static method in our code. That access our Zgura’s content management framework. This content framework stores local or specific content for different applications. It uses a NoSQL repository for the data (Azure Tables) and will be matter of separated post.

Cheers,

Danfer.

What I’m currently working on, Azure NoSQL tables

At Zgura I’m working on Azure NoSQL databases, using Azure tables. We are using that for different sites content storage.

We have used Azure SQL as storage for content (localization values) in other project. First impression, new NoSQL seems to be faster than the SQL solution, will set monitoring using New Relic on the NoSQL application so can compare data already have for the application that uses SQL repository for content.

I already know, from New Relic that one of the most resource consuming task on pages load for the application that uses SQL content repository, is reading the content values.

Until that.

Cheers,

Danfer.

What I’m currently working on

First of all, doing really cool things. Just to mention a few:

Keep working on telecommunication services and ecommerce platform at Zgura.

We are integrating services from multiple vendors adding our services. We are using MVC 5 and Web API 2.

We are also using Microsoft Azure websites, SQL databases. We use different websites to support user interfaces and services. We are using Azure Scheduler and we have several jobs running, triggering process through our Web API applications.

Another interesting aspect of the job is building processes that involve some business intelligence so to allow the platform to take business decisions automatically. Last is work in progress.

Cheers,

Danfer.