本文整理汇总了C#中TransactionManager类的典型用法代码示例。如果您正苦于以下问题:C# TransactionManager类的具体用法?C# TransactionManager怎么用?C# TransactionManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransactionManager类属于命名空间,在下文中一共展示了TransactionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveEdits
public static bool SaveEdits(IApplication app, TransactionManager tm)
{
bool result = false;
try
{
if (HasEdits(app, tm))
{
UID pUID = new UIDClass();
pUID.Value = "esriEditor.Editor";
IWorkspaceEdit workspace = (IWorkspaceEdit)tm.Current().PGDBConnection;
IEditor2 editor2 = (IEditor2)app.FindExtensionByCLSID(pUID);
editor2.StopEditing(true);
editor2.StartEditing((IWorkspace)workspace);
workspace.StopEditing(true);
workspace.StartEditing(false);
}
result = true;
}
catch (Exception e)
{
Logger.Write("Error saving edits to PGDB", Logger.LogLevel.Debug);
MessageBox.Show("An error occured while attempting to save current edits.");
result = false;
}
return result;
}
示例2: HasEdits
public static bool HasEdits(IApplication app, TransactionManager tm)
{
try
{
IWorkspaceEdit workspace = (IWorkspaceEdit)tm.Current().PGDBConnection;
bool processQA = false;
bool hasEdits = false;
workspace.HasEdits(ref hasEdits);
UID pUID = new UIDClass();
pUID.Value = "esriEditor.Editor";
IEditor editor = (IEditor)app.FindExtensionByCLSID(pUID);
IEditTask task = editor.CurrentTask;
IEditTask resetTask = editor.get_Task(0);
editor.CurrentTask = resetTask;
editor.CurrentTask = task;
IEditor2 editor2 = (IEditor2)app.FindExtensionByCLSID(pUID);
bool hasCachedEdits = editor2.HasEdits();
return hasCachedEdits || hasEdits;
}
catch (Exception e)
{
Logger.Write("Error testing if transaction has edits: " + e.Message + " : " + e.StackTrace, Logger.LogLevel.Debug);
throw new Exception("Error", e);
}
}
示例3: RunTestsForm
public RunTestsForm(ref dao.QATestCollection tests, IMap map, TransactionManager tm, QAManager qa)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
if (tests == null)
throw new ArgumentNullException("tests", "Must pass collection of QA tests to RunTestsForm");
if (tests.Count == 0)
throw new ArgumentException("No QA tests passed to RunTestsForm", "tests");
if (map == null)
throw new ArgumentNullException("map", "Must pass the focus map to RunTestsForm");
this._tests = tests;
this._tm = tm;
this._qa = qa;
this._map = map;
this._defaults = new util.SystemDefaults();
// Throw TM stuff at the QA tests and see if it sticks
if (tm.Current() != null)
{
object[] theArgs = new object[2] {
new ISDUTLib.tm.dao.EditsDAO((IFeatureWorkspace)tm.Current().PGDBConnection, tm.transactionConfig()),
tm.transactionConfig()
};
for (int i = 0; i < this._tests.Count; i++)
{
this._tests.get_Test(i).Test.UserData = theArgs;
}
}
}
示例4: AfmReturnsRightNumberOfJObjects
public void AfmReturnsRightNumberOfJObjects()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
var formatter = new BSONFormatter();
var core = new FileCore<int, long>() { IdSeed = new Seed32(999), SegmentSeed = new Seed64(), MinimumCoreStride = 512 };
var addEntities = TestResourceFactory.GetMockClassAObjects(10000).ToList();
foreach (var entity in addEntities)
entity.Id = _seed.Increment();
IDictionary<int, long> returnSegments = null;
using (var afm = new AtomicFileManager<MockClassA>(_testName + ".database", core))
{
afm.Load<int>();
using (var manager = new TransactionManager<int, MockClassA>
(new MockTransactionFactory<int, MockClassA>()
, new TransactionSynchronizer<int, MockClassA>()))
{
manager.TransactionCommitted += new TransactionCommit<int, MockClassA>(
delegate(ITransaction<int, MockClassA> tranny)
{
returnSegments = afm.CommitTransaction(tranny, new Dictionary<int, long>());
tranny.MarkComplete();
});
using (var tLock1 = manager.BeginTransaction())
{
addEntities.ForEach(delegate(MockClassA entity)
{
tLock1.Transaction.Enlist(Action.Create, entity.Id, entity);
});
tLock1.Transaction.Commit();
Assert.AreEqual(10000, afm.Length);
}
foreach (var group in afm.AsEnumerable())
{
var match = group.Where(i => i.SelectToken("Id").Value<int>() > 9999).ToList();
if (match == null || !match.Any())
continue;
var result = match.First(r => r.Value<int>("Id") == 10000).ToObject<MockClassC>();
Assert.IsNotNull(result);
Assert.AreEqual(10000, result.Id);
break;
}
}
}
}
示例5: Instead02
private void Instead02(TransactionManager tm, Customer cus)
{
tm.BeginTransaction();
DataRepository.CustomerProvider.Insert(tm, cus);
tm.Commit();
// Or, show the message box after the transaction completed,
// e.g. to notify them of an event after saving
MessageBox.Show("Something...");
}
示例6: Instead01
private void Instead01(TransactionManager tm, Customer cus)
{
MessageBox.Show("Something...");
// Begin the transaction after the message box,
// e.g. if you want to prompt them to do something before saving.
tm.BeginTransaction();
DataRepository.CustomerProvider.Insert(tm, cus);
tm.Commit();
}
示例7: CreateSession
public IDatabaseSession CreateSession(string connectionString)
{
var sqlConnectionProvider = new SqlConnectionProvider(connectionString);
var transactionManager = new TransactionManager(sqlConnectionProvider);
var databaseConnectionManager = new DatabaseCommandProvider(sqlConnectionProvider, transactionManager);
var databaseCommandCreator = new DatabaseCommandFactory(databaseConnectionManager);
var databaseReaderFactory = new SqlDatabaseReaderFactory();
var connectionHandler = new ConnectionHandler();
return new DatabaseSession(databaseCommandCreator, transactionManager, databaseReaderFactory, connectionHandler);
}
示例8: Get
public IList<Transaction> Get(int pageNumber, int pageSize, string filter)
{
var transactionManager = new TransactionManager();
return transactionManager.GetTransactions(new ListOptions
{
PageSize = pageSize,
PageNumber = pageNumber
});
}
示例9: ApplyRecord
/// <summary>
/// Apply a record to placeholders
/// </summary>
/// <param name="placeHolders">List of placeholder which should be applied</param>
/// <param name="recordName">Name of record</param>
/// <returns>Return true if one or more was applied</returns>
public static void ApplyRecord(IEnumerable<PlaceHolder> placeHolders, string recordName)
{
using (Transaction transaction = new TransactionManager().CreateTransaction())
{
foreach (PlaceHolder placeHolder in placeHolders)
{
placeHolder.ApplyRecord(recordName, true); // apply (with page data)
transaction.Commit(); // needed if not placed in project
}
}
}
示例10: GetTransactionsByCategory
public IList<Transaction> GetTransactionsByCategory(string from, string to, string balanceType, string category)
{
var dateFrom = DateTime.ParseExact(from, "yyyyMMdd", CultureInfo.InvariantCulture);
var dateTo = DateTime.ParseExact(to, "yyyyMMdd", CultureInfo.InvariantCulture);
var type = (BalanceType) Enum.Parse(typeof (BalanceType), balanceType, true);
var transactionManager = new TransactionManager();
var list = transactionManager.GetTransactions(dateFrom, dateTo, type, category);
return list;
}
示例11: BadlyMisplacedCode
// SAMPLE 01
//
// As mentioned in "C01_TransactionManager," the idea behind transactions
// is that it should surround a block of code that either saves everything
// or nothing.
//
// Here is the thing to remember: While the transaction is open it will prevent
// anything from accessing the database tables that you are busy with. This is
// to prevent "dirty" or incomplete records.
//
// The caveat: you want your transaction to execute as fast as possible. Be
// like a ninja: get in, do your thing, and get out.
//
private void BadlyMisplacedCode(TransactionManager tm, Customer cus)
{
tm.BeginTransaction();
DataRepository.CustomerProvider.Insert(tm, cus);
MessageBox.Show("Something...");
tm.Commit();
// Can you see it?
// This code will block the Customer table on the entire branch until the user
// clicks "OK" on the message box. The impact of this is enourmous.
}
示例12: ReadTransactionsFromFile_Valid_ObserverNeverCalled
public void ReadTransactionsFromFile_Valid_ObserverNeverCalled()
{
var mockObserver = new Moq.Mock<Observer>();
List<Observer> ol = new List<Observer>();
ol.Add(mockObserver.Object);
List<Product> listOfProducts = new List<Product>();
TransactionManager tm = new TransactionManager(ol, listOfProducts);
tm.ReadTransactionsFromFile(new StreamReader(@"C:\Users\vbhujan\Documents\Cart.txt"));
mockObserver.Verify(o => o.update(), Times.Never);
}
示例13: LsbLinuxHostInstaller
public LsbLinuxHostInstaller(LinuxServiceSettings settings, Installer[] installers, LinuxServiceLogWriter logWriter)
{
if (settings == null)
{
throw new ArgumentNullException(nameof(settings));
}
_settings = settings;
_installers = installers;
_logWriter = logWriter;
_installTransaction = new TransactionManager<LinuxServiceSettings>(_logWriter)
.Stage(Properties.Resources.CreateServiceFileStage, CreateServiceFile, DeleteServiceFile)
.Stage(Properties.Resources.SetServiceFileAsExecutableStage, SetServiceFileAsExecutable)
.Stage(Properties.Resources.RegisterServiceFileStage, RegisterServiceFile, UnregisterServiceFile);
}
示例14: Delete
public override bool Delete(long id, TransactionManager trans)
{
var sqlStatement = "Delete From BoxContract Where Id = @Id";
var parms = new[] { new OleDbParameter("@Id", OleDbType.BigInt) { Value = id } };
try
{
if (trans == null)
AccessHelper.ExecuteNonQuery(this.ConnectionString, sqlStatement, parms);
else
AccessHelper.ExecuteNonQuery(trans.TransactionObject as OleDbTransaction, sqlStatement, parms);
return true;
}
catch (Exception ex)
{
Logger.Error(ex.Message, ex);
return false ;
}
}
示例15: CreateRecordWithValueAndApply
/// <summary>
/// Create a record to a placeHolder by name and apply a record
/// </summary>
/// <param name="placeHolders">List of placeholder which should be applied</param>
/// <param name="placeHolderName">Name of placeholder</param>
/// <param name="recordName">Name of record</param>
/// <param name="variableName">Variable to set</param>
/// <param name="value">New value of the variable</param>
/// <returns>Return true if one or more was applied</returns>
public bool CreateRecordWithValueAndApply(PlaceHolder[] placeHolders, string placeHolderName, string recordName, string variableName, string value)
{
List<PlaceHolder> foundPlaceHolder = placeHolders
.Where(placeHolder => placeHolder.Name.Equals(placeHolderName)) // name
.ToList();
foreach (PlaceHolder placeHolder in foundPlaceHolder)
{
placeHolder.AddRecord(recordName);
placeHolder.set_Value(recordName, variableName, value);
using (Transaction transaction = new TransactionManager().CreateTransaction())
{
placeHolder.ApplyRecord(recordName, true); // apply (with page data)
transaction.Commit(); // needed if not placed in project
}
}
return foundPlaceHolder.Any(); // true == found | false == not found
}