November 11, 2002

Implementing Object Pooling with .NET Remoting – Part I

Implementing Object Pooling with .NET Remoting Part I As you probably know, Object Pooling is a powerful feature available when hosting .NET or COM components in a COM+ application. I was quite surprised when I found out there was no built The Pool Manager The Pool Manager has been defined

CreateAppendElement – appending a XmlElement under another XmlNode

‘ Create an XmlElement object with inner text and make it a child of another ‘ XmlNode.’ Note: requires Imports System.XmlFunction CreateAppendElement(ByVal parentNode As XmlNode, ByVal name As String, _ Optional ByVal innerText As String = Nothing) As XmlElement ‘ Create a new XmlElement object, set the return value. Dim

LoadSoapData – deserializing an object from a file in SOAP format

‘ Deserialize an object from a file in SOAP format.Function LoadSoapData(ByVal path As String) As Object ‘ Open a file stream for input. Dim fs As FileStream = New FileStream(path, FileMode.Open) ‘ Create a SOAP formatter for this stream. Dim sf As New SoapFormatter(Nothing, _ New StreamingContext(StreamingContextStates.File)) ‘ Deserialize the

CloneObject – cloning an object by serializing it to a memory stream

‘ A reusable function that does object cloning’ by serializing it to a memory streamFunction CloneObject(ByVal obj As Object) As Object ‘ Create a memory stream and a formatter. Dim ms As New System.IO.MemoryStream(1000) Dim bf As New BinaryFormatter(Nothing, _ New StreamingContext(StreamingContextStates.Clone)) ‘ Serialize the object into the stream. bf.Serialize(ms,

DisplayXmlFile – loading a XML file in a TreeView

‘ Display a XML file in a TreeView’ Note: requires Imports System.Xml’ Example: DisplayXmlFile(“employees.xml”, TreeView1)Sub DisplayXmlFile(ByVal filename As String, ByVal tvw As TreeView) Dim xmldoc As New XmlDocument() xmldoc.Load(filename) ‘ Add it to the TreeView Nodes collection DisplayXmlNode(xmldoc, tvw.Nodes) ‘ Expand the root node. tvw.Nodes(0).Expand()End SubSub DisplayXmlNode(ByVal xmlnode As XmlNode,

SaveSoapData – serializing an object to file in SOAP format

‘ Serialize an object to file in SOAP format.Sub SaveSoapData(ByVal path As String, ByVal o As Object) ‘ Open a file stream for output. Dim fs As FileStream = New FileStream(path, FileMode.Create) ‘ Create a SOAP formatter for this stream. Dim sf As New SoapFormatter(Nothing, _ New StreamingContext(StreamingContextStates.File)) ‘ Serialize

EvaluateModule – a module for evaluating expressions

‘ A module for evaluating expressions, with support for’ parenthesis and many math functions’ Example:’ Dim expr As String = “(SQR(9)^3)+COS(0)*3+ABS(-10)”‘ txtResult.Text = Evaluate(expr).ToString ‘ ==> 27+3+10 ==> 40 Imports System.Text.RegularExpressionsModule EvaluateModule Function Evaluate(ByVal expr As String) As Double ‘ A number is a sequence of digits optionally followed by