Enterprise Templates

With the advent of .NET came a lot of power and flexibility. You can now develop an application in any language you like and can even easily develop different parts of the application in different languages. If you prefer C++, another developer prefers Visual Basic, and yet another developer prefers C#, it is possible for each of you to develop the assemblies you are responsible for in the language you prefer and put them to work seamlessly.

Although that ability is great for the developer, it is not necessarily the best business decision. For example, imagine that you work for a development shop that codes primarily Visual Basic and one of your developers decides to code his portion of the project in C#. Although in theory this is not a problem and everything should work, what happens if that person leaves the company? Does the company have another person that knows C# and can take over the maintenance of the project? For the business, this could be a major risk and liability. This is one of many things that using enterprise templates can help with. Not only can you restrict projects to certain languages and which components and classes can be used, you can actually enforce how the application will be structured as well.

Introducing the Enterprise Template

An enterprise template is a mechanism by which you can restrict developers from coding in ways that do not fall in line with the policies and directives of your business. In addition, an enterprise template is also a means by which you can automate the creation of basic or shell applications, assemblies, and components. To understand an enterprise template, it is important to understand its architecture.

Enterprise Template Architecture

An enterprise template consists of three main parts: prototype, policy file, and custom help, (see Table 41.1 for more information). It can contain two types of projects: an enterprise template project (.etp) and a language-specific project (for C#, .csproj).

Table 41.1. Enterprise Template Parts




The prototype is the static content of the template. For example: In a Hello World program, the prototype would be the helloworld.cs file and any associated files that you choose to include.

Policy File

The policy file enables you to enforce the restrictions or policies of your company or development team.

Custom Help

Custom help enables you to add dynamic help or guidance to your template.


An interesting side effect of the enterprise template project is that it allows other enterprise template projects and language-specific projects to be contained within the project. In essence, this enables you to create solutions within solutions.

Even if you do not want to use any other feature available to enterprise templates, this is a significant benefit. By enabling you to contain multiple projects with an enterprise template, you are freed to break up your application logically. For example, many applications have a set of common libraries, common data libraries, and so on. Instead of creating a solution for each set of libraries, you can now create an enterprise template (.etp). The next time you need to work on those libraries while working on your project, all you have to do is add the enterprise template project to your solution.

Static and Dynamic Content

There are two types of content in the enterprise template. The first is static content. Static content is the material that remains the same for every instance of this template. For example, if you create a new console application by using the Visual Studio .NET Wizard, as in Listing 41.1, you will create an application created with a file called Class1.cs. With the exception of the namespace, it doesn't matter how many different times you create a project based on this template, the code file will always remain the same.

Listing 41.1. StaticAndDynamicContent Project
 using System; namespace StaticAndDynamicContent {   /// <summary>   /// Summary description for Class1.   /// </summary>   class Class1   {     /// <summary>     /// The main entry point for the application.     /// </summary>     [STAThread]     static void Main(string[] args)     {       //       // TODO: Add code to start application here       //     }   } } 

Dynamic content is the material that changes based upon user input. For example, when you create a new project, as in the new console project, you enter an application name. When the template generates the code for file Class1.cs, it generates a namespace that corresponds to the application name you entered. That is dynamic content.

Static Prototypes

Static prototypes are the easiest templates to understand and are a good example of static content. A static prototype is basically a shell application that can be used as the starting point for applications. Consider the following: Each time you create a Windows application, you have basically the same elements: a frame window with a menu, an About screen, and header comments for source control in each code file. In this situation, you could create a shell application that would contain these elements already laid out for you and save it as a static prototype template.

Unfortunately, there are two basic limitations with this approach. The first limitation is minor in that you cannot add dynamic content to the shell. Depending on the complexity of the requirements for your shell application, this might not be of much concern. The second limitation is a little more troubling in that this type of prototype might not be compatible with future versions of enterprise templates.

Subproject Wizards

Using Microsoft JScript, subproject wizards enable you to write custom content into the enterprise template. In an example of dynamic content, subproject wizards not only enable you to change namespaces and class names, they also make it possible for you to customize the application content based on any criteria that you choose, such as user permissions, time of day, or a random sequence of events. Subproject wizards are a powerful feature that supplements static prototypes. In addition, they will easily port to the next version of enterprise templates.

Custom Wizards

Similar to static prototypes and subproject wizards, custom wizards enable you to create custom application content. However, unlike the other techniques, a custom wizard is not based on built-in wizards contained within the IDE, which makes it the most complex technique to create. To create a custom wizard, you must use native C++ and build in a GUI to gather the user inputs and requirements. For more information about custom wizards, see the MSDN documentation.

    Visual C#. NET 2003 Unleashed
    Visual C#. NET 2003 Unleashed
    ISBN: 672326760
    EAN: N/A
    Year: 2003
    Pages: 316

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net