Thursday, April 20, 2017

Steps require to host your application into the Pivotal Cloud Foundry

Host your application into the Pivotal Cloud Foundry PCF

Register in Pivotal and go to “Pivotal Web Services”, you will get free trial upto 2 GB

 If you already have an account in PCF then Login using With User Id: Email Id and Pwd: Password

You will need a workspace where app can be hosted, for that you need to create Organization and then Workspace
Go to Given/Created Org >> Click Add Space >> create new space for you

For CF push to work, you will need manifest.yml file to be a part of your app’s output folder.
Sample manifest.yml file content

.NET Framework aAps, yml file 

- name: RiteshWebAPI
  memory: 512m
  disk_quota: 512m  
  buildpack: binary_buildpack
  stack: windows2012R2
    ConnectionString: @SQLConnectionString@
    App_Log: @AppLogConnection@
   - syslog-drain
   - route: @route@
instances: @instances@

.NET Core Apps,  buildpack and stack will be changed , run > cf buildpacks or > cf stacks to see available buildpack and stack in PCF environment.
        buildpack: dotnet_core_buildpack
        stack: cflinuxfs2

Build your App, WebAPI, WebApp etc. Following things needs to be taken care while code, Code need to follow 12 factor app
Best Practices for ASP.Net application Application Types: MVC, WebForm, WebAPI, WCF

  • Avoid Integrated Windows Authentication
  • Avoid the Global Access Cache (GAC)
  • Avoid custom IIS handlers
  • Avoid anything that uses the Windows registry
  • Avoid using local disk for storing application state. Any data that needs to persist needs to be stored in backing service. Ex.  Database (SQL Server,Mongo DB)
  • Avoid in process session state.
  • For ASP.NET override MachineKey in web.config and on ASP.NET Core
  • Avoid persisting keyring to filesystem
  • On ASP.NET avoid environment specific configuration in web.config      
  • Avoid using any Windows specific or disk based logging
  • Avoid any 32-bit specific libraries or libraries that cannot be bin deployable.
Once your App is ready you can publish it in some folder let’s say “C:\Ritesh\WebAPIPublish\”
First steps to start your deployment into the PCF, you need Common Language Interface (CLI) Download CLI from below

Now, Open Command Prompt (cmd), type following commands to login
Login By Browser URL:
Login By CLI URL:

Start Login by command prompt, Go to the directory where you have published your source code (make sure this folder has all required files to run the app, including “.yml” file

C:\Ritesh\ WebAPIPublish> cf login -a
Email> UserId
Password> Password
Space> 1        // if multiple space available, you need to choose desire space

Now you are ready to start the deployment
C:\Ritesh\WebAPIPublish> cf push

If error pops up go and see the log
C:\Ritesh\WebAPIPublish> cf log   - recent

If log shows that health check fail than turn off health check up
C:\Ritesh\WebAPIPublish> cf push --health-check-type=none

Let’s wait till you see application started message
1 of 1 instance running

After successfully deployed you can login online and get the URL and you can use it to access your app like:


Best way to understand Bubble sort and Insertion Sort Algorithm

Bubble Sort 

Below image will describe how bubble sort code work when code execute in loop, below pictures are self explanatory for algorithm steps. 
C# Code
public int[] BubbleSort(int[] val)
           bool flag = true;
           int temp;

           for (int i =0;(i<=val.Count()-1) && flag; i++)
               flag = false;
               for (int j = 0; j < val.Count()-1; j++)
                   if (val[j + 1] < val[j])
                       temp = val[j + 1];
                       val[j + 1] = val[j];
                       val[j] = temp;
                       flag = true;
           return val;

Insertion Sort

Faster than bubble sort
C# Code
public int[] InsertionSort(int[] val)
           for (int i = 0; i <= val.Count(); i++)
               int temp = val[i];
               int j = i - 1;

               while (j >= 0 && val[j] < temp)
                   val[j + 1] = val[j];
               val[j + 1] = temp;
           return val;

.NET Core Error: /Core and /WepApp.deps.json could not be found

When I tried to run my first .NET Core web application, I found wired issues and it took me longer time to figure out, what is actual issues was, error message was not helping at all to find out the solution

.NET Core Error: <<Project Dir Path>>/Core and <<Project Dir Path>>/WepApp.deps.json could not be found

To find out the solution, I started couple of times from scratch and finally I tried with different directory and file name to save my .NET Core project.

Previous Project Path was:  C:\Ritesh\NET Core\Core WebAPP

Later Project Path (works): C:\Ritesh\NETCore\CoreWebApp  (NO SPACE in dir name and file name)

It's works for me, I don't know this is the really solution or Microsoft need to release some patch to fix this.