本文整理汇总了C#中DataContext.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.BeginTransaction方法的具体用法?C# DataContext.BeginTransaction怎么用?C# DataContext.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataContext
的用法示例。
在下文中一共展示了DataContext.BeginTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateCompany2
static void UpdateCompany2(IConfigurator configurator, string companyId, int companyIndex, int companiesCount, bool processServices)
{
string counter = string.Empty;
if (companiesCount > 1)
counter = string.Format(CultureInfo.InvariantCulture, " {0} of {1}", companyIndex, companiesCount);
LogFile.WriteLine();
LogFile.WriteLine("* Updating Company", counter, " *");
LogFile.WriteFormatted("* Id: {0} *", companyId);
// Load company info
ICompanyInfo company = configurator.GetCompanyInfo(companyId);
if (company == null)
LogFile.WriteLine("* Company not found *");
else
{
LogFile.WriteFormatted("* Host: {0} *", company.Host);
string companyRoot = Path.Combine(configurator.InstallPath, company.CodePath);
string webPath = Path.Combine(companyRoot, "Web");
string portalPath = Path.Combine(webPath, "Portal");
IIisManager iisManager = IisManager.Create(webPath);
try
{
ManageDemoDatabase(configurator, false, company.Host, company.Database);
string connectionString = GetWebApplicationConnectionString(portalPath);
using (DataContext dataContext = new DataContext(connectionString))
using (DataContextSwitcher switcher = new DataContextSwitcher(dataContext))
using (TransactionScope transaction = dataContext.BeginTransaction())
{
if (processServices)
{
// Disable ScheduleService for company
if (company.IsScheduleServiceEnabled)
DisableScheduleService(configurator, companyId);
if (iisManager.IisVersion > 5)
{
// IIS 6+: Stop web site
StopWebSite(iisManager, company.SiteId);
// IIS 6+: Stop portal pool
StopApplicationPool(iisManager, company.PortalPool);
// IIS 6+: Stop IM pool
StopApplicationPool(iisManager, company.IMPool);
}
else
{
// IIS 5: Stop IIS
StopIis();
}
}
// Update files
UpdateFiles(company.CodeVersion, companyRoot, true);
// Update configs
UpdateConfigs(company.CodeVersion, companyRoot);
if (company.DatabaseState == 6) // Ready
UpdateDatabase(ScriptType.SqlPortal, company.Database, companyRoot);
else
LogFile.WriteLine("* Company database is not ready *");
// Update company version in ibn.config
configurator.UpdateCompanyVersion(companyId);
if (processServices)
{
if (iisManager.IisVersion > 5)
{
// IIS 6+: Start IM pool
StartApplicationPool(iisManager, company.IMPool);
// IIS 6+: Start portal pool
StartApplicationPool(iisManager, company.PortalPool);
// Start web site
StartWebSite(iisManager, company.SiteId);
}
else
{
// IIS 5: Start IIS
StartIis();
}
// Enable ScheduleService for company
if (company.IsScheduleServiceEnabled)
EnableScheduleService(configurator, companyId);
}
transaction.Commit();
}
}
catch (Exception ex)
{
LogFile.WriteLine("* Failed *");
LogFile.WriteLine();
//.........这里部分代码省略.........
示例2: UpdateCommon2
static void UpdateCommon2(IAspInfo asp)
{
LogFile.WriteLine();
LogFile.WriteLine("* Updating common components *");
string commonRoot = Settings.InstallDir;
try
{
int maxUpdateVersion = FindMaxUpdateVersion();
Version version = new Version(IbnConst.FullVersion);
int newCommonVersion = Math.Max(version.Build, maxUpdateVersion);
// Update files
UpdateFiles(Settings.CommonVersion, commonRoot, false);
// Update configs
UpdateConfigs(Settings.CommonVersion, null);
// Update ASP database
if (asp != null)
{
string aspPath = Path.Combine(commonRoot, "Asp");
string connectionString = GetWebApplicationConnectionString(aspPath);
using (DataContext dataContext = new DataContext(connectionString))
using (DataContextSwitcher switcher = new DataContextSwitcher(dataContext))
using (TransactionScope transaction = dataContext.BeginTransaction())
{
UpdateDatabase(ScriptType.SqlAsp, asp.Database, null);
// Update common version in registry
Settings.UpdateCommonVersion(newCommonVersion);
transaction.Commit();
}
}
if (asp == null)
{
// Update common version in registry
Settings.UpdateCommonVersion(newCommonVersion);
}
}
catch (Exception ex)
{
LogFile.WriteLine("* Failed *");
LogFile.WriteLine();
LogFile.WriteLine(ex.ToString());
LogFile.WriteLine();
LogFile.WriteLine("Rollback started");
#region Undo changes
// Recover configs
RecoverConfigs();
// Recover files
RecoverFiles(commonRoot);
#endregion
LogFile.WriteLine("Rollback finished");
throw;
}
finally
{
// Delete backup files
DeleteBackupFiles();
}
LogFile.WriteLine("* OK *");
}