views:

642

answers:

3
+1  Q: 

C# Transaction

I am looking to implement database like transactions in C#. I am processing multiple XML files. Any particular XML file can call child XML file during processing. The processor will start processing child XML file. If initialization conditions fail or there is an exception, then I want to resume processing parent XML file. This is the reason I am looking for transaction like implementation so that I can roll back. Is it possible to achieve? Can somebody provide me code snippet or pseudo code?

FYI - I am using .NET Compact Framework.

A: 

Without rolling your own custom transaction management component this will be difficult to implement.

Can't you validate/verify all the XML up front before allowing your application to embark on it's processing phase?

Kev
COM+ doesn't exist in Windows CE
ctacke
@ctacke - thanks - lern2readtehquestion :)
Kev
+1  A: 

On the compact framework I think your going to roll your own transaction manager.

On the full framework you could have probably built something using TransactionScope and IEnlistmentNotification. You would have had to do quite a bit of work to get all your actions transactable as there is not support for transcations in xml out of the box.

pjbelf
This is a good starting point. I have a long way to go implement transactions in xml.
rxm0203
A: 

Maybe you could try using subversion. There are libraries for controlling it from C#. So to begin a transaction you just start working, and to roll back, you do a rollback. Committing your svn tree finishes your transaction.

I don't know if this is too simple an approach. It might well be, but what you have described only requires some of the properties of a transaction. Specifically, you've indicated you need atomicity (i.e. the ability to roll back changes to several files simultaneously). Durability is implied, but the commit gets you that.

You haven't mentioned any consistency constraints other than that there are initialisation conditions and exceptions, but presumably your code could deal with these, and force a rollback if any rule is broken.

Isolation is either hard or easy. It all depends on whether you need to support more than one transaction at once. Is it a requirement that you allow concurrent updates? If not, just build something to enforce serial access to the system, and you're finished. If you need concurrent updates, I'm afraid I'm out of ideas :-)

Dominic Cronin
Seriously? You're suggesting that he ports and installs a SCC provider on his mobile device to handle transactional XML parsing?
ctacke
:-) OK - I wasnt' paying too much attention to the mention of the compact framework. It's still a fair question as to whether he needs all the elements of transaction management or only a subset.
Dominic Cronin