本文整理汇总了C#中IDatabaseCommands.ForDefaultDatabase方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabaseCommands.ForDefaultDatabase方法的具体用法?C# IDatabaseCommands.ForDefaultDatabase怎么用?C# IDatabaseCommands.ForDefaultDatabase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDatabaseCommands
的用法示例。
在下文中一共展示了IDatabaseCommands.ForDefaultDatabase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public void Execute(Guid myResourceManagerId, IDatabaseCommands commands)
{
var resourceManagersRequiringRecovery = new HashSet<Guid>();
using (var store = IsolatedStorageFile.GetMachineStoreForDomain())
{
var filesToDelete = new List<string>();
foreach (var file in store.GetFileNames("*.recovery-information"))
{
var txId = Guid.Empty;
try
{
IsolatedStorageFileStream stream;
try
{
stream = store.OpenFile(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
}
catch (Exception e)
{
logger.WarnException("Could not open recovery information: " + file +", this is expected if it is an active transaction / held by another server", e);
continue;
}
using (stream)
using(var reader = new BinaryReader(stream))
{
var resourceManagerId = new Guid(reader.ReadString());
if(myResourceManagerId != resourceManagerId)
continue; // it doesn't belong to us, ignore
filesToDelete.Add(file);
txId = new Guid(reader.ReadString());
var db = reader.ReadString();
var dbCmds = string.IsNullOrEmpty(db) == false ?
commands.ForDatabase(db) :
commands.ForDefaultDatabase();
TransactionManager.Reenlist(resourceManagerId, stream.ReadData(), new InternalEnlistment(dbCmds, txId));
resourceManagersRequiringRecovery.Add(resourceManagerId);
logger.Info("Recovered transaction {0}", txId);
}
}
catch (Exception e)
{
logger.WarnException("Could not re-enlist in DTC transaction for tx: " + txId, e);
}
}
foreach (var rm in resourceManagersRequiringRecovery)
{
try
{
TransactionManager.RecoveryComplete(rm);
}
catch (Exception e)
{
logger.WarnException("Could not properly complete recovery of resource manager: " + rm, e);
}
}
var errors = new List<Exception>();
foreach (var file in filesToDelete)
{
try
{
if (store.FileExists(file))
store.DeleteFile(file);
}
catch (Exception e)
{
errors.Add(e);
}
}
if (errors.Count > 0)
throw new AggregateException(errors);
}
}
示例2: Execute
public void Execute(IDatabaseCommands commands)
{
var resourceManagersRequiringRecovery = new HashSet<Guid>();
using (var store = IsolatedStorageFile.GetMachineStoreForDomain())
{
foreach (var file in store.GetFileNames("*.recovery-information"))
{
var txId = Guid.Empty;
try
{
using (var fileStream = store.OpenFile(file, FileMode.Open, FileAccess.Read))
using(var reader = new BinaryReader(fileStream))
{
var resourceManagerId = new Guid(reader.ReadString());
txId = new Guid(reader.ReadString());
var db = reader.ReadString();
var dbCmds = string.IsNullOrEmpty(db) == false ?
commands.ForDatabase(db) :
commands.ForDefaultDatabase();
TransactionManager.Reenlist(resourceManagerId, fileStream.ReadData(), new InternalEnlistment(dbCmds, txId));
resourceManagersRequiringRecovery.Add(resourceManagerId);
logger.Info("Recovered transaction {0}", txId);
}
}
catch (Exception e)
{
logger.WarnException("Could not re-enlist in DTC transaction for tx: " + txId, e);
}
}
foreach (var rm in resourceManagersRequiringRecovery)
{
try
{
TransactionManager.RecoveryComplete(rm);
}
catch (Exception e)
{
logger.WarnException("Could not properly complete recovery of resource manager: " + rm, e);
}
}
var errors = new List<Exception>();
foreach (var file in store.GetFileNames("*.recovery-information"))
{
try
{
if (store.FileExists(file))
store.DeleteFile(file);
}
catch (Exception e)
{
errors.Add(e);
}
}
if (errors.Count > 0)
throw new AggregateException(errors);
}
}