Sunday, February 16, 2020

wpf Interview question and answer

1.
How WPF Application (Architecture) Works?

The major components of WPF are
-PresentationFramework,
-PresentationCore, and
-Milcore unmanaged component
Milcore is written in unmanaged code in order to enable tight integration with DirectX. All display in WPF is done through the DirectX engine, allowing for efficient hardware and software rendering. WPF also required fine control over memory and execution. The composition engine in milcore is extremely performance sensitive, and required giving up many advantages of the CLR to gain performance.


2.
what is routed events?

Routed events are events which navigate up or down the visual tree according to their RoutingStrategy. The routing strategy can be bubble, tunnel or direct. You can hook up event handlers on the element that raises the event or also on other elements above or below it by using the attached event syntax: Button.Click="Button_Click". Routed events normally appear as pair. The first is a tunneling event called PreviewMouseDown and the second is the bubbling called MouseDown. They don't stop routing if the reach an event handler. To stop routing then you have to set e.Handled = true;
Tunneling The event is raised on the root element and navigates down to the visual tree until it reaches the source element or until the tunneling is stopped by marking the event as handeld. By naming convention it is called Preview... and appears before corresponding bubbling event.
Bubbling The event is raised on the source element and navigates up to the visual tree until it reaches the root element or until the bubbling is stopped by marking the event as handled. The bubbling event is raised after the tunneling event.
Direct The event is raised on the source element and must be handled on the source element itself. This behavior is the same as normal .NET events.
3.
What are Value Converters?

A value converter converts one type to another. Converters are frequently used in data binding scenarios where the target type and the source type are not the same. Value converters are used heavily in WPF because XAML attributes are strings, but these strings often need to be converted into objects. For instance, the string value of red for a background in XAML needs to be converted to a Color object representing red.
If you want to databind two properties that have incompatible types, you need a piece of code in between, that converts the value from source to target type and back. This piece of code is called ValueConverter. A value converter is a class, that implements the simple interface IValueConverter with the two methods object Convert(object value) andobject ConvertBack(object value).
4.
What is the difference between X:name and x:key?

X:name idetifies a UIElment in XAML Tree
X:Key identifies objects in resources section, can be accessed by resourceDictionary
5.
Explain WPF’s 2-Pass layout engine?

In some cases, an element may know exactly what size it should be (because it’s Width and Height properties have been explicitly set). But very often, the size of an element is determined by its content. To enable this “size to content” feature, the WPF layout engine uses a 2-pass layout cycle to size and position visual elements:
1. First a measure pass is used to determine the desired size of each element.
2. Then an arrange pass is used to explicitly size and position each element.







6.
What is the difference between Logical Tree and Visual Tree?

Logical Tree: XAML is natural for representing a user interface because of its hierarchical nature. In WPF, user interfaces are constructed from a tree of objects known as a logical tree
Visual Tree: A similar concept to the logical tree is the visual tree. A visual tree is basically an expansion of a logical tree, in which nodes are broken down into their core visual components. Rather than leaving each element as a "black box," a visual tree exposes the visual implementation details. Window's default visual tree consists of a Border, AdornerDecorator, two AdornerLayers, a ContentPresenter, and nothing more 

7.
What are the types for data binding modes in WPF?

1.One-way binding:
The data flows from the source to the target,each time a change is made on the source
2.One-time binding:
Sends data from source to the target, however it does this only when the application is started or when the datacontext changes
3.One-way-to-source binding:
sends data from the target to source
4.Two-way binding:(Default)
Sends the source to the target and if there are changes in the target, those values will be sent back to the source.
8.
What are the panels in WPF?

1.CANVAS - Explicitly positioning of controls
2.DOCKPANEL - Similar to windows form docking application
3.GRID - Can arrange child controls with rows and columns
4.STACKPANEL - Used to organize child controls either horizontally or vertically
5.WRAPPANEL - Can arrange child controls from left to right one after the other as long as they fit in to next line









9.
What are the Resources, Styles and Triggers?

Style - element containing setter elements.
Triggers - used to change the look and feel of the controls dynamically.
Resources - Styles and Triggers are stored in the resources
Static Resources - resources are searched at load time
Dynamic Resources - If the resource changes while the program is running
10.
What is CLR Property?

CLR properties are really just safe wrappers around a Private member variable, such that the correct access modifiers can be applied to the property, so we could have a Read or a Read/Write or just a Write property. But basically that's it. This is all CLR properties really do for us.
they are defined like this
private int x;
public int X
{
get { return x; }
set { x = value; }
}
11.
What is dependency property in WPF?

WPF elements are classes with methods, properties and events. Nearly every property of a WPF element is a dependency property. Dependency properties are used with databinding, animation, resources and styles.
Only a class that derive from base class DependencyObject can include dependency properties. For Example

public class MyDependencyObject : DependencyObject
{

public static readonly DependencyProperty SomeStateProperty = DependencyProperty.Register("SomeState", typeof(String), typeof(MyDependencyObject));

public string SomeState
{
get {return (string)this.GetValue(SomeStateProperty);}
set { this.SetValue(SomeStateProperty, value); }
}
}







12.
What is attached property in WPF?

A WPF element can also get features from the parent element. For example, if the button element is located inside a Canvas element. the button has Top and Left properties that are prefixed with the parent element's name. Such a property is known as attached property.

<Canvas>
<Button Canvas.Top="35" Canvas.Left="45">
Click Me!
</Button>
</Canvas>
13.
What is Property Invalidation?

Its used to update the custom control whenever the property changes.Adding property invalidation callbacks to a custom control is as easy as adding a PropertyChangedCallback object to a PropertyMetadata object and add this PropertyMetadata object to Register() or RegisterAttached() methods.
14.
What are templates?

A template is similar to a style, and two different kinds are available:
Data templates: allow using XAML's DataTemplate element to specify a group of characteristics for how data should be displayed. Colors, alignment, and more can be defined once in a data template, then used elsewhere in an application's user interface.
Control templates: allow using XAML's ControlTemplate element to define the appearance of a control.
15.
What is Resource Dictionary?

The content of the file is just a ResourceDictionary - and because the ResourceDictionary is the root element in the Xml file we need to define the default namespaces, which you would probably be more used to seeing on a new root-level Window or Page when you create a new Xaml file in Visual Studio. The contents of the resource dictionary is a perfectly normal WPF style.
The second step is to merge this resource stored in an external file into one of the resource dictionaries in our application. For this example we'll merge it in to the Application.Resouces collection (located in the App.xaml file). This is done by adding the elements highlighted below which point to the TextStyle.xaml file we created.
16.
what is ObservableCollection?

Represents a dynamic data collection that provides notifications when items get added, removed or when the whole list is refreshed.

17.
what is the diff between Window and Page?

WPF Windows Application --Stand alone application
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
Title="Window1" Height="300" Width="300">
WPF Browser Application – XBAB
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
Title="Page1">
18.
what is the diff between user control and Customcontrol in WPF?

--UI which will be used repeatedly in your own project, using UserControl is a much simpler and preferred way.
--a portion of UI and functionality which you believe will be used aross different projects, then using custom control is the right approach.
--A User Control doesn't support ControlTemplates and Themes. But creating a UserControl is much like creating a normal Window with Codebehind. A UserControl exists of a XAML-File and a Codebehind-File. Define Eventhandlers in XAML and implement them in Codebehind.
--A Custom Control supports ControlTemplates and Themes. A Custom Control is a "lookless" Control. The logic is in a Code-File (.cs) and the look is defined in a ControlTemplate that is part of a style. You can define more "theme"-styles for different windows themes.
19.
What are trees in WPF?

Logical Tree and Visual tree.
The logical tree in WPF represents the elements of an application at run time.the logical tree maps very closely to an application's markup definitions.
The visual tree contains all visual elements used in an application's user interface.
20.
what is INotifyPropertyChanged? Morgan(imp)

This interface has only one member - the PropertyChanged event, which you are supposed to call whenever a property changes. This, in turn, will notify WPF to update the controls on the screen.
Example:
public class ConversionOptions : INotifyPropertyChanged
21.
How WPF Application (Architecture) Works?

The major components of WPF are
-PresentationFramework,
-PresentationCore, and
-Milcore unmanaged component
Milcore is written in unmanaged code in order to enable tight integration with DirectX. All display in WPF is done through the DirectX engine, allowing for efficient hardware and software rendering. WPF also required fine control over memory and execution. The composition engine in milcore is extremely performance sensitive, and required giving up many advantages of the CLR to gain performance.



Thursday, February 6, 2020

ASP.NET Core Dependency Injection with AWS

This is my second post regarding the AWS Hope toy like my first post.

The AWSSDK.Extensions.NETCore.Setup NuGet package also integrates with a new dependency injection system in ASP.NET Core. The ConfigureServices method in Startup is where the MVC services are added. If the application is using Entity Framework, this is also where that is initialized.
public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); }
The AWSSDK.Extensions.NETCore.Setup NuGet package adds new extension methods to IServiceCollection that you can use to add AWS services to the dependency injection. The following code shows how to add the AWS options that are read from IConfiguration to add Amazon S3 and DynamoDB to our list of services.
public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); services.AddDefaultAWSOptions(Configuration.GetAWSOptions()); services.AddAWSService<IAmazonS3>(); services.AddAWSService<IAmazonDynamoDB>(); }
Now, if your MVC controllers use either IAmazonS3 or IAmazonDynamoDB as parameters in their constructors, the dependency injection system passes in those services.
public class HomeController : Controller { IAmazonS3 S3Client { get; set; } public HomeController(IAmazonS3 s3Client) { this.S3Client = s3Client; } ... }

Thank you Hope it will help will help you.



Some IMP angular interview questions and answers

1)Structure Of Angular Project?
Ans:


2) How do you deploy Angular apps?
Ans : 
Basic deployment to a remote server

For the simplest deployment, create a production build and copy the output directory to a web server.

1)Start with the production build:
ng build --prod

2)Copy everything within the output folder (dist/ by default) to a folder on the server.


3)Configure the server to redirect requests for missing files to index.html.

3) Types of pre-defined or built-in pipes in Angular 6.
Ans : Pipes are used to format the data before displaying in the View. A pipe is used by using |. This symbol is called a Pipe Operator.
Types of pre-defined or built-in pipes in Angular 6.
  1. Lowercase
  2. Uppercase
  3. Titlecase
  4. Slice
  5. Json Pipe
  6. Number Pipe
  7. Percent Pipe
  8. Currency Pipe
  9. Date Pipe
4) Angular — Promise vs Observable
Ans: 
In Angular, we can use either Promise or Observable for handling asynchronous data. Both get and post method of Http and HttpClient return Observable and it can be converted into Promise using toPromise() method. So, what’s the difference when they both are dealing with asynchronous data.

What actually the difference is?

Promise emits a single value while Observable emits multiple values. So, while handling a HTTP request, Promise can manage a single response for the same request, but what if there are multiple responses to the same request, then we have to use Observable. Yes, Observable can handle multiple responses for the same request.
Let’s implement this with an example.

Promise

Output

 Observable

Output
So, in the above code snippet, I have created promise and observable of Promise and Observable type respectively. But, promise returns the very first value and ignore the remaining values whereas Observable return all the value and print 1, 2, 3 in the console.
Promise is not lazy while Observable is lazy. Observable is lazy in nature and do not return any value until we subscribe.
home.component.ts (Observable)
In above example we are not subscribing the observable, so we do not receive the data and even there would be a no network call for this service.
home.component.ts (Observable)
Here, we have subscribed our Observable, so it will simply return the data. But Promise returns the value regardless of then() method.
home.component.ts (Promise)
Observable is cancellable in nature by invoking unsubscribe() method, but Promise is not cancellable in nature.
Hope this is helpful and gives you a basic understanding of how Promise differs from Observable. Please feel free to provide your suggestions 🙂

5) what is directive in angular.
Ans: Directives in Angular is a js class, which is declared as @directive. We have 3 directives in Angular. The directives are listed below −

Component Directives
These form the main class having details of how the component should be processed, instantiated and used at runtime.

Structural Directives
A structure directive basically deals with manipulating the dom elements. Structural directives have a * sign before the directive. For example, *ngIf and *ngFor.

Attribute Directives
Attribute directives deal with changing the look and behavior of the dom element. You can create your own directives as shown below.


6) Difference between Constructor and ngOnInit
Ans:
The Constructor is a default method of the class that is executed when the class is instantiated and ensures proper initialization of fields in the class and its subclasses. Angular or better DI analyzes the constructor parameters and when it creates a new instance by calling new MyClass() it tries to find providers that match the types of the constructor parameters, resolves them and passes them to the constructor like
new MyClass(someArg);
ngOnInit is a life cycle hook called by Angular2 to indicate that Angular is done creating the component.
We have to import OnInit in order to use like this (actually implementing OnInit is not mandatory but considered good practice):
import {Component, OnInit} from '@angular/core';
then to use the method of OnInit we have to implement in the class like this.
export class App implements OnInit{
  constructor(){
     //called first time before the ngOnInit()
  }

  ngOnInit(){
     //called after the constructor and called  after the first ngOnChanges() 
  }
}
Implement this interface to execute custom initialization logic after your directive’s data-bound properties have been initialized. ngOnInit is called right after the directive’s data-bound properties have been checked for the first time, and before any of its children have been checked. It is invoked only once when the directive is instantiated.
Mostly we use ngOnInit for all the initialization/declaration and avoid stuff to work in the constructor. The constructor should only be used to initialize class members but shouldn’t do actual “work”.
So you should use constructor() to setup Dependency Injection and not much else. ngOnInit () is better place to “start” - it’s where/when components' bindings are resolved.

7) Global Events in Angular
Ans: