Task 2 Write the code for the generic Vehicle class

To define the structure for the Vehicle class For Visual Basic 2005 Open the Modulel.vb file from Solution Explorer and then type the following code inside the class Vehicle. Public ReadOnly Property Vin() As T Get Public Property Description() As T Get tDescription value End Set End Property For C Open the Program.es file from Solution Explorer and then type the following code inside the class Vehicle. protected T tVin protected T tYear protected T tMake protected T tModel protected T tColor...

Attributes for custom XML format

You can apply these XML serialization attributes to classes and class members to control the way in which XmlSerializer serializes or deserializes an instance of the class. The following table describes the attributes for the custom XML format. XmlAnyAttributeAttribute contains arbitrary data, which is sent as part of an XML document, as the attribute of an element. The purpose of this attribute is to set up a field or property to receive XML attributes that do not map to any fields or...

Working with Byte Streams

A stream serves as a conduit between application code and a data backing store. A stream performs three primary tasks reading, writing, and seeking. The FileStream class is used to stream data to and from a file. The MemoryStream class is used to stream data to and from application memory. The BufferedStream class is used to provide an additional memory buffer to another type of stream.

Implementation of query strings

The following code sample shows how to use query strings to query WMI programmatically to create a system report. This system report contains the name and state of each Windows service, the connection name and username for each network connection, the name and serial number of each virtual device driver, the product name of every network adapter, and the name and process ID of every process currently executing in the Windows operating system. You use ManagementObjectSearcher to query the CIM...

How Custom Classes Are Created by Using Serialization Interfaces

Consider that you are creating an application and you need to serialize your objects to be stored in permanent structures or passed to another application for further processing. For example, you may need to serialize the information from a customer to a credit card processing application to complete the transaction and arrange the payment. Sometimes, when you are communicating with the components, you can use built-in serialization classes or any built-in classes available in the .NET...

How Data Is Converted to a Serialized Format by Using Formatter Classes

Consider that you have been assigned a task of creating an application that customers can use to order supplies from your company. These customers may belong to various classes such as New, Standard, and Preferred. You will need to store the data about the customers and use the stored data to allow the customers to place orders. Preferred customers gain a 10 percent savings on all orders. When a customer attains the Preferred status, you need to change the storage of the Customer object while...

Crse3359ae Lab01

You want to customize the way in which the values for certain members of the CRM and Customer class are stored in a target XML file during serialization. For this, you need to apply appropriate XML attributes to the members of the Customer and CRM class. The principal tasks for this exercise are Open an existing Console application. Apply XML attributes to the members of a class. 1. Open an existing Console application. Open Microsoft Visual Studio 2005. Locate and open the existing Console...

Crse3358ae Lab01

You want to list the existing journal entries represented by individual files in a subdirectory named Entries. For this you need to use the DirectoryInfo class to retrieve the list of files in the corresponding subdirectory. The principal tasks for this exercise are as follows Open an existing Console application. Write code to list the existing journal entries by using the System.IO.DirectoryInfo class. 1. Open an existing Console application. Open Microsoft Visual Studio 2005. Locate and open...

Introduction

The global assembly cache is a system-wide code cache managed by the CLR. Any assembly that needs to be shared among other applications is typically installed in the global assembly cache. The global assembly cache acts as a central repository for registering assemblies. Just as the Windows registry is a single entity containing all the information about the operating system, the global assembly cache is a system folder, where most of the shared assemblies reside. It is possible to share an...

Purpose of the Xml Serializer class

The XmlSerializer class maps the .NET Framework classes to XML types. In general, the serialized XML does not include type information when the object is serialized because the information is retrieved from the type when it is deserialized. However, this does not occur with a serialized object. In this case, the serializer embeds the XML-type information about the data being serialized. By default, the XmlSerializer class maps each field and property of the object to be serialized to an XML...

Implementation of the File and File Info classes

The following code example shows the implementation of the File and FileInfo classes in Visual Basic and C . The code example determines whether or not the MyFile.txt file exists by using the File class. If this file does not exist, it is created by using an instance of the FileInfo class. Dim fileName As String MyFile.txt Dim fileInfo As FileInfo New FileInfo C Windows Temp fileName Dim fileStream As FileStream fileInfo.Create fileStream. Close End If string fileName MyFile.txt FileInfo...

Implementation of the Soap Formatter class

The following code sample shows the implementation of SoapFormatter class in Visual Basic and C . The code defines a class named SoapFormatterDemo to demonstrate serialization and deserialization by using the SoapFormatter class. The code creates an object of ArrayList collection named colors to store the names of colors and adds four colors to the collection. The code uses the SoapFormatter class to write the state of an object of ArrayList to a file named Colors.soap. The code writes the...

Isolated StorageFile Stream class

The IsolatedStorageFileStream class exposes a file within the isolated storage. The IsolatedStorageFileStream class works with the IsolatedStorageFile class to read, write, and create files in isolated storage. The IsolatedStorageFileStream class also inherits from the FileStream class, which further inherits from the Stream class. Therefore, you can use the IsolatedStorageFileStream class at those instances where either the FileStream class or the Stream class is used. For example, you can use...

Implementation of the IDisposable interface

The following code example shows the implementation of the IDisposable interface in a class named CustomerDataAccess. The class implements the Dispose method defined by IDisposable to provide a way to release resources explicitly. The Dispose method releases the resources with the help of a supporting custom-defined ReleaseResource method and removes the current object from the finalization queue. This relieves the garbage collector from calling the finalizer of an object after the object is...

Stack Frame and Stack Trace classes

StackFrame class Provides information about a stack frame. A stack frame is the physical representation of a function call on the call stack for the current thread. A StackFrame object is created and placed on the call stack for every function call made during the execution of a thread. The members of the StackFrame class are GetFileName method You can use this method to retrieve the name of the file that has provided the code in execution. If the file name cannot be determined, the method...

Implementation of the event handler attributes

The following code sample shows how to implement event handler attributes by using the ISerializable interface and IDeserializableCallback with CustomFormatter and its methods. The code implements both the ISerializable and the IDeserializableCallback interfaces in a class named Rectangle, which gives the result of the area of a rectangle whose length and width are passed through the constructor of the class. The class defines five variables, which are initialized through a constructor and five...

Trace listener classes

The following table describes the various trace listener classes. This class is the base class used by the listeners that trace and debug output. To add a new trace listener or remove an existing trace listener, you need to modify the configuration file. This class is available in the System.Diagnostics namespace. This class transfers tracing or debugging output as XML-encoded data to a TextWriter or to a Stream such as a FileStream. Its XML elements and attributes specify the type of trace...

Wql Queries Getfilesecurity Class

Your organization has 600 servers running Windows Server 2003. Seventy percent of these servers are used in production and the rest in development. The systems administrators in your organization need to know exactly what services are running on which servers. Often, the systems administrators have to make emergency changes to deal with production issues. You need to generate a weekly report that details the services running on each server, such as the service account under which the services...

Implementation of custom validation class

The following code example shows the implementation of ConfigurationValidatorBase class in Visual Basic and C . Inheri ts Configurati onValidatorBase Public Overrides Sub Validate ByVal value Throw New Exception String is longer Public Overrides Function CanValidate ByVal type As System.Type As Boolean If type Is GetType String Then Return True Return False End If End Function End Class class myTextValidator ConfigurationValidatorBase public override void Validate object value throw new...

Implementation of the GZip Stream class

The following code example shows the implementation of the GZipStream class in Visual Basic and C . The code example shows how to use the GZipStream class to compress and decompress a file by using the GZip compression format. Dim myFileStream As FileStream Dim myZipStream As GZipStream Dim myFile As FileInfo Dim originalXMLFileName As String UserData.xml Dim decompressedXMLFileName As String _ UnzippedUserData.xml Dim compressedXMLFileName As String _ UserData_Zipped.gz Dim dsTest As New...

Configure the Trace Source class by using a configuration file

With the help of a configuration file, you can configure and implement the TraceSource class. The following configuration file shows how to configure and implement the TraceSource class. First, you add a trace source named TraceTest that will write trace information to the console. You add a trace switch named SourceSwitch and enable tracing by setting the trace level to Warning. Then, you write trace information to the console file by adding ConsoleTraceListener as a shared listener and add...

Streaming Context structure Provides information about the source and destination of a specific serialized stream

While working with objects, you need to implement serialization in some form to save information in the object or to move the object to another process. Serialization is a functionality that is critical while building a distributed application. You can use the built-in classes or create custom classes to serialize data in the distributed application. While implementing custom serialization and deserialization functionalities in a class, you need to take care of two things. During the...

Purpose of the Component Installer class

The .NET Framework not only offers the AssemblyInstaller class to collectively invoke custom installer classes to start an installation process, but it also provides the ComponentInstaller class that has the ability to let custom installer classes access information from other running components during the installation process. This is especially useful when you do not want the user to enter certain information to complete the installation when that information is already available on the...

Interfaces used to validate the configuration data

Although there are predefined classes in the .NET framework that you can use to programmatically access application settings, specific sections within a configuration file, or even the custom application settings, you may want to create your own classes that provide such services. You can do that by implementing the validation interfaces described in the following table. Manages the access to various sections of the configuration files. Helps you define a settings provider for custom settings...

Implementation of the Management EventWatcher class

The following code sample shows the implementation of the ManagementEventWatcher class in both Visual Basic and C . The code sample displays information about the new process in the console. First, a new query object that looks for an instance creation event is created. An instance creation event occurs when a new instance of an object is created in the CIM. In this case, you are looking for objects of type Win32_Process that are created when a new process is started on a computer. The code...

Use of the Management ObjectSearcher class with query strings

The following code sample shows how to retrieve an enumeration of paused services using the ManagementObjectSearcher class programmatically. In this code sample, you create a new instance of the ManagementObjectSearcher named mos with the scope of root CIMV2 and the query SELECT FROM Win32_Service WHERE State 'Paused' that finds paused services. You then loop through the results of the query and display the paused services that are found. Imports System Imports System.Management Public Class...

Implementation of the Trace Listener class

You can implement the TraceListener class by using Visual Basic or C to send the trace information to an output location. The following code sample shows the implementation of the TraceListener class. Class SampleTraceListener Inherits TraceFilter Public Overrides Function Shou1dTrace ByVa1 cache As TraceEventCache _ , ByVal source As String, ByVal eventType As TraceEventType _ , ByVal id As Integer, ByVal formatOrMessage As String, ByVal args As , ByVal data1 As Object, ByVal data As Object As...

How a Custom Xml Serializable Class Is Created by Using IXml Serializable

IXmlSerializable interface provides custom formatting for XML serialization and deserialization f The methods that control serialization and deserialization in the The IXmlSerializable interface provides custom formatting for XML serialization and deserialization. The XmlSerializer class implements the IXmlSerializable interface, and the custom classes use it to control how they will be serialized or deserialized through the XmlSerializer class. For a finer granularity of control on the code in...

Implementation of the Configuration Element and Configuration ElementCollection classes

The following code example shows how you can create a user-defined configuration element, MyConfigElement, by inheriting the ConfigurationElement class in Visual Basic and C . The MyConfigElement class validates the value assigned to its ID property by using an instance of the ConfigurationElementProperty class. The code example also shows how you can create a user-defined configuration element collection, MyConfigElements, by inheriting the ConfigurationElementCollection class, to create and...

Implementation of the generic Sorted Dictionary class

The following code example shows implementation of the generic SortedDictionary class in Visual Basic and C . Public Sub New ByVal Code As String, ByVal Name As String Me._code Code Me._name Name End Sub Public ReadOnly Property Code As String Get Return Me._code End Get End Property Public Property Name As String Get Set ByVal value As String Me._name value End Set End Property End Class Dim deptSD As New SortedDictionary Of String, Department deptSD.Add MKT, New Department MKT, Marketing...

Lab Shutdown

After you complete the lab, you must shut down the 2956A-LON-DEV1 virtual machine and discard any changes. Important If the Close dialog box appears, ensure that Turn off and delete changes is selected, and then click OK. You can use the property procedures that get and set players' information in the Player structure to include validation logic. For example, you can include validation code inside the BirthYear property block to check the upper and lower age limit of a player. Instead, if you...

Scenario

You need to develop an application to manage the players on a sports team. To do this, you will first create a type named Player to add the information of a new player. Then, you will use a Console-based application for this exercise, and a portion of the application is already created. The principal tasks for this exercise are as follows Open an existing Console application. Write the code for the Player class. 1. Open an existing Console application. Open Microsoft Visual Studio 2005. Locate...

Implementation of the Assembly Installer class

The following code example shows how to implement the AssemblyInstaller class. The code example shows how you can use the AssemblyInstaller class to invoke the installer of the AssemblyWithInstallerClass assembly. The code example creates an instance of the AssemblyInstaller class with the name of the assembly to be installed and installation parameters as arguments. The instance of the AssemblyInstaller class is then used to install the given assembly with the help of the Install method. This...

Members of the Trace class

The following table describes the members of the Trace class and gives a description for each. You use this method to check for a condition and display a message if the condition is false. The Assert method displays as the output of the call stack with the file and line number for each line of code. You can use this method to find logical errors when developing a program. By default, the Assert method displays a message box when the application runs in a user-interface mode. You use this method...

Implementation of the Memory Stream class

The following code example shows an implementation of the MemoryStream class in Visual Basic and C . The code example shows how to implement the MemoryStream class to read from and write to a byte array in memory synchronously. The code example shows how to store a portion of the course overview in the application memory. The MemoryStream class s a concrete MemoryStream class and is used to stream data to and from Class application memory, both synchronously Dim overview As Byte New...

Implementation of the configuration section classes

The following code example shows how to implement the configuration section classes in Visual Basic and C . The code example shows how to retrieve information related to the configuration sections in the configuration file by using the ConfigurationSectionGroup, ConfigurationSection, ConfigurationSectionCollection and ConfigurationSectionGroupCollection classes. The code example opens the configuration file for the current assembly and retrieves a collection of section groups in the...

Implementation of the Correlation Manager class

The following code sample shows how to use the CorrelationManager class programmatically in Visual Basic and C . In this code sample, you are creating two methods, EatContext and DrinkContext. These methods are executed concurrently on different threads. For the listener to know what information is received from each method, you call the method. Now, you can distinguish trace information based on method and thread. Dim listener As TextWriterTraceListener New TextWri li stener.TraceOutputOptions...

Configure the Trace Listener class by using a configuration file

With the help of a configuration file, you can configure and implement the TraceListener class. The following configuration file shows how to configure and implement trace listeners. In this file, you add a trace switch named MagicTraceSwitch and enable tracing by setting the trace level to 3, which indicates information. Then, you write trace information to the myListener.log file by adding myListener of the type TextWriterTraceListener. By setting autoFlush to false in the configuration file,...