Tuesday, 29 August 2017

.Net Architecture Interview Questions:

What is .net framework?

The .Net framework is a software development platform developed by Microsoft. The framework was meant to create applications, which would run on the Windows Platform. The first version of the .Net framework was released in the year 2000.
The version was called .Net framework 1.0. The .Net framework has come a long way since then, and the current version is 4.6.1. The .Net framework can be used to create both - Form based and Web based applications. Web services can also be developed using the .Net framework.
The framework also supports various programming languages such as Visual Basic and C#. So developers can choose and select the language to develop the required application. In this chapter, you will learn some basics of the .Net framework.
In this tutorial, you will learn-
·         What is the .NET Framework
·         Different versions of the .Net framework

The architecture of the .Net framework is based on the following key components;
Common Language Runtime(CLR) –Common Language Runtime is a heart of the .net framework. It actually manages the code during Execution. The Code that runs under the CLR is called "Managed Code". The code that is executed  under .net run-time gets benefits like cross language inheritance, cross language exception handling, enhanced Security, Versioning and development support, a simplified model for component interaction, debugging and Profiling services.
        CLR Managed Code Execution Process
           The Process of Compiling and executing managed code is given below:-

·  When you compile a program written in any of language that target CLR., the compiler translate it into Microsoft Intermediate Language (MSIL) or Intermediate Language (IL). It does not depend on Language and always get translated to IL, This ensures language Interoperability.
· In addition to translating the code into IL, Compiler also produces metadata about the program during the process of compilation. Metadata contains the description of the program such as Classes and interfaces, the dependencies etc.
·  The IL and the metadata are linked in an assembly.
·  The Compiler creates .EXE or .Dll File.
·  When you execute the .exe or .dll file, the code and all the other relevant information from the base class library is sent to the class Loader, who loads the code in memory.
· Before code gets executed, The Just-in-Time (JIT) compiler translates the code from IL to native code (machine code). CLR supplies a JIT compiler for each supports CPU architecture. During the process of compilation, the JIT compiler compiles only the code that is required during execution instead of compiling the complete IL code.
· During JIT Compilation, the code is also checked for type safety. Type Safety ensures that object are accessed in a compatible way. Type Safety also ensures that objects are isolated from each other and are therefore safe from any malicious corruption.
· After Converted to native code, converted code is sent to .net runtime manager.
· The .net runtime manager executed the code, while executed the code, a security check is performed to ensure that the code has the appropriate permission for accessing the available resources.

Features provided by CLR
Some of the features provided by the CLR are as follows:
·Automatic memory management: - The CLR provides the Garbage Collection feature for managing the life time of object. This relives a programmer from memory management task.
· Standard Type System: - The CLR Implement a formal Specification called the Common Type System (CTS). CTS is important part of rules that ensures that objects written in different language can interact with each other.
· Language interoperability: - It is the ability of an application to interact with another application written in a different programming language. Language interoperability helps maximum code reuse. The CLR provides support for language interoperability by specifying and enforcing CTS and by providing metadata.
· Platform Independence: - The Compiler compiles code language, which is CPU-independent. This means that the code can be executed from any platform that supports the .Net CLR.
· Security Management: - In .net platform, Security is achieved through the code access Security (CAS) model. In  the model, CLR enforces the restriction an managed code through the object called “permissions”. The CLR allows the code to perform only that task for which it has permissions. In other words, the CAS model specifies what the code can access instead of specifies who can access resources.
· Type Safety: - This feature ensures that object is always accessed in compatible ways. Therefore the   CLR will prohibit a code from assign a 10-byte value to an object that occupies 8 bytes.

Benefits of CLR 
  Followings are some of benefits of the CLR
· Performance improvement
· The ability to easily use components developed in other languages.
· Extensible types provided by library.
· New Language features such as inheritance, interfaces etc.
· Complete Object-Oriented design.
· Very Strong Type Safety.
· Use of delegates rather than function pointers for increased type safety and security.
 .
CTS: Common Type Specification:
CTS provide a standard that all the .net framework is follows when declaring and using type .the main benefit of CTS is that language interoperability (mean more than one language is communicating each other.


Eg:-To implement or see how CTS is converting the data type to a common data type, for example, when we declare an int type data type in C# and VB.Net then they are converted to int32. In other words, now both will have a common data type that provides flexible communication between these two languages.
MSIL(Microsoft intermediate language):

MSIL stand for microsoft intermediate code or it is also called intermediate languange (IL).When your .net language program is complied it is first converted into the MSIL code.The MSIL code is a CPU independent code (ie the MSILcode is not dependent on the CPU ) that can easily converted into the native code.During the runtime the Just In Time (JIT) convert the MSIL code into the Native Code to the operating system
When a compiler produces Microsoft Intermediate Language (MSIL), it also produces Metadata. The Microsoft Intermediate Language (MSIL) and Metadata are contained in a portable executable (PE) file . Microsoft Intermediate Language (MSIL) includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations.

Feature of MSIL code:

1.MSIL code provide language interoperability as the compile code is converted into the MSIL code
2.Same performance for all language

Friday, 14 April 2017

Binding values in Dropdown in angular js

This is the code for binding the values into the drop down  using angular

HTML CODE:   
 <div class="form-group">

                            <label class="control-label col-md-4">State</label>
                            <div class="col-md-8">
                                <select class="form-control" ng-model="model.StateId" ng-options="item.StateId as item.StateName for item in states"> <option value="">--Select State--</option> </select>
                            </div>

                        </div>

Angular code:
 
$scope.states = [];

            $http({
                method: 'GET',
                url: 'GetStates',
            }).success(function (result) {
                $scope.states = result;
            });


.CS CODE

 public JsonResult GetStates()
        {
            ApplicationDbContext _db = new ApplicationDbContext();
            return Json(_db.States.Select(c => new { StateId = c.StateId, StateName = c.StateName }), JsonRequestBehavior.AllowGet);
        }

Code to upload the image in 64 bit in Angularjs

Code to upload the image in 64 bit in Angularjs  

Html code 
<div class="col-md-8">
                                <img ng-src="data:image/png;base64,{{model.Logo}}" id="photo-id" />
                         
                                <input type="file" name="file" onchange="angular.element(this).scope().uploadFile(this)" id="photo-upload" />


                            </div>


Angular code

 $scope.uploadFile = function (input) {
           
           
                if (input.files && input.files[0]) {
                    var reader = new FileReader();
                    reader.readAsDataURL(input.files[0]);
                    reader.onload = function (e) {

                        $('#photo-id').attr('src', e.target.result);                    
                        var canvas = document.createElement("canvas");
                        var imageElement = document.createElement("img");
                                           
                        imageElement.setAttribute = $('<img>', { src: e.target.result });
                        var context = canvas.getContext("2d");
                        imageElement.setAttribute.load(function()
                        {
                            debugger;
                            canvas.width = this.width;
                            canvas.height = this.height;
                       
                       
                            context.drawImage(this, 0, 0);
                            var base64Image = canvas.toDataURL("image/png");

                            var data = base64Image.replace(/^data:image\/\w+;base64,/, "");
                       
                            $scope.model.Logo = data;
                        });
                   
                       
                   
                    }
               

                }
            }

Screen sort