Click or drag to resize

IBcfTransactionFactory Interface

[This is preliminary documentation and is subject to change.]

The transaction factory interface.

Namespace:  CalculationWorks.BusinessModel
Assembly:  CalculationWorks.BusinessModel (in CalculationWorks.BusinessModel.dll) Version: 4.0.0-beta7
Syntax
public interface IBcfTransactionFactory

The IBcfTransactionFactory type exposes the following members.

Properties
  NameDescription
Public propertyEnforceConstraints
Gets or sets the default value for transaction builders EnforceConstraints-property.
Public propertyMicroTransactionMode
Gets or sets the default value for transaction builders MicroTransactionMode-property.
Public propertyTriggersEnabled
Gets or sets the default value for transaction builders TriggersEnabled-property.
Top
Methods
  NameDescription
Public methodCreateTransaction
Creates and returns a new transaction instance.
Public methodCreateTransactionBuilder
Creates and returns a new transaction builder instance.
Public methodCreateTransactionInfoObject
Infrastructure. The member supports the infrastructure and is not intended to be used directly from your code.
Public methodCreateTransactionName
Creates a name for the BcfTransaction.
Top
Examples
Custom Transactions
using System;
using CalculationWorks.BusinessModel;
using CalculationWorks.BusinessModel.Design;
using CalculationWorks.BusinessModel.UndoRedo;

namespace MyNamespace 
{
    public class MyTransactionBuilder : BcfTransactionBuilder 
    {
        /// <summary>
        /// An additional comment
        /// </summary>
        public string Comment { get; set; }
    }
    public class MyTransactionInfo : IBcfTransactionInfo 
    {
        /// <summary>
        /// The <see cref="IBcfTransactionInfo.Name"/> implementation.
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// The <see cref="MyTransactionBuilder.Comment">additional comment from builder</see>.
        /// </summary>
        public string Comment { get; set; }
        /// <summary>
        /// Date and time when transaction was committed.
        /// </summary>
        public DateTime? CommittedAt { get; set; }
    }
    public class MyTransaction : BcfTransaction 
    {
        public MyTransaction([NotNull] BcfDataSet dataSet, [NotNull] BcfTransactionBuilder builder) : base(dataSet, builder) 
        {
            // Info is not initialized for subtransactions
            if(IsSubTransaction) Info = DataSet.TransactionFactory.CreateTransactionInfoObject();
            Comment = ((MyTransactionBuilder)builder).Comment;
        }
        public MyTransactionInfo MyInfo 
        {
            get { return (MyTransactionInfo)Info; }
        }
        /// <summary>
        /// The <see cref="MyTransactionBuilder.Comment">additional comment from builder</see>.
        /// </summary>
        public string Comment 
        {
            get { return MyInfo.Comment; }
            set { MyInfo.Comment = value; }
        }
        /// <summary>
        /// Date and time when transaction was committed.
        /// </summary>
        public DateTime? CommittedAt 
        {
            get { return MyInfo.CommittedAt; }
        }
        /// <summary>
        /// If using file-based undo here is the last chance for updates on <see cref="MyInfo"/> before it is serialized.
        /// </summary>
        protected override void OnBeforeCommitComplete() 
        { 
            MyInfo.CommittedAt = DateTime.Now;
        }
    }
    public class MyTransactionFactory : BcfTransactionFactoryBase<MyTransaction, MyTransactionInfo, MyTransactionBuilder> {
        public MyTransactionFactory([NotNull] BcfDataSet dataSet) : base(dataSet) 
        {
            // changing default because it sucks
            EnforceConstraints = false;
        }
        public override MyTransaction CreateTransaction(BcfTransactionBuilder transactionBuilder) 
        {
            return new MyTransaction(DataSet, transactionBuilder);
        }
    }
    // Handwritten part for BCF-Editor generated partial DataSetSetup-class.
    partial class MyDataSetSetup 
    {
        // BCF-Editor generates "partial void Initialized();" we can implement in same cs-project the generated DataSetSetup-class resides.
        partial void Initialized() 
        {
            CreateTransactionFactory = dataSet => new MyTransactionFactory(dataSet);
        }
    }
}
See Also