Monday, September 25, 2017

Does C# support multiple inheritance?

C# does not support multiple inheritance (meaning a single class inherits from multiple classes). You can, however, implement multiple interfaces in a single class.
As far as chaining together inherited classes, there isn't a limit per-se. Just keep in mind the complexity you will introduce to your system. When using inheritance, make sure you are using it in a "is a" scenario.

A dog is an animal. A Honda is a car. Otherwise, your inheritance tightly couples your classes with a design that becomes much more difficult to maintain.
If they are static "utility" methods, just invoke them directly without inheriting. Unless those methods belong to the entity you are creating, you should not use inheritance.

Saturday, September 23, 2017

WCF vs WebAPI

Some fact about WCF :

If you need to communicate over pure TCP socket or any other protocol then HTTP use WCF. WCF can communicate is wide range of protocol.
Creating services that are transport/protocol independent. Single service with multiple endpoints.
Like one WCF service can have multiple endpoints based on clients. For example- One  web application request protocol -> http and response -> xml, another client could be TCP and Binary response.

If you have limitation and stuck with .Net framework 3.5 then create WCF restful service otherwise use WebAPI Resuful service. Lot of configuration is required to turn WCF service to turn in to Restful service.

Now WebAPI:
WebAPI is Restful service which only rely on HTTP protocol.

REST Constraints:
Client Server: In REST architecture there is always a client and a server where the communication is always initiated by the client. The client and server are decoupled by a uniform interface there by making both the client and server to develop independently. Every resource in the server is accessed by a unique address (URI).

Stateless : we should not storing anything related to client on server.

Cacheable: some data provided by server does not change that often, so let client know how long data is good and does not require change and avoid requests to server.

Uniform Interface: An important concept of REST is the uniform interface. The uniform interface contains a set of methods that can be understood by both the client and the server. In the HTTP uniform interface the important methods are GET, POST, PUT, DELETE, HEAD and OPTIONS. It is important to choose the right method for the right operation. For ex. if the client is going to get the resource from the server then they should use GET method.

Friday, September 22, 2017

What is event loop in javascript?

I was reading more details on Heap and Stack in JavaScript. I came across video of Philip Roberts where he discuss how event loop works and what is execution process of JavaScript engine. Really nicely explained concept.

He also developed tool LOUNE to understand how JavaScript executes and processes requests.

Worth listening and understanding as web developer.

Friday, September 1, 2017

Remote Event Receiver - Difference Process Event() And Process One Way Event()

Remote Event Receiver in SharePoint (2013 and more up to date), we go over two methods that are available default when we create a remote event receiver *.svc file (generated by system). These are --
  • ProcessEvent()
  • ProcessOneWayEvent()
Both the methods are always confusing as for their usage. There is very limited information available on the web with respect to these methods. In this way, here is the essential difference between them by which one can get the unmistakable fundamental thought of them both, subsequently, choosing the required one between them to write their business codes.

We should comprehend the sorts of events fired in event receivers. There are for the most part 2 types event fired on any operations on list or libraries - "before events" and "after events".
Now all events finishing with "- ing" are named as “Before events”, while every one of the events finishing with "- ed" are called as “After events”.
Below are the Before and After Events -
Before Events
After Events
ListAdding
ListAdded
ListDeleting
ListDeleted
FieldAdding
FieldAdded
FieldDeleting
FieldDeleted
FieldUpdating
FieldUpdated
ItemAdding
ItemAdded
ItemUpdating
ItemUpdated
ItemDeleting
ItemDeleted
ItemCheckingOut
ItemCheckedOut
ItemCheckingIn
ItemCheckedIn
ItemUnCheckingOut
ItemUnCheckedOut
ItemAttachmentAdding
ItemAttachmentAdded
ItemAttachmentDeleting
ItemAttachmentDeleted
ItemFileMoving
ItemFileMoved
ItemVersionDeleting
ItemVersionDeleted
Now, when we are aware of After and Before events, it becomes easy to understand the basic difference between these methods.

ProcessEvent()
  • It handles "Before" events and returns an object to SharePoint that reports on whether it should cancel the current process or terminate it.

  • If you want to use any of the “-ing” events, then write your codes in ProcessEvent().

  • Example: If you wish that there should be only excel (*.xlsx) file uploaded in particular document library, this can be done using the file type extension setting in SharePoint Server Administration.

    But, what about SharePoint Online?

    So, here you have to create remote event receiver and in that, you can use the event of ItemAdding and check whether the uploaded document is of *.xlsx type or not. If not, then you can cancel the uploading event. This cancelled event will return back to SharePoint by this ProcessEvent() as this is 2 way method. This can be achieved by writing your logic code in ProcessEvent().
ProcessOneWayEvent()
  • It handles "After" events. It runs asynchronously and does not return anything to SharePoint.

  • If you are using any code which is to be run after the “-ed” event, then write your codes in ProcessOneWayEvent().

  • Example: Let's say, you want to duplicate the document uploaded in document library to any other document library, in that case, you can use ItemAdded. This does not require any 2 way communications between SharePoint, so you can use ProcessOneWayEvent() for this kind of requirement.