Search in Help for developer site.

Thursday 27 September 2018

Rest parameter in Javascript


What is Rest parameter in Javascript.

Rest parameter is a modern feature of Javascript that allows a function to store multiple arguments in a single array.
It is similar to param keyword in C#.

Lets understand it by an example.


function sendOrders(...allOrderIds)
{
    allOrderIds.forEach(id=>console.log(id));
}

sendOrders(100,200,300);

//output
//100 200 300


...allOrderIds is a rest parameter. In sendOrders function we are passing three integer and all will be stored in allOrderIds array.

We can send any number of parameter in Rest parameter.





Rest parameter with normal parameter:


function sendOrders(day,...allOrderIds)
{
    allOrderIds.forEach(id=>console.log(id));
}
sendOrders('Monday',100,200,300);

Rest parameter should be the last parameter in a function:


function sendOrders(...allOrderIds,day) //Error
{
    allOrderIds.forEach(id=>console.log(id));
}

Above code will throw an error saying "comma is not permitted after the rest element", because rest parameter should be last parameter.


Difference between let and var keyword in javascript

Let and Var keyword in Javascript

Let and var keywords are used to declare variable in Javascript.

When to use Let over var keyword in Javascript.

It is recommended to use Let keyword over var keyword in javascript. Lets see why

Example 1: Declaration scope

In the below example, if we use let keyword and use the variable before its declaration it gives an error. Which is absolutely fine. 
console.log(orderId);  //Gives an error
let orderId = 10;

Now if we use var keyword and try to use the variable before its declaration it doesn't give any error. Which is strange. Not Recommended.
console.log(orderId); //undefined(not an error)
var orderId = 10;

Example 2: Scope in code block

Here let variable is bound to if block
if (true) {
let orderQty = 10;
}
console.log(orderQty);  //Error, Out of scope

var keyword is not bound to if block you can use outside the if block.
if (true) { 
var orderQty = 10;
}
console.log(orderQty);  //it will print 10, No error

So it is best practice to use let keyword over var keyword for declaring variable in Javascript.

Wednesday 1 August 2018

Deploy Dotnet Core API and Angular 5 on IIS - PART 2

Deploy Dotnet Core API and Angular 5 on IIS - PART 1


Deploy Angular Application on IIS Part 2. 
In this post, I am talking about deployment of angular 5 application on Internet Information Service.

      

NOTE: Your Angular Application is working in the Non-root folder on IIS

In our application usually, we are using Angular Router module for purpose of single page application.

While deploying it to production you will need to do some configuration.
this Article explain you steps required to deploy an Angular Router application On IIS.     

What will be covered in this Article 

Create a new Angular CLI example project.
Install URL Rewrite Module on IIS.
Add web.config with URL rewrite rule.
Publish application code using the base-href flag.  
Deploy application.

Create a new Angular CLI example project.

ng new hello-word
and simple run ng serve --open in localhost
It’s just a testing that generated Cli code is working fine.   

Install URL Rewrite Module on IIS.

If you did not install IIS on your system then Install Internet Information Services.

Install The URL Rewrite Module 



Add Web.config with URL Rewrite rule.





The server configuration requirement is documented on the Angular Deployments page in the Server configuration section    

<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
 <conditions logicalGrouping="MatchAll">
  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
  </conditions>
   <action type="Rewrite" url="/helloword/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

I Added Url base as helloword it means our base URL will be
http://localhost/helloword/index.html, and the rest of the routes will be open with this.

  <action type="Rewrite" url="/helloword/" />

Now we want it to get included in our build folder so we can deploy it with our application. Let’s add it to the .angular-cli.json

  "assets": [
"assets",
"favicon.ico",
"web.config"
],

Publish application code using the base-href flag

Angular Deployment page is explaining the Base Tag


<base href="/">

This generated page will not work as it router will use “/” as the base for composing navigation URL’s and static assets will be looked in the current directory.

To resolve this problem here we use base-href flag with and the flag will get available in Index.html.  

ng build --base-href /helloword/ --prod

Look into your Dist folder there is index.html file and web.config
Both files have the same URL “/helloword/”.

<base href="/helloword/">

<action type="Rewrite" url="/helloword/" />

Deploy Application

 

Give it to alias name and select your build (dist) folder path.

Now Simply Run And test your hosted application from
Manage Application > Browse


Thursday 12 July 2018

Timeout exception in stored procedure sql server

How to resolve Timeout exception in Stored Procedure Sql Server.

Using Temp tables.

Today i will be talking about how to improve Stored Procedure performance. I was working on a lengthy stored procedure where some tables are used frequently.
For example tblDoctors, tblPatients and a master table.

In the store procedure i was using these tables around 10 times.
all tables are having around 10 lakh records.

I need to select all records from tblDoctors table based on some key fields and update in patient table or master table.
Likewise i wanted to update around 10 column in each table based on some conditions.
So there were some 10 update and 10 select statements.

So due to that Timeout exception was coming in the stored procedure, Because i was hitting the tables around 10 times and then updating.

So to solve this problem we have added 2 local temporary tables where data was more.
Like #tblDoctors, #tblPatients

Now we will select all records based on some key fields which is used filter those records. Then insert them into Temp tables.
Now the load will be less.
Do your all operations in temp table and at the find Join with actual table and update all the fields from temp to actual tables.

Thanks