Sunday, July 26, 2009

Chapter 10-Lesson 3

  • An isolated task performed by Operating System is called a Process.
  • An application may be using 1 or more processes.
  • 32-bit processors can allocate a maximum of 4GB memory.
  • Within the memory, a Virtual Memory Manager keeps setting in the form of 4KB memory pages (chunks) that it assigns to processes as and when required.
  • Process class in System.Diagnostics namespace is used to handle processes through .NET
  • GetProcessById( ) static method takes ID of a process as argument and throws an ArgumentException if one is not found.
  • Performace for applications running on Windows can be measured using PerformanceCounter class, since it uses Registry to store values retrieved from code.
  • CounterCreationData may be used to specify Name, Type and other information related to a PerformanceCounter.
  • PerformanceCounterCategory class is used to manage and manipulate PerformanceCounter objects.
  • The Start( ) method of the Process class may be used to invoke an outside process.
  • If we use the overload of Start( ) method that takes Username and Password, then the UseShellExecute property must be set to false.
  • ProcessStartInfo object may also be passed to Start( ) method to specify process name and any Command-line arguments.
  • The StackTrace object represents the CLR Stack trace for a given application.
  • StackTrace is composed of StackFrames which represent individual method calls.

Chapter 10-Lesson 2

  • Debug and Debugger classes are used to programatically control the debugging of code.
  • .NET Runtime considers these classes only when program is built in Debug mode.
  • Debugger.Log( ) static method logs a given message to a target. For that, we need to confirgure the Listeners collection of the Trace object. (overloads define the target which could be a File, Output Window, etc)
  • Debugger class provides only two useful methods, namely Break( ) and Log( )
  • To have more control over debugging, we may use Debug class.
  • Debug.Assert( ) evaluates a given condition and if it is false breaks into the debugger and displays a given message.
  • The following methods send messages to the output window with difference only in either formatting or in use of conditions: Write( ), WriteLine( ), WriteIf( ), WriteLineIf( ).
  • The Print( ) method, however, sends message only to any attached Trace Listeners.
  • DebuggerBrowsable attribute over any member of class would determine its visibility in the Debug window whenever a breakpoint is set. (It is supported only in C#.NET)
  • DebuggerDisplay attribute determines how particular members of a class will be shown when an object is displayed in the Debug window. This method is used to decorate a class.
  • DebuggerHidden attribute tells the debgger to ignore the lines of code that it decorates.
  • DebuggerStepThrough attribute tells the debugger to Step Over the code it decorates. (This will save time for code that we are sure won't cause problems)
  • DebuggerVisualizer attribute is new in .NET 2.0
  • Trace class is implemented both in Debug and Release builds.
  • DefaultTraceListener is attached to the output window.
  • TextWriterTraceListener can redirect trace messages to a text file or Stream. (which is mentioned in the constructor)
  • XmlWriterTraceListener directs Trace or Debug information to a TextWriter or Stream object. However, the file will contain XML as ouput rather than plain text as in the above listener. (XML indeed contains more information than plain text)
  • XmlWriterTraceListener is new in .NET 2.0. If no filename is specified in constructor, CLR uses a GUID to create a filename.
  • EventLogTraceListener directs messages to an EventLog specified in the constructor.
  • DelimitedListTraceListener works the same as the above two but can use a delimiter to seperate entries.
  • All of the above listeners may be configured either by using code or the configuration file.

Chapter 10-Lesson 1

  • Event Log is available in Windows 2000 and above.
  • Event Logs should be avoided in partial trust environments.
  • System.Disgnostics nampespace is required to use objects such as EventLog.
  • WriteEntry( ) method of the EventLog class is used to actually create an entry.
  • The Entries property of the EventLog class is a collection containing objects of type EventLogEntries.
  • We may use any of the existing logs or we may choose to create our own by specifying its name in the EventLog constructor.

Tuesday, July 21, 2009

Chapter 9-Lesson 2

  • Installer class allows for creation of Setup files to help deploy our Assemblies.
  • Adding a class to the project that inherits from Installer class and overriding Install( ), Commit( ), Rollback( ) and Uninstall( ) methods will make an Application installable. Additionally we add a RunInstaller Attribute and set it to true.
  • To initiate an Installer programmatically, we use AssemblyInstaller or ComponentInstaller classes.

Chapter 9-Lesson 1

  • To put Application settings without using Windows Registry or database, we use configuration files in .NET
  • System.Configuration namespace is required to use classes that serve to read/write configuration information for .NET applications.
  • ConfigurationManager class provides properties and methods that return Configuration objects related to a particular Assembly.
  • CodeBase section of the configuration file tells the CLR which .NET Framework version to use.
  • ConfigurationSettings class is obsolete in .NET 2.0. Instead use ConfigurationManager.AppSettings
  • ConfigurationManager.AppSettings is a NameValueCollection containing strings
  • ConnectionString settings can be accessed as ConnectionStringSettingsCollection. It is exposed as ConfigurationManager.ConnetionStrings property.
  • It is better to use WebConfigurationManager in ASP.NET applications rather than ConfigurationManager.
  • We may create settings file by hand or we may add a SettingsFile to our project in order to visually create settings.
  • Configuration Settings are case-sensitive and white-space sensitive.
  • System.Runtime.Remoting section may be used to define settings for remote applications.

Saturday, July 18, 2009

Chapter 8-Lesson 3

  • Windows Services are processes that run in their own user-session without any UI.
  • Windows Services inherit from ServicesBase class.
  • The Main( ) method in a service contains code to call Run( ) method responsible for starting/executing the service.
  • The OnStart( ) method method should NOT stick into an infinte loop not should it get blocked. If we wish to create polling mechanism, use System.Timers.Timer object.
  • To override OnPause( ), OnContinue( ) and OnShutDown( ) methods, first set ServiceBase.CanPauseAndContinue or ServiceBase.CanShutdown to true.
  • Remember to always set the ServiceName property in the property pane.
  • System.ServiceProcess.ServiceController class is required to interact with a service from .NET Assembly.
  • To install the service, we need ServiceInstaller and ServiceProcessInstaller objects (automatically created in Visual Studio when we right click Service Design View and choose Add Installer)
  • LocalService is the least previliged Account and LocalSystem is the most previliged Account property for ServiceProcessInstaller.
  • While creating MSI installer for Service, add Project Output from Service Project as Primary Output and then add a Custom Action. (refer to page 462-463)
  • To record Exceptions for a Service use EventLog.

Chapter 8-Lesson 2

  • In-depth security means we are able to prevent damage caused due to a vulnerability in a (third-party) Assembly that we are not aware of, cannot prevent and cannot fix.
  • We may run Assemblies within an AppDomain with certain previliges by specifying an Evidence object to the Assembly. An Evidence is an object that behaves as an ID card displaying role/status of an entity. The authorities may then use this object to determine what kind of previliges an object (an Assembly in this case) recieves.
  • The Evidence object takes an object array in its constructor. We may store anything in that array or we may use any of the predefined enumerations to define a specific type of previlige-level. The Evidence object will then be passed when ExecuteAssembly( ) method is run on an AppDomain.
  • We may also pass such an Evidence object to CreateDomain( ) method to limit previliges for the entire AppDomain.
  • Certain properties of an AppDomain are configurable via the AppDomainSetup class, which may be passed along with the Evidence object while creating new AppDomains.