Enterprise Framework

Software Solutions in the Enterprise

How To : ASP.NET MVC With Microsoft Identity with a GUID Id and Unity Injection

How To : ASP.NET MVC With Microsoft Identity with a GUID Id and Unity Injection

This downloadable project contains the code to do ASP.NET Identity with a GUID ID and doing Unity Injection


Download File:  AspNet Identity Working with GUID ID and Unity Injection Final.zip (8.2MB)


Previous Version for default ASP.NET Identity is available :

http://www.enterpriseframework.com/post/how-to-asp-net-mvc-with-microsoft-identity-and-unity-bootstrapper


OpenStreetMap Mapnik Make Error: mapnik/version.hpp: No such file or directory

robert@robert-Ubuntu-Virtual-Platform:~/src/mod_tile$ make
Making all in iniparser3.0b
make[1]: Entering directory '/home/robert/src/mod_tile/iniparser3.0b'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/robert/src/mod_tile/iniparser3.0b'
make[1]: Entering directory '/home/robert/src/mod_tile'
g++ -DHAVE_CONFIG_H -I. -I./includes  -pthread -DSYSTEM_LIBINIPARSER=0   -g -O2 -MT src/renderd-gen_tile.o -MD -MP -MF src/.deps/renderd-gen_tile.Tpo -c -o src/renderd-gen_tile.o `test -f 'src/gen_tile.cpp' || echo './'`src/gen_tile.cpp
src/gen_tile.cpp:1:30: fatal error: mapnik/version.hpp: No such file or directory
 #include <mapnik/version.hpp>
                              ^
compilation terminated.
Makefile:1124: recipe for target 'src/renderd-gen_tile.o' failed
make[1]: *** [src/renderd-gen_tile.o] Error 1
make[1]: Leaving directory '/home/robert/src/mod_tile'
Makefile:1288: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1


Fix the error by installing libmapnik-dev:


robert@robert-Ubuntu-Virtual-Platform:~/src/mod_tile$ sudo apt-get install libmapnik-dev

Auto Generate C# Client Proxy from Swagger Metadata from ASP.NET WEB API

Here are some tools for automatic C# client side proxy code generators from Swagger Metadata
 
Microsoft - Azure
Article:  Get started with API Apps and ASP.NET in Azure App Service
Section: Consume from a .NET client by using generated client code
Link : https://azure.microsoft.com/en-us/documentation/articles/app-service-api-dotnet-get-started/#codegen

Git Repository:  https://github.com/azure/autorest
Community - Swagger Code Generator
https://github.com/swagger-api/swagger-codegen
Community - NSwag
https://github.com/NSwag/NSwag
Microsoft - MSDN
Article:  Introducing the Azure API Apps Tools for Visual Studio 2013
Section:  Enable Developers with One-click Strongly-typed REST API Clients
Section:  One-click API App Client Code Generation in Visual Studio
Link:  http://blogs.msdn.com/b/visualstudio/archive/2015/03/24/introducing-the-azure-api-apps-tools-for-visual-studio-2013.aspx

C# Serialization - Deserialize from one Name and Serialize To A different Name

Scenario:

We have a Web Service which talks to a 3rd party service and receives json where the property names that are not standard to our organization.  We don't want the overhead of created multiple DTO objects to support transformations.

Example:  {"office_code" : "ABC1234"}  (office_code needs to be "Code")

We have to take the incoming json and deserialize to a organization standard POCO and run rules to it and serialize it again back out to the organization so it would now look like:

Example:  {"Code" : "ABC1234"} 

The workflow:

3rd Party Json => Our Web Service => Run Rules => Serialize to Internal consumer using company standard naming
so:
{"office_code" : "ABC1234"} => POCO Deserialzied to {"Code" : "ABC1234"} => Run Rules => POCO Serialized {"Code" : "ABC1234"}

example:  

Our Original POCO looks like:  If I Serialize it as is, it will have Code serialized to office_code which what I don't want.  I want to stay as Code
    [DataContract]
    public class Test
    {
        [DataMember]
        public int Id { get; set; }

        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public string Description { get; set; }

        [DataMember]
        public string Whatever { get; set; }

        [DataMember]
        [JsonProperty("office_code")]
        public string Code { get; set; }
}
Updated Test Object by adding a private method called _code with Attributes and method
   
        [DataMember]
        [JsonProperty("office_code")]
        private string _code { get; set; }
Then updated the public string Code property to use the private property _code

        [DataMember]
        public string Code
        {
            get
            {
                return _code;
            }
            set
            {
                _code = value;
            }
        }

Microsoft Serializer and Newtonsoft both support a method called ShouldSerialize{Property} that is not heavily documented.  We'll create a method for our _code property

        public bool ShouldSerialize_code()
        {
            return false;
        }
You can deserialize Json office_code to C# _code but when you Serialize Test, it will not serialize _code

    [DataContract]
    public class Test
    {
        [DataMember]
        public int Id { get; set; }

        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public string Description { get; set; }

        [DataMember]
        public string Whatever { get; set; }

        [DataMember]
        public string Code
        {
            get
            {
                return _code;
            }
            set
            {
                _code = value;
            }
        }

        [DataMember]
        [JsonProperty("office_code")]
        private string _code { get; set; }

        public bool ShouldSerialize_code()
        {
            return false;
        }

        public bool ShouldSerializeWhatever()
        {
            return false;
        }
    }
Running the Test
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Practices.Unity;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using System.Web.Http;

namespace Generic
{
    public class BlahController : ApiController
    {
        [HttpGet]
        public Test Get()
        {
            Test test1 = null;

            //JSON Deserialization string  {"Id":0,"Name":"Robert","Description":"Cool","office_code":"BlahBlahBlah"}
            //office_code will be deserialized to a private property called _code
            string deserializeFrom = "{\"Id\":0,\"Name\":\"Robert\",\"Description\":\"Cool\",\"office_code\":\"BlahBlahBlah\"}";

            test1 = JsonConvert.DeserializeObject(deserializeFrom);

            string serializeTo = JsonConvert.SerializeObject(test1);

            //Results
            // Json string to Serialized Object    {"Id":0,"Name":"Robert","Description":"Cool","office_code":"BlahBlahBlah"}
            // Serialized objec to json string     {"Id":0,"Name":"Robert","Description":"Cool","Code":"BlahBlahBlah"}

            //
            Test test2 = new Test();
            test2.Id = 0;
            test2.Name = "Robert";
            test2.Description = "Cool";
            test2.Whatever = "How Annoying";
            test2.Code = "BlahBlahBlah";
            //test._code = "BlahBlahBlah"  Inaccessible

            return test2;
        }
    }
}

AngularJS template javascript code from the snippets of John Papa's Angular Style Guide best practices

Here is the outputted AngularJS template javascript code from the snippets of John Papa's Angular Style Guide best practices

<script>
/* CONTROLLER BEST PRACTICE TEMPLATE */
(function() {
   'use strict';
   angular
       .module('module')
       .controller('Controller', Controller);
   Controller.$inject = ['dependencies'];
   /* @ngInject */
   function Controller(dependencies) {
       var vm = this;
       vm.title = 'Controller';
       activate();
       ////////////////
       function activate() {
       }
   }
})();
</script>

<script>
/* DIRECTIVE BEST PRACTICE TEMPLATE */
(function() {
   'use strict';
   angular
       .module('module')
       .directive('directive', directive);
   directive.$inject = ['dependencies'];
   /* @ngInject */
   function directive (dependencies) {
       // Usage:
       //
       // Creates:
       //
       var directive = {
           bindToController: true,
           controller: Controller,
           controllerAs: 'vm',
           link: link,
           restrict: 'A',
           scope: {
           }
       };
       return directive;
       function link(scope, element, attrs) {
       }
   }
   /* @ngInject */
   function Controller () {
   }
})();
</script>

<script>
/* FACTORY BEST PRACTICE TEMPLATE */
(function() {
   'use strict';
   angular
       .module('module')
       .factory('factory', factory);
   factory.$inject = ['dependencies'];
   /* @ngInject */
   function factory(dependencies) {
       var service = {
           func: func
       };
       return service;
       ////////////////
       function func() {
       }
   }
})();
</script>

<script>
/* FILTER BEST PRACTICE TEMPLATE */
(function() {
   'use strict';
   angular
       .module('module')
       .filter('filter', filter);
   function filter() {
       return filterFilter;
       ////////////////
       function filterFilter(params) {
           return params;
       };
   }
})();
</script>

<script>
/* SERVICE BEST PRACTICE TEMPLATE */
(function() {
   'use strict';
   angular
       .module('module')
       .service('Service', Service);
   Service.$inject = ['dependencies'];
   /* @ngInject */
   function Service(dependencies) {
       this.func = func;
       ////////////////
       function func() {
       }
   }
})();
</script>

Windows Server 2012 RabbitMQ Remote Access 3.0.0 and up

By default, trying to access RabbitMQ Management UI (http://localhost:15672/) from a remote machine is not allowed.  You must turn this on by setting the setting an environment variable and then creating a rabbitmq.config file before installing rabbitmq on Windows.

Here are the steps before you install. 

Clean Install on Windows Server 2012:

  1. Set System Environment Variables
    1. Go to System > Advanced System Settings > Advanced Tab > Environment Variables
    2. Under System variables > New...
    3. variable name  : RABBITMQ_BASE
      variable value : c:\rabbitmq
    4. Click OK
    5. Click OK at Environment Variables screen.
    6. Create a new file called rabbitmq.config in c:\rabbitmq
      1. Edit rabbitmq.config and paste the following into it: 
        [{rabbit, [{loopback_users, []}]}].
  2. Install Erlang
    1. Go to http://www.erlang.org/download.html
    2. Download:  OTP 17.5 Windows 64-bit Binary File (91.1 MB)
  3. Install RabbitMQ
    1. Go to https://www.rabbitmq.com/download.html
    2. Download:  RabbitMQ 3.5.3 Windows 

If you already installed rabbitmq, you will need to uninstall rabbitmq service and then do the above 1 through 3 steps.

Javascript Unit Test Links


https://github.com/Microsoft/nodejstools/wiki/Test-Framework-Extensibility

http://madskristensen.net/post/visual-studio-extensions-for-web-developers


https://github.com/Microsoft/nodejstools/wiki/Test-Explorer


http://www.codit.eu/blog/2015/03/18/continuous-integration-with-javascript-nunit-on-tfsbuild-%28part-13%29/

https://www.visualstudio.com/en-us/features/node-js-vs.aspx

https://nodejstools.codeplex.com/

https://github.com/Microsoft/nodejstools

https://github.com/Microsoft/nodejstools/wiki


https://github.com/Microsoft/nodejstools/wiki/Pre-and-Post-Build-Actions

https://social.msdn.microsoft.com/Search/en-US/vscom?query=javascript%20unit%20test&Refinement=198&emptyWatermark=true&ac=5


https://nodejstools.codeplex.com/

http://webtooling.visualstudio.com/languages/javascript/

https://visualstudiomagazine.com/articles/2013/12/01/javascript-unit-testing-with-visual-studio.aspx

http://blogs.msdn.com/b/matt-harrington/archive/2014/10/27/javascript-unit-testing-using-the-chutzpah-test-runner-in-visual-studio.aspx

NodeJS Code for Chat Application with Redis

Sign up for a FREE Redis DB account at RedisLab.

After logging into RedisLabs, click on Manage My Resources
Click "New Redis Subscription"
Choose the Standard Tab > 30MB Free Version

Enter a Resource Name (Example: MyRedisDb)
Enter a Password (Example: P@ssw0rd)
Click "Activate".

This will take you the activation screen.

Click on My Resources

Click on the newly created Db (Example: MyRedisDb)
You will use the EndPoint defined for using within your chat application

  1. Unzip the NodeChat.zip file to a directory
  2. Edit Chat_App.js and Set:
  3. var redisPort = (Example:  12345)
  4. var redisUrl = (Example: pub-redis-12345.us-east-1-2.3.ecc.data.com)
  5. var redisPassword = (Example: P@ssw0rd)
  6. Save.
Run the chat app:  node chat_app.js

Download the Chat App: chat_app.zip (3.5MB)

Related links:  Node JS Chat on Azure App Service