I hope you have idea of how to use KnockoutJS visible or hidden based on the value passed in the binding. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.
The text binding causes the associated DOM element to display the text value of our parameter. This is used in text-level DOM elements such as div,span. The text binding accepts any data type and parses it into String before rendering it.
Syntax:
text: <binding-value>
Parameters
Knockout sets the element’s content to a text node with your parameter value. And if there is any previous content then it will be overwritten.
If this parameter is an observable value, then the binding value will update the element’s text whenever the value changes. If the parameter isn’t observable then it will only set the element’s text once and will not update again.
I hope you have idea of Controlling text and appearance. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.
In this post we will discuss about how to check the response code from a website. In this article, we’re going to cover how to build a PowerShell function that will query a specific URL and attempt to find out if that URL is working fine or not. To get started, let’s construct a function for this task called CheckSiteURLStatus with a single parameter called URL.
Net.WebReques makes a request to a Uniform Resource Identifier (URI). This is an abstract class.
Using Net.WebRequest class (which is under the System.Net namespace), we get a response from a web server. Unlike the Net.WebClient class, you will not be able to download the site page. However, using Net.WebRequest class, you can get a response code and also see what type of web server is being used to host the site. The WebRequest class has a static method called Create in which we can pass a URL to invoke a HTTP, We’ll add the code to create the request into our function as shown below.
[string] $_URL = 'https://dotnet-helpers.com'
function CheckSiteURLStatus($_URL) {
try {
$request= [System.Net.WebRequest]::Create($_URL)
$response = $request.getResponse()
if ($response.StatusCode -eq "200") {
write-host "`nSite - $_URL is up (Return code: $($response.StatusCode) -
$([int] $response.StatusCode)) `n" -ForegroundColor green
}
else {
write-host "`n Site - $_URL is down `n" ` -ForegroundColor red
}
} catch {
write-host "`n Site is not accessable, May DNS issue. Try again.`n" ` -ForegroundColor red
}
}
CheckSiteURLStatus $_URL
Based on the response code, the condition will execute and write on the console.Finally, we’ll need to dispose of the response after we’re done to clear it from memory which would finish it off to make it look like this:
OUTPUT
What do you think?
I hope you have idea of how to check the Website status using Powershell script. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.
One of the great benefits of PowerShell is its pipeline mechanics that enable the output of one command to be passed to the next command in the pipeline. That output is not sent as basic text but rather the actual objects generated from a command are sent in the native object format to the next command and this is enabled for all commands.
Example: 1
If you open a PowerShell window and type the following commands the result is the same for both, Let us test this by the below cmdlet.
If we look at the above script, it like they are the same but in reality, they are working in very different ways. Let us discuss more to understand this more.
Example: 2
From Example 1, we think that it seemed to achieve the same result for both Write-Output and Write-Host but we have differences between these two cmdlets. This can be demonstrated in more detail in this example. Write-Output sends the output to the pipeline. From there it can be piped to another cmdlet or assigned to a variable. Write-Host sends it directly to the console
From the above example, we can able see the Write-Output cmdlet has passed the value to the next process but Write-Host just directly writes to the host and nothing has to send forward to the next cmdlet.
In simpler, if you possibly want to write data to the screen, but also want the data to be passed down the pipeline to further commands, then use Write-Output. Write-Host does not output data to PowerShell Object flow Engine but rather, as the name implies, writes directly to the host and sends nothing to the PowerShell engine to be forwarded to commands later in the pipeline.
Here’s we can discuss on how to add text to the end of a text file using the Add-Content cmdlet using PowerShell. In our example let’s add “This is the last line” to the end of a file using add-content cmdlet to append data to a text file.
Add-Content "C:\dotnet-helpers\DummyfiletoDelete.txt" "This is the last line"
The above example above adds the text to the last line of the text, it doesn’t actually create a new line. We can use an escape character to tell PowerShell to add a carriage return, new line… while appending the text in existing file.
Escape characters:
‘n — New line ‘t — Horizontal tab ‘’ — Single quote ‘” — Double quote ‘0 — Null ‘a — Alert ‘b — Backspace ‘r — Carriage return
Append Text using Escape characters:
Add-Content -Path "C:\dotnet-helpers\DummyfiletoDelete.txt" -Value "`r`nThis is the last line".
The above example append the “This is the last line” as a new line at end of the text file with help of ‘n and’ r
Add-Content -Path "C:\dotnet-helpers\DummyfiletoDelete.txt" -Value "This is the last line added from $env:computername system"
PowerShell offers a number of different ways to manage the variety of text files. Here we learn how to retrieve text from text files and how to find text in text files, all through PowerShell cmdlets.
How To Retrieve Text From Text Files
You can use the powershell Get-Content cmdlet which is used to retrieve all text from a text file specified by the Path parameter.
Executing the above cmdlet, You’ll see that the result was the entire contents of TestFile.txt. If you just wanted to see a particular line number? By default, Get-Content reads all the line in a text file and creates an array as its output with each line of the text as an element in that array.In this case, the array index number is equal to the text file line number. So we can get the each line of the txt file by using the array index number.
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
This is test text file
Thanks for reading this posts.
In the above example, the result of Get-Content is a type of System.Array and that by using index numbers in brackets you can get the value of text file. The index is start from Zero.
How To Find Text In Text Files
There are a many different ways to do this but the we can use Where-Object cmdlet which will be the easilest way. The Where-Object cmdlet is a popular cmdlet that allows you to “filter out” various information from the output of other cmdlets. When using Where-Object we must use the $_ variable and this is a special variable in PowerShell known as the pipeline variable.
Before start executing the Delete powershell command we need to make sure you are logged in to the server or PC with an account that has full access to the objects you want to delete.
# Using PowerShell commnads to delete a file
Remove-Item -Path "C:\dotnet-helpers\DummyfiletoDelete.txt"
The above command will excute and delete the “DummyfiletoDelete.txt” file which present inside the “C:\dotnet-helpers” location.
Use PowerShell to Delete all File and Folders inside the folder
We can also use wildcard ‘*’ characters to remove multiple items. For example, this command removes all the files in “C:\dotnet-helpers\*.*”
# Using PowerShell commnads to delete all file
Remove-Item -Path "C:\dotnet-helpers\*.*"
# Using PowerShell commnads to delete all file and folders
Remove-Item -Path "C:\dotnet-helpers\*.*" -recurse
Recurse drills down and finds lots more files. The –recurse parameter will allow PowerShell to remove any child items without asking for permission. Additionally, the –force parameter can be added to delete hidden or read-only files.
Using -Force command to delete files force fully
# Using PowerShell commnads to delete all file force fully
Remove-Item -Path "C:\dotnet-helpers\*.*" -Force
The above command will delete all hidden or read-only files from the location “C:\dotnet-helpers\”
In this tutorial section, we will discuss how to create a new project in Visual Studio using ASP.NET CORE. Once you have installed the Visual Studio 2015 tooling, you can start building a new ASP.NET Core Application .
STEP: 1
Once you have installed the Visual Studio 2015 tooling, you can start building a new ASP.NET Core Application using File → New Project menu option.
STEP: 2
On the New Project dialog box, you can able to see the three different templates for Web projects as shown below. After selecting ASP.NET Core Web Application (.NET Core),specify the location and name for your ASP.NET Core project click OK
ASP.NET Web Application − The simple ASP.NET application templates .
ASP.NET Core Web Application (.NET Core) − This will start you with a crossplatform compatible project that runs on the .NET Core framework.
ASP.NET Core Web Application (.NET Framework) − This starts a new project that runs on the standard .NET Framework on Windows.
STEP: 3
In the below dialog box, you can select a specific template for the ASP.NET application from the available ASP.NET Core Templates. Here, we select and start with an empty template. This would help us build it from scratch. Let us select the Empty template, turn off the Host in the cloud and click OK.
Now the Visual Studio will launch your new project. In the Solution Explorer window, you will see all the files that are in this project.
STEP: 4
Now you can run your application by pressing Ctrl+F5 or by going to the Debug menu. After going to the Debug menu, select Start Without Debugging.
STEP: 5
We can see it display only Hello World! This runs on http://localhost:44432. In your window system tray, you can also see that IIS Express is running as shown below.
What do you think?
I hope you have idea about creating first ASP.NET CORE application. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.
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.
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 <=.
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.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.