How To Get ASP.NET Web API to Return JSON

first remove xml format :

config.Formatters.Remove(config.Formatters.XmlFormatter);

accepts text/html requests and returns application/json responses :

public class BrowserJsonFormatter : JsonMediaTypeFormatter
    {
        public BrowserJsonFormatter()
        {
            this.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
            this.SupportedMediaTypes.Add(new MediaTypeHeaderValue("multipart/form-data"));
            this.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
            this.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/x-www-form-urlencoded"));
            this.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/plain"));
            this.SerializerSettings.Formatting = Formatting.Indented;
        }

        public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
        {
            base.SetDefaultContentHeaders(type, headers, mediaType);
            headers.ContentType = new MediaTypeHeaderValue("application/json");
        }
    }

Register like so:

config.Formatters.Add(new BrowserJsonFormatter());

References
http://stackoverflow.com/questions/9847564/how-do-i-get-asp-net-web-api-to-return-json-instead-of-xml-using-chrome
https://github.com/aspnet/Mvc/issues/1765

Use OWIN to Self-Host ASP.NET Web API and SignalR

Startup.cs

[assembly: OwinStartup(typeof(ERPSelfHostServer.Startup))]
namespace ERPSelfHostServer
{
    public class Startup
    {
        // This code configures Web API. The Startup class is specified as a type
        // parameter in the WebApp.Start method.
        public void Configuration(IAppBuilder appBuilder)
        {
            // Configure Web API for self-host. 
            HttpConfiguration config = new HttpConfiguration();
            config.Formatters.Remove(config.Formatters.XmlFormatter);
            config.Formatters.Add(new BrowserJsonFormatter());

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );


            // Any connection or hub wire up and configuration should go here
            appBuilder.MapSignalR();

            appBuilder.UseWebApi(config);
            
        }
    }
}

Program.cs

static void Main(string[] args)
        {
            // bind to all network interfaces
            //string baseAddress = "http://*:13602/";
            string baseAddress = "http://172.20.63.161:13602";

            using (WebApp.Start<Startup>(baseAddress))
            {
                Thread.Sleep(Timeout.Infinite);
            }
        }

References
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api
http://anthonychu.ca/post/web-api-owin-self-host-docker-windows-containers/
http://stackoverflow.com/questions/21634333/hosting-webapi-using-owin-in-a-windows-service
http://stackoverflow.com/questions/20068075/owin-startup-class-missing
http://stackoverflow.com/questions/16642651/self-hosted-owin-and-urlacl

How to update gradle for Android

To update Android Plugin for Gradle:
You can find the list of available plugin versions in:
Android Studio\gradle\m2repository\com\android\tools\build\gradle\ directory. In my case I have:

  • 1.3.0
  • 1.5.0
  • 2.1.0-alpha3
  • 2.1.0-alpha4

Use the desired version by editing your project build.gradle file.
Example of build.gradle:

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0-alpha4'
}

To update Gradle:
In your project directory navigate to \gradle\wrapper\ directory and edit:
gradle-wrapper.properties file.
Example: To change from version 2.8 to version 2.10
before: distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
after: distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
At the end in Android Studio select: ToolsAndroidSync Project with Gradle files

References
http://stackoverflow.com/questions/17727645/how-to-update-gradle-in-android-studio

Setting Weights And Styles With The @font-face Declaration

 

@font-face {
   font-family: 'UbuntuItalic';
      src: url('Ubuntu-RI-webfont.eot');
      src: url('Ubuntu-RI-webfont.eot?#iefix') format('embedded-opentype'),
           url('Ubuntu-RI-webfont.woff') format('woff'),
           url('Ubuntu-RI-webfont.ttf') format('truetype'),
           url('Ubuntu-RI-webfont.svg#UbuntuItalic') format('svg');
   font-weight: normal;
   font-style: normal;
}

@font-face {
   font-family: 'UbuntuBold';
      src: url('Ubuntu-B-webfont.eot');
      src: url('Ubuntu-B-webfont.eot?#iefix') format('embedded-opentype'),
           url('Ubuntu-B-webfont.woff') format('woff'),
           url('Ubuntu-B-webfont.ttf') format('truetype'),
           url('Ubuntu-B-webfont.svg#UbuntuBold') format('svg');
   font-weight: normal;
   font-style: normal;
}
.u400 {
   font-family: 'UbuntuRegular', arial, sans-serif;
   font-weight: normal;
   font-style: normal;
}

.u400i {
   font-family: 'UbuntuRegularItalic', arial, sans-serif;
   font-weight: normal;
   font-style: normal;
}

.u700 {
   font-family: 'UbuntuBold', arial, sans-serif;
   font-weight: normal;
   font-style: normal;
}

.u700i {
   font-family: 'UbuntuBoldItalic', arial, sans-serif;
   font-weight: normal;
   font-style: normal;
}

References
https://www.smashingmagazine.com/2013/02/setting-weights-and-styles-at-font-face-declaration/