/// <summary> /// Adds a row lock to the list of locks that must be released at the end of a transaction. /// </summary> /// <param name="enlistment">Facilitates communication bewtween an enlisted transaction participant and the transaction /// manager during the final phase of the transaction.</param> public void Commit(global::System.Transactions.Enlistment enlistment) { try { global::System.Collections.Generic.List <object> transactionLogItem = new global::System.Collections.Generic.List <object>(); DataModel.TransactionLogLock.EnterWriteLock(); DataModel.DataLock.EnterWriteLock(); for (int recordIndex = 0; (recordIndex < this.recordList.Count); recordIndex = (recordIndex + 1)) { global::FluidTrade.Core.IRow iRow = this.recordList[recordIndex]; global::FluidTrade.Core.ITable iTable = ((global::FluidTrade.Core.ITable)(iRow.Table)); if ((iRow.RowState == global::System.Data.DataRowState.Modified)) { transactionLogItem.Clear(); transactionLogItem.Add(global::FluidTrade.Core.RecordState.Modified); transactionLogItem.Add(iTable.Ordinal); for (int keyIndex = 0; (keyIndex < iTable.PrimaryKey.Length); keyIndex = (keyIndex + 1)) { transactionLogItem.Add(iRow[iTable.PrimaryKey[keyIndex]]); } for (int columnIndex = 0; (columnIndex < iTable.Columns.Count); columnIndex = (columnIndex + 1)) { if ((iRow[columnIndex].Equals(iRow[columnIndex, global::System.Data.DataRowVersion.Original]) == false)) { transactionLogItem.Add(columnIndex); transactionLogItem.Add(iRow[columnIndex]); } } DataModel.AddTransaction(iRow, transactionLogItem.ToArray()); iRow.AcceptChanges(); } else { if ((iRow.RowState == global::System.Data.DataRowState.Added)) { transactionLogItem.Clear(); transactionLogItem.Add(global::FluidTrade.Core.RecordState.Added); transactionLogItem.Add(iTable.Ordinal); for (int keyIndex = 0; (keyIndex < iTable.PrimaryKey.Length); keyIndex = (keyIndex + 1)) { transactionLogItem.Add(iRow[iTable.PrimaryKey[keyIndex]]); } for (int columnIndex = 0; (columnIndex < iTable.Columns.Count); columnIndex = (columnIndex + 1)) { if ((iRow[columnIndex].Equals(iTable.Columns[columnIndex].DefaultValue) == false)) { transactionLogItem.Add(columnIndex); transactionLogItem.Add(iRow[columnIndex]); } } DataModel.AddTransaction(iRow, transactionLogItem.ToArray()); iRow.AcceptChanges(); } else { transactionLogItem.Clear(); transactionLogItem.Add(global::FluidTrade.Core.RecordState.Deleted); transactionLogItem.Add(iTable.Ordinal); for (int keyIndex = 0; (keyIndex < iTable.PrimaryKey.Length); keyIndex = (keyIndex + 1)) { transactionLogItem.Add(iRow[iTable.PrimaryKey[keyIndex], global::System.Data.DataRowVersion.Original]); } DataModel.AddTransaction(iRow, transactionLogItem.ToArray()); iRow.AcceptChanges(); } } } } finally { ClearRowLockList(); DataModel.TransactionLogLock.ExitWriteLock(); DataModel.DataLock.ExitWriteLock(); try { //txn is done remove this txn from the threads stack //in theory the stack should only be accessed from the same thread so dont need a lock //although might want to look at the stack through the DataModelTransaction //via another thread. so lock just to be safe lock (this.dataModelTransactionStack) this.dataModelTransactionStack.Pop(); } catch (Exception ex) { try { global::FluidTrade.Core.EventLog.Information("Error in Commit dataModelTransactionStack.Pop {0}\r\n{1}", ex.Message, ex.StackTrace); } catch { } } } enlistment.Done(); }
private void ReadData() { global::System.Collections.Generic.IList <string> RenderItemList = new global::System.Collections.Generic.List <string>(), RenderDeleteList = new global::System.Collections.Generic.List <string>(); do { while (this.Base.HasChange)//如果得到或者設置數據狀態改變 { // read current job information ..//讀黨前的工作信息 DataTable DataStatus = this.Base.GetQueueStatus; if (DataStatus != null) { #region Invoke Render Status Data Object Delegate Procedure調用Render狀態數據對象代表Procedure RenderDataCallBack RenderData = delegate(ListViewItem Item, string DeleteItemText) { if (!string.IsNullOrEmpty(DeleteItemText)) { for (int i = 0; i < ListView_Render_Status.Items.Count; i++) { // processing application all events ..//進程應用程序所有事件 Application.DoEvents(); if (this.ListView_Render_Status.Items[i].SubItems[0].Text == DeleteItemText) { // remove item ..//移除項 this.ListView_Render_Status.Items[i].Remove(); } // refresh control ..//刷新控制 this.ListView_Render_Status.Update(); } return; } foreach (ListViewItem RenderItem in this.ListView_Render_Status.Items) { // processing application all events ..//進程應用程序所有事件 Application.DoEvents(); if (RenderItem.Text == Item.Text) { // update the item of sub items ..//修改子項的項 for (int i = 0; i < RenderItem.SubItems.Count; i++) { RenderItem.SubItems[i] = Item.SubItems[i]; } // refresh control ..//刷新控制 this.ListView_Render_Status.Update(); return; } } // processing application all events ..//processing應用程序所有事件 Application.DoEvents(); // add new items to the listview control ..//添加新項到listview控制 this.ListView_Render_Status.Items.Add(Item); // sorting ..//排序 this.ListViewSorter.SortColumn = 0; this.ListView_Render_Status.Sort(); // refresh control ..//刷新控制 this.ListView_Render_Status.Update(); // append to logs object ..//追加到日志對象 RenderEvents.AppendLog(string.Format("{0}", "refresh listview render data.")); }; foreach (global::System.Data.DataRow row in DataStatus.Rows) { if (!RenderItemList.Contains(row["Job_Id"].ToString().Trim())) { RenderItemList.Add(row["Job_Id"].ToString().Trim()); } string[] subitems = { row["Job_Id"].ToString().Trim(), row["Job_Group_Id"].ToString().Trim(), row["Proc_Id"].ToString().Trim(), row["Proc_Type"].ToString().Trim(), row["Command"].ToString().Trim(), row["Args"].ToString().Trim(), row["Status"].ToString().Trim(), row["Start_Time"].ToString().Trim(), row["Finish_Time"].ToString().Trim() }; try { // invoke job list view delegate control ..//調用工作列view代表控制 this.Invoke(RenderData, new object[] { new ListViewItem(subitems), null });//調用RenderData } catch (InvalidOperationException) { // if delegate object already clean, exit loop ..//如果代表對象已經清空,退出loop break; } } // search deleted items ..//查看刪除項 foreach (string s in RenderItemList) { if (DataStatus.PrimaryKey.Length == 0) { break; } if (!DataStatus.Rows.Contains(s)) { try { // invoke job list view delegate control ..//調用工作列視圖代表控制 this.Invoke(RenderData, new object[] { new ListViewItem(), s }); // add to remove list ..//添加到移除列 RenderDeleteList.Add(s); } catch (InvalidOperationException) { // if delegate object already clean, exit loop ..//如果代表對象已經清空,退出loop break; } } } foreach (string s in RenderDeleteList) { // remove data record ..//移除數據記錄 RenderItemList.Remove(s); } // clear all delete list ..//清空所有刪除列 RenderDeleteList.Clear(); #endregion } // reset change flag ..//重置改變標志 this.Base.HasChange = false; } // set access state timespan ..//設置接口狀態timespan Thread.Sleep(500); } while (!requeststop); }