Pilot

Pilot.cs
01/* Copyright (C) 2004 - 2008 db4objects Inc. http://www.db4o.com */ 02using Db4objects.Db4o; 03using Db4objects.Db4o.Activation; 04using Db4objects.Db4o.TA; 05 06namespace Db4objects.Db4odoc.TP.Rollback 07{ 08 public class Pilot : IActivatable 09 { 10 private string _name; 11 private Id _id; 12 13 [System.NonSerialized] 14 IActivator _activator; 15 16 public Pilot(string name, int id) 17 { 18 _name = name; 19 _id = new Id(id); 20 } 21 22 // Bind the class to an object container 23 public void Bind(IActivator activator) 24 { 25 if (_activator == activator) 26 { 27 return; 28 } 29 if (activator != null && null != _activator) 30 { 31 throw new System.InvalidOperationException(); 32 } 33 _activator = activator; 34 } 35 36 // activate the object fields 37 public void Activate(ActivationPurpose purpose) 38 { 39 if (_activator == null) 40 return; 41 _activator.Activate(purpose); 42 } 43 44 public Id Id 45 { 46 get 47 { 48 Activate(ActivationPurpose.Read); 49 return _id; 50 } 51 set 52 { 53 Activate(ActivationPurpose.Write); 54 _id = value; 55 } 56 } 57 58 public string Name 59 { 60 get 61 { 62 // even simple string needs to be activated 63 Activate(ActivationPurpose.Read); 64 return _name; 65 } 66 set 67 { 68 Activate(ActivationPurpose.Write); 69 _name = value; 70 } 71 } 72 73 public override string ToString() 74 { 75 return string.Format("{0}[{1}]",Name, Id) ; 76 } 77 } 78 79}
Pilot.vb
01' Copyright (C) 2004 - 2008 db4objects Inc. http://www.db4o.com 02 03Imports Db4objects.Db4o 04Imports Db4objects.Db4o.Activation 05Imports Db4objects.Db4o.TA 06 07Namespace Db4objects.Db4odoc.TP.Rollback 08 Public Class Pilot 09 Implements IActivatable 10 Private _name As String 11 Private _id As Id 12 13 <Transient()> _ 14 Private _activator As IActivator 15 16 Public Sub New(ByVal name As String, ByVal id As Integer) 17 _name = name 18 _id = New Id(id) 19 End Sub 20 21 ' Bind the class to an object container 22 Public Sub Bind(ByVal activator As IActivator) Implements IActivatable.Bind 23 If _activator Is activator Then 24 Return 25 End If 26 If activator IsNot Nothing AndAlso _activator IsNot Nothing Then 27 Throw New System.InvalidOperationException() 28 End If 29 _activator = activator 30 End Sub 31 32 ' activate the object fields 33 Public Sub Activate(ByVal purpose As ActivationPurpose) Implements IActivatable.Activate 34 If _activator Is Nothing Then 35 Return 36 End If 37 _activator.Activate(purpose) 38 End Sub 39 40 Public Property Id() As Id 41 Get 42 Activate(ActivationPurpose.Read) 43 Return _id 44 End Get 45 Set(ByVal value As Id) 46 Activate(ActivationPurpose.Write) 47 _id = value 48 End Set 49 End Property 50 51 Public Property Name() As String 52 Get 53 ' even simple string needs to be activated 54 Activate(ActivationPurpose.Read) 55 Return _name 56 End Get 57 Set(ByVal value As String) 58 Activate(ActivationPurpose.Write) 59 _name = value 60 End Set 61 End Property 62 63 Public Overloads Overrides Function ToString() As String 64 Return String.Format("{0}[{1}]", Name, Id) 65 End Function 66 End Class 67 68End Namespace