当前位置: 首页>>代码示例>>C#>>正文


C# IDatabaseCommands.ForDatabase方法代码示例

本文整理汇总了C#中IDatabaseCommands.ForDatabase方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabaseCommands.ForDatabase方法的具体用法?C# IDatabaseCommands.ForDatabase怎么用?C# IDatabaseCommands.ForDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDatabaseCommands的用法示例。


在下文中一共展示了IDatabaseCommands.ForDatabase方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetupCommands

 private static IDatabaseCommands SetupCommands(IDatabaseCommands databaseCommands, string database, ICredentials credentialsForSession, OpenSessionOptions options)
 {
     if (database != null)
         databaseCommands = databaseCommands.ForDatabase(database);
     if (credentialsForSession != null)
         databaseCommands = databaseCommands.With(credentialsForSession);
     if (options.ForceReadFromMaster)
         databaseCommands.ForceReadFromMaster();
     return databaseCommands;
 }
开发者ID:heinnge,项目名称:ravendb,代码行数:10,代码来源:DocumentStore.cs

示例2: 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.ForSystemDatabase();

							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);
			}
		}
开发者ID:jjchiw,项目名称:ravendb,代码行数:77,代码来源:PendingTransactionRecovery.cs

示例3: 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);
			}
		}
开发者ID:remcoros,项目名称:ravendb,代码行数:62,代码来源:PendingTransactionRecovery.cs


注:本文中的IDatabaseCommands.ForDatabase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。