本文整理汇总了C#中Raven.Database.TransactionInformation类的典型用法代码示例。如果您正苦于以下问题:C# TransactionInformation类的具体用法?C# TransactionInformation怎么用?C# TransactionInformation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransactionInformation类属于Raven.Database命名空间,在下文中一共展示了TransactionInformation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPut
public override void OnPut(string key, JObject document, JObject metadata, TransactionInformation transactionInformation)
{
if (VersioningContext.IsInVersioningContext)
return;
if (key.StartsWith("Raven/", StringComparison.InvariantCultureIgnoreCase))
return;
if (excludeByEntityName.Contains(metadata.Value<string>("Raven-Entity-Name")))
return;
if (metadata.Value<string>(RavenDocumentRevisionStatus) == "Historical")
return;
using(VersioningContext.Enter())
{
var copyMetadata = new JObject(metadata);
copyMetadata[RavenDocumentRevisionStatus] = JToken.FromObject("Historical");
copyMetadata.Remove(RavenDocumentRevision);
var parentRevision = metadata.Value<string>(RavenDocumentRevision);
if(parentRevision!=null)
{
copyMetadata[RavenDocumentParentRevision] = key + "/revisions/" + parentRevision;
metadata[RavenDocumentParentRevision] = key + "/revisions/" + parentRevision;
}
PutResult newDoc = Database.Put(key + "/revisions/", null, document, copyMetadata,
transactionInformation);
int revision = int.Parse(newDoc.Key.Split('/').Last());
RemoveOldRevisions(key, revision, transactionInformation);
metadata[RavenDocumentRevisionStatus] = JToken.FromObject("Current");
metadata[RavenDocumentRevision] = JToken.FromObject(revision);
}
}
示例2: AssertNotModifiedByAnotherTransaction
public static void AssertNotModifiedByAnotherTransaction(TableStorage storage, ITransactionStorageActions transactionStorageActions, string key, PersistentDictionary.ReadResult readResult, TransactionInformation transactionInformation)
{
if (readResult == null)
return;
var txIdAsBytes = readResult.Key.Value<byte[]>("txId");
if (txIdAsBytes == null)
return;
var txId = new Guid(txIdAsBytes);
if (transactionInformation != null && transactionInformation.Id == txId)
{
return;
}
var existingTx = storage.Transactions.Read(new JObject { { "txId", txId.ToByteArray() } });
if (existingTx == null)//probably a bug, ignoring this as not a real tx
return;
var timeout = existingTx.Key.Value<DateTime>("timeout");
if (DateTime.UtcNow > timeout)
{
transactionStorageActions.RollbackTransaction(txId);
return;
}
throw new ConcurrencyException("Document '" + key + "' is locked by transacton: " + txId);
}
示例3: OnDelete
public override void OnDelete(string key, TransactionInformation transactionInformation)
{
var document = Database.Get(key, null);
if (document == null)
return;
Database.Delete(document.Metadata.Value<string>("Cascade-Delete"), null, null);
}
示例4: ProcessReadVetoes
public JsonDocument ProcessReadVetoes(JsonDocument document, TransactionInformation transactionInformation, ReadOperation operation)
{
if (document == null)
return document;
foreach (var readTrigger in triggers)
{
var readVetoResult = readTrigger.AllowRead(document.Key, document.DataAsJson ?? document.Projection, document.Metadata, operation, transactionInformation);
switch (readVetoResult.Veto)
{
case ReadVetoResult.ReadAllow.Allow:
break;
case ReadVetoResult.ReadAllow.Deny:
return new JsonDocument
{
DataAsJson = new JObject(),
Metadata = new JObject(
new JProperty("Raven-Read-Veto", new JObject(new JProperty("Reason", readVetoResult.Reason),
new JProperty("Trigger", readTrigger.ToString())
))
)
};
case ReadVetoResult.ReadAllow.Ignore:
return null;
default:
throw new ArgumentOutOfRangeException(readVetoResult.Veto.ToString());
}
}
return document;
}
示例5: PutNewDocInTxAndThenGetItBeforeCommitInSameTransactionReturnsNonNull
public void PutNewDocInTxAndThenGetItBeforeCommitInSameTransactionReturnsNonNull()
{
var transactionInformation = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromMinutes(1) };
db.Put("ayende", null, JObject.Parse("{ayende:'rahien'}"), new JObject(), transactionInformation);
Assert.NotNull(db.Get("ayende", transactionInformation));
}
示例6: AfterDelete
public override void AfterDelete(string key, TransactionInformation transactionInformation)
{
if (ReplicationContext.IsInReplicationContext)
return;
Database.Put(key, null, new JObject(), new JObject(new JProperty("Raven-Delete-Marker", true)),
transactionInformation);
}
示例7: WhileCreatingDocumentInTransactionTryingToWriteOutsideTransactionFail
public void WhileCreatingDocumentInTransactionTryingToWriteOutsideTransactionFail()
{
var transactionInformation = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromMinutes(1) };
db.Put("ayende", null, JObject.Parse("{ayende:'rahien'}"), new JObject(), transactionInformation);
Assert.Throws<ConcurrencyException>(
() => db.Put("ayende", null, JObject.Parse("{ayende:'oren'}"), new JObject(), null));
}
示例8: CanModifyTxId
public void CanModifyTxId()
{
var transactionInformation = new TransactionInformation
{
Id = Guid.NewGuid(),
Timeout = TimeSpan.FromDays(7)
};
using (var tx = new TransactionalStorage("test"))
{
tx.Write(mutator => mutator.Transactions.AddDocumentInTransaction("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject(),
transactionInformation));
var txInfo2 = new TransactionInformation
{
Id = Guid.NewGuid(),
Timeout = TimeSpan.FromDays(1)
};
tx.Write(mutator => mutator.Transactions.ModifyTransactionId(transactionInformation.Id, txInfo2.Id, txInfo2.Timeout));
tx.Read(viewer =>
Assert.NotNull(viewer.Documents.DocumentByKey("Ayende", txInfo2)));
}
}
示例9: DeletingDocumentInTransactionInNotVisibleBeforeCommit
public void DeletingDocumentInTransactionInNotVisibleBeforeCommit()
{
db.Put("ayende", null, JObject.Parse("{ayende:'oren'}"), new JObject(), null);
var transactionInformation = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromMinutes(1) };
db.Delete("ayende", null, transactionInformation);
Assert.NotNull(db.Get("ayende", null));
}
示例10: AfterCommittingCanSeeChangesWithoutTx
public void AfterCommittingCanSeeChangesWithoutTx()
{
var transactionInformation = new TransactionInformation
{
Id = Guid.NewGuid(),
Timeout = TimeSpan.FromDays(7)
};
using (var tx = new TransactionalStorage("test"))
{
tx.Write(mutator => mutator.Transactions.AddDocumentInTransaction("Ayende", null, JObject.FromObject(new { Name = "Rahien" }), new JObject(),
transactionInformation));
tx.Write(mutator => mutator.Transactions.CompleteTransaction(transactionInformation.Id, data =>
{
if (data.Delete)
{
JObject metadata;
mutator.Documents.DeleteDocument(data.Key, null, out metadata);
}
else
mutator.Documents.AddDocument(data.Key, null, data.Data, data.Metadata);
}));
tx.Read(viewer =>
Assert.NotNull(viewer.Documents.DocumentByKey("Ayende", null)));
}
}
示例11: WhileDocumentIsBeingUpdatedInTransactionCannotUpdateOutsideTransaction
public void WhileDocumentIsBeingUpdatedInTransactionCannotUpdateOutsideTransaction()
{
db.Put("ayende", null, JObject.Parse("{ayende:'oren'}"), new JObject(), null);
var transactionInformation = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromMinutes(1) };
db.Put("ayende", null, JObject.Parse("{ayende:'rahien'}"), new JObject(), transactionInformation);
Assert.Throws<ConcurrencyException>(
() => db.Put("ayende", null, JObject.Parse("{ayende:'oren'}"), new JObject(), null));
}
示例12: RemoveOldRevisions
private void RemoveOldRevisions(string key, int revision, VersioningConfiguration versioningConfiguration, TransactionInformation transactionInformation)
{
int latestValidRevision = revision - versioningConfiguration.MaxRevisions;
if (latestValidRevision <= 1)
return;
Database.Delete(key + "/revisions/" + (latestValidRevision - 1), null, transactionInformation);
}
示例13: WhenUsingTransactionWillFailIfDocumentEtagDoesNotMatch
public void WhenUsingTransactionWillFailIfDocumentEtagDoesNotMatch()
{
db.Put("ayende", null, JObject.Parse("{ayende:'oren'}"), new JObject(), null);
var transactionInformation = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromMinutes(1) };
Assert.Throws<ConcurrencyException>(
() =>
db.Put("ayende", Guid.NewGuid(), JObject.Parse("{ayende:'rahien'}"), new JObject(),
transactionInformation));
}
示例14: AllowPut
public override VetoResult AllowPut(string key, JObject document, JObject metadata, TransactionInformation transactionInformation)
{
if (VersioningContext.IsInVersioningContext)
return VetoResult.Allowed;
if (metadata.Value<string>(RavenDocumentRevisionStatus) == "Historical")
return VetoResult.Deny("Modifying a historical revision is not allowed");
return VetoResult.Allowed;
}
示例15: AllowPut
public override VetoResult AllowPut(string key, JObject document, JObject metadata, TransactionInformation transactionInformation)
{
var name = document["name"];
if(name != null && name.Value<string>().Any(char.IsUpper))
{
return VetoResult.Deny("Can't use upper case characters in the 'name' property");
}
return VetoResult.Allowed;
}