本文整理汇总了C#中TransactionInformation类的典型用法代码示例。如果您正苦于以下问题:C# TransactionInformation类的具体用法?C# TransactionInformation怎么用?C# TransactionInformation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransactionInformation类属于命名空间,在下文中一共展示了TransactionInformation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDelete
public override void OnDelete(string key, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven"))
return;
var doc = Database.Get(key, transactionInformation);
if (doc == null)
return;
var metadata = doc.Metadata;
var entityName = metadata.Value<string>(Constants.RavenEntityName) + "/";
var uniqueConstraits = metadata.Value<RavenJArray>(Constants.EnsureUniqueConstraints);
if (uniqueConstraits == null)
return;
foreach (var property in uniqueConstraits)
{
var constraint = Util.GetConstraint(property);
var prefix = "UniqueConstraints/" + entityName + constraint.PropName+ "/"; // UniqueConstraints/EntityNamePropertyName/
var prop = doc.DataAsJson[constraint.PropName];
string[] uniqueValues;
if (!Util.TryGetUniqueValues(prop, out uniqueValues))
continue;
foreach (var uniqueValue in uniqueValues)
{
Database.Delete(prefix + Util.EscapeUniqueValue(uniqueValue, constraint.CaseInsensitive), null, transactionInformation);
}
}
}
示例2: CanModifyTxId
public void CanModifyTxId()
{
var transactionInformation = new TransactionInformation
{
Id = Guid.NewGuid(),
Timeout = TimeSpan.FromDays(7)
};
using (var tx = NewTransactionalStorage())
{
tx.Batch(mutator => mutator.Transactions.AddDocumentInTransaction("Ayende", null, RavenJObject.FromObject(new { Name = "Rahien" }), new RavenJObject(),
transactionInformation));
var txInfo2 = new TransactionInformation
{
Id = Guid.NewGuid(),
Timeout = TimeSpan.FromDays(1)
};
tx.Batch(mutator => mutator.Transactions.ModifyTransactionId(transactionInformation.Id, txInfo2.Id, txInfo2.Timeout));
tx.Batch(viewer =>
Assert.NotNull(viewer.Documents.DocumentByKey("Ayende", txInfo2)));
}
}
示例3: AfterCommittingCanSeeChangesWithoutTx
public void AfterCommittingCanSeeChangesWithoutTx()
{
var transactionInformation = new TransactionInformation
{
Id = Guid.NewGuid(),
Timeout = TimeSpan.FromDays(7)
};
using (var tx = NewTransactionalStorage())
{
tx.Batch(mutator => mutator.Transactions.AddDocumentInTransaction("Ayende", null, RavenJObject.FromObject(new { Name = "Rahien" }), new RavenJObject(),
transactionInformation));
tx.Batch(mutator => mutator.Transactions.CompleteTransaction(transactionInformation.Id, data =>
{
if (data.Delete)
{
RavenJObject metadata;
mutator.Documents.DeleteDocument(data.Key, null, out metadata);
}
else
mutator.Documents.AddDocument(data.Key, null, data.Data, data.Metadata);
}));
tx.Batch(viewer =>
Assert.NotNull(viewer.Documents.DocumentByKey("Ayende", null)));
}
}
示例4: using
public void Should_save_put_to_tenant_database_if_tenant_database_is_reloaded_in_the_middle_of_the_put_transaction()
{
using (var server = GetNewServer(runInMemory: false))
using (var store = new DocumentStore
{
Url = "http://localhost:8079"
}.Initialize())
{
store.DatabaseCommands.CreateDatabase(new DatabaseDocument { Id = TenantName, Settings = { { "Raven/DataDir", @"~\Databases\Mine" } }, });
var tx1 = new TransactionInformation { Id = Guid.NewGuid().ToString() };
var tx2 = new TransactionInformation { Id = Guid.NewGuid().ToString() };
var tenantDatabaseDocument = store.DatabaseCommands.Get("Raven/Databases/" + TenantName);
server.Database.Put("Raven/Databases/mydb", null, tenantDatabaseDocument.DataAsJson, tenantDatabaseDocument.Metadata, tx1);
var tenantDb = GetDocumentDatabaseForTenant(server, TenantName);
tenantDb.Put("Foo/1", null, new RavenJObject { { "Test", "123" } }, new RavenJObject(), tx2);
server.Database.PrepareTransaction(tx1.Id);
server.Database.Commit(tx1.Id);
tenantDb = GetDocumentDatabaseForTenant(server, TenantName);
tenantDb.PrepareTransaction(tx2.Id);
tenantDb.Commit(tx2.Id);
var fooDoc = tenantDb.Get("Foo/1", new TransactionInformation { Id = Guid.NewGuid().ToString() });
Assert.NotNull(fooDoc);
}
}
示例5: OnPut
public virtual void OnPut(
string key,
RavenJObject document,
RavenJObject metadata,
TransactionInformation transactionInformation)
{
}
示例6: OnPut
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven/")) // we don't deal with system documents
return;
var doc = Database.Get(key, null);
if (doc != null)
{
var history = doc.Metadata.Value<RavenJArray>(ReplicationConstants.RavenReplicationHistory) ?? new RavenJArray();
metadata[ReplicationConstants.RavenReplicationHistory] = history;
history.Add(new RavenJObject
{
{ReplicationConstants.RavenReplicationVersion, doc.Metadata[ReplicationConstants.RavenReplicationVersion]},
{ReplicationConstants.RavenReplicationSource, doc.Metadata[ReplicationConstants.RavenReplicationSource]}
});
if (history.Length > ReplicationConstants.ChangeHistoryLength)
{
history.RemoveAt(0);
}
}
metadata[ReplicationConstants.RavenReplicationVersion] = RavenJToken.FromObject(hiLo.NextId());
metadata[ReplicationConstants.RavenReplicationSource] = RavenJToken.FromObject(Database.TransactionalStorage.Id);
}
示例7: WhileCreatingDocumentInTransactionTryingToWriteOutsideTransactionFail
public void WhileCreatingDocumentInTransactionTryingToWriteOutsideTransactionFail()
{
var transactionInformation = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromMinutes(1) };
db.Put("ayende", null, RavenJObject.Parse("{ayende:'rahien'}"), new RavenJObject(), transactionInformation);
Assert.Throws<ConcurrencyException>(
() => db.Put("ayende", null, RavenJObject.Parse("{ayende:'oren'}"), new RavenJObject(), null));
}
示例8: AssertNotModifiedByAnotherTransaction
public static void AssertNotModifiedByAnotherTransaction(TableStorage storage, ITransactionStorageActions transactionStorageActions, string key, Table.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);
}
示例9: TransactionInformation
private TransactionInformation (TransactionInformation other)
{
local_id = other.local_id;
dtcId = other.dtcId;
creation_time = other.creation_time;
status = other.status;
}
示例10: SetupReplication
private void SetupReplication()
{
if (RoleEnvironment.CurrentRoleInstance.Role.Instances.Count < 2)
{
var tr = new TransactionInformation();
_database.Put("Debug", null,
JObject.Parse(@"{""Url"":""" +
GetEndPointAddress(MyInstanceEndpoint.IPEndpoint) + @"""}"),
new JObject(), tr);
_database.Commit(tr.Id);
}
else
{
var json = BuildDestinationsString();
Trace.WriteLine(json);
var tr = new TransactionInformation();
_database.Delete("Raven/Replication/Destinations", null, tr);
_database.Put("Raven/Replication/Destinations", null, JObject.Parse(json),
new JObject(), tr);
_database.Commit(tr.Id);
}
}
示例11: OnDelete
public override void OnDelete(string key, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven"))
return;
var doc = Database.Get(key, transactionInformation);
if (doc == null)
return;
var metadata = doc.Metadata;
var entityName = metadata.Value<string>(Constants.RavenEntityName) + "/";
var uniqueConstraits = metadata.Value<RavenJArray>(Constants.EnsureUniqueConstraints);
if (uniqueConstraits == null)
return;
foreach (var property in uniqueConstraits)
{
var constraint = Util.GetConstraint(property);
var prefix = "UniqueConstraints/" + entityName + constraint.PropName+ "/"; // UniqueConstraints/EntityNamePropertyName/
var prop = doc.DataAsJson[constraint.PropName];
if (prop == null || prop.Type == JTokenType.Null)
continue;
var array = prop as RavenJArray;
var checkKeys = array != null ? array.Select(p => p.Value<string>()) : new[] {prop.Value<string>()};
foreach (var checkKey in checkKeys)
{
Database.Delete(prefix + Util.EscapeUniqueValue(checkKey, constraint.CaseInsensitive), null, transactionInformation);
}
}
}
示例12: PutNewDocInTxAndThenGetItBeforeCommitInSameTransactionReturnsNonNull
public void PutNewDocInTxAndThenGetItBeforeCommitInSameTransactionReturnsNonNull()
{
var transactionInformation = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromMinutes(1) };
db.Put("ayende", null, RavenJObject.Parse("{ayende:'rahien'}"), new RavenJObject(), transactionInformation);
Assert.NotNull(db.Get("ayende", transactionInformation));
}
示例13: OnDelete
public override void OnDelete(string key, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven"))
return;
var doc = Database.Get(key, transactionInformation);
if (doc == null)
return;
var metadata = doc.Metadata;
var entityName = metadata.Value<string>(Constants.RavenEntityName) + "/";
var uniqueConstraits = metadata.Value<RavenJArray>(Constants.EnsureUniqueConstraints);
if (uniqueConstraits == null)
return;
foreach (var property in uniqueConstraits)
{
var checkKey = "UniqueConstraints/" + entityName + property + "/" + doc.DataAsJson.Value<string>(property.Value<string>());
Database.Delete(checkKey, null, transactionInformation);
}
}
示例14: TransactionInformation
private TransactionInformation(TransactionInformation other)
{
this.local_id = other.local_id;
this.dtcId = other.dtcId;
this.creation_time = other.creation_time;
this.status = other.status;
}
示例15: PutNewDocInTxAndThenGetItBeforeCommitReturnsNull
public void PutNewDocInTxAndThenGetItBeforeCommitReturnsNull()
{
var transactionInformation = new TransactionInformation { Id = Guid.NewGuid(), Timeout = TimeSpan.FromMinutes(1) };
db.Put("ayende", null, RavenJObject.Parse("{ayende:'rahien'}"), new RavenJObject(), transactionInformation);
Assert.True(db.Get("ayende", null).Metadata.Value<bool>(Constants.RavenDocumentDoesNotExists));
}