Disclaimer

The views expressed on this weblog are mine alone and do not necessarily reflect the views of my employer, Avanade.

Search
Recomends...
  • Code Complete, Second Edition
    Code Complete, Second Edition
    by Steve McConnell
Login

Try Snip-It Pro 2.5 Free

Sni-It Pro is a code snippet manager with features designed to make you more productive. Version 2.5 has just been released and includes a ton of new features including support for code teplates, automatic commenting, snipplr integration and more. Try it Today!
> Learn More

Entries in Microsoft Exam 70-553 (49)

Saturday
Mar112006

Exam 70-553 - Access files and folders by using the File System classes.

Section 1

  • Part 3
    • Topic 3

Access files and folders by using the File System classes. (Refer System.IO namespace)

  • File class and FileInfo class
  • Directory class and DirectoryInfo class
  • DriveInfo class and DriveType enumeration
  • FileSystemInfo class and FileSystemWatcher class
  • Path class
  • ErrorEventArgs class and ErrorEventHandler delegate
  • RenamedEventArgs class and RenamedEventHandler delegate

Summary

The File Class exposes static methods for creating, copying, moving, deleting and opening files and can create filestream objects while the FileInfo class provides instance methods for the same functions. See the resources if you are not familiar with using these classes.

The Directory Class exposes static methods for creating, moving and enumerating through directories while the Directory Info Class provides instance methods for the same functions. See the resources if you are not familiar with using these classes.

The DriveInfo Class is new to .Net 2.0 and exposes information about drives like Available space, drive format, drive type, IsReady, Name, RootDirectory, TotalFreeSpace, Total Space and the volume label. The Drive Type is an enum with seven members: CDRom, Fixed, Network, NoRootDirectory, Ram, Removable and unknown.

The FileSystemInfo class is the base class that both the FileInfo and DirectoryInfo classes derive from. It can represent either a file or a directory so use this class when parsing large amounts of files or directories.

The FileSystemWatcher Class listens to file system change notifications for files or directories and raises events.

The Path Class is used to perform operations on strings that contain file and path information. By passing a string with a path in into it to some of this classes static methods you can get information like the path root, filename and extension without having to parse the string yourself.

The ErrorEventHandler delegate is the method that will handle the error event for a FileSystemWatcher Object. The ErrorEventArgs are the argurments (like the Exception itself) that will be passed into the method handling the event.

The RenamedEventHandler delegate is the method that will handle the file renamed event for a FileSystemWatcher object. The RenamedEventArgs contain the argurments (old file path, new file path) that will be passed into the method handling the event.

Other Resources & Links:

File Class
http://msdn2.microsoft.com/en-us/library/system.io.fileinfo(VS.80).aspx

FileInfo Class
http://msdn2.microsoft.com/en-us/library/system.io.fileinfo(VS.80).aspx

Directory Class
http://msdn2.microsoft.com/en-us/library/system.io.directory(VS.80).aspx

DirectoryInfo Class
http://msdn2.microsoft.com/en-us/library/system.io.directoryinfo(VS.80).aspx

DriveInfo Class
http://msdn2.microsoft.com/en-us/library/system.io.driveinfo(VS.80).aspx

DriveType Enumeration
http://msdn2.microsoft.com/en-us/library/system.io.drivetype(VS.80).aspx

FileSystemInfo Class
http://msdn2.microsoft.com/en-us/library/system.io.filesysteminfo(VS.80).aspx

FileSystemWatcher Class
http://msdn2.microsoft.com/en-us/library/system.io.filesystemwatcher(VS.80).aspx

Path Class
http://msdn2.microsoft.com/en-us/library/system.io.path(VS.80).aspx

ErrorEventArgs
http://msdn2.microsoft.com/en-us/library/system.io.erroreventargs(VS.80).aspx

ErrorEventHandler Delegate
http://msdn2.microsoft.com/en-us/library/system.io.erroreventhandler(VS.80).aspx

RenamedEventArgs
http://msdn2.microsoft.com/en-us/library/system.io.renamedeventargs(VS.80).aspx

RenamedEventHandler
http://msdn2.microsoft.com/en-us/library/system.io.renamedeventhandler(VS.80).aspx
Wednesday
Mar082006

Exam 70-553 - Control the serialization of an object into XML format by using the System.Xml.Serialization namespace.

Section 1

  • Part 3
    • Topic 2

Control the serialization of an object into XML format by using the System.Xml.Serialization namespace.

  • Serialize and deserialize objects into XML format by using the XmlSerializer class.
  • Control serialization by using serialization attributes.
  • Implement XML Serialization interfaces to provide custom formatting for XML serialization.
  • Delegates and event handlers provided by the System.Xml.Serialization namespace

Summary

The XmlSerializer Class can be used to easily serialize and deserialize an object to Xml. Below are examples of Serializing and Deserializing an object using this class:

Serialization
MyTypeOfObject myObject = new MyTypeOfObject();
XmlSerializer mySerializer = new XmlSerializer(typeof(MyTypeOfObject));
XmlTextWriter myWriter = new XmlTextWriter("MyObject.xml", System.Text.Encoding.UTF8);
mySerializer.Serialize(writer, myObject);
myWriter.Close();

Deserialization
XmlSerializer mySerializer = new XmlSerializer(typeof(MyTypeOfObject));
XmlTextReader myReader = new XmlTextReader("MyObject.xml");
MyTypeOfObject myObject = (MyTypeOfObject) mySerializer.Deserialize(myReader);

To Control Serialization by using Serialization attributes simple apply the attributes described in the previous section to public properties and methods.

The System.Xml.Serialization Namespace provides the IXmlSerializable Interface to provide custom formatting for XML serialization. For a good explanation for why you would use this interface read the following two paragraphs taken from msdn2.

There are two reasons to implement this interface. The first is to control how your object is serialized or deserialized by the XmlSerializer. For example, you can chunk data into bytes instead of buffering large data sets, and also avoid the inflation that occurs when the data is encoded using Base64 encoding. To control the serialization, implement the ReadXml and WriteXml methods to control the XmlReader and XmlWriter classes used to read and write the XML.

The second reason is to be able to control the schema. To enable this, you must apply the XmlSchemaProviderAttribute to the serializable type, and specify the name of the static member that returns the schema. See the XmlSchemaProviderAttribute for an example.

The following list of delegates and event handler comes right from the first article in the resources

UnknownAttribute event - thrown when the serializer encounters an unknown attribute. By default the Xml serializer ignores unknown attributes.

UnknownElement event - thrown when the serializer encounters an unknown element. By default the Xml serializer ignores unknown elements.

UnknownNode event -thrown when the serializer encounters an unknown node. By default the Xml serializer ignores unknown node.

UnreferencedObject event - section 5 of the SOAP document at w3c. Basically you can reference other object within the same Xml document. This event is thrown when it can't find the referenced object.

Other Resources & Links:

XmlSerializer.Net Tutorial
http://www.topxml.com/xmlserializer/default.asp

IXmlSerializable Interface
http://msdn2.microsoft.com/en-us/library/system.xml.serialization.ixmlserializable(VS.80).aspx

What Did you learn Today (List of Xml Delegates/Events)
http://blog.denoncourtassociates.com/default,date,2006-02-01.aspx

Tuesday
Mar072006

Exam 70-553 - Serialize or deserialize an object or an object graph by using runtime serialization techniques.

Section 1

  • Part 3
    • Topic 1

 

Serialize or deserialize an object or an object graph by using runtime serialization techniques. (Refer System.Runtime.Serialization namespace)

  • Serialization interfaces
  • Serilization attributes
  • SerializationEntry structure and SerializationInfo class
  • ObjectManager class
  • Formatter class, FormatterConverter class, and FormatterServices class
  • StreamingContext structure

Summary

Serialization Interfaces include the ISerializable interface which allows you to control the serialization process. In order to implement ISerializable you must provide a GetObjectData method as well as a specialized constructor that accepts two parameters: an instance of SerializationInfo, and an instance of StreamingContext.

Other Seriailization Interfaces include (This list comes from the list of Interfaces in the System.Runtime.Serialization Namespace as indicated on msdn2)

IDeserializationCallback - Indicates that a class is to be notified when deserialization of the entire object graph has been completed.

IFormatter - Provides functionality for formatting serialized objects.

IFormatterConverter -Provides the connection between an instance of SerializationInfo and the formatter-provided class best suited to parse the data inside the SerializationInfo.

IObjectReference - Indicates that the current interface implementer is a reference to another object.

ISerializationSurrogate - Implements a serialization surrogate selector that allows one object to perform serialization and deserialization of another.

ISurrogateSelector - Indicates a serialization surrogate selector class.

The following list of XmlAttributes came from the first link in the resources section:

XmlRoot – Controls the XML root. ElementName, namespace..

XmlElementAttribute – Serialize the field/property as an element in the XML document.

XmlAttributeAttribute – Aside from being the victim of strict naming conventions, it tells the XML serializer to serialize field/prop as an attribute in the XML document

XmlIgnoreAttribute – Tells the XML Serializer to omit the field/property.

XmlEnumAttribute – Controls the name of an enumeration member (Not the enum name, a member of the enum)

XmlTextAttribute - Tells the XML Serializer that the member contains raw XML text.

XmlTypeAttribute - Controls the XML Schema (XSD) that is generated by the XmlSerializer. It is used to specify other namespaces and types when serializing.

XmlIncludeAttribute - Allows the XmlSerializer to recognize a type when it serializes or deserializes an object. Used when deserializing custom types.

XmlChoiceIdentifierAttribute - Tells the XML Serializer that the type should be XSI:Choice. It is used in conjunction with an enum field/prop in the class to tell the serializer where to get its info from.

XmlArrayAttribute Class - Specifies that the XmlSerializer must serialize a particular class member as an array of XML elements.

XmlArrayItemAttribute – Specifies the types that are contained in an XmlArray. This is used when you are serializing polymorphic classes.

XmlAnyAttributeAttribute – Any attributes that are not matched up during deserialization is placed in the field decorated with this attribute. Field must be an array of XmlAttribute.

XmlAnyElementAttribute – Any elements that are not matched up during deserialization is placed in the field decorated with this attribute. Field must be an array of XmlElement.

XmlNamespaceDeclarationsAttribute – Decorates a field that returns XmlSerializerNamespaces. That field will be use to get namespace prefixes during serialization.

XmlSchemaProviderAttribute – "When applied to a type, stores the name of a static method of the type that returns an XML schema and a XmlQualifiedName that controls the serialization of the type. " Used by WSDL.exe to return the schema for the class. Target class must implement IXmlSerializable. New to 2.0.

XmlSerializerAssemblyAttribute – Specifies the name of an assembly that the Xml Serializer can use. If specified, the Xml Serializer doesn’t need to create a temporary assembly. New to 2.0

XmlSerializerVersionAttribute – Signifies that the code was generated by the serialization infrastructure and can be reused for increased performance, when this attribute is applied to an assembly. I’m not sure I should use this attribute. I think this is used by code produced by sgen.

The SerializationEntry Structure encapsulates the name, type and value of the object being serialized.

The ObjectManager Class is used by the formatter to keep track of object during deserialization. It checks and handles objects for forward references (a reference to an object that has not been deserialized) and also raises events.

The Formatter Class is used to determine the base abstract class for Formatter Implementation that format the data for Serialization. Two Implementations of this class include the BinaryFormatter and SOAPFormatter.

The FormatterConverter Class is used to Convert Objects to .Net CLR value types. It containes methods like ToString, ToInt, ToByte, etc.

The FormatterServices Class is used to give information to the formatter, including retrieving a list of the serializable members in their object, as well as their types and values.

The StreamingContext Structure encapsulates the source and destination of a Serialized stream. During serialization,the state property exposes the destination of the transmitted data. During deserialization, the source of the data.

Other Resources & Links:

ISerialization Interface
http://msdn2.microsoft.com/wf4375ks(en-US,VS.80).aspx

System.Runtime.Serialization Namespace
http://msdn2.microsoft.com/system.runtime.serialization.aspx

What Did you learn Today (List of Xml Attributes)
http://blog.denoncourtassociates.com/default,date,2006-02-01.aspx

SerializationEntry Structure
http://msdn2.microsoft.com/wb7s1ykw(en-US,VS.80).aspx

ObjectManager Class
http://msdn2.microsoft.com/dd3w47bb(en-US,VS.80).aspx

.Net Serialization
http://www.codeguru.com/columns/DotNet/article.php/c6595/

FormatterConverter Class
http://msdn2.microsoft.com/cb3z6hzc(en-US,VS.80).aspx

StreamingContext Structure
http://msdn2.microsoft.com/t16abws5(en-US,VS.80).aspx

Monday
Mar062006

Exam 70-553 - Debug and trace a .NET Framework application by using the System.Diagnostics namespace.

Section 1

  • Part 2
    • Topic 2

 

Debug and trace a .NET Framework application by using the System.Diagnostics namespace.

  • Debug class and Debugger class
  • Trace class, CorrelationManager class, TraceListener class, TraceSource class, TraceSwitch class, XmlWriterTraceListener class, DelimitedListTraceListener class, and EventlogTraceListener class
  • Debugger attributes

Summary

The Debug class exposes properties and methods to help you debug your code. It exposes methods like Write, WriteLine, WriteLineIf, WriteIf and Assert for displaying methods. It also exposes a Listeners collection which monitor the output.

The Debugger class communicates with the debugger programmatically. With it you can log message, check if the debugger is attached or even call out a break point.

The Trace Class is just like the debugger but also exists in release builds. The ListnersCollection is the collection of TraceListener objects monitoring the output.

The Trace Source Class is new to .Net. It enables you to configure a group of Listeners through configuration and then turn them on in the switches section of your configuration file. Each entry represents an instance of the TraceSwitch class. See the Resources for a better understanding of this.

The XmlWriterTraceListener, DelimitedListTraceListener, and EventlogTraceListener are all listeners that write output to different sources in different formats.

Debugger Attributes are used to give you control over what and how properties and method appear in the watches during debugging.

Other Resources & Links:

Debug Class
http://msdn2.microsoft.com/en-us/library/system.diagnostics.debug.aspx

Debugger Class
http://msdn2.microsoft.com/en-us/library/7kzs2ysh(en-US,VS.80).aspx

Trace Class
http://msdn2.microsoft.com/en-us/library/36hhw2t6(en-US,VS.80).aspx

Trace Source Class
http://msdn2.microsoft.com/en-us/library/hd7z6as6(en-US,VS.80).aspx

TraceSwitch Class
http://msdn2.microsoft.com/en-us/library/eb1fee91(en-US,VS.80).aspx

Tracing in .NET and Implementing Your Own Trace Listeners
http://www.15seconds.com/issue/020910.htm

DataTips, Visualizers and Viewers Make Debugging .NET Code a Breeze
http://msdn.microsoft.com/msdnmag/issues/04/05/VisualStudio2005Debugging/

Sunday
Mar052006

Exam 70-553 - Embed configuration management functionality into a .NET Framework application.

 Section 1

  • Part 2
    • Topic 1

 

 

Embed configuration management functionality into a .NET Framework application. (Refer System.Configuration namespace)

  • Configuration class and ConfigurationManager class
  • ConfigurationSettings class, ConfigurationElement class, ConfigurationElementCollection class, and ConfigurationElementProperty class
  • Implement IConfigurationSectionHandler interface
  • ConfigurationSection class, ConfigurationSectionCollection class, ConfigurationSectionGroup class, and ConfigurationSectionGroupCollection class
  • Implement ISettingsProviderService interface
  • Implement IApplicationSettingsProvider interface
  • ConfigurationValidationBase class
  • Implement IConfigurationSystem interface

Summary

.Net 2.0 has completely revamped how it handles Configuration. So much in so, that Enterprise Library 2.0 no longer contains a Configuration Application Block since most of the functionality that it exposed is built right into the core .Net library.

The Configuration Class represents a merged view of the configuration settings that apply to a physical or logical entity (computer, application, web site etc). This class exposes AppSettings (Collection of Name Value Pairs), ConnectionStrings (Configuration Section designed specifically for Connection Strings), A Collection of Sections and Section Groups (for dealing with other types of sections. It also exposes methods to retrieve Sections in a variety of ways as well as has the ability to save changes or save Changes to another file (Save as).

The Configuration Manager Class gives you the ability to access a particular application’s Configuration Class Instance. It exposes methods like OpenExeConfiguration, OpenMachineConfiguration, OpenMappedExeConfiguration, OpenMappedMachineConfiguration to obtain handles to configurations. It also exposes a RefreshSection method to refresh the named section. It also has AppSettings and ConnectionString properties which return the section for the current applications configuration.

The ConfigurationSettings Class exposes the AppSettings object and the GetSection method in a read only fashion.

The ConfigurationElement class represents a section that is serialized into Xml like AppSettings and ConnectionStrings. It uses Attributes to define its default value, validation rules among other features. The public methods will be mapped to attributes of the add node in Xml.

The ConfigurationElementCollection Represents a Collection of Configuration Elements. A good way to think of this is in terms of AppSettings. Each Add Node represents one Configuration Element instance with two public properties: name and value. All the different Add Nodes together are the ConfigurationElementCollection. And to tie it all together the Configuration Section represents the Configuration Section and Contains the ConfigurationElementCollection that is contains.

Every ConfigurationElement object creates an internal ConfigurationPropertyCollection collection of ConfigurationProperty objects that represents either the element attributes or a collection of child elements. A ConfigurationElementProperty instance can be used to apply validation rules. (I suspect these properties can be specified as attributes, but am not sure).

The IConfigurationSectionHandler is used to define the interface for creating a ConfigurationSectionHandler. To implement this interface simply expose a Create Method that returns an Object.

The ConfigurationSection Class represents one Node that may contain a ConfigurationElement or ConfigurationElementCollection. It exposes properties to lock Elements and attributes for editing and retrieve elements. The ConfigurationSectionCollection Class represents a collection of ConfigurationSections. It exposes methods for managing the Collection of sections (Add, Remove, count, etc).

The ConfigurationSectionGroup Class represents the container for groups of ConfigurationSections. The ConfigurationSectionGroupCollection allows you to ititerate through all the ConfigurationSettingGroups in a configuration. The Configuration Class mentioned in the second paragraph of this section exposes a ConfigurationSettingsGroupCollection which gives you access to ConfigurationSectionGroups which give you access to ConfigurationSection Collections and so on.

The ISettingsProviderService interface defines the interface for providing an alternative application settings provider. To implement this interface provide a GetSettingsProvider method which returns an object that derives from the SettingsProvider Class. This object exposes methods like GetPropertyValues and SetPropertyValues. The only SettingsProvider that comes with the core library is the LocalFileSettingsProvider which stores it to the filesystem as Xml.

The IApplicationSettingsProvider Interface defines the interface for providing custom storage for applicationsettings. It is the interface that the SettingsProvider Class and LocalFileSettingsProvider Class implement.

The ConfigurationValidatorBase Class is the base class for creating custom validators that can be applied to ConfigurationElementProperties.

The IConfigurationSystem interface defines the interface for providing access to configuration. It exposes two methods: GetConfig and Init. GetConfig returns an Object.

Other Resources & Links:

Configuration Class
http://msdn2.microsoft.com/en-us/library/system.configuration.configuration.aspx

ConfigurationManager Class
http://msdn2.microsoft.com/en-us/library/system.configuration.configuration.aspx

ConfigurationSettings Members
http://msdn2.microsoft.com/en-us/library/8737esh7(en-US,VS.80).aspx

ConfigurationSection Class
http://msdn2.microsoft.com/en-us/library/x0kca287(en-US,VS.80).aspx

ConfigurationSectionCollection Class
http://msdn2.microsoft.com/en-us/library/wfda1bhk(en-US,VS.80).aspx

ConfigurationSectionGroup Class
http://msdn2.microsoft.com/en-us/library/z6ckd2fd(en-US,VS.80).aspx

ISettingsProviderService Interface
http://msdn2.microsoft.com/en-us/library/k7x3hfde(en-US,VS.80).aspx

IApplicationSettingsProvider Interface
http://msdn2.microsoft.com/en-us/library/d7z8hf8y(en-US,VS.80).aspx

ConfigurationValidatorBase Class
http://msdn2.microsoft.com/en-us/library/ms134341(en-US,VS.80).aspx

List of Items In Configuration Files
http://twmurph.blogspot.com/2006/02/lists-of-items-in-configuration-files.html