Tuesday, January 30, 2018

Build a web API with .NET Core using CLI Tools

In this blog i will start with an introduction to .NET Core CLI tools with an example of how to create a web API using the CLI tools provided with .NET Core. At the end we will set up a solution grouping an API project and a test project. Let's dive into the steps,

Step 1 :  Installing the tools

Need to install .NET Core and Visual Studio Code that are supported on Mac, Unix and Windows. You can read more on how it works on multi-platform/framework.

Step 2 :  Creating the solution

Let's open the terminal/Powershell as a administrator to create our solution. Lets create a solution named DotNetCoreDemoApi

  dotnet new sln -o DotNetCoreDemoApi  

The above command will create a new folder and DotNetCoreDemoApi a solution file with the  name DotNetCoreDemoApi sln .


Lets get into that folder.

Step 3: Creating the web API project

Run the following command,

 cd DotNetCoreDemoApi 

Now that the solution is here, we can create our API project. Lets name the web API as DotNetCoreDemoApi. Run the following command to create the project.

dotnet new webapi -o DotNetCoreDemoApi  

That command will create a sub folder named DotNetCoreDemoApi  inside the solution DotNetCoreDemoApi and the ouput is as follows.


The web API folder should contain a few files generated as above  but what we require right now is DotNetCoreDemoApi.csproj. We will add a reference to it in our solution. To do so, run the following command:

 dotnet sln add ./DotNetCoreDemoApi/DotNetCoreDemoApi.csproj



Step 4: Run the Web API
After getting a confirmation message as above , lets start the API by running that command:

 dotnet run --project DotNetCoreDemoApi  


After a few seconds, it should display a message  that the API is now running locally as above. You may access it at http://localhost:5000/api/values which is the Values API default endpoint.

That's all , API is ready and it is up and running locally. I will continue setting up the TestProject in the same solution in the upcoming blog. With the DotNet core it is very feasible to get your web api setup and running in 5 minutes. 



Monday, January 1, 2018

Build Web Applications With Angular 5 Using Visual Studio Code

My first post for the year 2018 and i wanted to write something about a technology in which i have vast experience and passionate about. This blog will be very useful for those who want to start with angular for developing web applications.In this blog i am going to set up Angular 5 app using Visual Studio Code. I will be using Angular CLI for our sample application. The following are the steps needed to create your first angular application using angular5.

Steps
  • Install Node.js.
  • Install Angular CLI.
  • Design our  Angular App.
  • Launch  App in the browser.
  • Displaying our custom information on a page.

1. Install Node.js
In this approach, the first step is to install Node.js. If you have not installed nodejs in your machine visit the website and download according to your OS. You will see the following display.

Download and install the latest LTS version as per the configuration of your machine. The current version of Node LTS is 8.9.3. Installing node.js will also install npm (node package manager) on your system.
Next step is to make sure everything related to node is installed, To check the version of node and npm installed on your machine, run the following command in command prompt.
  • node -v 
  • npm -v

which will be as follows,


2. Install Angular CLI
We are done with the step1, next is to install angular cli. For those who are very new to angular , angular cli is a command line interface for angular applications. After installing node and npm, the next step is to install Angular CLI. Run the following command in a command window.
  • npm install -g @angular/cli

The above command will start Angular CLI installation on your machine. This might take bit of time  based on the internet connectivity.


 3. Design our  Angular App.
That's all folks, we have setup the necessary environment to start coding. Lets create our application in a folder named Angular5Demo. Run the following command to create a folder for our application.
  • mkdir Angular5Demo

lets navigate to our created folder, so run the following command.
  • cd Angular5Demo

we are in the same folder where our application resides, so lets create our template/structure for our application using angular cli. run the following command
  • ng new myFirstApp

if you have missed anything the following screen shows the steps and the output.
Lets see the code in visual studio code editor. Type code. in the command prompt.
  • code .  

Which will open up the code in the visual studio code. And that’s it.  You can see the following file structure in Solution Explorer. We have created our first Angular app using VS Code and Angular CLI.
4. Launch  App in the browser
 To launch the application and to start the web server run the following command 
  • ng serve 
After running this command, you can see that it is asking to open http://localhost:4200 in your browser. So, open any browser on your machine and navigate to this URL. Now, you can see the following page.


We'll leave the web server as it is while we look into the code of this application. Again open the code inside the path by typing the foolwoing command.
      code .
5. Displaying our custom information on a page.
Now, Let's display a message saying "" using JSON data on the page instead of the message “Welcome to app!”. To achieve this, open /src/app/app.component.ts file. Change it as follows or according to the data you want to see on the page.
and HTML template as,


Change the value of title property to a JSON object as shown above.  You can see the updated web page as shown below.
With angular cli If the web server is running and you make any changes in the Angular application, then you don’t need to refresh the web page. It will automatically update itself as you save the application code file. You can now play with the appellation by using various JSON objects also by making requests.
That's it folks, we have learned about creating our first Angular 5 app using VS Code and Angular CLI. Please post your valuable feedback in comments section.  

Thursday, December 21, 2017

Fix : Could not load file or assembly “System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”

Even though there are several answers on stackoverflow, nothing helped me to solve this issue and found the solution as follows,

1. Update Visual studio if you have older version to 15.5.4 (Optional)
2. Remove all binding redirects from web.config
3. Add this to the csproj file:
     
4. Build.
5. In the bin folder, there should be a `(WebAppName).dll.config` file.
6. It should have redirects in it. Copy these to the web.config
7. Remove the above snipped from the csproj file again
8. It should work

Tuesday, December 19, 2017

Angular2 - DatePipe period in lower case.

There are several occasions customer would have requested to change the date format in your application to be in small case as follows.

Tuesday, December 19, 7:00 am 
Since the date format does not support the above format, either we can display entire thing in small case with the  lowercase pipe

Since it converts the whole format in lowercase, you can split it in two and apply the lowercase only for the period as follows

{1234567 | date:'EEEE, MMMM d, h:mm '} {1234567 l date:' a' | lowercase }

that's it, it is easier rather than using a custom pipe! Here is the working demo

Tuesday, December 12, 2017

Start using Azure Logic apps and save your time

This is my first blog and Azure and i am inspired to write this one after attending the Microsoft's workshop "App innovation day".

There was a cool technology "Windows Workflow Foundation" provided by Microsoft with dot net framework to create workflows to cater business logic in dot net applications. With Azure, The Logic Apps service fulfill the purpose to have business processes or workflows take shape of an app. It required no coding just simple logic that needs to placed in a right way to have right business flow. It was also meant for the purpose of integrating 3rd party apps like Facebook,YouTube, Twitter and Evernote etc. All we need to have is the dynamic work flow.

There are different benefits and different use cases in which we can apply azure logic apps. Let's discuss some of the benefits when using logic apps!

Rapid development

Logic Apps is great for rapid development.With ever growing list of connectors, we can easily create a workflow to monitor invoice, send for approval to a admin, upload to dropbox and send email notification in matter of few seconds.

Solutions with Hybrid cloud

5 years back ,Lot of businesses have invested heavily in on premises solutions and hardware, so it’s not possible to move everything to the cloud. With Logic Apps, it’s easy to have a hybrid cloud during this transition. With its on premises data gateway, you can easily connect your on premises database, file share, BizTalk server to Azure cloud.

It is the new way of Automating business process. You can build long running business process, that orchestrate data and services across all cloud services and not just Azure. It's not only for the developers but for everyone. The best bit you need to write code , you can use Visual editor to build your orchestration.

Lets Dive into Simple Demo

Use Case: Filter twitter feeds with specific hashtags and post the specific tweets on the Facebook wall.

In this example , i just created a process that repeats every few minutes to pull some data from twitter feed and post it on your Facebook wall. Even though this feature is already supported with Facebook, here its slightly different since it is filtering only the specific keywords which is a custom filtering.

The entire flow i described about is composted of 3 simple steps , that you can build using a Visual UI.

Step 1: Select Logic App click "Create" and give a specific name ,resource 



 Step 2: There are number of workflow templates will be shown as below and select the appropriate one , in this case i will use "when a new tweet is posted"


also authorize with your twitter account from which you want to fetch the feeds


Also configure the conditions by mentioning the filters and the timeline you want to trigger the action.


Step 3: Next step is to post on facebook wall , click "Add step"  


Search for Facebook and authenticate will your Facebook account as follows,


Click post to my timeline


Also you can map the fields that you want to fetch from the feed and post it on the wall as below,


That's it folks, once all fields are mapped you need to save the Logic app with the save button.



With the above 3 steps posting a filtered tweet on Facebook wall is configured and can be scheduled as you need. If the above particular feature needs to be developed without azure means it will need a huge development time and cost, which can be avoided using the Logic app as shown above.

That's the demo. You can explore several steps and several templates provided in the portal without 
writing a single line of code. I will be writing a separate blog on how to configure custom logic app 
in the upcoming blog posts. Happy connecting with app logic!

Friday, November 10, 2017

Angular Language Service - A handy extension for angular developers

Even though there have been plenty of tools/extension to check the typescript/javascript code, but there have not been any extension to validate the HTML code or related features to it. Angular Language Service was released to make the developers more productive and reduce the errors by offering better code completion. This service is available in the market place for installation for the Visual Studio as well as other code editors that support Type Script. Errors can be detected at the time of code creation . Hints are also provided for code completion. This effectively allows us to use the Intellisence for variables defined and used in the template. The navigation service is provided to link properties and their definition. This extension provides a rich editing experience for Angular templates, both inline and external templates including:


  • Completions lists
  • AOT Diagnostic messages
  • Quick info
  • Go to definition



The language service is developed by the Angular core team. At the time of writing, it is ready to use in VSCode, Sublime Text and WebStorm.

Language service uses the Angular compiler for parsing our application and producing diagnostics. It decorates the TypeScript language service in and uses its logic again. The coolest feature about the service is that it is not coupled to a specific Angular version and can be used in any text editor and IDE as soon as there’s an available plugin.

More about the language service can be found in the ng-conf talk by Chuck Jazdzewski (the creator of the language service) “Using the Angular Template Language Service”.

Start using in your angular projects and be more productive. Cheers!