473,802 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to keep track of changes of an object???

Hi,



I need to track all changes made to an object. Consider the following class:



Public Class Dog



Private _Name As System.String

Private _Weight As System.Byte



Public Property Name() As System.String

Get

Return _Name

End Get

Set(ByVal Value As System.String)

_Name = Value

End Set

End Property



Public Property Weight() As System.Byte

Get

Return _Weight

End Get

Set(ByVal Value As System.Byte)

_Weight = Value

End Set

End Property



Public Sub New(ByVal Name As System.String)

_Name = Name

End Sub



End Class



For the sake of understanding let's create a dog called "Fido" and - as it is still a puppy - assign a weight of 5 (let this be kg, pound, what ever.) to it.



Dim myDog As New Dog("Fido")

myDog.Weight = 5

' Fido get's saved to a database



As Fido gains more weight with the ages the following changes are made.



' Fido get's loaded from a database

myDog.Weight = 10



I now want to be able to track all the changes made to the Fido-Object during its lifetime. I thought about creating an XML file like the following using the properties of my class to save every change to Fido:



<?xml version="1.0" encoding="utf-8" ?>

<LogFile>

<Dog>

<Name>Fido</Name>

<Weight>5</Weight>

</Dog>

</LogFile>



<?xml version="1.0" encoding="utf-8" ?>

<LogFile>

<Dog>

<Weight>10</Weight>

</Dog>

</LogFile>



I now could store all the changes as an ntext (for they might get really long depending on the underlying object) in a database and display them in a DataGrid (or any other display of my choice) if it is possible to merge all the XML-Files into one big one?? Does anybody know how this merge can be done? I also assume that I have to use the system.Xml.XmlD ataDocument class to create the XML-File but I am not sure how.

I also am absolutely not positive if this is a good approach to track changes of an object. What would be a better approach to track changes of an object on your opinion?



Thank you a huge lot in advance.

Daniel Walzenbach
Nov 20 '05 #1
5 4041
Hi Daniel,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to track a property's
change of one object and log it onto one xml file.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think you can try to serialize the Name as an attribute also declare the
timestamp to know when the weight change.

The Log File will look like below.
<?xml version="1.0" encoding="utf-8" ?>
- <LogFile xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
- <Dog Name="Fido" TimeStamp="2004-02-12T16:12:59.708 6582+08:00">
<Weight>20</Weight>
</Dog>
</LogFile>
[The class1.vb file used to (de)serialize the file]

Option Strict Off
Option Explicit On

Imports System.Xml.Seri alization
Imports System.IO

<System.Xml.Ser ialization.XmlR ootAttribute([Namespace]:="",
IsNullable:=Fal se)> _
Public Class LogFile
<System.Xml.Ser ialization.XmlE lementAttribute ("Dog",
Form:=System.Xm l.Schema.XmlSch emaForm.Unquali fied)> _
Public Items() As Dog
End Class

Public Class Dog
Public Event Weight_Changed( )
'
<System.Xml.Ser ialization.XmlE lementAttribute (Form:=System.X ml.Schema.XmlSc h
emaForm.Unquali fied)> _
Private _Weight As Byte

<System.Xml.Ser ialization.XmlE lementAttribute (Form:=System.X ml.Schema.XmlSc h
emaForm.Unquali fied)> _
Public Property Weight() As Byte
Get
Return _Weight
End Get
Set(ByVal Value As Byte)
If Not Value = _Weight Then
_Weight = Value
RaiseEvent Weight_Changed( )
End If
End Set
End Property
' <System.Xml.Ser ialization.XmlA ttributeAttribu te()> _
Private _Name As String
<System.Xml.Ser ialization.XmlA ttributeAttribu te()> _
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property
Private _TimeStamp As DateTime
<System.Xml.Ser ialization.XmlA ttributeAttribu te()> _
Public Property TimeStamp() As DateTime
Get
Return _TimeStamp
End Get
Set(ByVal Value As DateTime)
_TimeStamp = Value
End Set
End Property
Public Sub New()

End Sub
Public Sub New(ByVal nm As String)
_Name = nm
End Sub
End Class

[The Main file]
Option Strict Off
Option Explicit On

Imports System.Xml.Seri alization
Imports System.IO
Imports System.Text

Module Module1
Dim ds As DataSet
Dim lf As LogFile
Sub Main()
' At the first time create the file
'CreateLogFile( )
Dim dt As DateTime

'Deserialize an object
Dim x As XmlSerializer = New XmlSerializer(G etType(LogFile) )
Dim reader As TextReader = New StreamReader("C :\LogFile.xml")
lf = x.Deserialize(r eader)
ds = New DataSet
ds.ReadXml("C:\ LogFile.xml")
AddHandler lf.Items(0).Wei ght_Changed, AddressOf Dog_Weight_Chan ged
lf.Items(0).Wei ght = 20
'Change the Weight will be log to file
lf.Items(0).Wei ght = 30
'You also can write to a file
ds.WriteXml(Con sole.Out)
End Sub

Private Sub CreateLogFile()
Dim dg As Dog
Dim lb As New LogFile
dg = New Dog("Fido")
dg.TimeStamp = Now
dg.Weight = 20
lb.Items = New Dog() {dg}
Dim x As XmlSerializer = New XmlSerializer(G etType(LogFile) )
Dim writer As TextWriter = New StreamWriter("C :\LogFile.xml")
x.Serialize(wri ter, lb)
writer.Close()
End Sub

Private Sub Dog_Weight_Chan ged()
Dim x As XmlSerializer = New XmlSerializer(G etType(LogFile) )
'Dim writer As TextWriter = New StreamWriter("H ello.xml")
Dim sm As MemoryStream = New IO.MemoryStream
x.Serialize(sm, lf)
sm.Position = 0
Dim reader As Xml.XmlTextRead er = New Xml.XmlTextRead er(sm)
ds.ReadXml(read er)
sm.Close()
End Sub
End Module

Did this works for you?
If you have any concern on this issue,please post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #2
Cor
Hi Peter,

No critique, you got enough the last days,

Try to avoid Option Strict Off in your messages. The regulars from this
newsgroup (from which are you of course also one) try that.

No answer necessary, only to make you attend on it.

Cor
Nov 20 '05 #3
Peter

thank you. I like this approach. It gives me a nice base to build onto..

Have a nice day. Best regards

Daniel Walzenbach
Nov 20 '05 #4
Cor,

why don’t you just email Peter privately instead of criticizing him in front of the whole newsgroup? @ least as you seem to know him. And comments like “No critique, you got enough the last days” aren’t really productive…

Think about you’d feel if roles where changed… Just my $.02.

Daniel Walzenbach
Nov 20 '05 #5
Cor
Hi Daniel,

I do not see anything wrong to attend regulars on some things that we are
used to do.

If they attend me on that, I only say, thank you.

And posting unasked emails is something against Netiquete from a newsgroup.

I do not do that.

Cor
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4474
by: d.schulz81 | last post by:
Hi all, We have about 10 different domains that are linked very closely and we want to identify and keep track of every single user that surfs our websites by the use of sessions. The problem is how to keep track of the session ID across domains. - cookies don't work because not acepted by 40 % of or users and cookies don't work across domains
4
3190
by: SQLDBA | last post by:
What would be the best practice to follow to keep track of MS SQL server changes... Stroed procs, tables, views, triggers, indexes, DTS and also jobs ect.... I am not quite sure how Source safe works with sql server. Any other way to do this... Even if its manual work, its okey.. I would appreciate if any of the DBA's let me know how they are facing this issue.... Thanks in advance...
2
4188
by: Uwe Range | last post by:
Hi to all, I am developing a database where, with time, it proved to be necessary to keep track of the changes to the data. It is fairly easy to keep track of the time when a record was changed (afterupdate event) -> Is there there a smart way of finding out which field has been changed? I don't want to set a procedure on every field on the edit form for keeping track of that, because the forms will be changed from time to time.
1
2256
by: strvariant | last post by:
Hi all, I am searching for a way to track when a form/report/query is changed by users. For instance: 1) A user opens a form/report 2) The user enters the Design mode of that form/report 3) The user makes a change
3
2914
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have any experience on how to keep track of session value. Any help it's appreciated. Thanks Alan
2
2770
by: metaperl | last post by:
I'm actually taking Microsoft's 2779 and just finished a lab where we kept track of our changes to the database. However, I'm not happy with the scripts interface because it does not tell me the chronological order of my changes to the database. Could someone share with me their technique for keeping track of database changes? I'm actually thinking a set of tables would be best, because sometimes
15
6725
by: l3vi | last post by:
I have a new system Im building that stores entries of what people are searching for on my sites. I want to be able to keep records of how many times a keyword was searched for daily, and from that I can calculate weekly and monthly. At this point I have one entry per search phrase with the number of hits the search phrase has gotten, and the last time it was updated. As I start to take the program out of testing and move in more...
3
2605
by: PJ6 | last post by:
What's the best way to, in the general case, track changes to an object's public fields and properties? In a lot of applicatoins I've seen bahavior consistant with simple periodic checking from a timer, or checking otherwise initiated from a user event. I don't believe I can make that approach work in the project I'm working on... are there other ways to do this, where I can actually get an event raised on a field change, that don't involve...
11
2766
by: Andrew G. Koptyaev | last post by:
Please help. I need to keep track of how many object of a given class without introducing a non-class member variable. Which one of the following will allow me to do this? 1) Add member variable that gets incremented in the default constructor and decremented in the destructor. 2) Add local variable that gets incremented in the each constructor and decremented in the destructor.
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10538
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10305
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.