Learn IT

Free learning anything to everything in Information Technology.

Overview: Test Driven Development

There are many benefits of test driven development including better end product with well defined supporting unit tests and having a programming paradigm that is a bit more flexible in regards to scope changes. Having unit tests available will make our code more maintainable over the long run is invaluable because we can modify our code without fear such as when we are adding/modifying functionality or refactoring. It could even be considered crucial when we have projects where the scope is likely to change throughout the development lifecycle like in the case where the functional specifications are not clearly defined before we begin producing code.

Test driven development can be a huge shift in the development approach for many of us. The test driven approach basically chips away at the solution like a sculptor would at a marble block instead of trying to define and create a monolithic application in one shot.

As a first step, we'll define the interfaces out software will adhere to. The interface should clearly define how our class is to interact with other classes and what information it will expose. This is a crucial step in any software design process because we really have to know where we are going and the interface serves as a map that will help us get there.

After we have an interface, we'll begin with the test-driven development cycle.
  1. Add a test
  2. Run all tests and watch the new one fail (and the rest succeed)
  3. Modify our code to make the test succeed
  4. Run all tests and watch them succeed
  5. Refactor, if necessary
  6. Run tests to ensure everything still works
  7. Repeat

Understanding MOSS 2007

The core target of Microsoft Office SharePoint Server (MOSS 2007) is to aggregate disparate (Different but separate applications) information, events, processes and enterprise services into a unified single view without to open multiple applications and cut and paste information across multiple screens.

In MOSS 2007 these composite applications are based on the concept of a service-oriented architecture (SOA). MOSS 2007 framework helps you develop components as distributed, reusable business services. MOSS 2007 split into small applications in small pieces.
MOSS 2007 is basically superstructure who represents the high-level integration of users, one-stop shop form information, managing interactions between people, and line-of-business (LOB) data within organization and cross enterprises. MOSS 2007 based on SOA framework that is driven by standard XML/ Web services.

It provides a window that connects people, processes, and information to create a unique & rich end user experience. For example, during a natural disaster, it can provide critical information to coordinate a response effort, monitoring traffic patterns, delivering supplies, dispatching resources, and aggregating information to present operational insight. In a manufacturing setting, you might use it to monitor inventory levels and assembly processes up and down a supply chain. It's an excellent aggregation point for all of these types of situations.

MOSS 2007 is point of collaboration & contents sharing. For example, SharePoint Portal includes workspace to help loan officers find, organize, and share information so they can process loans more efficiently. These workspaces used to be very limited in their reach, which resulted in a proliferation of mediums to support discrete processes. A mortgage broker might use a file system to store documents, e-mail to deliver loan applications to customers, a Web site to gather additional customer information, and a spreadsheet to monitor the loan approval process.

MOSS 2007 can unify all these tasks and offer collaboration tools to streamline the loan approval workflow. Loan officers will then have a single place to access and modify documents, check documents in and out of a repository, and work collaboratively to process loans, all without having to use multiple interface mechanisms.

So, MOSS 2007 become more process-centric, they serve as clearinghouses for managing multiple activities in multiple manners.

How To: Generate unique strings and numbers in C#

The System.Guid is used whenever we need to generate a unique key, but it is very long. That's in many cases not an issue, but in a web scenario where it is part of the URL we need to use its string representation which is 36 characters long. It clutters up the URL and is just basically ugly.

It is not possible to shorten it without loosing some of the uniqueness of the GUID, but we can come a long way if we can accept a 16 character string instead.

We can change the standard GUID string representation:

21726045-e8f7-4b09-abd8-4bcc926e9e28

Into a shorter string:

3c4ebc5f5f2c4edc

The following method creates the shorter string and it is actually very unique. An iteration of 10 million didn.t create a duplicate.
It uses the uniqueness of a GUID to create the string.

private string GenerateId()
{
long i = 1;
foreach (byte b in Guid.NewGuid().ToByteArray())
{
i *= ((int)b + 1);
}
return string.Format("{0:x}", i - DateTime.Now.Ticks);
}


If you instead want numbers instead of a string, you can do that to but then you need to go up to 19 characters.

The following method converts a GUID to an Int64.

private long GenerateId()
{
byte[] buffer = Guid.NewGuid().ToByteArray();
return BitConverter.ToInt64(buffer, 0);
}


The standard GUID is still the best way to ensure the uniqueness even though it isn't 100% unique.

The benefits of Office PerformancePoint Server 2007

Office PerformancePoint Server 2007 greatly improves visibility into company performance and the factors that are driving it. Office PerformancePoint Server 2007 also enables employees to monitor and act on performance variances.
Office PerformancePoint Server 2007 offers:
  • Robust monitoring and analytics capabilities. Office PerformancePoint Server 2007 monitoring and analytics capabilities enable business users to see and understand performance issues quickly so they can make better decisions faster—all without the need for technical assistance. The fact that scorecards, dashboards, and analytics are all integrated into the same application makes deployment simple and helps drive alignment and accountability. Office PerformancePoint Server 2007 helps individuals to be more effective and the organization to be more agile.

  • Improved planning, budgeting, and forecasting. Drive strategic objectives and goals into the planning and budgeting process to ensure departmental plans align with corporate strategy. Reduce the time and effort required through centralized control and administration and workflow that manages the creation and submission.

  • Faster financial reporting and consolidation. Consolidate financial data from multiple general ledgers and reporting systems to achieve a single, integrated view of financial information. Robust integration and administration of financial information helps increase information accuracy and reduce the time and effort required for statutory and management reporting.

  • Extends Existing IT Investments. Office PerformancePoint Server 2007 utilizes widely used and supported Microsoft technologies such as Windows Server, SQL Server, and Microsoft Office SharePoint Portal Server. This utilization enables companies to extend their existing investments and IT skill sets in these mission-critical enterprise technologies.

Features: Office PerformancePoint Server 2007

Office PerformancePoint Server 2007 features robust performance management capabilities including:
  • An integrated application for performance management. Office PerformancePoint Server 2007 provides all of the functionality that is needed for performance management in a single, integrated application including scorecards, dashboards, management reporting, analytics, planning, budgeting, forecasting, and consolidation. With Office PerformancePoint Server 2007, users can better understand variances between plan and actual, quickly analyze root-causes, and recast plans when necessary. Customers can enter the performance management process at any point, benefiting from a common data model shared across monitoring, analytical, and planning activities.

  • Business users shape their plans the way they think about their business. Office PerformancePoint Server 2007 provides business users with the ability to define, modify, and maintain their plans easily. The application handles the sophistication of the company business processes (rules, logic, calculations, and workflows) while helping more users contribute to the performance management process.

  • Flexibility to handle complex environments. Office PerformancePoint Server 2007 uses a model-driven approach to make it easier to create corporate models for scorecards, analytics, and plans that can also be used for departmental-level performance management. By providing synchronized models up and down the organization as well as across departments, users can more easily get a consistent view of organizational performance.

  • Reducing complexity for IT and for the business. Office PerformancePoint Server 2007 enables businesses to broadly deliver performance management across the organization by rapidly bringing together the power of Microsoft Office and the performance, scalability, and security of SQL Server. Office PerformancePoint Server 2007 is easy to use and less costly to deploy than traditional solutions. Office PerformancePoint Server 2007 also helps IT better support corporate governance through the ability the audit the performance management process as well as control versions and report on the processes.

Overview: Microsoft Office PerformancePoint Server 2007

Microsoft Performance Management allows customers to monitor, analyze, and plan their business as well as drive alignment, accountability, and actionable insight across the entire organization.

With Office PerformancePoint Server 2007 server:

  • Business executives can drive accountability and alignment across and up-and-down the organization.
  • Information workers can monitor, analyze, and plan activities with an integrated and collaborative solution.
  • IT managers can drive better adoption and compliance by enabling organizations to better associate business intelligence and corporate performance.

Office PerformancePoint Server 2007 provides all of the functionality that is needed for performance management including scorecards, dashboards, management reporting, analytics, planning, budgeting, forecasting, and consolidation. The application reaches all employees, across all business functions (finance, operations, marketing, sales, and human resources).

Decisions makers need to drive performance by accelerating business decision making, while adapting to changing business conditions and enforcing corporate governance. Office PerformancePoint Server 2007 allows the organization to build reliable plans faster and execute against them by aligning and driving accountability across business operations.

Abstract Class Vs Interface

Interfaces:
  1. Interfaces doesn’t have constructors
  2. Can implement multiple inheritances.
  3. Contain only abstract methods (Only method prototype is declared)
  4. Can not create object for interfaces.
  5. Interfaces are reference type.
  6. An interface can implement by multiple classes.
  7. A derived class can implement multiple interfaces, but can inherit from only one class (abstract or not).
  8. Interfaces are default public.

Abstract Class:

  1. Abstract classes can have constructors.
  2. Can’t implement multiple inheritances.
  3. Contain abstract methods and general methods also.
  4. Can not create object for abstract class.
  5. Abstract classes are reference type.

Garbage Collection in C#

Introduction

All the garbage collection mechanisms have one thing in common, that is they take the responsibility of tracking memory usage.

Understanding Garbage Collection in C#

The .NET garbage collector is optimized for the following assumptions
  1. Objects that were recently allocated are most likely to be freed.
  2. Objects that have lived the longest are least likely to be become free.
  3. Objects allocated together are often used together.

The .NET garbage collector is known as generational garbage collector. The objects allocated are categorized into three generations. Most recently allocated objects are placed in Generation 0.

Objects in Generation 0, that survive a garbage collection pass are moved to Generation 1.

Generation 2 contains long-lived objects, that survive after the two collection passes.

A garbage collection pass for Generation 0 is the most common type of collection. Generation 1 collection pass is performed if Generation 0 collection pass is not sufficient to reclaim memory.

Atlast, Generation 2 collection pass is peformed if collection pass on Generation 0 and 1 are not sufficient to reclaim memory. If no memory is available, after all the collection passes, an OutOfMemoryException is thrown.

Finalizers

A class could expose a finalizer, which executes when the object is destroyed. In C#, the finalizer is a protected method as shown below.

protected void Finalize()

{

base.Finalize(); // clean external resources

}

The method Finalize(), is only called by the .NET framework.

C#, will generate a code to a well formed Finalizer, if we declare a destructor as shown
~class1

{

// Clean external resources.

}

Declaring a Finalize method and destructor in a class, will lead to an error.

Dispose

Instead of declaring a Finalizer, exposing a Dispose method is considered as good.

If we clean up a object, using Dispose or Close method, we should indicate to the runtime that the object is no longer needed finalization, by calling GC.SuppressFinalize() as shown below:

public void Dispose()

{

// all clean up source code here..

GC.SuppressFinalize(this);

}

If we are creating and using objects that have Dispose or Close methods, we should call these methods when we’ve finished using these objects. It is advisable to place these calls in a finally clause, which guarantees that the objects are properly handled even if an exception is thrown.

Summary

The System.GC class provides methods that control the system garbage collector. We have to use methods from this class in our application with extreme caution.

Microsoft .Net Assemblies

Introduction
  • Assembly is a small unit of Code for Deployment
  • The basic building block for Dot Net Framework is an Assembly
  • Assembly can be an exe or dll file
  • But the difference between dll and exe is exe is an executable file
  • Dll is a reusable component.
  • Exe is a Stand alone application that can run on its own
  • Dll is used in other applications
  • Assembly is Collection of Data Types, Namespaces and Resources Information
  • Namespace is a logical design-time naming convenience, whereas an assembly establishes the name scope for types at run time.

The Four Main Parts

The main Parts of the Assembly are

  1. Manifest
  2. Type Meta Data
  3. MSIL Code
  4. Resources

Manifest

It will describe the assembly it will contain all the files information required for the assembly. These files includes all the other assemblies required for the application. It will be prepared by the complier by providing set of built in libraries and custom libraries provided with reference. This is required for the runtime to load the files at the time of execution Public key with Version number are stored here.

Meta Data

It will provide information about all the user defined types available with assembly

  • Includes
  • Namespace name
  • Class names
  • Interface names
  • Method names

This Meta data is required for the user of the assembly to access methods and classes.

IL Code

The source code in Dotnet is Compiled into IL code with the help of JIT complier in CLR .This code is responsible for Language independency, Architecture independency, Plat form independency and Security.
VS Command Prompt c :\> ildasm app.exe
File-->new-->open any dll from your existing web application
Double Click on manifest to examine manifest
You will find public key token with version number that is generated for Assembly
The expanded tree view of name spaces and classes methods is called Meta data
Try to examine Meta data MSIL/IL code that is generated for each method
MSIL IL code is in Assembly language it ‘s understands by only JIT Complier with the help of jitters inside it.
Double Click on Any Method Source code Converted to IL Code
// Code size 12 (0xc)
.maxstack 2
IL_0000: ldarg.0
IL_0001: callvirt instance string Infragistics.WebUI.CalcEngine.RefBase::get_NormalizedAbsoluteName()
IL_0006: callvirt instance int32 [mscorlib]System.String::GetHashCode()
IL_000b: ret
} // end of method RefBase::GetHashCode
This is the MSIL code starts with IL
If we can write code in IL code and understand it we can develop our own complier in the corresponding language.
There are around 30 third party language compliers available like COBOL.net,C#.net etc.

Resources

If assembly using any gif/image files that information is stored in resource section of the assembly. Note: To Examine the Components of the Assembly use Intermediate Language Disassembler (ILDASM) Go to
VS Command Prompt and type ILDASM
File -->Open the Dll
We can see the Manifest Meta Data ,IL Code Public key version number
This information can be helpful in determining whether a file is an assembly or part of an assembly, and whether the file has references to other modules or assemblies.

Advantages of .Net Assemblies

  1. No dll Hell
  2. Platform independency
  3. Inheritance is supported

Prototype Design Pattern

A Prototype Pattern is a creational design pattern used in software development when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. This pattern is used for example
to avoid subclasses of an object creator in the client application, like abstract factory pattern does.
or when the inherent cost of creating a new object in the standard way (e.g., using the 'new' kkeyword) is prohibitively expensive for a given application.

C# sample code


public enum RecordType
{
Car,
Person
}

///
/// Record is the Prototype
///

public abstract class Record
{
public abstract Record Clone();
}

///
/// PersonRecord is the Concrete Prototype
///

public class PersonRecord : Record
{
string name;
int age;

public override Record Clone()
{
return (Record)this.MemberwiseClone(); // default shallow copy
}
}

///
/// CarRecord is another Concrete Prototype
///

public class CarRecord : Record
{
string carname;
Guid id;

public override Record Clone()
{
CarRecord clone = (CarRecord)this.MemberwiseClone(); // default shallow copy
clone.id = Guid.NewGuid(); // always generate new id
return clone;
}
}

///
/// RecordFactory is the client
///

public class RecordFactory
{
private static Dictionary _prototypes =
new Dictionary();

///
/// Constructor
///

public RecordFactory()
{
_prototypes.Add(RecordType.Car, new CarRecord());
_prototypes.Add(RecordType.Person, new PersonRecord());
}

///
/// The Factory method
///

public Record CreateRecord(RecordType type)
{
return _prototypes[type].Clone();
}
}