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...
Task 1 Open an existing application
1. On the Start menu, point to All Programs, point to Microsoft Visual Studio 2005, and then click Microsoft Visual Studio 2005. 2. To open an existing console application, in Microsoft Visual Studio 2005, click File, point to Open, and then click Project Solution. 3. To locate the existing console application, in the Open Project dialog box, click the Look in list, and then open the folder For Visual Basic 2005 For C 4. Double-click the crse3368ae_lab01.sln file.
Scenario Oau
You want to modify the order entry application to automatically print the documents when a customer order is placed. To do this, you need to write code in the Customer class to create a new event that will be fired when an order is placed for a customer. The high-level steps for this task are as follows Open the existing application. Open Microsoft Visual Studio 2005. Locate and open the existing console application crse3368ae_lab01.sln. Use E Labfiles Starter VB crse3368ae_lab01 or E Labfiles...
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 Ppr
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 XmlSerializer 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 FileInfo 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 SoapFormatter 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...
Scenario Msk
You have created a sample application to read and update the configuration setting. You now need to open this application and create an installer program for it. The principal tasks for this exercise are Create the installer program. Add a class to the crse3356ae_lab01 project. Create an installer program. 2. Write the code to read configuration settings. Use the Module1.vb or Program.cs file, depending on the language you are using.
ReadOnlyCollectionBase class
The read-only version of the CollectionBase class is the ReadOnlyCollectionBase class. This class represents an abstract base class for a strongly typed non-generic collection. The ReadOnlyCollectionBase class maintains an underlying or internal collection that stores elements that are added to it. This class makes the underlying collection or internal collection available by using the InnerList property. In the following code example, you create a read-only collection, giving it a constructor...
IsolatedStorageFileStream 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...
How TypeSafe and Reusable Code Is Created by Using Generics
Dim name As New ConmonData 0f String name.Value .NET Framework Dim version As New CommonData Of Single
Introduction Vnl
Although you are aware of the flexibility of non-generic collections, you may wonder how often you really need to store different data types in a single collection. For example, you have written a Web application and you want to record the user ID of a customer as the customer visits your Web site. You often get high volumes and cannot process all the visitors to the site. You want to store this data as an integer in a Queue so that you can process the orders in the background. Generic...
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...
OnDeserializedAttribute
When applied to a particular method in a class, this attribute specifies that the method has to be executed immediately after an object of the corresponding class is deserialized. This attribute can be used to execute methods performing some value fixing tasks on an object immediately after it is deserialized and before the object graph is reconstructed. In addition to the above listed event handler attributes, the .NET Framework serialization architecture provides the OptionalFieldAttribute...
StackFrame and StackTrace 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...
Introduction Gzu
Applications are generally required to work with large streams of information, such as text or XML files. You may need to transfer streams from one location to another and then save streams at a specific location. To reduce the amount of space that the stream uses, you can compress a stream before saving or transferring it and then decompress the stream before using it. During compression, the bytes in a file are first converted into a stream and then the stream is compressed. While the stream...
Implementation of the EventLog and EventLogPermission classes
You can view event logs programmatically in your code by using the EventLog class in the .NET Framework. The EventLog class allows you to read, write, and delete entries within a log. You can also create custom logs that you can use to write to from your application. You can also create, modify, and delete event sources. Logging permissions also enables you to protect event logs. The EventLogPermission class allows you to specify code access security permissions for event logs. When you use...
Task 1 Open an existing assembly
1. On the Start menu, point to All Programs, and then point to Microsoft Visual Studio 2005, and then click Microsoft Visual Studio 2005. The Microsoft Visual Studio 2005 window appears. 2. To open an existing Console application, click File, point to Open, and then click Project Solution. The Open Project dialog box appears. 3. In the Open Project dialog box, to locate the existing Console application, click the Look in list, select the folder For Visual Basic 2005 crse3357ae_lab1. For C 4....
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 InstallEventHandler delegate
The following code example shows the implementation of the InstallEventHandler delegate. The code example shows how you can use the InstallEventHandler delegate to handle the AfterInstall event in a custom installer class called MyCustomInstaller. For simplicity, the code example just prints a simple message in the console through the corresponding event handler method of the AfterInstall event. The event handler method is automatically called when the OnAfterInstall method of the installer...
Implementation of the GZipStream 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...
Management classes
Management classes are available within the System.Management namespace The following is the list of management classes ManagementQuery Class Is the base class for all managed query objects. ObjectQuery Class Is derived from the ManagementQuery class. You can use the ObjectQuery class to query WMI for classes or for instances of classes. EventQuery Class Is derived from the ManagementQuery class. You can use the EventQuery class to create queries that will look for specific WMI events....
Configure the TraceSource 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...
StreamingContext structure Provides information about the source and
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 ComponentInstaller 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...
Introduction Dxx
Consider a situation where you have multiple buttons, text boxes, and labels on a particular screen of an application. You want to display some of these items in different situations. You can add all these items to a generic collection that is set up to contain Windows forms controls. After that, it will be easy for you to loop through the controls in the collection and set their visible property to either true or false. If the collection is generic, you do not need to implicitly cast 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 ManagementEventWatcher 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...
Benefits of assemblies over COM components
There are many benefits of using .NET assemblies Versioning With assemblies, you can install and run multiple versions of the application simultaneously on the same machine, which is not possible with COM. If you install a brand new COM component or another version of the same COM component, it would normally overwrite the pre-existing version. This limitation of COM components has led to other problems. You can rectify this situation by having multiple versions of assemblies installed...
Use of the ManagementObjectSearcher 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 TraceListener 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 XmlSerializable Class Is Created by Using IXmlSerializable
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 ConfigurationElement and ConfigurationElementCollection
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 SortedDictionary 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...
Task 1 Open an existing Console application
1. On the Start menu, point to All Programs, point to Microsoft Visual Studio 2005, and then click Microsoft Visual Studio 2005. 2. To open an existing Console application, click File, point to Open, and then click Project Solution. 3. To locate the existing Console application, in the Open Project dialog box, click the Look in list, and then open the folder For Visual Basic 2005 E Labfiles Starter VB. For C E Labfiles Starter CS. 4. Double-click the crse3354ae_lab01 folder. 5. Double-click the...
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...
Lab Shutdown Izb
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. During the lab session, you implemented the functionality to serialize and deserialize the CRM Customer graph using the XmlSerializer class and used various XML attributes to format the resulting XML in a desired format. Considering the same CRM and Customer classes, what is an...
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...
Performance consideration while using the FileSystemWatcher class
Although it is useful to monitor file and directory events, you need to be careful when using the FileSystemWatcher class because it can affect application performance. The FileSystemWatcher class uses a buffer to store event notifications until it can address them. Windows notifies the FileSystemWatcher class of events by adding event notifications to the buffer. This buffer is similar to an array and is fixed in size. If many events occur simultaneously, the buffer may overflow and stop...
Implementation of the AssemblyInstaller 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 MemoryStream 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...
Introduction Of Vrl
Your company uses a third-party solution to check for attacks against routers on your network. It provides an executable file that can be run to check if an attack has occurred. This utility is very limited, but it is the only way that an independent application can check for attacks. The utility creates a file, logs the attack information in this file, and then closes. You have been asked to write an auditing application that generates certain attacks and checks if this system catches the...
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 CorrelationManager 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 TraceListener 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,...



