Thursday, December 22, 2011

Access Modifiers in C#

Access modifiers specifies access level for a type or type member. C# has 4 access modifiers,
  • public
  • protected
  • internal
  • private
 
  • Access modifiers are not allowed on namespaces. 
  • Top level types which are not nested in other types can only have internal or public accessibility. The default is internal

public

access modifier for types and type members. There is no restriction for accessing public members. 

protected

Is a member access modifier. A protected member is accessible within it's class and derived class type. 



Since structs cannot be inherited its members cannot be protected. You can create protected classes as nested classes

internal

Access modifier for types and type members. Internal types or members are accessible within files of the same assembly. 

Types or members with access modifier protected internal can be accessed within same assembly or through the types derived from containing class.

private

Member access modifier. Private members are accessible only within body of the class or the struct. Nested types also can access private members.

Resources
Access Modifiers

Sunday, December 18, 2011

Security in ASP.NET MVC

Security is a major concern when developing web applications. 
Here we'll talk about security in ASP.NET MVC

Some of the main concepts to understand when dealing with security are,
  • Authentication
  • Authorization
  • XSS
  • CSRF (Cross site request forgery)

Authentication

In ASP.NET there are two main authentication mechanisms
  • Windows Authentication Provider
  • Forms Authentication Provider

Authorization 

Basically you can apply AuthorizeAttribute filter to actions and controllers to achieve authorization in MVC. See how to create Custom AuthroizeAttribute.

Role based security #

This is useful when you need to enforce policies where you have multiple users with different privileges. .NET framework role-based security supports authorization by making information about the Principal, which is constructed from an associated Identity.

What is a principal object?

A principal object represents the security context of the user. It includes the user's identity and the roles to which they belong. In .NET, IPrincipal defines the basic functionality of a principal object.

Resources

Principal and Identity objects (MSDN)
Key security concepts (MSDN)
Custom IIdentity or IPrincipal (SO)
http://nipunasilva.blogspot.com/2012/07/filters-in-aspnet-mvc.html
http://www.codeproject.com/Articles/654846/Security-In-ASP-NET-MVC 

Wednesday, December 14, 2011

Memory Basics : Stack and Heap

Stack and heap are closely related with memory. Actually both are stored in computers RAM. Let's firstly look at what they are.

The Stack

Is a special region of the computer memory which holds temporary variables created by each function. This is managed and optimized by the CPU itself therefore you don't have to worry about allocating memory or anything as such. 

When you enter a function the variables defined inside the function will be pushed into the stack and when you exit the function the variables will be cleared from the stack. 

The stack is always reserved in LIFO (last in first out order). The stack is set aside for a thread. Each thread gets a stack.

 
Understanding stack in  JavaScript (blog article)

In JavaScript sometimes you'll encounter Maximum call stack exceeded in JavaScript error. This happens when you exceed the  call stack size in JavaScript. You can replicate this with a simple code like below



The Heap

Is the memory set aside for dynamic allocation. Unlike stack there is no pattern for allocation or deallocation of blocks from the heap. You must manually destroy variables on the heap. 

Heap can have fragmentation when there are lot of allocations and deallocations happening. Heap is usually responsible for memory leaks as well. 

In .NET unless you're building a compiler, knowing how stack and heap works is not needed much. (Stack vs. Heap in .NET - Stackoverflow).

Resources

Wednesday, December 7, 2011

Interesting Findings - JavaScript

Design

Design considerations for JavaScript API (Smashing Magazine)
  • Fluent interfaces
    • Referred to as method chaining
  • Treating undefined as an expected value
  • Named arguments (Python has this but currently not possible in JavaScript)
  • Argument maps.
    • visual representation of the structure of an argument
  • Module Pattern Explained

Other

How JavaScript timers works
Controlling Robots

Testing

Exception Handling 

Here are some reference articles for Exception handling in JavaScript
- http://eloquentjavascript.net/1st_edition/chapter5.html

Catch JavaScript errors on server side. This way you can find more details about how your system performs in production environment. See articles.

Debugging

http://amasad.me/2014/03/09/lesser-known-javascript-debugging-techniques/

Monday, November 28, 2011

Events in JavaScript

Events are the core of JavaScript. You use events to make the interaction between the DOM and the JavaScript. 

Event capturing and Event bubbling

Following diagram extracted from guistuff shows what is event capturing and bubbling are.



Example1 - Using pure JavaScript - return false and event.stopPropogation

        var outer = document.getElementById('outer'), //Outer element
            inner = document.getElementById('inner'); //Inner element

        outer.addEventListener('click', function (event) {
            console.log('outer');
        });

        inner.addEventListener('click', function () {
            console.log('inner');

            //Without anything outer will get fired

            //event.stopPropagation(); //outer won't get fired

            //return false; //Doesn't do anything.
        });

- When you use return false, it won't stop event from bubbling up.
- See this google search,  this, this or this for more information.

Event.preventDefault vs return false
You can use either of above return statements to prevent other event handlers from executing after a certain event. 

http://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false

document ready functions
window.load vs document.ready


Sources
http://stackoverflow.com/questions/4616694/what-is-event-bubbling-and-capturing
http://www.quirksmode.org/js/events_order.html
http://www.quirksmode.org/js/support.html
http://stackoverflow.com/questions/tagged/javascript-events

Saturday, August 27, 2011

Transactions in Databases

Transaction is databases is executing set of database instructions in a sequence which should be accomplished together. Transactions have following properties which are known as ACID (wiki).
  • Atomicity : Ensure all operations are completed successfully or in a failure, all operations are rolled back to its previous state
  • Consistency : Ensure database properly changes state upon a successful transaction completion
  • Isolation : Ensure transactions are operate independently 
  • Durability : Ensure result or effect of a committed  transaction persist in a case of a system failure

Transactions in Entity Framework

Whenever you execute SaveChanges(), the framework will wrap that operation in a transaction. Starting with EF6, Database.ExecuteSqlCommand() by default wrap the command in a transaction if one was not already present. Entity framework does not wrap queries in a transaction.

Read below articles for more information Working with Transactions (Data Developer Center)
Managing connections in Entity Framework (Visual Studio)
Using Transactions or SaveChanges (SO)


Transactions in SQL Server

Implicit Transaction 
http://dba.stackexchange.com/questions/43254/is-it-a-bad-practice-to-always-create-a-transaction
http://www.codeproject.com/Articles/4451/SQL-Server-Transactions-and-Error-Handling
http://stackoverflow.com/questions/10153648/correct-use-of-transactions-in-sql-server-2008
http://www.tutorialspoint.com/sql/sql-transactions.htm
http://www.dotnet-tricks.com/Tutorial/sqlserver/c2XF120412-SQL-Server-Transactions-Management.html


SAP
https://help.sap.com/saphelp_gateway20sp08/helpdata/en/41/7af4bca79e11d1950f0000e82de14a/frameset.htm

Friday, August 19, 2011

The most seamless tool set to develop applications


Are you looking for the seamless set of tools to develop your applications? You have great languages like Java, C#. But what is the best tool set? Well, when it comes to that the obvious choice of yours would be Microsoft products. These MS products have such a nice compatibility with each other.

Expression Blend, Visual Studio, Silverlight and .NET provide the most compelling and seamless design and development workflow on the market today. You will amazed by how easily they can be handled.

Wednesday, August 10, 2011

Introduction to Cloud Computing

What is cloud computing?
Large group of remote servers networked to allow centralize data storage and online access to computer services or resources. (Wikipedia). Cloud computing can be classified as private, public and hybrid.

Fundamental models 

Infrastructure as a service (IaaS)
Provides Virtual Machines, Servers, Storage, Load balancer's etc.

Platform as a service (PaaS)
Typically provides execution runtime, database, web server

Software as a service (SaaS)
Provided access to software and databases. Cloud provider manages the infrastructure. Also known as On demand software. Usually priced pay per use. 



Deployment models

Private cloud
Typically used for a single organization 


Public cloud
Open for public use. Technically there may not be any difference between between private and public clouds however security considerations are different. 

Web Server, Garden and Farm

Web Garden scales across multiple processes
Web Farm scales across multiple servers

Hybrid Cloud




Some of the enterprise software companies include
Hewlett Packed Enterprise - https://www.hpe.com/





Wednesday, July 20, 2011

Serialization in C#

Serialization is used to convert an object into a byte stream. This is usually done to store the object in the memory, database or a file and retrieve the state of the object later. This reverse process is called de-serialization.

To make a type serialize, you need to apply SerializeAttribute to it. If you haven't specify the attribute and when you try to serialize it, it'll through SerializationException. If you want to make some fields in your class not serialized, you can decorate it with NonSerializedAttribute. 

You cannot serialize iterator types such as IEnumerable etc. See SO

Binary Serialization 

Uses binary encoding to produce compact serialization. In Binary, all members are serialized. 

XML Serialization

Serializes public fields and properties of an object, or parameters and return values of a method. This serializes object into a XML stream. This provides more readable code.

SOAP Serialization

Serialize objects into XML streams which conforms to SOAP specification (which is a protocol based on XML).

Serialization in JavaScript
Convert form data to JSON using JQuery

Sources

Wednesday, February 16, 2011

Windows Communication Foundation


WCF is a runtime and set of APIs in .NET framework for building connected, service-oriented applicatons.

Difference with Web Services

Some of  the differences between WCF and Web service is that Web service only supports HTTP protocol. But WCF supports other protocols like TCP, HTTP, HTTPS, Named Pipes and MSMQ. Another major difference is that Web Services use XmlSerializer while WCF uses DataContractSerializer which is better in performance than XmlSerializer. Serialization in WCF.

ABC of WCF (msdn)

 

A - Address :  Where is the service
B - Binding : How do I talk to the service
C - Contract : What can the service do for me

 

Authentication and Authorization in WCF (MSDN)


You can also look in to this article series on MSDN about learning WCF.


Exception Handling in WCF

Handling exceptions in WCF is different than usual exceptions in .NET. Because WCF client may or may not base on .NET. Therefore we should have a generic way to pass exceptions to all types of clients. For this we have SOAP faults. 

SOAP faults are a way to propagate exceptions from service to the client application.  .NET framework has FaultException which can raise SoapFault exception. Here Service should throw FaultException<T> instead of usual CLR Exception object. T can be any type which can be serialized. 

WCF - Exception Handling

Resources

SO - Is there any official WCF Logo 
http://stackoverflow.com/questions/50114/wcf-wtf-does-wcf-raise-the-bar-or-just-the-complexity-level
http://www.codeproject.com/Articles/139787/What-s-the-Difference-between-WCF-and-Web-Services

Monday, February 7, 2011

What you need to know about JavaScript functions

As in any other language, functions are one of the building blocks of JavaScript. You can define functions and call them in different ways. In this article we'll see some basic but important things you need to know about JavaScript functions. 

Function declaration

The basic syntax for creating function declaration is like this. declarations loads to execution context before any code is executed. Below I'll show you function declaration example and 5 ways you can call the function.


Function expression

Functions can be created like expressions as well. Function expression gets load only when interpreter gets to the line of code. Also you can give a name to a function in a function expression they are called named function expression. If you do not give a name to a function expression it'll be called anonymous function expression.

The difference between function expression and declaration is how browser loads them to execution context. With functions comes a important concept called hoisting. Usually in JavaScript variable declarations are hoisted on top of a function. Read this for more info on hoisting

function themselves are objects of type Function. It has methods like apply, call etc.. Every functions by default accepts arguments object. You can find all arguments passed from the caller from argument object. Closures are related with functions. Read this article written by me about closures. JavaScript has predefined functions such as eval, isNaN, parseInt etc. If no return value is defined, functions will return undefined.

You can pass different parameters to functions. If you pass primitive type (primitive types in JavaScript) they get passed by value. But if you pass object (such as Array) the change will be reflected outside the function. That is you're passing an reference to an object by value. There is no pass by reference in JavaScript. 


Constructor functions vs Factory functions
Constructor function uses the new keyword to create a new object, set this within the function of that object and return it.





Factory function also uses to create new objects but it does not use new keyword. In fact factory creates the object for you and returns it. You can return different types of objects from a factory. 



With factories you get better encapsulation and data hiding. 

When you create an object from constructor function the prototype will be included in that object. When you create a n object through a factory since it just returns an object, the prototype won't be available.

Some Useful Stuff

Exclamation mark in front of a function (SO1 , SO2)


Resources

Tuesday, January 25, 2011

Data types in JavaScript

As in any other programming language, JavaScript also has Primitive data types and non-primitive data types. In case you didn't know primitive data types are predefined data types which comes with the language. Non-primitive are data types which are defined by the programmer.

Data types in JavaScript
  • Primary data types
    • Number
    • String
    • Boolean
  • Composite data types
    • Object
    • Function
JavaScript consists of lot of objects in it. Following diagram shows some of them. (source)

Array
Array is a high-level, list like object. Array prototype includes methods to perform operation on it.

Array. forEach
Array.prototype.map()
Creates a new array after manipulating the array elements from the callback function which is passed to map.
There are lot of other methods available for use in Array.prototype
Resources
Powered by Blogger.


Software Architect at Surge Global/ Certified Scrum Master

Experienced in Product Design, Software Engineering, Team management and Practicing Agile methodologies.

Search This Blog

Facebook