Exemplo n.º 1
0
        private TccTransactionData ConvertDataRowToTccTransactionData(DataRow dr)
        {
            TccTransactionData data = new TccTransactionData();

            data.TxId = dr["TxId"].ToString();
            data.ServiceAtComputer = dr["ServiceAtComputer"].ToString();
            data.SchemaName        = dr["TxSchema"].ToString();
            data.BeginTime         = Convert.ToDateTime(dr["BeginTime"]);
            data.TxState           = (TccTransactionState)dr["TxState"];
            string temp = dr["WorkState"].ToString();

            string[]       strs   = temp.Split(new string[] { "," }, StringSplitOptions.None);
            TccWorkState[] states = new TccWorkState[strs.Length];
            for (int i = 0; i < strs.Length; i++)
            {
                states[i] = (TccWorkState)Convert.ToInt32(strs[i]);
            }
            data.WorkStates  = states;
            data.ContextKey  = dr["ContextKey"].ToString();
            data.ContextData = (byte[])dr["ContextData"];
            if (dr["Error"] != DBNull.Value)
            {
                data.Error = Convert.ToString(dr["Error"]);
            }
            return(data);
        }
Exemplo n.º 2
0
        public TccTransaction(TccTransactionData data, TccCoordinator <TContext> coordinator, TContext ctx)
        {
            // TODO: 从TransactionData中恢复数据
            _context = ctx.Deserialize <TContext>(data.ContextData);
            _txId    = data.TxId;
            _txState = data.TxState;

            _lock  = null;
            _works = new List <TccWorkUnit <TContext> >();
            _txCtx = null;

            _coordinator = coordinator;
            if (_coordinator != null)
            {
                _coordinator.NewTransaction(this);
                _tracing = _coordinator.Tracing;
            }
            else
            {
                _tracing = _defaultTracing;
            }

            Prepare();

            foreach (var a in _works)
            {
                a.Tracing = _tracing;
            }
        }
Exemplo n.º 3
0
        private void InsertTransactionLog(TccTransactionData data)
        {
            string spName = "USP_TCC_InsertTransactionLog";

            string[] spParams = { "@TxId", "@ServiceAtComputer", "@TxSchema", "@BeginTime", "@LastUpdateTime", "@TxState", "@WorkState", "@ContextKey", "@ContextData", "Error" };
            string   states   = WorkStatesToString(data.WorkStates);

            object[] spValues = { data.TxId, data.ServiceAtComputer, data.SchemaName, data.BeginTime, DateTime.Now, (Int16)data.TxState, states, data.ContextKey, data.ContextData, data.Error };
            _db.SpExecuteNonQuery(spName, spParams, spValues);
        }
Exemplo n.º 4
0
 public override void UpdateTransaction(TccTransactionData data)
 {
     if ((int)_mode >= (int)TccPersisterMode.ActiveAndAllFailed)
     {
         string   spName   = "USP_TCC_UpdateTransaction";
         string[] spParams = { "@TxId", "@LastUpdateTime", "@TxState", "@WorkState", "@ContextData" };
         string   states   = WorkStatesToString(data.WorkStates);
         object[] spValues = { data.TxId, DateTime.Now, (Int16)data.TxState, states, data.ContextData };
         _db.SpExecuteNonQuery(spName, spParams, spValues);
     }
 }
Exemplo n.º 5
0
        public override void CloseTransaction(TccTransactionData data)
        {
            switch (_mode)
            {
            case TccPersisterMode.None:
                break;

            case TccPersisterMode.CloseFailed:
                if (data.TxState == TccTransactionState.CancelFailed || data.TxState == TccTransactionState.ConfirmFailed)
                {
                    //插入TransactionLog表
                    InsertTransactionLog(data);
                }
                break;

            case TccPersisterMode.AllFailed:
                if (data.TxState != TccTransactionState.Confirmed)
                {
                    //插入TransactionLog表
                    InsertTransactionLog(data);
                }
                break;

            case TccPersisterMode.ActiveAndAllFailed:
                //删除ActiveTransaction表中内容
                DeleteActiveTransaction(data.TxId);
                if (data.TxState != TccTransactionState.Confirmed)
                {
                    //插入TransactionLog表
                    InsertTransactionLog(data);
                }
                break;

            case TccPersisterMode.All:
                //删除ActiveTransaction表中内容
                DeleteActiveTransaction(data.TxId);
                //插入TransactionLog表
                InsertTransactionLog(data);
                break;
            }
        }
Exemplo n.º 6
0
        public TccTransactionData GetData()
        {
            // TODO: 返回此次Transaction的数据
            //throw new NotImplementedException();
            TccTransactionData data = new TccTransactionData();

            data.TxId              = _txId;
            data.SchemaName        = _coordinator.TransName;
            data.ServiceAtComputer = ServiceEnviornment.ServiceName + "@" + ServiceEnviornment.ComputerName;
            data.BeginTime         = _beginTime;
            data.TxState           = _txState;
            List <TccWorkState> workStates = new List <TccWorkState>();

            //第一个状态为Lock的状态,如果没有,则默认是None
            if (_lock != null)
            {
                workStates.Add(_lock.WorkState);
            }
            else
            {
                workStates.Add(TccWorkState.None);
            }
            foreach (TccWorkUnit <TContext> work in _works)
            {
                workStates.Add(work.WorkState);
            }
            data.WorkStates  = workStates.ToArray();
            data.ContextKey  = _context.Key;
            data.ContextData = Context.Serialize();
            Exception ex = GetFirstError();

            if (ex != null)
            {
                data.Error = ex.Message + ex.StackTrace;
            }
            else
            {
                data.Error = string.Empty;
            }
            return(data);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 查询出所有没有Confirmed的Transaction
        /// </summary>
        /// <returns></returns>
        public override IList <TccTransactionData> LoadFailedTransaction()
        {
            string spName = "USP_TCC_GetTransactionLog";

            string[]  spParams = { "@TxSchema", "@TxState" };
            object[]  spValues = { _transName, TccTransactionState.Confirmed };
            DataTable dt       = _db.SpExecuteTable(spName, spParams, spValues);

            if (dt != null && dt.Rows.Count > 0)
            {
                List <TccTransactionData> list = new List <TccTransactionData>();
                foreach (DataRow dr in dt.Rows)
                {
                    TccTransactionData data = ConvertDataRowToTccTransactionData(dr);
                    list.Add(data);
                }
                return(list);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 8
0
 public override void CloseTransaction(TccTransactionData data)
 {
     switch (_mode)
     {
         case TccPersisterMode.None:
             break;
         case TccPersisterMode.CloseFailed:
             if (data.TxState == TccTransactionState.CancelFailed || data.TxState == TccTransactionState.ConfirmFailed)
             {
                 //插入TransactionLog表
                 InsertTransactionLog(data);
             }
             break;
         case TccPersisterMode.AllFailed:
             if (data.TxState != TccTransactionState.Confirmed)
             {
                 //插入TransactionLog表
                 InsertTransactionLog(data);
             }
             break;
         case TccPersisterMode.ActiveAndAllFailed:
             //删除ActiveTransaction表中内容
             DeleteActiveTransaction(data.TxId);
             if (data.TxState != TccTransactionState.Confirmed)
             {
                 //插入TransactionLog表
                 InsertTransactionLog(data);
             }
             break;
         case TccPersisterMode.All:
             //删除ActiveTransaction表中内容
             DeleteActiveTransaction(data.TxId);
             //插入TransactionLog表
             InsertTransactionLog(data);
             break;
     }
 }
Exemplo n.º 9
0
 public abstract void NewTransaction(TccTransactionData data);
Exemplo n.º 10
0
 public abstract void NewTransaction(TccTransactionData data);
Exemplo n.º 11
0
 private void InsertTransactionLog(TccTransactionData data)
 {
     string spName = "USP_TCC_InsertTransactionLog";
     string[] spParams = { "@TxId", "@ServiceAtComputer", "@TxSchema", "@BeginTime", "@LastUpdateTime", "@TxState", "@WorkState", "@ContextKey", "@ContextData", "Error" };
     string states = WorkStatesToString(data.WorkStates);
     object[] spValues = { data.TxId, data.ServiceAtComputer, data.SchemaName, data.BeginTime, DateTime.Now, (Int16)data.TxState, states, data.ContextKey, data.ContextData, data.Error };
     _db.SpExecuteNonQuery(spName, spParams, spValues);
 }
Exemplo n.º 12
0
 private TccTransactionData ConvertDataRowToTccTransactionData(DataRow dr)
 {
     TccTransactionData data = new TccTransactionData();
     data.TxId = dr["TxId"].ToString();
     data.ServiceAtComputer = dr["ServiceAtComputer"].ToString();
     data.SchemaName = dr["TxSchema"].ToString();
     data.BeginTime = Convert.ToDateTime(dr["BeginTime"]);
     data.TxState = (TccTransactionState)dr["TxState"];
     string temp = dr["WorkState"].ToString();
     string[] strs = temp.Split(new string[] { "," }, StringSplitOptions.None);
     TccWorkState[] states = new TccWorkState[strs.Length];
     for (int i = 0; i < strs.Length; i++)
     {
         states[i] = (TccWorkState)Convert.ToInt32(strs[i]);
     }
     data.WorkStates = states;
     data.ContextKey = dr["ContextKey"].ToString();
     data.ContextData = (byte[])dr["ContextData"];
     if (dr["Error"] != DBNull.Value)
         data.Error = Convert.ToString(dr["Error"]);
     return data;
 }
Exemplo n.º 13
0
 public abstract void UpdateTransaction(TccTransactionData data);
Exemplo n.º 14
0
 public abstract void UpdateTransaction(TccTransactionData data);
Exemplo n.º 15
0
 public override void NewTransaction(TccTransactionData data)
 {
     if ((int)_mode >= (int)TccPersisterMode.ActiveAndAllFailed)
     {
         string spName = "USP_TCC_NewTransaction";
         string[] spParams = { "@TxId", "@ServiceAtComputer", "@TxSchema", "@BeginTime", "@LastUpdateTime", "@TxState", "@WorkState", "@ContextKey", "@ContextData" };
         string states = WorkStatesToString(data.WorkStates);
         object[] spValues = { data.TxId, data.ServiceAtComputer, data.SchemaName, data.BeginTime, DateTime.Now, (Int16)data.TxState, states, data.ContextKey, data.ContextData };
         _db.SpExecuteNonQuery(spName, spParams, spValues);
     }
 }
Exemplo n.º 16
0
 public abstract void CloseTransaction(TccTransactionData data);
Exemplo n.º 17
0
 public abstract void CloseTransaction(TccTransactionData data);