Learn IT

Free learning anything to everything in Information Technology.

Prototype - As a Design Guideline

"A picture can replace a thousand words; a prototype can save you lots of meetings and possibly avoid a project failure."

A prototype is a dynamic view of the system, while a requirements documents and design documents create a static view. It is the same with blueprints; they are a static model. A small-scale model is a dynamic view. Using a dynamic view, you can see things in action; you can add another dimension to the design phase: the time dimension.

The most important benefit of using prototypes is that it helps promote communication with the client, project managers and other developers.

Prototypes help in tracking the requirements back and forth. They ensure that you implement what is needed, no more and no less.

Building Blocks of Design

There are three high level elements that are considered for design:
  • Patterns
    A pattern is a specification for addressing a common problem in solution design. Patterns are not algorithms, they are higher level and more broadly applicable. Adopting a widely accepted pattern as part of solution design can help us address not only the problem we recognize, but also the related problems we may not recognize on first glance.

  • Frameworks
    Occasionally, you may find targeted reference implementations of patterns that may be useful, and they are often in the form of a framework. In classic object-oriented design, a framework is a set of abstract classes to be incorporated into and reused as part of a software application. The current thinking is that a framework also may be a set of abstract data constructs, rules, or processes. A framework is different from a pattern in that a framework is something real that can be incorporated into and used as a foundational element of your solution—it is commonly the implementation of a pattern or specification.
    A framework provides guidance beyond that of a pattern, and typically provides deployable elements that can be used as the foundation for your solution. The more well- understood the framework, the easier it will be for an organization to support it over time.

  • Components
    Components are encapsulated elements of a system (hardware, software, network, etc.) and are by definition not case-specific. Components can be wrapped into your solution seamlessly, or can be managed as separate entities, regardless of deployment environment. Incorporating well-understood components into your solution definition can save time in delivery and increase the quality of your solution, but components may have associated support costs that can be considerable.
    Most components can be satisfactorily configured to meet our needs without any custom work. Incorporating a component and customizing it beyond the standard configuration is risky—you should understand the cost associated with supporting it going forward, and the risk of losing vendor-provided support.

Enterprise Architecture

The definition of an architecture used in ANSI/IEEE Std 1471-2000 is: "the fundamental organization of a system, embodied in its components, their relationships to each other and the environment, and the principles governing its design and evolution."

An enterprise architecture (EA) is a conceptual tool that assists organizations with the understanding of their own structure and the way they work. It provides a map of the enterprise and is a route planner for business and technology change.

Normally an enterprise architecture takes the form of a comprehensive set of cohesive models that describe the structure and the functions of an enterprise. Important uses of it are in systematic IT planning and architecting, and in enhanced decision making.

The individual models in an EA are arranged in a logical manner, and this provides an ever-increasing level of detail about the enterprise, including:

  • Its objectives and goals.
  • Its processes and organization.
  • Its systems and data.
  • The technology used.

Software Architecture

Software Architecture can be defined in terms of building blocks and software components. These building blocks are software components, frameworks, IDE’s, SDK’s, and Commercial off the shelf (COTS) packages.

The primary role of a Software Architect is to choose the components, integrate the ones that can be incorporated, and lead the team in creating custom supporting code to link the components in times where there are no obvious connectors from one component to another and build something that will benefit the business.

WSS 3.0 - WorkFlows

A workflow allows you to attach a business process to items in Windows SharePoint Services 3.0. This process can control almost any aspect of an item in Windows SharePoint Services 3.0, including the life cycle of that item. For example, you could create a simple workflow that routes a document to a series of users for approval.

Workflows can be as simple or complex as your business processes require. You can create workflows that the user initiates, or workflows that Windows SharePoint Services 3.0 automatically initiate based on some event, such as when an item is created or changed.

Windows SharePoint Services 3.0 workflows are made available to end-users at the list or document-library level. Workflows can be added to documents or list items. Workflow can also be added to content types. Multiple workflows may be available for a given item. Multiple workflows can run simultaneously on the same item, but only one instance of a specific workflow can run on a specific item at any given time. For example, you might have two workflows, SpecReview and LegalReview, available for a specific content type, Specification. Although both workflows can run simultaneously on a specific item of the Specification content type, you can't have two instances of the LegalReview workflow running on the same item at the same time.

WSS 3.0 & MOSS 2007 - WebParts

Web Parts in Windows SharePoint Services provide developers with a way to create user interface elements that support both customization and personalization. A site owner or a site member with the appropriate permissions can customize Web Part Pages using a browser or Microsoft Office SharePoint Designer 2007 by adding, reconfiguring, and removing Web Parts.

The term customization implies that changes are seen by all site members. Individual users can further personalize Web Part Pages by adding, reconfiguring, and removing Web Parts. The term personalization implies that these changes will be seen only by the user that made them. Developing custom Web Parts provides an easy and powerful way to extend Windows SharePoint Services sites.

Because the Windows SharePoint Services Web Part infrastructure is now built on top of the ASP.NET 2.0 Web Parts control set, you can reuse your knowledge of ASP.NET programming to create quick and robust custom Web Parts.

Following are some ways in which you can use custom Web Parts:

  • Creating custom properties you can display and modify in the user interface.

  • Improving performance and scalability. A compiled custom Web Part runs faster than a script.

  • Implementing proprietary code without disclosing the source code.

  • Securing and controlling access to content within the Web Part. Built-in Web Parts allow any users with appropriate permissions to change content and alter Web Part functionality. With a custom Web Part, you can determine the content or properties to display to users, regardless of their permissions.

  • Making your Web Part connectable, allowing Web Parts to provide or access data from other connectable Web Parts.

  • Interacting with the object models that are exposed in Windows SharePoint Services. For example, you can create a custom Web Part to save documents to a Windows SharePoint Services document library.

  • Controlling the cache for the Web Part by using built-in cache tools. For example, you can use these tools to specify when to read, write, or invalidate the Web Part cache.

  • Benefiting from a rich development environment with debugging features that are provided by tools such as Microsoft Visual Studio 2005.

  • Creating a base class for other Web Parts to extend. For example, to create a collection of Web Parts with similar features and functionality, create a custom base class from which multiple Web Parts can inherit. This reduces the overall cost of developing and testing subsequent Web Parts.

  • Controlling the implementation of the Web Part. For example, you can write a custom server-side Web Part that connects to a back-end database, or you can create a Web Part that is compatible with a broader range of Web browsers.

WSS 3.0 - Content Types & Site Columns

Windows SharePoint Services 3.0 provides two new tools to help you organize and standardize your data: content types and site columns.

Content Types
Content types—a core concept used throughout the functionality and services offered in Windows SharePoint Services 3.0—are designed to help users organize their SharePoint content in a more meaningful way. A content type is a reusable collection of settings you want to apply to a certain category of content. Content types enable you to manage the metadata and behaviors of a document or item type in a centralized, reusable way.

For example, consider the following two types of documents: software specifications and legal contracts. It is reasonable that you might want to store documents of those two types in the same document library. However, the metadata you would want to gather and store about each of these document types would be very different. In addition, you would most likely want to assign very different workflows to the two types of documents.

Content types enable you to store multiple, different types of content in the same document library or list. In the preceding example, you could define two content types named Specification and Contract. Each content type could include different columns for gathering and storing item metadata, as well as have different workflows assigned to it. Yet items of both content types could be stored in the same document library.

You can further extend content type functionality by using content types to assign additional settings, such as workflows or even custom attributes, to your items.

Because you can define content types independently of any specific list or document library, you can make a given content type available for the lists on multiple SharePoint sites. This enables you to centrally define and manage the types of content you store in your site collection. For example, you could use your Specification content type to ensure that all software specifications track the same metadata, even if those specifications are stored across multiple sites.
Content types are independent of file formats. For document libraries, you can specify a document template; when the user requests a new document of this content type, Windows SharePoint Services creates a document based on the template. However, users can still upload a document based on a different template, or even of a completely different file type.

Site Columns
Site columns provide a central, reusable model for column definition. When you create a site column, each list that uses this column has the same definition, and you do not have to do the tedious work of reproducing the column in each list.

A site column is a reusable column definition, or template, that you can assign to multiple lists across multiple SharePoint sites. Site columns decrease rework and help you ensure consistency of metadata across sites and lists. For example, suppose you define a site column named Customer. Users can add that column to their lists and reference it in their content types. This ensures that the column has the same attributes, at least to start with, wherever it appears.

Additionally, site columns provide you with the simplicity of a single maintenance point. For example, you can create a status site column, which might contain multiple choices of an enterprise's specific statuses, and implement the column in dozens of project master lists across the site collection. If you add a new status, you can modify the site column instead of having to modify each list that contains a status column.

Much like site content types, you define a site column at the site level, independent of any actual list or content type.

When you add a column to a list, Windows SharePoint Services copies the site column locally onto the list as a list column. You can then make changes to the list column; these changes apply to the column only as it behaves on that list.

In certain situations, you may want to modify the column for a specific list. For this reason, you still have the option of one-off customization of columns at the list level. For example, suppose all projects within your company's Information Technology department have an additional status of On Hold—Waiting for Hardware. You could add this status to the column within the IT department's master project list.

You can also create your own list columns, directly on a list. Either way, list columns apply only to the list to which you add them; they cannot be added to multiple lists.

You can reference a site or list column in a content type.

Features Of Common Language Runtime

The .NET Framework provides a run-time environment called the common language runtime, which runs the code and provides services that make the development process easier.


The common language runtime manages memory, thread execution, code execution, code safety verification, compilation, and other system services. These features are intrinsic to the managed code that runs on the common language runtime.



With regards to security, managed components are awarded varying degrees of trust, depending on a number of factors that include their origin (such as the Internet, enterprise network, or local computer). This means that a managed component might or might not be able to perform file-access operations, registry-access operations, or other sensitive functions, even if it is being used in the same active application.



The runtime enforces code access security. For example, users can trust that an executable embedded in a Web page can play an animation on screen or sing a song, but cannot access their personal data, file system, or network. The security features of the runtime thus enable legitimate Internet-deployed software to be exceptionally feature rich.



The runtime also enforces code robustness by implementing a strict type-and-code-verification infrastructure called the common type system (CTS). The CTS ensures that all managed code is self-describing. The various Microsoft and third-party language compilers generate managed code that conforms to the CTS. This means that managed code can consume other managed types and instances, while strictly enforcing type fidelity and type safety.



In addition, the managed environment of the runtime eliminates many common software issues. For example, the runtime automatically handles object layout and manages references to objects, releasing them when they are no longer being used. This automatic memory management resolves the two most common application errors, memory leaks and invalid memory references.



The runtime also accelerates developer productivity. For example, programmers can write applications in their development language of choice, yet take full advantage of the runtime, the class library, and components written in other languages by other developers. Any compiler vendor who chooses to target the runtime can do so. Language compilers that target the .NET Framework make the features of the .NET Framework available to existing code written in that language, greatly easing the migration process for existing applications.



While the runtime is designed for the software of the future, it also supports software of today and yesterday. Interoperability between managed and unmanaged code enables developers to continue to use necessary COM components and DLLs.



The runtime is designed to enhance performance. Although the common language runtime provides many standard runtime services, managed code is never interpreted. A feature called just-in-time (JIT) compiling enables all managed code to run in the native machine language of the system on which it is executing. Meanwhile, the memory manager removes the possibilities of fragmented memory and increases memory locality-of-reference to further increase performance.



Finally, the runtime can be hosted by high-performance, server-side applications, such as Microsoft® SQL Server™ and Internet Information Services (IIS). This infrastructure enables you to use managed code to write your business logic, while still enjoying the superior performance of the industry's best enterprise servers that support runtime hosting.

.NET Framework

The .NET Framework is an integral Windows component that supports building and running the next generation of applications and XML Web services. The .NET Framework is designed to fulfill the following objectives:


  • To provide a consistent object-oriented programming environment whether object code is stored and executed locally, executed locally but Internet-distributed, or executed remotely.

  • To provide a code-execution environment that minimizes software deployment and versioning conflicts.

  • To provide a code-execution environment that promotes safe execution of code, including code created by an unknown or semi-trusted third party.

  • To provide a code-execution environment that eliminates the performance problems of scripted or interpreted environments.

  • To make the developer experience consistent across widely varying types of applications, such as Windows-based applications and Web-based applications.

  • To build all communication on industry standards to ensure that code based on the .NET Framework can integrate with any other code.


Components of .NET Framework



The .NET Framework has two main components:


The common language runtime :


The common language runtime is the foundation of the .NET Framework. You can think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and other forms of code accuracy that promote security and robustness. In fact, the concept of code management is a fundamental principle of the runtime. Code that targets the runtime is known as managed code, while code that does not target the runtime is known as unmanaged code.


The .NET Framework Class Library:


The class library, the other main component of the .NET Framework, is a comprehensive, object-oriented collection of reusable types that you can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET, such as Web Forms and XML Web services.



The .NET Framework can be hosted by unmanaged components that load the common language runtime into their processes and initiate the execution of managed code, thereby creating a software environment that can exploit both managed and unmanaged features. The .NET Framework not only provides several runtime hosts, but also supports the development of third-party runtime hosts.



For example, ASP.NET hosts the runtime to provide a scalable, server-side environment for managed code. ASP.NET works directly with the runtime to enable ASP.NET applications and XML Web services, both of which are discussed later in this topic.



Internet Explorer is an example of an unmanaged application that hosts the runtime (in the form of a MIME type extension). Using Internet Explorer to host the runtime enables you to embed managed components or Windows Forms controls in HTML documents. Hosting the runtime in this way makes managed mobile code (similar to Microsoft® ActiveX® controls) possible, but with significant improvements that only managed code can offer, such as semi-trusted execution and isolated file storage.

Creating Database Objects Using Managed Code (Microsoft .NET 2.0)

One of the neat features of SQL Server 2005 is the integration with the .NET CLR. The integration of CLR with SQL Server extends the capability of SQL Server in several important ways. This integration enables developers to create database objects such as stored procedures, user defined functions, and triggers by using modern object-oriented languages such as VB.NET and C#.

In this post, I will demonstrate how to create the stored procedures using C#. Before looking at the code, let us understand the pros and cons of using managed language in the database tier to create server side objects.

T-SQL Vs Managed Code

Although T-SQL, the existing data access and manipulation language, is well suited for set-oriented data access operations, it also has limitations. It was designed more than a decade ago and it is a procedural language rather than an object-oriented language. The integration of the .NET CLR with SQL Server enables the development of stored procedures, user-defined functions, triggers, aggregates, and user-defined types using any of the .NET languages.

This is enabled by the fact that the SQL Server engine hosts the CLR in-process. All managed code that executes in the server runs within the confines of the CLR. The managed code accesses the database using ADO.NET in conjunction with the new SQL Server Data Provider. Both Visual Basic .NET and C# are modern programming languages offering full support for arrays, structured exception handling, and collections.

Developers can leverage CLR integration to write code that has more complex logic and is more suited for computation tasks using languages such as Visual Basic .NET and C#. Managed code is better suited than Transact-SQL for number crunching and complicated execution logic, and features extensive support for many complex tasks, including string handling and regular expressions. T-SQL is a better candidate in situations where the code will mostly perform data access with little or no procedural logic.

Creating CLR Based Stored Procedures

For the purposes of this example, create a new SQL Server Project using Visual C# as the language of choice in Visual Studio 2005. Since you are creating a database project, you need to associate a data source with the project. At the time of creating the project, Visual Studio will automatically prompt you to either select an existing database reference or add a new database reference. Choose pubs as the database. Once the project is created, select Add Stored Procedure from the Project menu. In the Add New Item dialog box, enter Authors.cs and click Add button. After the class is created, modify the code in the class to look like the following.



using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;

public class Authors
{
[SqlProcedure]
public static void GetAuthors()
{
SqlPipe sp = SqlContext.Pipe;
using (SqlConnection conn = new
SqlConnection("context connection=true"))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
cmd.CommandText = "Select DatePart(second, GetDate()) " +
" As timestamp,* from authors";
SqlDataReader rdr = cmd.ExecuteReader();
sp.Send(rdr);
}
}

[SqlProcedure]
public static void GetTitlesByAuthor(string authorID)
{
string sql = "select T.title, T.price, T.type, " +
"T.pubdate from authors A" +
" inner join titleauthor TA on A.au_id = TA.au_id " +
" inner join titles T on TA.title_id = T.title_id " +
" where A.au_id = '" + @authorID + "'";
using (SqlConnection conn = new
SqlConnection("context connection=true"))
{
conn.Open();
SqlPipe sp = SqlContext.Pipe;
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
cmd.CommandText = sql;
SqlParameter paramauthorID = new
SqlParameter("@authorID", SqlDbType.VarChar, 11);
paramauthorID.Direction = ParameterDirection.Input;
paramauthorID.Value = authorID;
cmd.Parameters.Add(paramauthorID);
SqlDataReader rdr = cmd.ExecuteReader();
sp.Send(rdr);
}
}
}
Let us examine the above lines of code. The above code starts by importing the required namespaces and then declares a class named Authors. There are two important classes in the Microsoft.SqlServer.Server namespace that are specific to the in-proc provider:
  • SqlContext: This class encapsulates the extensions required to execute in-process code in SQL Server 2005. In addition it provides the transaction and database connection which are part of the environment in which the routine executes.
  • SqlPipe: This class enables routines to send tabular results and messages to the client. This class is conceptually similar to the Response class found in ASP.NET in that it can be used to send messages to the callers.

The Authors class contains two static methods named GetAuthors and GetTitlesByAuthor. As the name suggests, the GetAuthors method simply returns all the authors from the authors table in the pubs database and the GetTitlesByAuthor method returns all the titles for a specific author.

Inside the GetAuthors method, you start by getting reference to the SqlPipe object by invoking the Pipe property of the SqlContext class.

SqlPipe sp = SqlContext.Pipe;

Then you open the connection to the database using the SqlConnection object. Note that the connection string passed to the constructor of the SqlConnection object is set to "context connection=true" meaning that you want to use the context of the logged on user to open the connection to the database.

using (SqlConnection conn = new SqlConnection("context connection=true"))

Here open the connection to the database using the Open() method.

conn.Open();

Then you create an instance of the SqlCommand object and set its properties appropriately.

SqlCommand cmd = new SqlCommand();cmd.CommandType = CommandType.Text;cmd.Connection = conn;cmd.CommandText = "Select DatePart(second, GetDate()) " + " As timestamp,* from authors";

Finally you execute the sql query by calling the ExecuteReader method of the SqlCommand object.

SqlDataReader rdr = cmd.ExecuteReader();

Then using the SqlPipe object, you then return tabular results and messages to the client. This is accomplished using the Send method of the SqlPipe class.
sp.Send(rdr);
The Send method provides various overloads that are useful in transmitting data through the pipe to the calling application. Various overloads of the Send method are:

  • Send (ISqlDataReader) - Sends the tabular results in the form of a SqlDataReader object.
  • Send (ISqlDataRecord) - Sends the results in the form of a SqlDataRecord object.
  • Send (ISqlError) - Sends error information in the form of a SqlError object.
  • Send (String) - Sends messages in the form of a string value to the calling application.

Both the methods in the Authors class utilize one of the Send methods that allows you to send tabular results to the client application in the form of a SqlDataReader object. Since the GetTitlesByAuthor method implementation is very similar to the GetAuthors method, I will not be discussing that method in detail.

Now that the stored procedures are created, deploying it is very simple and straightforward. Before deploying it, you need to build the project first. To build the project, select Build->Build from the menu. This will compile all the classes in the project and if there are any compilation errors, they will be displayed in the Error List pane. Once the project is built, you can then deploy it onto the SQL Server by selecting Build->Deploy from the menu. This will not only register the assembly in the SQL Server but also deploy the stored procedures in the SQL Server. Once the stored procedures are deployed to the SQL Server, they can then be invoked from the data access layer, which is the topic of focus in the next section.

Before executing the stored procedure, ensure you execute the following sql script using SQL Server Management Studio to enable managed code execution in the SQL Server.

EXEC sp_configure 'clr enabled', 1;

RECONFIGURE WITH OVERRIDE;

GO