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


C# IDatabaseCommands.ForSystemDatabase方法代码示例

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


在下文中一共展示了IDatabaseCommands.ForSystemDatabase方法的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.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

示例2: WaitForRestore

        protected void WaitForRestore(IDatabaseCommands databaseCommands)
        {
            var systemDatabaseCommands = databaseCommands.ForSystemDatabase(); // need to be sure that we are checking system database

            var failureMessages = new[]
            {
                                      "Esent Restore: Failure! Could not restore database!", 
                                      "Error: Restore Canceled", 
                                      "Restore Operation: Failure! Could not restore database!"
                                  };

            var restoreFinishMessages = new[]
                {
                    "The new database was created",
                    "Esent Restore: Restore Complete", 
                    "Restore ended but could not create the datebase document, in order to access the data create a database with the appropriate name",
                };

            var done = SpinWait.SpinUntil(() =>
            {
                // We expect to get the doc from the <system> database
                var doc = systemDatabaseCommands.Get(RestoreStatus.RavenRestoreStatusDocumentKey);

                if (doc == null)
                    return false;

                var status = doc.DataAsJson.Deserialize<RestoreStatus>(new DocumentConvention());

                if (failureMessages.Any(status.Messages.Contains))
                    throw new InvalidOperationException("Restore failure: " + status.Messages.Aggregate(string.Empty, (output, message) => output + (message + Environment.NewLine)));

                return restoreFinishMessages.Any(status.Messages.Contains);
            }, TimeSpan.FromMinutes(5));

            if (!done) throw new Exception("WaitForRestore failed");
        }
开发者ID:hero106wen,项目名称:ravendb,代码行数:36,代码来源:RavenTestBase.cs


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