Paul Gielens:ThoughtsService

another Endpoint to my thoughts

News

Syndication

Ads


Favorites

Projects

February 2005 - Posts

Having fun with System.Transactions
Just having fun with System.Transactions in Whidbey. The Bank class implements a couple of interfaces (ITransactionManager, IEnlistmentNotification, IResourceManager) making it possible to enlist the Bank class in the main programs TransactionScope. The Bank class participates in the transactions outcome and rolls back any changes made to its fund. This is by no means a reliable example explaining System.Transactions.

#region Using directives

using System;
using
System.Collections.Generic;
using
System.Text;
using
System.Threading;
using
System.Transactions;

#endregion

 

namespace PaulGielens.Samples.Transactions.TransactedWork
{
    class Program
   
{
        static void
Main(string[] args)
        {
            Bank bank1 = null;
            Bank bank2 = null;

            TransactionScope scope = new TransactionScope();

            try
           
{
                using (scope)
                {
                    bank1 = new Bank(100);
                    bank2 = new Bank(0);
                    bank1.TransferTo(bank2, 25);

                    scope.Consistent = true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + " , rolling back changes");
            }
            finally
           
{
                // Apparently it takes some time?!?
               
Thread.Sleep(100);
                Console.WriteLine("Bank1 fund = {0} and bank2 fund = {1}",
                    bank1.Fund,
                    bank2.Fund);
                Console.WriteLine("Press any key to exit");
                Console.ReadLine();
           }
        }
    }
}

#region Using directives

using System;
using
System.Collections.Generic;
using
System.Text;
using
System.Transactions;

#endregion

namespace PaulGielens.Samples.Transactions.TransactedWork
{
    public class Bank :
        ITransactionManager,
        IEnlistmentNotification,
        IResourceManager
   
{
        private int fund;
        private int preparedFund;

        #region ITransactionManager Implementation

        public ICommittableTransaction CreateTransaction()
        {
            throw new NotImplementedException();
        }

        public ICommittableTransaction CreateTransaction(TimeSpan span)
        {
            throw new NotImplementedException();
        }

        public ICommittableTransaction CreateTransaction(TransactionOptions options)
        {
            throw new NotImplementedException();
        }

        public IEnlistment ReenlistTransaction(IResourceManager resourceManager,
            byte[] recoveryInformation,
            IEnlistmentNotification enlistmentNotification)
        {
            throw new NotImplementedException();
        }

        public void ResourceManagerRecoveryComplete(IResourceManager resourceManager)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IEnlistmentNotification Implementation

        public void Commit(IEnlistment enlistment)
        {
            throw new NotImplementedException();
        }

        public void InDoubt()
        {
            throw new NotImplementedException();
        }

        public void Prepare(IPreparingEnlistment preparingEnlistment, byte[] recoveryInformation)
        {
            preparedFund = fund;
        }

        public void Rollback(IEnlistment enlistment)
        {
            fund = preparedFund;
        }

        #endregion       

        #region IResourceManager

        public Guid Identifier
        {
            get { return Guid.NewGuid(); }
        }

        #endregion

        private void Prepare()
        {
            Prepare(null, new byte[] {});
        }

        public Bank(int amount)
        {
            Transaction.Current.DurableEnlist(this, this, false);
            this.fund = amount;
        }

        private void Withdraw(int amount)
        {
            Prepare();
            fund -= amount;
        }

        private void Deposit(int amount)
        {
            Prepare();
            fund += amount;
        }

        public void TransferTo(Bank to, int amount)
        {
            Withdraw(amount);
            throw new Exception("Failed to deposit");
        }

        public int Fund
        {
            get { return fund; }
        }
    }
}

 

Posted: Feb 19 2005, 05:46 PM by p.gielens | with 5 comment(s)
Filed under:
Kicking the "DataSet" Habit
David Foderick a solution architect at Versant will give an introduction to Versant’s Open Access Suite February 24th. You can sign up for the web seminar here. For what I’ve heard, Versant is more or less the short term replacement for ObjectSpaces which is ridicules imo. The .NET community already has an outstanding set of object relational-mapping tools available today! Nevertheless I think each effort to evangelize rich domain models will bring us closer to more flexible, maintainable and more agile applications.
(MSF) for Agile Software Development, Beta
With Visual Studio Team System appearing on the horizon... a process guidance shipping with Visual Studio Team System is available here.
Posted: Feb 18 2005, 11:46 AM by p.gielens | with no comments
Filed under:
Free ASP.NET 2.0 Training

Via TheServerSide, free ASP.NET 2.0 training in ISO format.

Posted: Feb 16 2005, 01:44 PM by p.gielens | with 1 comment(s)
Filed under:
CDATA XmlSerializer

Trying to add a CDATA section while serializing your instance? Try this or wait a bit longer for .NET 2.0 to arrive.

Posted: Feb 16 2005, 01:35 PM by p.gielens | with 2 comment(s)
Filed under:
Tech-Ed 2005 Europe
Via Sander Gerz Tech-Ed 2005 Europe and the RSS feed. The place to be with .NET 2.0 on the horizon.
Posted: Feb 15 2005, 10:54 AM by p.gielens | with no comments
Filed under:
Tree Surgeon

The first release of Tree Surgeon, nevertheless worth a look! I always enjoy stuff coming from the Thoughtworks camp.

2.573
     [exec]
     [exec] The format of the file 'ThoughtWorks.TreeSurgeon.UnitTests' is inval
id.

BUILD FAILED

E:\Pub\TreeSurgeon-Source-0[1].1\TreeSurgeon.build(51,4):
External Program Failed: E:\Pub\TreeSurgeon-Source-0[1].1\tools\nunit\nunit-cons
ole.exe (return code was 2)

Total time: 3 seconds.

Although I receive a BadImageFormatException while trying to load the unit-tests assembly. Perhaps Whidbey messing up NUnit on this box.

Posted: Feb 14 2005, 09:58 PM by p.gielens | with no comments
Filed under:
Indigo news

Mujtaba Syed shares his VSLive Indigo day notes:

Introducing Indigo: Eric Rudder and Ari Bixhorn
Programming Indigo: Don Box and Steve Swartz
Indigo upgrade and interop: Steve Swartz and Anand Rajagopalan
Building Secure Services with Indigo: Doug Purdy

Building service-oriented applications today: Richard Turner

and Don Box spells the concept of a service contract.

Posted: Feb 14 2005, 09:25 PM by p.gielens | with no comments
Filed under:
*Update, Dutch .NET Developers Alliance

Newest additions are: Rick van den BoschRobert Jan van Holland and Edward Bakker. Grab the latest OPML file here which contains allot of Dutch .Net developers. Are you a Dutch .Net developer and want your name on our list, drop a line pgielens@gmail.com

Posted: Feb 11 2005, 07:12 PM by p.gielens | with no comments
Filed under:
DevDays 2005

My schedule (haven’t decided on the pre conference day yet):
Track 1 : Choosing an application integration strategy
Track 2 : Indigo update
Track 3 : Enterprise Library - patterns & practices application blocks united
Track 4 : ASP.NET Web Services 2.0

Since I’m reading Integration Patterns and already did some integration work in the past, choosing an integration strategy lies in the line of my work field. Indigo is a must! I’m excited about Indigo ever since I’ve read the news coming back from the VSLive event. I’m looking forward to Enterprise Library because I’ve missed it at the monthly dotned meeting due to a traffic jam :( (which are quit common in The Netherlands). Another interesting presentation should be Web Services with ASMX 2.0. I consider this to be “the” path to take if you consider migrating to Indigo in the near future (I agree with Ken Brubaker and his WSE 2.0 Remote Communication Comparative Analysis).

I hope to see you all there. There’s a plan to do a get together with other Dutch bloggers during lunch.

Posted: Feb 11 2005, 12:00 PM by p.gielens | with 1 comment(s)
Filed under:
More Posts Next page »