<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="2" MadCap:lastHeight="120" MadCap:lastWidth="624" MadCap:disableMasterStylesheet="true" MadCap:tocPath="Basics Operations & Concepts|Activation|Transparent Activation|TA Enhanced Example" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem"> <head><title>TA Enhancement With Db4oTool </title> <script type="text/javascript">/* <![CDATA[ */ window.onload = function(){ var pathToFlash = $('html').attr('MadCap:PathToHelpSystem') + 'Content/Resources/Code/ZeroClipboard.swf'; ZeroClipboard.setMoviePath(pathToFlash); function bindToClipBord(element,content){ var clip = new ZeroClipboard.Client(); clip.setText(content); clip.glue(element); }; if(location.protocol==='file:'){ $('.copylink-marker').remove(); } else{ $('.copylink-marker').each(function(){ var text = $(this).parent().parent().children('.prettyprint').html(); $(this).hover(function(){ bindToClipBord(this,text); }, function(){}); }); } prettyPrint(); }; /* ]]> */</script> <link href="../../../../SkinSupport/MadCap.css" rel="stylesheet" /> <link href="../../../../Resources/Stylesheets/OnlineStyle.css" rel="stylesheet" /> <script src="../../../../SkinSupport/MadCapAll.js"> </script> <script src="../../../../Resources/Code/prettify.js"> </script> <script src="../../../../Resources/Code/lang-vb.js"> </script> <script src="../../../../Resources/Code/jquery.min.js"> </script> <script src="../../../../Resources/Code/ZeroClipboard.js"> </script> </head> <body> <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../../../../index_CSH.html#basics/activation_concept/transparent_activation_framework/ta_enhanced_example/ta_enhancement_with_db4otool.htm" style="">Open topic with navigation</a> </p> <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../../../../basics.htm">Basics Operations & Concepts</a><span class="MCBreadcrumbsDivider"> > </span><a class="MCBreadcrumbsLink" href="../../../activation.htm">Activation</a><span class="MCBreadcrumbsDivider"> > </span><a class="MCBreadcrumbsLink" href="../../transparent_activation_framework.htm">Transparent Activation</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">TA Enhancement With db4otool</span> </div> <p> <script type="text/javascript">/*<![CDATA[*/document.write('<a href="' + location.href +'">'); document.write("Direct Link"); document.write('</a>');/*]]>*/</script> </p> <p> </p> <h1>TA Enhancement With Db4oTool</h1> <p><span class="MCTextPopup"><a href="javascript:void(0);" class="MCTextPopupSpot" onclick="FMCTextPopup( event, this ); return false;">TA<img style="border: none;margin-left: 5px;" src="../../../../SkinSupport/ExpandingClosed.gif" MadCap:altsrc="../../../../SkinSupport/ExpandingOpen.gif" class="MCExpandingIcon" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../../../SkinSupport/ExpandingOpen.gif' ); }" /></a><span class="MCTextPopupBody" style="display: none; ">Transparent Activation</span></span> instrumentation can be done by applying <![CDATA[ ]]></p> <p><a href="../../../../advanced_topics/enhancement_tools/enhancement_for_.net/db4otool.htm">Db4oTool</a> utility to the ready .NET assemblies:</p> <p><code>Db4oTool -ta assembly</code> </p> <p>Let's look at a simple example. We will use SensorPanel class from <a href="../../../activation.htm">Activation</a> example: </p> <p MadCap:conditions="Primary..NET,Primary.c#,Primary.All languages"> <pre class="prettyprint" xml:space="preserve">SensorPanelTA.cs /**//* Copyright (C) 2004 - 2007 Versant Inc. http://www.db4o.com */ using Db4objects.Db4o; using Db4objects.Db4o.Activation; using Db4objects.Db4o.TA; namespace Db4ojects.Db4odoc.TAExamples { public class SensorPanelTA /**//*must implement Activatable for TA*/ { private object _sensor; private SensorPanelTA _next; public SensorPanelTA() { // default constructor for instantiation } public SensorPanelTA(int value) { _sensor = value; } public SensorPanelTA Next { get { return _next; } } public object Sensor { get { return _sensor; } } public SensorPanelTA CreateList(int length) { return CreateList(length, 1); } public SensorPanelTA CreateList(int length, int first) { int val = first; SensorPanelTA root = NewElement(first); SensorPanelTA list = root; while (--length > 0) { list._next = NewElement(++val); list = list.Next; } return root; } protected SensorPanelTA NewElement(int value) { return new SensorPanelTA(value); } public override string ToString() { return "Sensor #" + Sensor; } } }</pre> </p> <p MadCap:conditions="Global.Primary:cs" /> <p MadCap:conditions="Primary..NET,Primary.VB.NET,Primary.All languages"> <pre class="prettyprint lang-vb" xml:space="preserve">SensorPanelTA.vb ' Copyright (C) 2004 - 2007 Versant Inc. http://www.db4o.com Imports Db4objects.Db4o Imports Db4objects.Db4o.Activation Imports Db4objects.Db4o.TA Namespace Db4ojects.Db4odoc.TAExamples Public Class SensorPanelTA Private _sensor As Object Private _next As SensorPanelTA Public Sub New() End Sub Public Sub New(ByVal value As Integer) _sensor = value End Sub Public ReadOnly Property NextSensor() As SensorPanelTA Get Return _next End Get End Property Public ReadOnly Property Sensor() As Object Get Return _sensor End Get End Property Public Function CreateList(ByVal length As Integer) As SensorPanelTA Return CreateList(length, 1) End Function Public Function _ CreateList(ByVal length As Integer, ByVal first As Integer) _ As SensorPanelTA Dim val As Integer = first Dim root As SensorPanelTA = NewElement(first) Dim list As SensorPanelTA = root While System.Threading.Interlocked.Decrement(length) > 0 list._next = NewElement(System.Threading.Interlocked.Increment(val)) list = list.NextSensor End While Return root End Function Protected Function NewElement(ByVal value As Integer) As SensorPanelTA Return New SensorPanelTA(value) End Function Public Overloads Overrides Function ToString() As String If Sensor Is Nothing Then Return "" Else Return "Sensor #" + Sensor.ToString() End If End Function End Class End Namespace</pre> </p> <p MadCap:conditions="Global.Primary:vb" /> <p>In your code you will need to add Transparent <span class="MCPopup"><a href="javascript:void(0);" class="MCPopupSpot" onclick="FMCPopup( event, this ); return false;" MadCap:src="../../../activation.htm">Activation<img style="border: none;margin-left: 5px;" src="../../../../SkinSupport/ExpandingClosed.gif" MadCap:altsrc="../../../../SkinSupport/ExpandingOpen.gif" class="MCExpandingIcon" onload="if ( typeof( FMCPreloadImage ) == 'function' ) { FMCPreloadImage( '../../../../SkinSupport/ExpandingOpen.gif' ); }" /></a></span> support to the configuration:</p> <p MadCap:conditions="Primary..NET,Primary.c#,Primary.All languages"> <pre class="prettyprint" xml:space="preserve">TAExample.cs: ConfigureTA private static IConfiguration ConfigureTA() { IConfiguration configuration = Db4oFactory.NewConfiguration(); // set normal activation to 0 configuration.ActivationDepth(0); // add TA support configuration.Add(new TransparentActivationSupport()); return configuration; }</pre> <pre class="prettyprint" xml:space="preserve">TAExample.cs: StoreSensorPanel private static void StoreSensorPanel() { File.Delete(Db4oFileName); IObjectContainer container = Database(Db4oFactory.NewConfiguration()); if (container != null) { try { // create a linked list with length 10 SensorPanelTA list = new SensorPanelTA().CreateList(10); container.Store(list); } finally { CloseDatabase(); } } }</pre> <pre class="prettyprint" xml:space="preserve">TAExample.cs: TestActivation private static void TestActivation() { StoreSensorPanel(); IConfiguration configuration = ConfigureTA(); IObjectContainer container = Database(configuration); if (container != null) { try { System.Console.WriteLine("Zero activation depth"); IObjectSet result = container.QueryByExample(new SensorPanelTA(1)); ListResult(result); if (result.Size() > 0) { SensorPanelTA sensor = (SensorPanelTA)result[0]; // the object is a linked list, so each call to next() // will need to activate a new object SensorPanelTA next = sensor.Next; while (next != null) { System.Console.WriteLine(next); next = next.Next; } } } finally { CloseDatabase(); } } }</pre> </p> <p MadCap:conditions="Global.Primary:cs" /> <p MadCap:conditions="Primary..NET,Primary.VB.NET,Primary.All languages"> <pre class="prettyprint lang-vb" xml:space="preserve">TAExample.vb: ConfigureTA Private Shared Function ConfigureTA() As IConfiguration Dim configuration As IConfiguration = Db4oFactory.NewConfiguration ' set normal activation to 0 configuration.ActivationDepth(0) ' add TA support configuration.Add(New TransparentActivationSupport) Return configuration End Function</pre> <pre class="prettyprint lang-vb" xml:space="preserve">TAExample.vb: StoreSensorPanel Private Shared Sub StoreSensorPanel() File.Delete(Db4oFileName) Dim container As IObjectContainer = Database(Db4oFactory.NewConfiguration) If Not (container Is Nothing) Then Try ' create a linked list with length 10 Dim list As SensorPanelTA = (New SensorPanelTA).CreateList(10) container.Store(list) Finally CloseDatabase() End Try End If End Sub</pre> <pre class="prettyprint lang-vb" xml:space="preserve">TAExample.vb: TestActivation Private Shared Sub TestActivation() StoreSensorPanel() Dim configuration As IConfiguration = ConfigureTA() Dim container As IObjectContainer = Database(configuration) If Not (container Is Nothing) Then Try System.Console.WriteLine("Zero activation depth") Dim result As IObjectSet = container.QueryByExample(New SensorPanelTA(1)) ListResult(result) If result.Size > 0 Then Dim sensor As SensorPanelTA = CType(result(0), SensorPanelTA) ' the object is a linked list, so each call to next() ' will need to activate a new object Dim nextSensor As SensorPanelTA = sensor.NextSensor While Not (nextSensor Is Nothing) System.Console.WriteLine(nextSensor.ToString()) nextSensor = nextSensor.NextSensor End While End If Finally CloseDatabase() End Try End If End Sub</pre> </p> <p MadCap:conditions="Global.Primary:vb" /> <p>Compile and run the application. Now, you can add TA support by using the following command-line:</p> <p><code>Db4oTool -ta TAExamples.exe</code> </p> <p>use -vv option for verbose output:</p> <p><code>Db4oTool -ta -vv TAExamples.exe</code> </p> <p>You can also apply type filter to TA enable only selected types:</p> <p><code>Db4oTool.exe -vv -ta -by-name:S* TAExamples.exe</code> </p> <p>Db4oTool uses .NET regex to parse the -by-name parameter, in the example above all types starting with "S" will be TA enabled.</p> <p>Run TA enabled assembly and compare results to the previous run. </p> <script type="text/javascript" src="../../../../SkinSupport/MadCapBodyEnd.js"> </script> </body> </html>