Microsoft – Suraj | Coding Passion Tue, 09 Oct 2018 07:03:49 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.8 .Net Core, The Beginning! /net-core-the-beginning/ /net-core-the-beginning/#respond Sun, 06 Aug 2017 15:28:19 +0000 /?p=760 What is Asp.Net Core

Asp.Net Core is completely re-written prior to earlier versions works on .Net framework. Asp.Net was developed with main focus to make it cross-platform! Yes Asp.Net core is now cross platform. It has gained popularity in quick time for modern day web development. One go cloud development with configurations made easy, with self hosting process with IIS and many more features added to Asp.Net core which makes it stand tall!

Cross Platform!

Yes! you read it right, Asp.Net core is now cross platform. The Asp.Net core CLR now has now WPF & winforms. It is built to code once and run on any platform. We can now have the .Net framework installed on Linux, Unix or OSX.

.Net Core CLR has joined the open source community and is on github. Anyone can contribute now on github for the .Net Core. Asp.Net Core applications can run both on .Net earlier frameworks and also on .Net core, which puts a great benefit for the developers. .Net Framework 4.6 is the same .Net we have been using and continue to develop the same way. .Net Core gives a platform to generate cross-platform solutions. But .Net 4.6 is stable and .Net core is under progress.

Merged stack MVC & Web API

Now this seems interesting. What? MVC & Web API merged!! Yes it is, in Asp.Net core we will have the merged stack of MVC and API and moreover Webforms is completely gone! Earlier we were required to add more than one Web project, one for MVC and one for Web API. But in Asp.Net core, we need to have only one project.
Multiple inbuilt tools are being used with .Net Core to build web applications with ease like NPM used for tools support, Client side support using Bower, Grunt & Gulp for building automatically, & as usual Nuget for .Net packages.

.Net Core application with Command Prompt & VS Code

Once we have installed .Net core framework in our system, since it is open source the .Net Framework can be accessed and projects can be maintained through command prompt.
Open command prompt, and hit “dotnet”. It will result the entire information of the .Net framework.

To create a new project using the dotnet templates, using scaffolding in VS IDE. The same scaffolding is also possible in the command prompt. With the command, “dotnet new”. This creates the scaffolding and restores the packages required if not exist.

Then the scaffolding templates:

Here we see multiple templates
Choose one of the templates setting the path where the project needs to be added. Lets create a console application as of now in one of our drives. To add a new console application, the command goes like below:

Here a new project is created, a console application for “Hello World”. Then when you run, you get namespaces missing error and navigating into the directory, you find the bin and obj folders go missing. Thus the error shown below:

Thus, restoring the packages solves the issue.
“dotnet restore”
This resolves and restores the required default packages for the console application.
Then build the project in order to ensure the code is errorless.
“dotnet build”
After build succeeds, then run the project to get the out put.
“dotnet run”
Output goes as below:

The same can be achieved in the terminals of Linux OS & Mac OS, just .net Core framework needs to be installed on the OS, which is why .Net core is developed to make it cross platform.
Upcoming articles we will look into the more details of the dotnet core. Creating Web applications using .net core and the MVC6.

]]>
/net-core-the-beginning/feed/ 0
Run an exe from web application /run-an-exe-from-web-application/ /run-an-exe-from-web-application/#respond Mon, 30 May 2016 12:56:27 +0000 /?p=652 Introduction

An interesting topic to share again! Recently while I was using GIT, the options in the browser on the GITHUB site, launched the application installed on my system! I wondered if that is possible I can run any exe from my web application and create wonders!
Nice story huh! Actually, that is possible and I will be sharing the process how we can achieve the same from code.
I will be using windows registry to register my exe to be pinged from any web application. Now wondering what is Windows Registry!

The Windows Registry is a hierarchical database that stores low-level settings for the Microsoft Windows operating system and for applications that opt to use the Registry..Wiki

Now yes, windows registry is an important section of the windows operating system having all the low level settings, but very essential for the applications to run on the OS. Windows registry is basically used to store all the important information for the software programs, hardware devices connected. There are basically few root keys pre-defined under the registry belt!
1

2
They are:

  • HKEY_LOCAL_MACHINE:- Setting are stored which are local or specific to the system.
  • HKEY_CURRENT_CONFIG:- All the gathered run time information are contained withing this key. This key is never in the memory, but generated at the boot time process.
  • HKEY_CURRENT_USER:- Settings that are valid/applicable to the current logged in user on the system.
  • HKEY_USERS:- All sub keys corresponding to the current user are stored.
  • HKEY_CLASSES_ROOT:- Information about any registered application on the system is contained.

Each of the above root keys have sub-keys attached to them.
For example: HKEY_CURRENT_USER\Software\Classes\ means ‘Classes’ is the sub key of the ‘Software’ sub key under the ‘HKEY_CURRENT_USER’ root key.
We will be creating a key inside the HKEY_CURRENT_USER in order to ping the exe. We have chosen this root key as that would not require any Admin access to add/edit any key inside this root. So the exe can be pinged by any user.

Diving into the code!

Here, what we would be doing is, we will be creating one console application(.exe), which will act as a medium to add a registry sub key to the “HKEY_CURRENT_USER/Software/Classes”. The same console application will be used to be executed/run from the web application. alert is the key command name which is used for this purpose.

using Microsoft.Win32;
using System;
using System.IO;
using System.Linq;

namespace WMConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Listening..");
            
            //Gets the current location where the file is downloaded
            var loc = System.Reflection.Assembly.GetExecutingAssembly().Location;
            if (!Directory.Exists(@"D:\Console\"))
            {
                System.IO.Directory.CreateDirectory(@"D:\Console\");
            }
            //Creates the Downloaded file in the specified folder
            if (!File.Exists(@"D:\Console\" + loc.Split('\\').Last()))
            {
                File.Move(loc, @"D:\Console\" + loc.Split('\\').Last());
            }
            var KeyTest = Registry.CurrentUser.OpenSubKey("Software", true).OpenSubKey("Classes", true);
            RegistryKey key = KeyTest.CreateSubKey("alert");
            key.SetValue("URL Protocol", "wnPing");
            key.CreateSubKey(@"shell\open\command").SetValue("", @"D:\Console\WMConsole.exe %1");
        }         
        
    }
}

Understanding the code!

In the above snippet, we are first creating folder where the same exe will be downloaded from the web application and stored. The path is being dynamically generated and used.

  • Then we open the existing root key of the registry, i.e. HKEY_CURRENT_USER through the Registry class field “CurrentUser” and the “OpenSubKey(“Software”, true)”, opens the instance of the sub-key or allows the write access to it. Same with the sub-key “Classes” which lies under the Software key.
  • Then, we are creating a new key using the “CreateSubKey(“alert”)” command, with the name “alert”.
  • Then we set the value to the sub key “alert”, as “URL protocol” and the name to be used in the anchor tag in web application as “wnPing”.
    Subkey alert created, also gets a subkey added to it in the following hierarchy:
    shell->open->command
    and to this, the value is set as the path to the exe file, which will run.

Once the registry is created, we add the below anchor tag for the exe application to be triggered from any web.

<a href="alert:wmPing">Click to trigger</a>

And done, click to see the magic!
3
The above window comes up, asking user to Launch the application. Done!!
You can always click the check box to remember the action, if you want the exe to run in the background without prompting.

Conclusion

This is it. I hope you find this topic interesting and try the same. This can be helpful in any web application when you are dealing with any hardware components attached to local client systems and your server needs input from them.
Please share your thoughts and views on any improvement!
Keep learning and keep sharing!

]]>
/run-an-exe-from-web-application/feed/ 0
Microsoft Azure: Get started! /microsoft-azure-get-started/ /microsoft-azure-get-started/#respond Wed, 30 Mar 2016 12:11:08 +0000 /?p=504 Overview

Cloud! Cloud! Cloud! What is this cloud! What is Azure! What is cloud computing again!
Oh! So many questions, when we get into this software industry. We will discuss about cloud computing and then move to Azure.

think

Cloud computing is one the most hyped and most demanding is the industry now.It is actually a paradigm shift for providing computing over the internet. Innovations are what now the companies are looking forward to. Cloud computing is a big enemy to On-premise computing which has been prevailing since long and is still in process. Now what is On-premise computing, when the solutions are installed on user/user’s systems, whereas cloud provides solutions via the Internet. Cloud computing now no longer wastes your time and space with installing the hardware, servers physically, it just needs a good reliable internet connection.

Cloud comprises of various virtual Data Centers that provide different software, hardware & information resources/services. Organizations now just need to connect to the cloud and use the available resources based on their requirement.
1
Cloud computing for organizations can be done in three ways:

  • Private: This is only for one organization and is totally secure as the name itself is private. 😛
  • Public: This is acquired and managed by the cloud service provider and it provides the highest level of efficiency for the resources provided by the cloud provider.
  • Hybrid: This is the blend of both private and public, where few resources are added and managed in under the public i.e. the cloud provider and few other resources are managed by the organization. This also provides increased efficiency.

We will now learn more facts and information to make our understanding on cloud clear ..:D
23

Microsoft Azure

Microsoft Azure is a cloud computing platform provided by Microsoft, previously named as Windows Azure. Lets have a pictorial view of what Azure can provide:
4

This is what the summary is about azure. All the overheads i.e. the Operating system to be used for the application we develop, the network on which we have the application set up, the storage space and how scalable is the storage used, Monitoring the performance of the application. These are few important things we note and keep in mind before developing an application.
Just imagine, how it would be if we have a provider which will handle and manage for us and let us only focus on our application development? Would not that be just great? Here come the hero, Microsoft Azure.


5

Microsoft Azure, the cloud service provider provides us with all the required resources.
According to Garnet,

A style of computing in which scalable and elastic IT enabled capabilities are derived as a service using the internet technologies.

Below image shows how the Microsoft Azure portal looks like:
5

The above image shows the various resources Azure portal provides us.

App Services: These are the Web app services on which we deploy our websites in general. Suppose we create an MVC application and want to run on Azure, we need to create a web app service on which the Website will be deployed and running.

Virtual Machines (Classic): As Microsoft suggests, the VMs are the same but the classic mode denotes that the old platform/portal is outdated but the API is still intact. This will not support the newest resources added, whereas in new mode, it supports the very new and updated added resources.

Sql Databases: This as discussed below also, helps create a database for the application. The creation would need a new or existing server on which it will run and also based on location. we have discussed more on this below.

Cloud Services: It is one of the PaaS services provided bt Azure. This can simply be thought of as a collection of number of VMs which in turn would have software installed on them.
Microsoft Azure runs on three basic structures. Iaas, Paas & Saas. Lets discuss about them in brief below:
Iaas (Infrastructure as a Service)
Infrastructure as a service when used by the organization, provides the infrastructure resources required for the build. Here you are concerned only for the service we get from the Infrastructure, for example Database service. Microsoft provides with the Remote Desktops, Virtual machines, Servers as IaaS resources.
PaaS (Platform as a Service)
This is the platform which Microsoft Azure provides required for only development. Here we only need to focus on the development, maintenance and management of the application. Azure SQL Database, HD Insights, Application Insights,Azure Storage, Active directory are all a part of PaaS of Azure.

The difference would go like, PaaS have more economic advantage than IaaS, where as IaaS has more control over the entire resources being used may it be, OS, servers, VMs, etc.

Lets see an example how we can add a IaaS service and PaaS i.e. for instance Database (SQL):
At first as we have seen the azure portal above in the image, now we click on SQL Database and then on Add like below:
6

Then we will see a new tab besides the above tab on the same window like below:

7

This is the new portal style in which the tabs open up side by side, whereas in earlier portal, every time a new tab was overlapping the clicked tab.

Here on this image, there are many things we need to know. Remember we are going to add a new Sql Database.
First it asks for the database name, enter the name. Then the next box is for the Server name. Once you click on the Server, the tab opens up with options such as Create a new server or use existing. Here I am adding a new server instance.

Another interesting thing to mark is Location. Out of different options, be decisive and wise in choosing the location based on the nearest location to the deployment server, to decrease the latency rate.
8
Here, while creating the database, we created a new Server instance with a name and location. The Server here acts as IaaS and the Database as PaaS.

Virtual Machines (IaaS):
There are a lot of services provided by Microsoft Azure, while adding a new virtual machine, we have options for adding as a Windows Server, Linux, Joomla and many more pre-build images. Interesting is they provide you with an image of Sql Sevrer. We take this as an example and see how to add VMs.

11
As you see above, when we select the Sql Server as our VM, it means it will create a Windows Server with Sql Server (* version) installed on it. The list of versions is shown in the image. i would be selecting 2016 instance and lets see what happens.
12

When we click the Sql Server version to be created, the above tab pops up, to configure the settings for the VM. The above details are just names and password you would be using for login.

13

This the VM configuration, the windows server configuration on which our SQL 2016 would be installed.  Select any one and proceed with the other configuration. The next are default setting, you may change also based on your need.

Then finally hit Ok to create the VM, it will start the initial deployment and after submitting the deployment, it will take few minutes, to complete and set up the VM for you to download the VM instance and use using Remote desktop connection.

The configuration can be seen on All resources and on click of the virtual machine.

14

As you can see here, the OS is Windows, and every Virtual Machine requires a Virtual Network to be created, so while creating the virtual machine, a virtual network is created in the setting, if wished the name of VN can be changes as in this case it is, surajsql2016.

Then after the VM is updated and set up is completed, you will get a notification regarding the same.

Then hit Connect, this will download the .rdp file. Then as you know the process, add the username password you had set up during the configuration of VM and play around on the Server with SQL 2016 installed on  it.
SaaS (Software as a service)
This is an interesting concept provided by the cloud. This lets users access to online applications like Sharepoint online, MS Office based on subscription. This can also be termed as software delivered over internet/web. We need not worry about the installation the bit information, OS, etc before using the product/software.

Here comes another interesting fact about microsoft azure. The Pay as you Go model.

10 9

 

Here the payment is like the electricity use. 😀 You pay only when you use. That is called utility. You are not asked to pay for units that you have not used at all, right? May sound weird but true. 😛
Microsoft Azure also follows the utility graph. It is the green in the graph. Only pay for the services you use and that are up and running. Is’nt that great! economical..:)

Conclusion

Thus, here we just had a brief idea about what the Cloud computing is, why Microsoft Azure, the architecture, different platforms. I upcoming modules we will have a detailed walk through of the Azure portal and learn how to create an MVC application and deploy to the Azure app service.
Resources:- Google Images, Microsoft Azure Site

]]>
/microsoft-azure-get-started/feed/ 0