All posts by Thiyagu

ASP.NET Core – Project Structure

If we had created a new blank project (EMPTY template) of ASP.NET Core in VS 2015, we see the following structure at the start. Here you can see a couple of things like wwwroot, Dependencies, Startup class and project.json and also you  see some other things like “References” and “Properties” these are the common parts of the .NET application.

 

 global.json

The file allows selection of the .NET Core tools version being used through the sdk property. The version (and optionally run time and architecture) are important because your computer have multiple versions of dnx.exe (.NET Execution Environment). 

 

wwwroot

ASP.NET Core has a new Feature for maintaining wwwroot folder where we put our static contents and libraries so that they are accessible right from the root of the project like HTML files, CSS , image files, and JavaScript files which are sent to the users’ browsers should be stored inside the wwwroot folder.

 Dependencies

There is a special folder called Dependencies which does not present physically but categorically shows the project dependency packages added in the project. Dependencies section is used to manage Bower and NPM tooling packages dependencies in your project. For example, Bower for client-side packages with their dependencies (i.e. jQuery, Bootstrap, Angular). Bower has bower.json file which contains all the packages and dependencies that have installed. So Bower and NPM dependencies appear here in this section. 

 Program.cs class

Program.cs file is the main entry point of our application. As per below code (inside the program.cs), you can see that this class contains a Main() method which looks quite familiar with that you have been seeing in C# Console Apps. This class is used to initiate, build, run the server (IIS and Kestrel) and host the  application. 

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;

namespace FirstASPCoreApplication
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}

 project.json

The first file of our project is project.json. All top level dependencies and libraries that are used by the application are listed in project.json. The project.json file maintains a list of packages used in a project, known as a package reference format.

 Startup.cs Class

The startup class is helpful to define the request handling pipeline and configure the Services required by the app. It has 2 methods ConfigureServices() and Configure(). This class basically is used to configure middle-wares on the request pipeline. The Startup class(Startup.cs) is where application pipeline is configured for request processing.

Web.config

In the previous versions, everything is handled by Web.Config but in ASP.NET Core, we don’t know about Web configure file and the only purpose it gives the instruction to iis for what should be done and it receives the http request.

What do you think?

I hope you have overview about ASP .NET Core Layout/structure of the Application. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

 

Powershell : How to Compare Two Files, and List Differences

What is Compare-Object cmdlet do?

The Compare-Object cmdlet compares two sets of objects. One set of objects is the “reference set,” and the other set is the “difference set”. The below format will be out of the comparison.

<= This indicates that property value appears only in the -ReferenceObject set.
=> Indicates that property value appears only in the -differenceObject.
== Indicates that both property value appears the same.

Example:

In the Compare-Object cmdlet, there are two required parameters -referenceObject and -differenceObject. For example, -referenceObject controls the master content, the file which holds all the information, while -differenceObject has the secondary file.

Demo

Let we create two files, the first (Master & Child list) is for reference and the second for comparison. Now we are ready to execute this Compare-Object script.

MasterList.txt

WaterMelon
Grapes
Mango
Oranges
Bananas
Cucumber
Guva

ChildList.txt

Mango
Apple
Oranges
Bananas
Cucumber
WaterMelon
Grapes

Example 1: To Compare Two Files, and List Their Differences

This command compares the contents of two text files. Here Apple is present in the second file (-differenceObject set) not in the first file (-ReferenceObject set)  so the output will be => and Guva is present in the first file and not in the second file, so the output will be <=.

Clear-Host
$strReference = Get-Content "D:\BLOG\Power Shell\Examples\Masterlist.txt"
$strDifference = Get-Content "D:\BLOG\Power Shell\Examples\ChildList.txt"
Compare-Object $strReference $strDifference

Example 2: To Compare Two Files, with -Parameters

Clear-Host
$strReference = Get-Content "D:\BLOG\Power Shell\Examples\Masterlist.txt"
$strDifference = Get-Content "D:\BLOG\Power Shell\Examples\ChildList.txt"
Compare-Object $strReference $strDifference -IncludeEqual

Optional Parameters

Optional Parameters

-CaseSensitive This indicates that comparisons should be case-sensitive.
-Culture Specifies the culture to use for comparisons.
-Property Specifies an array of properties of the reference and difference objects to compare.
-ExcludeDifferent Indicates that this cmdlet displays only the characteristics of compared objects that are equal
-SyncWindow Specifies the number of adjacent objects that this cmdlet inspects while looking for a match in a collection of objects.
-IncludeEqual Indicates that this cmdlet displays characteristics of compared objects that are equal. By default, only characteristics that differ between the reference and different objects are displayed.
-PassThru Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.

 

NOTE: If the reference set or the difference set is null ($null), Compare-Object generates a terminating error.

 

What do you think?

I hope you have got an idea about how to use PowerShell Compare-Object cmdlet. I would like to have feedback from the readers of my post. Your valuable feedback, question, or comments about this article are always welcome.

PowerShell : Continue Keyword

Continue Keyword in PowerShell

One of the things that is a bit confusing for powershell beginner is the Continue statement. This is partially because it does not act like it might in some other languages. Next question will arise, then what does the Continue statement do in Windows PowerShell? the answer is it returns flow to the top of the innermost loop that is controlled by a WhileFor, or Foreach statement. 

Example:

In the following example, program flow returns to the top of the While loop if value of $myValue variable is equal to 6. As a result, all the numbers between 1 and 10 are displayed except for 5:

while ($myValue -lt 10)
{
$myValue += 1
if ($myValue -eq 6) {Continue}
Write-Host $myValue 
}

Output:

1
2
3
4
5
7
8
9
10

The Continue keyword supports labels. A label is a name you assign to a statement in a script, so the continue will skip in the current loop and execute form the  assigned label location. Let we discuss more about the labels in upcoming articles.

ASP.NET Core Real Power: Features And Benefits

Introduction

ASP.NET Core 1.0 is not a continuation of ASP.NET 4.6. It is a whole new framework, a side-by-side project which happily lives alongside everything else we know. It is an actual re-write of the current ASP.NET 4.6 framework, but much smaller and a lot much more modular. There is no System. Web namespace anymore and everything which came with it.

It is the framework you want to use for web development with .NET. ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-based, Internet-connected applications. If you have any experience with MVC or Web API over the last few years, you will notice some familiar features. ASP.NET Core 1.0 is a 1.0 release that includes Web API and MVC but doesn’t have SignalR or Web Pages. It doesn’t yet support VB or F#.

If you have any experience with MVC or Web API over the last few years, you will notice some familiar features.This sequence of tutorials, will help you write an application using ASP.NET Core that can create, edit, and view data from a database.

Advantages of ASP.NET Core

Open Source:

ASP.NET Core is open source and available on GitHub,Which help to reduce the cost of hosting.NET application.

Platform Independent (Cross Platform Support):

ASP.NET Core 1.0 is a big fundamental change to the ASP.NET landscape and it is open source. ASP.NET Core is supported on Windows, Mac and Linux OSX

Built from scratch:

ASP.NET Core is not like an enhancement to ASP.NET 4.5 but it has been built from scratch. A lot of new features have been added to it and some of the existing features has been dropped also. To support Cross Platform and improve performance some existing features have been removed.

Modular Web Framework:

Asp.Net core everything is managed using nugget package, so it’s easy to upgrade new framework without releasing new .net framework version. In ASP.NET Core, a community can just release new NuGet package version and you will get latest changes by updating your packages. The .NET developer has the ability to pick and choose which ASP.NET features to include in their solutions. This opt-in model allows developers to be more deliberate with regard to which libraries are included in their projects

Dependency Injection:

Dependency injection is integrated into the framework for achieving loose coupling between objects and their collaborators.Third party products such as Autofac should still be available as an alternative to the build-in ASP.NET DI functionality.

Combination of MVC and WEB.API

In previous versions of ASP.NET, MVC and WEB.API were based on different versions of the framework ie., System.Web.Mvc and System.Web.Http/System.Net.Http, respectively. This has been removed and its been integrated with ASP.NET CORE 1.0 MVC 6. There is now a single set of objects within a single namespace (Microsoft.AspNet.Mvc). This standardized approach simplifies developing both MVC and WEB.API endpoints.

What do you think?

I hope you have basic about ASP .NET Core and its advantage . I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

Introduction to ASP.NET Core

Introduction

ASP.NET Core is the new web framework from Microsoft. It is the framework you want to use for web development with .NET. ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-based, Internet-connected applications. If you have any experience with MVC or Web API over the last few years, you will notice some familiar features.

ASP.NET Core 1.0 is a 1.0 release that includes Web API and MVC but doesn’t have SignalR or Web Pages.
It doesn’t yet support VB or F#.

What is ASP.NET Core

ASP.NET Core is an open source and cloud-optimized web framework for developing modern web applications that can be developed and run on across the many platforms like Windows, Linux and the Mac. It includes the MVC framework, which now combines the features of MVC and Web API into a single web programming framework.

What is New in ASP.NET Core?

ASP.NET Core ships entirely as NuGet packages. This allows you to optimize your application to include only the necessary NuGet packages rather than having all in application.

  • Open-source and community-focused.
  • A lightweight, high-performance, and modular HTTP request pipeline.
  • Ability to build and run on Windows, macOS, and Linux.
  • Ability to host on IIS, Nginx, Apache, Docker, or self-host in your own process.
  • ASP.NET Core apps can run on .NET Core or on the full .NET Framework.

What do you think?

I hope you have basic introduction and overview about ASP .NET Core. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

 

Power Shell – Containment Operators

Power Shell Containment Operators

The containment operators (-contains and -notcontains) are similar to the equal operators. However, the containment operators always return a Boolean value, even when the input is a collection. The conditional operator -Contains is similar to -eq, except it returns ‘True’ or ‘False’. -Contains is designed for situations where you wish to test for one particular item in a collection, array or a hash table.

Operators Description
-contains Returns true when reference value contained in a collection
-notcontains Returns true when reference value not contained in a collection
-in Returns true when test value contained in a collection
-notin Returns true when test value not contained in a collection

contains

Always returns a Boolean value. Returns TRUE only when the test value exactly matches at least one of the reference values. When the test value is a collection, the Contains operator uses reference equality. It returns TRUE only when one of the reference values is the same instance of the test value object.

Syntax: <Reference-values> -contains <Test-value>

Example: 1

Contains checks each item between the commas

$Name = "John", "Ray Matt", "Anthony" 
$Name -Contains "Ray Matt"

OUTPUT

True

Example: 2

-Contains requires exact equality

$Name = "John", "Ray Matt", "Anthony" 
$Name -Contains "Ray"

OUTPUT

False

-notcontains

The negative -NotContains is not as useful as -NotMatch. However, from what we have already learned the syntax is predictable.

Syntax: <Reference-values> -notcontains <Test-value>

Example:

$Name = "John", "Ray Matt", "Anthony" 
$Name -notContains "Ray"

OUTPUT

True

-in Operator

In operator return the boolean value if the test value appears in a collection of reference values. Always return as Boolean value. Returns TRUE only when the test value exactly matches at least one of the reference values else it will returns FALSE.

Syntax: <Test-value> -in <Reference-values>

Example: 1

$Name = "John", "Ray Matt", "Anthony" 
"Ray" -in $Name

Output:

False

Example: 2

$Name = "John", "Ray Matt", "Anthony" 
"Ray Matt" -in $Name

Output:

True

-notin Operator

In operator return the boolean value if the test value appears in a collection of reference values. Always return as Boolean value. Returns TRUE only when the test value not a exactly matches at least one of the reference values else it will returns FALSE.

Syntax: <Test-value> -notin \<Reference-values>

Example: 1

$Name = "John", "Ray Matt", "Anthony" 
"Ray" -in $Name

Output:

True

Example: 2

$Name = "John", "Ray Matt", "Anthony" 
"Ray Matt" -in $Name

Output:

False

PowerShell : Do-While & Do-Until Loop

Do-While & Do-Until Loop in PowerShell

Loops are an essential construct in any programming language as they enable a block of code to be repeatedly executed based on the condition. This can be useful for iterating through items in an object or repeatedly performing an operation. PowerShell supports involves setting a condition which either allows the loop to process as long as the condition is true or until it is met. 

  • The Do keyword works with the While keyword or the Until keyword to run the statements in a script block, up to the condition. The script block in a Do loop always runs at least once.
  • In a Do-While loop, the condition is evaluated after the script block has run. Then the while loop repeat the script until as long as the condition became false.
  • In a Do-Until loop always runs at least once before the condition is evaluated. However, the script block runs as long as the condition is false.

Do-While

Syntax : do {<statement list>} while (<condition>)

Example:

In below example, the loop will stop executing if condition became false that is if loop_index value reach 0 then condition became false.

$myArray = 1,2,3,0,4
do
{
$loop_index++;
}
while ($myArray[$loop_index] -ne 0)
$loop_index

Output:

3

Do-Until

Syntax : do {<statement list>} until (<condition>)

Example:

In below example, Do…Until loop is used when we want to repeat a set of statements as long as the condition is false.

$myArray = 1,2,3,0,4
do
{
$loop_index++;
}
until($myArray[$loop_index] -ne 0)
$loop_index

Output:

4

 

Power Shell – Type comparison

What is comparison Operator?

Comparison operators let you specify conditions for comparing values and finding values that match specified patterns. To use a comparison operator, specify the values that you want to compare together with an operator that separates these values.

Type comparison

The type comparison operators (-is and -isnot) are used to determine if an object is a specific type.

Operators  Description
-is Returns true if both object are the same type
-isnot Returns true if the objects are not the same type

-is Operator

Syntax: <object> -is <type reference>

Example:

PS C:\>
$stringMsg1 = "dotnet-helpers"
$stringMsg2 = 100
$stringMsg1 -is $stringMsg2.GetType()
$stringMsg2 -is [int]

OUTPUT

False
True

-isnot Operator

Syntax: <object> -is <type reference>

Example:

PS C:\>
$stringMsg1 = "dotnet-helpers"
$stringMsg2 = 100
$stringMsg1 -isnot $stringMsg2.GetType()
$stringMsg2 -isnot [int]

OUTPUT

True
False

PowerShell – Replacement Operator

Replacement Operator

PowerShell provides several options to help you replace text in a string with other text. The -replace operator replaces all or part of a value with the specified value using regular expressions. It replaces every occurrence of the exact string you specify with the exact replacement string that you provide. The -replaceoperator provides much more flexibility because its arguments are regular expressions that can match and replace complex patterns.

Operators  Description
-replace replace a string pattern


Syntax:

<input> <operator> <original> <substitute>

The syntax of the -replace operator is as follows, where the <original> placeholder represents the characters to be replaced, and the <substitute> placeholder represents the characters that going to replace.

Example:

PS C:\> 
$stringMsg = "Hi Welcome to dotnet-helpers.com"
$stringMsg -replace 'Hi' , "You are"

OUTPUT

You are Welcome to dotnet-helpers.com

By default, the -replace operator is case-insensitive. To make it case sensitive, you need to introduce ‘c’ as prefix like  -creplace. To make it explicitly case-insensitive, you need to prefix ‘it’ like -ireplace.

Example:

Here the output will be same text beacuse we maked a replace operator as case sensitive, so ‘HI’ does’t macth with the string.

PS C:\>
$stringMsg = "Hi Welcome to dotnet-helpers.com"
$stringMsg -creplace 'HI' , "You are"

OUTPUT

Hi Welcome to dotnet-helpers.com

PowerShell – Matching Operators

-like and -notlike Operators

The like operators find elements that match or do not match a specified pattern using wildcard expressions.

How its handle single & Collection values?

If we input scalar value, comparison operators return a Boolean value. When the input is a collection of values, the comparison operators return any matching values. If there are no matches found in a collection then the comparison operators do not return anything.

The syntax is:

<string[]> -like <wildcard-expression>
<string[]> -notlike <wildcard-expression>

Example:1

PS C:\>

$singleValue = "Aadharsh"
$singleValue = $singleValue -like "Aadharsh"
Write-Host ""
Write-Host "Is varible contain 'Aadharsh' : " $singleValue

OUTPUT:

Is varible contain 'Aadharsh' : True

Example:2

$singleValue = "Aadharsh" , "Rakshu"
$singleValue = $singleValue -like "Aadharsh"
Write-Host ""
Write-Host "The matched value is : " $singleValue

OUTPUT:

The matched value is : Aadharsh

-match and -notmatch Operators

The match operators find elements that match or do not match a specified pattern using regular expressions. It search only in strings and they can’t search in arrays of integers or other objects.

The syntax:

<string[]> -match <regular-expression>
<string[]> -notmatch <regular-expression>

Example:1

PS C:\>

$singleValue = "Aadharsh"
$singleValue = $singleValue -match "Aadharsh"
Write-Host ""
Write-Host "Is variable contain 'Aadharsh' : " $singleValue

OUTPUT:

Is variable contain 'Aadharsh' : True

Example:2

$singleValue = "Aadharsh" , "Rakshu"
$singleValue = $singleValue -like "Aadharsh"
Write-Host ""
Write-Host "The matched value is : " $singleValue

OUTPUT:

The matched value is : Aadharsh

Note:

There is automatic variable called “matches” element which return the match elements. You can use $matches variable to get the matched value.

What is difference between -Like & -Match?

The most technical distinction is -Match is a regular expression, whereas -Like is just a wildcard comparison, a subset of -Match. If you need a wildcard to find this item’, then start with -Like. However, if you are sure that most of the letters in the value that you are looking for, then you are better you can go with -Match. -match operator is quite faster than -like operator.