Saturday, April 25, 2009

Interviewing with Microsoft India

"What to expect in the interview" I've had this question from candidates that I have referred or distant relatives or friend's friend (you get the idea!) who are appearing for an interview with Microsoft . Somehow people still get to hear that Microsoft asks riddles. Though this was true way back but now these questions are rarely asked as they indicate very little about the candidate's potential.

I have been through interviews with some leading companies as an interviewer or interviewee and IMO Microsoft's interview process is a bit different. So here goes a list of what to expect and be prepared for in a technical interview with Microsoft.

  1. Unlike some other companies, Microsoft takes people from a lot of diverse background. E.g. if you are from C++ compiler development background you can be easily considered for the VS IDE's intelli-sense development if your interviewers think that you can fit in.
  2. Your dress really doesn't matter. You can expect to see your interviewer in shorts and he can't care less about what you wear.
  3. The interview process is loooooong. Expect multiple people to interview you one after the other. So when you get the lunch break, eat well.
  4. Put things in your resume only when you know about them well. People in Microsoft comes from diverse background (see above) and their  is every possibility that your interviewer will be very aware about the technologies you have mentioned in your resume and will ask you about them.
  5. Know your past projects well.
  6. You will be asked to solve technical problems and write pseudo-code for the solution. 
  7. Whether you are interviewing for Software development role, a test role or a lead/manager role you will be asked to code. The reason is simple, in Microsoft leads and development/test managers and even PUMs in some case (Program Unit Managers) code.
  8. Think aloud when solving problems, approach is as important as the final solution.
  9. When giving a solution, find out the fallacies your self and try to come up with better alternatives.
  10. Its an interview, so ask questions about Microsoft and the position/role you are being interviewed for.
  11. This is not true :)

Aspect Oriented Programming using .NET

What is AOP

Aspect Oriented Programming or AOP is an interesting concept that can be applied to many of the programming problems we solve everyday. In our Visual Studio team system code we have a lot of web-services and remoting code that essentially does the following

public void MyMethod(int parameter)

{

Trace.EnteredMethod("MyMethod", parameter);

SecurityCheck();

// Bunch of processing

Trace.ExitMethod("MyMethod");

}

This is not just peculiar to our domain but is seen across different domains. In OO programming classes and methods are designed for performing specific operations and common/duplicate functionality are factored out into common classes. However, there are cross-cutting concerns that span accross all classes and methods, like logging and security checks. OOP only partially solves this problem by requiring users to define separate classes for logging and security checks and requiring each class/methods needing these services to call them. AOP targets and solves this problem elegantly.

AOP divides code into base-code (code for your functionality) and a new construct called aspect. Aspect encapsulates these cross-cutting concerns using the following concepts

  • join-points: The points in the structure of base-code where the cross-cutting functionality needs to execute. This is typically when specific methods are entered or exited or properties are accessed.
  • point-cut: A logical description of join-points using some specific syntax
  • advice: additional code like logging and security check that each of these methods need to perform

The most mature AOP language is probably AspectJ which adds AOP extensions to Java. However, for this blog, I'd stick to .NET languages like AspectDNGAspect# and C#.

Language support for AOP

AOP support has to be built in to the language and/or framework because it is based on method call interception. Whenever a methods is called the framework needs to provide a stub to call some other piece of code. Though .NET CLR has this capability, but it is intrusive as you need an object to extend fromMarshalByRefObject  or ContextBoundObject to allow method-interception. This is a serious limitation because each class needs to be written so that it supports AOP. Many AOP languages or language-extensions get around this limitation by using various techniques. The techniques generally fall into two broad categories runtime or dynamic weaving, compile-time or static weaving.

Aspect# is AOP language which uses static compile time weaving. It uses its own proxy (and not CLR's proxy) called DynamicProxy. DynamicProxy is generated compile time and works differently while proxying interfaces (generates dynamic class and delegates method calls to the target of invocation) and proxying classes (generates stub class that inherits from the target).

Aspect# provides syntax to define point-cut and call method-interceptors or advice for them. It's done as follows 

import YourCompany.CMS.ContentProviders in YourCompanyAssembly
import YourCompany.CMS.Aop.Interceptors
aspect SecurityAspect for RSSContentProvider
     include Mixins.SecurityResourceImpl in MyMixinsAssembly

pointcut method(* MyMethod(*))
           advice(TracingInterceptor)
     end



end
public class
TracingInterceptor : IMethodInterceptor { public object Invoke(IMethodInvocation invocation) { // Trace using information from IMethodInvocation
// like Method, MethodInvocationTarget
return invocation.Proceed(); } }

The important bits are marked in bold. The first block is the point-cut in a Ruby like syntax which specifies all methods with the name MyMethod to be included in the join-points.  The second block is the interceptor (advice) TracingInterceptor. The TracingInterceptor is a class that has to implement theIMethodInterceptor. It can call invocation.Proceed to continue with the method invocation once it's done with the tracing. So whenever the MyMethod is called TracingInterceptor.Invoke gets called.

Other languages like AspectDNG (.NET based AOP language-extension) accomplishes this using something called IL weaving. In this the target or base-code is coded in any language that can be compiled into MSIL like C#, VB.NET, J#. So the target code can look like

using System;

 

public class MyClass {

public int ProcessString(String s, out string outStr) {

// ...  

}

}

There is no special code or any type of modification needed on the base-code as evident from above which is plain-vanilla C# code. The aspect code is written as follows which can also be C# code and needs some additional assembly reference and attribute decoration for AspectDNG to pick them up

using DotNetGuru.AspectDNG.MetaAspects;

using DotNetGuru.AspectDNG.Joinpoints;

using System;

public class AspectsSample{

[AroundCall("* MyClass::ProcessString(*)")]

public static object YourMethodCallInterceptor(JoinPoint jp) {

Console.WriteLine("Code before calls to '.. MyClass.ProcessString(..)'");

object result = jp.Proceed();

Console.WriteLine("Code after calls to '.. MyClass.ProcessString(..)'");

return result;

}
}

Here point-cut is specified using attributes like AroundCallAroundBody. Both the base-code and the aspect code are separately compiled into different assemblies using respective compilers like csc into Target.exe and aspect.dll. Then the aspectdng.exe tool can be used which uses reflection to reach to the attribute in the aspect code to weave call to them so that a new assembly called Target-weaved.exe is created. In target-weaved.exe AspectDNG directly puts in calls to the aspects around the target code by inserting/replacing IL code wherever required.

There are some AOP languages like Encase which apply the aspects at run time. These languages use AOP frameworks which reads in configuration files for point-cuts and at runtime generate proxy classes that intercept calls, allows advice of the aspect to execute first and then invokes the actual target. The benefit is that there is not edit-compile cycle but it faces performance issues.

AOP in C#

Till now we were talking about non-mainstream languages to get AOP done. However, by doing a bit extra work we can get the same functionality in C# as well. The limitation with CLR is that it allows method interception only when the classes containing the methods inherit from MarshalByRefObject  orContextBoundObject. When a class inheriting from ContextBoundObject is activated, the .NET interceptor comes into play. It creates a trasparent-proxy and a real-proxy. The transparent-proxy gets called for all invocation of the target. The transparent proxy serializes the call stack and passes that on to the real-proxy. The real-proxy calls the first message sink which is an object implementing theIMessageSink interface. Its the duty of this first message sink to call the next until the final sink goes and calls the actual target. In this sink chaining we can insert objects which can execute our aspect advice.

Another limitation with C# is that there is no way in C# syntax to specify join-points. We will circumvent these two limitations by inheriting the target classes from ContextBoundObject. We'll use attributes on specific classes so that all methods and field-setters in them become included into the join-points.

using System;

// Include the aspect framework

using Abhinaba.Aspect.Security;


[
Security()]

public class MyClass : ContextBoundObject {

public int ProcessString(String s, out string outStr) {

Console.WriteLine("Inside ProcessString");

outStr = s.ToUpper();

return outStr.Length;

}
}

Here Security is an attribute defined in our Abhinaba,Aspect.Security namespace which pulls in our support for AOP and includes the current class and all its methods in the join-points. The whole AOP framework looks as follows. All the important parts are marked in bold.

using System;

using System.Diagnostics;

using System.Runtime.Remoting.Messaging;

using System.Runtime.Remoting.Contexts;

using System.Runtime.Remoting.Activation;

namespace Abhinaba.Aspect.Security

{

internal class SecurityAspect : IMessageSink {

internal SecurityAspect(IMessageSink next)

{

m_next = next;

}

 

private IMessageSink m_next;

#region IMessageSink implementation

public IMessageSink NextSink

{

get{return m_next;}
}

public IMessage SyncProcessMessage(IMessage msg)

{

Preprocess(msg);

IMessage returnMethod =
m_next.SyncProcessMessage(msg);

return returnMethod;

}

public IMessageCtrl AsyncProcessMessage(IMessage msg,
IMessageSink replySink)

{

throw new InvalidOperationException();

}

#endregion //IMessageSink implementation


#region
Helper methods

private void Preprocess(IMessage msg)

{

// We only want to process method calls

if (!(msg is IMethodMessage)) return;

IMethodMessage call = msg as IMethodMessage;

Type type = Type.GetType(call.TypeName);

string callStr = type.Name + "." + call.MethodName;

Console.WriteLine("Security validating : {0} for {1}",
callStr,
Environment.UserName);

}

#endregion Helpers

}

public class SecurityProperty : IContextProperty,
IContributeObjectSink

{

#region IContributeObjectSink implementation

public IMessageSink GetObjectSink(MarshalByRefObject o,
IMessageSink next)

{

return new SecurityAspect(next);

}

#endregion // IContributeObjectSink implementation

#region IContextProperty implementation

// Implement Name, Freeze, IsNewContextOK

#endregion //IContextProperty implementation

}

[AttributeUsage(AttributeTargets.Class)]

public class SecurityAttribute : ContextAttribute

{

public SecurityAttribute() : base("Security") { }

public override void GetPropertiesForNewContext(
IConstructionCallMessage ccm)

{

ccm.ContextProperties.Add(new SecurityProperty());

}

}
}

 

SecurityAttribute derives from ContextAttribute and MyClass derives from ContextBoundObject, due to this even before the ctor of the class is called the framework instantiates SecurityAttribute and calls the GetPropertiesForNewContext passing it a reference to IConstructionCallMessage.SecurityAttribute creates an instance of SecurityProperty and adds it to the context. This addition makes the framework call the various IContextProperty methods that SecurityProperty implements and then calls the ctor of MyClass.

After this the first time any MyClass method or variable is referenced it calls GetObjectSink method ofSecurityProperty through its IContributeObjectSink interface. This method returns a newly created instance of SecurityAspect. Till this you can consider everything as initialization code andSecurityAspect implements our main functionality for AOP advice.

When the instance of SecurityAspect is created its constructor is passed a reference to next message sink so that all the sinks can be chained and called one after the other. After this SyncProcessMessage is called which is our main method interceptor and where all processing is done. After doing all processing like security verification the code calls the target method. Then it can refer to the return value and do post-processing. With this we have AOP implementation albeit some intrusive code as the target codes needs to be modified for AOP support.

Possibilities

AOP is a very generic programming method and can be used in a variety of situation. Some of them are as follows

Sample code

The sample solution (VS2005) including all sources are available here. It contains sources for two different aspects, one for security and one for tracing both applied on the same class. I have applied conditional compilation attribute to the tracing aspect so that on release build tracing gets disabled.

True object oriented language

Today I was spreading the goodness of Ruby and why I love it so much (and you can expect multiple posts on it). SmallTalk programmers can sneer at me, but hey I wasn't even born when SmallTalk came into being and hence I can be pardoned for pretending that Ruby invented this :)

Languages like Ruby are "truly" object oriented. So even a number like 2 is an instance of the FixNum class. So the following is valid Ruby code which returns the absolute value of the number.

-12345.abs

Taking this to an extreme is the iteration syntax. In C# to write something in a loop "n" time I'd be needed to get into for/foreach syntax, however in Ruby I can do the following

5.times { puts "Hello"} 

Which prints Hello 5 times.

However, I actually lied about having to use for/foreach statement in C#. With the new extension-method/lambda goodness we can very well achieve something close in C#.

For that first we create the following extension method

public static class Extensions

{

    public static void times(this int n, Action a)

    {

        for (int i = 0; i <>

        {

            a();

        }

    }

}

Then we can call "times" on an int as easily (well almost as I still need some lambda ugliness).

5.times(() => Console.WriteLine("Hello"));

// Or 

6.times(delegate { Console.WriteLine("Hello"); }); 


How do you name your computer

Windows gives examples of "Kitchen Computer" or "Mary's Computer" for setting the name of a computer (Computer Name tab in System Properties). But I'm sure that most people don't name their computers that way and show off a bit of creativity in it.

Previously I used to use names from Asterix like GetAFix for my main dev box. Now I exclusively use names from Hitchhiker's Guide to the Galaxy. Some of the machines I use are named as below

  1. traal: My test box
  2. Krikkit: My dev box
  3. Vogon: A old vintage machine I have at work which I use to test some perf scenarios (Vista on 512mb RAM :^) )
  4. Hooloovoo : My personal laptop
  5. Bugblatter: Another laptop

What name do you use?

Friday, April 24, 2009

Projects With Source Code

Hi Here we Are Providing Links To Get Projects with Source Code


nopCommerce(shopping cart)

nopCommerce is a fully customizable shopping cart. It's stable and highly usable. nopCommerce is a open source e-commerce solution that is ASP.NET 3.5 based with a MS SQL 2005 (or higher) backend database. Our easy-to-use shopping cart solution is uniquely suited for merchants that have outgrown existing systems, and may be hosted with your current web host or our hosting partners. It has everything you need to get started in selling physical and digital goods over the internet.


Download sample Projects from Microsoft official Site CodePlex


CodePlex is Microsoft's open source project hosting web site. You can use CodePlex to create new projects to share with the world, join others who have already started their own projects, or use the applications on this site and provide feedback.


Library Management System

A simple library management system that provides following facilities login, register, add category, add / remove book, search / issue book, return book. Language used is C# and db is SQL server 2000 and SQL Client has been used in code.

Some sample Projects are provides by dotnetspider.com


BlogEngine.NET is a full-featured blogging platform that is a breeze to set up, customize, and use. BlogEngine.NET works with your choice of data source; you may use SQL Server, or you may take the plug’n’play approach using XML files.


Jobs Site Starter Kit

Jobs Site Starter Kit (JSSK) is an ASP.NET starter kit demonstrating many new features of ASP.NET 2.0 including themes, master pages, new data controls, membership, roles and profiles. JSSK is a web application that provides a platform for candidates seeking job and the employers to share their needs.


Starter Kits and asp.net Community ProjectsThe ASP.NET 2.0 Starter Kits for Visual Web Developer are fully functional sample applications to help you learn ASP.NET 2.0 and accomplish common Web development scenarios. Each sample is complete and well-documented so that you can use the code to kick start your Web projects today! These kits, once downloaded are integrated directly into the Visual Web Developer 2005 Express Edition or Visual Studio 2005 experience.

Attendance Analysis System:

“Attendance Analysis System” is developed, keeping in mind the requirements about day-to-day handling of attendance of the students by the faculties in the engineering colleges. By using Attendance analysis system, a lecturer can keep track of attendance of every student, analyze it and finally build a Microsoft Word based report.


This is a fictitious Web Based E-Commerce Site developed for users who visit a typical shopping site for online buying . Apart from normal features of a sales site ,some value added features such as accessing Web Services, Credit Card validation, Emailing ,Report Generation using inbuilt crystal reports for managerial access have been added. I have also made a provision for adding new products,categories ,sub categories…….image uploading etc for the manager of the company.


eBilling and Invoice System is a live project written in Visual Basic 6 programming language. It is a working solution. I give you complete project listing with all project file, source code, database, crystal reports. You can use this project as you want. You can free download all the project documentation, project source code, project executable files, database downlodefrom link. Code are well commented for your reference, however if you want any clarification you can contact me for further explanation.


IMPRO (Industrial Manpower Resource Organizer)

IMPRO is a live project written in VB.NET and SQL Server. It is a working solution. I give you complete project listing with all project file, source code, database. You can use this project as you want. I am not claim any copyright for this project. You can free download all the project documentation, project source code, project executable files, database from downlode link. Code are well commented for your reference, however if you want any clarification you can contact me for further explanation.

Sales Invoice System

This is a database project .which I made for my six month training.
It is very user friendly Once user has entered the information about the product ,there prices and supplier of the product all these fields will be automatically filled up in the invoice and purchase order form.


The following sites gives Hundreds of Examples With Source Code

SourceForge.net

SourceForge.net is the world's largest open source software development web site. We provide free services that help people build cool stuff and share it with a global audience.


planet-source-code.com


The Below Example is One Of Those

Using TreeView, DataGridView, and WebBrowser to view and display records in an Access DB

The purpose of this sample application is to demonstrate the utilization of various controls in VB.NET that will allow you to access, view and display records in an MS Access database. I have tried to demonstrate, through usage of various procedures, functions and events how to: (1) Initializing a new Connection to an Access Database using the OpenFileDialog to search for the particular database, (2) Display records in a TreeView Control, (3) By selecting and expanding any one of the TreeView Nodes, you will be able to view selected items in a recordset in a DataGridView Control utilizing a DataTable as the DataSource, (4) Create, and populate selected items in an HTML report, (5) Display the HTML report(s) in a WebBrowser Control, (6) Display the HTML reports in your default browser. References: Add a reference to Microsoft ActiveX Data Objects 2.8 Library in order to access the MS Access Database. NOTE: If you using a version of VB.NET older than VB2008, you must first create a new project and than import all the files in this sample project before running it.


Sourcecodesworld.com

At Source Codes World.com, you can find thousands of categorised source codes and projects submitted by members for the growth of Feel free to use these source codes, but leave the credit to the author intact.

See all ASP Home


Sourcecodeonlinee.com

Source code online.com is provides free source code and scripts Downloads

Browse all 
ASP.NET
Projests