Monday, 23 August 2021

Angular : Directives Vs. Components Vs. Attribute directives Vs. Structural directives

 Angular : Directives Vs. Components Vs. Attribute directives Vs. Structural directives


Directives are classes that add additional behavior to elements in your Angular applications. With Angular's built-in directives, you can manage forms, lists, styles, and what users see


Components—directives with a template. This type of directive is the most common directive type.


Attribute directives—directives that change the appearance or behavior of an element, component, or another directive.


Structural directives—directives that change the DOM layout by adding and removing DOM elements.

Thursday, 19 August 2021

C# Question and answers

 --Type of serializations and the fastest serialization in c#

--List down the caches you have used, and name 2 distributed caching

--How to perform memory optimizations in C#. Name 2 incidents

--Lazy loading

--what are middleware’s in c# and how to create them

--Difference between SAML and ws-federation protocol in authentication

--How to create test certificates during development, and name the tools you have used

--Difference between symmetric and asymmetric algorithm

--What are the databases you have used?

--How to connect MongoDB database from C# code? Please name the C# driver you have used for this

=============================================================


1.The binary serializer included with .net should be faster that the XmlSerializer. Or another serializer for protobuf, json, ...

But for some of them you need to add Attributes, or some other way to add metadata. For example ProtoBuf uses numeric property IDs internally, and the mapping needs to be somehow conserved by a different mechanism. Versioning isn't trivial with any serializer.

2.This is being primarily used in the industries today, for having the potential to scale on demand & being highly available.

(A). Scalability, High Availability, Fault-tolerance are crucial to the large scale services running online today.
(B). Businesses cannot afford to have their services go offline. Think about health services, stock markets, military. They have no scope for going down. They are distributed across multiple nodes with a pretty solid amount of redundancy.
 Google Cloud uses Memcache for caching data on its public cloud platform. 2.b. OutputCache filter 2.c.Data Caching3.d.Fragment Caching.

3.Dispose an object after use or make it null.

Use try/finally or using block.
Use GC. Collect() if required.
Remove unnecessary object initialization.
Manage Image caching.
Mange BLOB data, Memory stream and file stream.

4.Lazy loading is essential when the cost of object creation is very high and the use of the object is vey rare. So, this is the scenario where it's worth implementing lazy loading.
The fundamental idea of lazy loading is to load object/data when needed.
5.Middleware is software that's assembled into an app pipeline to handle requests and responses. Each component:
Chooses whether to pass the request to the next component in the pipeline.
Can perform work before and after the next component in the pipeline.
Request delegates are used to build the request pipeline. The request delegates handle each HTTP request.
Request delegates are configured using Run, Map, and Use extension methods. An individual request delegate can be specified in-line as an anonymous method (called in-line middleware), or it can be defined in a reusable class. These reusable classes and in-line anonymous methods are middleware, also called middleware components. Each middleware component in the request pipeline is responsible for invoking the next component in the pipeline or short-circuiting the pipeline. When a middleware short-circuits, it's called a terminal middleware because it prevents further middleware from processing the request.
6.WS-Federation is primarily championed by Microsoft Corporation which has invested heavily into incorporating WS-Federation into its products. SAML is an older specification that is well supported by many identity management vendors. However, most vendors, including Microsoft, are moving to support both standards.
7.Test-signing requires a test certificate. After a test certificate is generated, it can be used to test-sign multiple drivers or driver packages. For more information, see Test Certificates.

This topic describes how to use the MakeCert tool to create test certificates. In most development environments, test certificates generated through MakeCert should be sufficient to test the installation and loading of test-signed drivers or driver packages. For more information about this type of test certificate.
8.Symmetric Key Encryption:
Encryption is a process to change the form of any message in order to protect it from reading by anyone. In Symmetric-key encryption the message is encrypted by using a key and the same key is used to decrypt the message which makes it easy to use but less secure. It also requires a safe method to transfer the key from one party to another.

Asymmetric Key Encryption:
Asymmetric Key Encryption is based on public and private key encryption technique. It uses two different key to encrypt and decrypt the message. It is more secure than symmetric key encryption technique but is much slower.
9. SqlS erver, Oracle, Sybase,MySql. Azure Sql, Blob Storage, MongoDB

10.using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Timers;  
using MongoDB.Bson;  
using MongoDB.Driver;  
using MongoDB.Driver.Builders;  
using MongoDB.Driver.GridFS;  
using MongoDB.Driver.Linq;  
using System.Data.SqlClient;  
namespace MongodbRND  
{  
   class Program  
   {  
      static void Main(string[] args)  
      {  
         Console.WriteLine("Mongo DB Test Application");  
         Console.WriteLine("====================================================");  
         Console.WriteLine("Started By:Kailash Chandra Behera");  
         Console.WriteLine("Started On: 14 July 2014");  
         Console.WriteLine("Configuration Setting: 172.16.1.24:27017");  
         Console.WriteLine("====================================================");  
         Console.WriteLine("Initializaing connection");  
         string connectionString = "mongodb://172.16.1.24:27017";  
 
 
         Console.WriteLine("Creating Client..........");  
         MongoClient client = null;  
         try  
         {  
            client = new MongoClient(connectionString);  
            Console.WriteLine("Client Created Successfuly........");  
            Console.WriteLine("Client: " + client.ToString());  
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Filed to Create Client.......");  
            Console.WriteLine(ex.Message);  
         }  
 
         Console.WriteLine("Initianting Mongo Db Server.......");  
         MongoServer server = null;  
         try  
         {  
            Console.WriteLine("Getting Servicer object......");  
            server = client.GetServer();  
 
            Console.WriteLine("Server object created Successfully....");  
            Console.WriteLine("Server :" + server.ToString());  
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Filed to getting Server Details");  
            Console.WriteLine(ex.Message);  
         }  
 
 
         Console.WriteLine("Initianting Mongo Databaser.........");  
         MongoDatabase database = null;  
         try  
         {  
            Console.WriteLine("Getting reference of database.......");  
            database = server.GetDatabase("Kailash");  
            Console.WriteLine("Database Name : " + database.Name);  
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Failed to Get reference of Database");  
            Console.WriteLine("Error :" + ex.Message);  
         }  
         try  
         {  
            Console.WriteLine("Deleteing Collection Symbol");  
            database.DropCollection("Symbol");  
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Failed to delete collection from Database");  
            Console.WriteLine("Error :" + ex.Message);  
         }  
 
         Console.WriteLine("Getting Collections from database Database.......");  
 
 
         MongoCollection symbolcollection = null;  
         try  
         {  
            symbolcollection = database.GetCollection<Symbol>("Symbols");  
            Console.WriteLine(symbolcollection.Count().ToString());  
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Failed to Get collection from Database");  
            Console.WriteLine("Error :" + ex.Message);  
         }  
         ObjectId id = new ObjectId();  
         Console.WriteLine("Inserting document to collection............");  
         try  
         {  
            Symbol symbol = new Symbol ();  
            symbol.Name = “Star”;  
            symbolcollection.Insert(symbol);  
            id = symbol.ID;  
 
            Symbol symbol = new Symbol ();  
            symbol.Name = “Star1”;  
            symbolcollection.Insert(symbol);  
            id = symbol.ID;  
 
            Console.WriteLine(symbolcollection.Count().ToString());  
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Failed to insert into collection of Database " + database.Name);  
            Console.WriteLine("Error :" + ex.Message);  
         }  
 
         try  
         {  
            Console.WriteLine("Preparing Query Document............");  
            List< Symbol > query = symbolcollection.AsQueryable<Entity>().Where<Entity>(sb => sb.Name == "Kailash").ToList();  
 
            Symbol symbol = symbolcollection.AsQueryable<Entity>().Where<Entity>(sb => sb. ID == id).ToList();  
 
         }  
         catch (Exception ex)  
         {  
            Console.WriteLine("Failed to query from collection");  
            Console.WriteLine("Exception :" + ex.Message);  
         }  
         Console.WriteLine("");  
         Console.WriteLine("====================================================");  
         Console.ReadLine();  
      }  
   }  
   public class Symbol  
   {  
      public string Name { get; set; }  
      public ObjectId ID { get; set; }  
   }  

Sunday, 8 August 2021

Azure Function Vs Logic Apps

Azure Functions is code being triggered by an event, whereas Logic Apps is a workflow triggered by an event.

Azure Concepts

1. App service

2. Azure function
3. Azure AD -a)RBAD b)Graph Api
4) Service BUS
5) Logic app
6) API management
7) Event Grid 
8) Event Hub
9)  Blob storage
10) Queue storage, Table storage, File storage, Data lake storage
11) Azure SQL 
12) Radis Cache
13) VM in Azure
14) Subnet
15)  Load balancers
16). Azure kubernetes vs.  Docker
17) Azure Service Fabric- micro services- department
18) Power BI
19) App insights, Monitoring,  telemetry
20) Dev ops CI CD pipe
 lines
21) Middle ware in dot net core
22) Git
23) ARM Templates and Power Shell
24) Azure Cosmos DB
25) Security- Authentication- Authorization(basic-bearer - oauth authentication)
26) SendGrid in Azure
27) Web Jobs in Azure
28) Web hook in Azure
29) Data Factory in Azure (SSIS)

Currently these are the concepts for Azure.

Azure Data Factory

 Azure Data Factory 

Azure Data Factory is Azure's cloud ETL service for scale-out serverless data integration and data transformation. It offers a code-free UI for intuitive authoring and single-pane-of-glass monitoring and management. You can also lift and shift existing SSIS packages to Azure and run them with full compatibility in ADF. SSIS Integration Runtime offers a fully managed service.

Web Hook in Azure

 A webhook in azure is an HTTP endpoint. It is a user defined address you can call with relevant information to interact with several other services. Think of it as a sort of mailbox that you can configure services to respond to. You send an HTTP request (mail a letter) and it lands in this mailbox and you have configured say... Azure functions to respond to that particular mailbox or … logic apps or … data factory … The last one for example. You can have data factory post to a webhook when its completed its work if you need some follow on function to be notified upon job complete.

These are different from functions or webjobs in that they do not have any programable logic to execute a task or job. Webhooks are a customizable location to which you can post HTTP requests.

Saturday, 7 August 2021

Middleware in dot net core

 What is Middleware?

 

Middleware is a piece of code in an application pipeline used to handle requests and responses.

 

For example, we may have a middleware component to authenticate a user, another piece of middleware to handle errors, and another middleware to serve static files such as JavaScript files, CSS files, images, etc.

 

Middleware can be built-in as part of the .NET Core framework, added via NuGet packages, or can be custom middleware. These middleware components are configured as part of the application startup class in the configure method. Configure methods set up a request processing pipeline for an ASP.NET Core application. It consists of a sequence of request delegates called one after the other.


public void Configure(IApplicationBuilder app, IWebHostEnvironment env)    

{    

    if (env.IsDevelopment())    

    {    

        //This middleware is used reports app runtime errors in development environment.  

        app.UseDeveloperExceptionPage();    

    }    

    else    

    {    

        //This middleware is catches exceptions thrown in production environment.   

        app.UseExceptionHandler("/Error");   

        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.    

        app.UseHsts(); //adds the Strict-Transport-Security header.    

    }    

    //This middleware is used to redirects HTTP requests to HTTPS.  

    app.UseHttpsRedirection();   

    

    //This middleware is used to returns static files and short-circuits further request processing.   

    app.UseStaticFiles();  

    

    //This middleware is used to route requests.   

    app.UseRouting();   

    

    //This middleware is used to authorizes a user to access secure resources.  

    app.UseAuthorization();    

    

    //This middleware is used to add Razor Pages endpoints to the request pipeline.    

    app.UseEndpoints(endpoints =>    

    {    

        endpoints.MapRazorPages();               

    });    

delegate vs Func vs Predicate

 

A delegate is a type that represents references to methods with a particular parameter list and return type. When you instantiate a delegate, you can associate its instance with any method with a compatible signature and return type. You can invoke (or call) the method through the delegate instance.


Delegates are used to pass methods as arguments to other methods. Event handlers are nothing more than methods that are invoked through delegates. You create a custom method, and a class such as a windows control can call your method when a certain event occurs. The following example shows a delegate declaration:

Action is a delegate (pointer) to a method, that takes zero, one or more input parameters, but does not return anything.


Func is a delegate (pointer) to a method, that takes zero, one or more input parameters, and returns a value (or reference).


Predicate is a special kind of Func often used for comparisons.


Though widely used with Linq, Action and Func are concepts logically independent of Linq. C++ already contained the basic concept in form of typed function pointers.


Func:


using System;  

  

namespace Delegates.Samples.Demo  

{  

    class Program  

    {  

        static void Main(string[] args)  

        {   

            Func<int, int, int> addFunc = new Func<int, int, int>(Add);  

            int result = addFunc(3, 4);  

            Console.WriteLine(result);  

            Console.ReadLine();  

  

        }  

        static int Add(int a, int b)  

        {  

            return a + b;  

        }  

    }  

}  


=====================================

Predicate


using System;  

  

namespace Delegates.Samples.Demo  

{  

    class Program  

    {  

        static void Main(string[] args)  

        {  

            Predicate<int> IsEven = new Predicate<int>(IsEvenNumber);  

            Console.WriteLine(IsEven(10));  

            Console.WriteLine(IsEven(1567));  

            Console.ReadLine();  

  

        }  

        static bool IsEvenNumber(int number)  

        {  

            return number % 2 == 0;  

        }  

    }  

}   

Angular Components communication

 Components can communicate with each other in various ways, including:

Parent to Child: via Input

Child to Parent: via Output() and EventEmitter

Child to Parent: via ViewChild

Unrelated Components: via a Service

Friday, 6 August 2021

Event Grid and Event Hubs and Service Bus

Event Hub--Big Data Handling--Event Distribution (Discrete)--Telemetry Data


Eg: Application Insights, Logs


Event Grid---Reactive Programming--Event Streaming (Series)---Status Changes Reaction


Eg: Approval, Rejection


Service Bus--Enterprise Messaging---Messaging---Order Processing & Financial Transactions 


Differences between Event Grid and Event Hubs

The noticeable difference between them is that Event Hubs are accepting only endpoints for the ingestion of data and they don’t provide a mechanism for sending data back to publishers. On the other hand, Event Grid sends HTTP requests to notify events that happen in publishers.

Event Grid can trigger an Azure Function. In the case of Event Hubs, the Azure Function needs to pull and process an event.


Azure Service Bus


In simple terms we can compare this model with a IBM MQ i.e. a Queueing mechanism. Asynchronous flow of data which is based on FirstIn-FirstOut model. You sent a message to a queue and want this message to be processed within a specific amount of time. What if the messages is not processed either move it to dead letter queue or  perform some action to it. There is a temporary control and consistency over the data that is being processed.


EXAMPLE – Super market where the cashiers bills your item one by one


Azure Event Grid


If you have been working with Microsoft BizTalk Server, this concept is quite easy to relate to. Azure Event Grid is a Publisher/Subscriber model, where there is a publisher who sends a message and multiple party at the receiver ends receives these messages. This model is loosely coupled.


EXAMPLE – Supermarket buys similar product from multiple vendors. The place an order which is subscribed by multiple vendors. Each vendor receives a copy of the order.


Azure Event Hub

This is a messaging at scale mechanism where you process large volume of telemetry data. This cloud offering is a one-way event processing system that can take millions of events per second and can be used for analysis and storage. As compared with Queues message will not be removed from the Hub and can be read multiple times.


EXAMPLE : Super Market – All the details related to the purchase, sent to the event hub which can be used to analyse the stock in the inventory and alert the Inventory department whenever the product goes out of stock.