本文整理汇总了C#中RavenJObject.EnsureSnapshot方法的典型用法代码示例。如果您正苦于以下问题:C# RavenJObject.EnsureSnapshot方法的具体用法?C# RavenJObject.EnsureSnapshot怎么用?C# RavenJObject.EnsureSnapshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RavenJObject
的用法示例。
在下文中一共展示了RavenJObject.EnsureSnapshot方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AfterPut
public override void AfterPut(string key, RavenJObject document, RavenJObject metadata, System.Guid etag, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven/"))
{
return;
}
var entityName = metadata.Value<string>(Constants.RavenEntityName) + "/";
var properties = metadata.Value<RavenJArray>(Constants.EnsureUniqueConstraints);
if (properties == null || properties.Length <= 0)
return;
var constraintMetaObject = new RavenJObject { { Constants.IsConstraintDocument, true } };
constraintMetaObject.EnsureSnapshot();
foreach (var property in properties)
{
var propName = ((RavenJValue)property).Value.ToString();
var uniqueValue = document.Value<string>(propName);
if(uniqueValue == null)
continue;
string documentName = "UniqueConstraints/" + entityName + propName + "/" +Util.EscapeUniqueValue(uniqueValue);
Database.Put(
documentName,
null,
RavenJObject.FromObject(new { RelatedId = key }),
(RavenJObject)constraintMetaObject.CreateSnapshot(),
transactionInformation);
}
}
示例2: Constants
static Constants()
{
InDatabaseKeyVerificationDocumentContents = new RavenJObject
{
{"Text", "The encryption is correct."}
};
InDatabaseKeyVerificationDocumentContents.EnsureSnapshot();
}
示例3: Put
public PutResult Put(string key, Etag etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
workContext.DocsPerSecIncreaseBy(1);
key = string.IsNullOrWhiteSpace(key) ? Guid.NewGuid().ToString() : key.Trim();
RemoveReservedProperties(document);
RemoveMetadataReservedProperties(metadata);
Etag newEtag = Etag.Empty;
lock (putSerialLock)
{
TransactionalStorage.Batch(actions =>
{
if (key.EndsWith("/"))
{
key += GetNextIdentityValueWithoutOverwritingOnExistingDocuments(key, actions, transactionInformation);
}
AssertPutOperationNotVetoed(key, metadata, document, transactionInformation);
if (transactionInformation == null)
{
PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, null));
var addDocumentResult = actions.Documents.AddDocument(key, etag, document, metadata);
newEtag = addDocumentResult.Etag;
CheckReferenceBecauseOfDocumentUpdate(key, actions);
metadata[Constants.LastModified] = addDocumentResult.SavedAt;
metadata.EnsureSnapshot("Metadata was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?");
document.EnsureSnapshot("Document was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?");
PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, null));
actions.AfterStorageCommitBeforeWorkNotifications(new JsonDocument
{
Metadata = metadata,
Key = key,
DataAsJson = document,
Etag = newEtag,
LastModified = addDocumentResult.SavedAt,
SkipDeleteFromIndex = addDocumentResult.Updated == false
}, indexingExecuter.PrefetchingBehavior.AfterStorageCommitBeforeWorkNotifications);
TransactionalStorage
.ExecuteImmediatelyOrRegisterForSynchronization(() =>
{
PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag));
RaiseNotifications(new DocumentChangeNotification
{
Id = key,
Type = DocumentChangeTypes.Put,
Etag = newEtag,
});
});
}
else
{
newEtag = actions.Transactions.AddDocumentInTransaction(key, etag,
document, metadata, transactionInformation);
}
workContext.ShouldNotifyAboutWork(() => "PUT " + key);
});
}
log.Debug("Put document {0} with etag {1}", key, newEtag);
return new PutResult
{
Key = key,
ETag = newEtag
};
}
示例4: Put
public PutResult Put(string key, Etag etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
WorkContext.MetricsCounters.DocsPerSecond.Mark();
key = string.IsNullOrWhiteSpace(key) ? Guid.NewGuid().ToString() : key.Trim();
RemoveReservedProperties(document);
RemoveMetadataReservedProperties(metadata);
Etag newEtag = Etag.Empty;
using (Database.DocumentLock.Lock())
{
TransactionalStorage.Batch(actions =>
{
if (key.EndsWith("/"))
{
key += GetNextIdentityValueWithoutOverwritingOnExistingDocuments(key, actions);
}
AssertPutOperationNotVetoed(key, metadata, document, transactionInformation);
if (transactionInformation == null)
{
if (Database.InFlightTransactionalState.IsModified(key))
throw new ConcurrencyException("PUT attempted on : " + key +
" while it is being locked by another transaction");
Database.PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, null));
var addDocumentResult = actions.Documents.AddDocument(key, etag, document, metadata);
newEtag = addDocumentResult.Etag;
Database.Indexes.CheckReferenceBecauseOfDocumentUpdate(key, actions);
metadata[Constants.LastModified] = addDocumentResult.SavedAt;
metadata.EnsureSnapshot(
"Metadata was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?");
document.EnsureSnapshot(
"Document was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?");
actions.AfterStorageCommitBeforeWorkNotifications(new JsonDocument
{
Metadata = metadata,
Key = key,
DataAsJson = document,
Etag = newEtag,
LastModified = addDocumentResult.SavedAt,
SkipDeleteFromIndex = addDocumentResult.Updated == false
}, documents =>
{
if(Database.IndexDefinitionStorage.IndexesCount == 0 || Database.WorkContext.RunIndexing == false)
return;
Database.Prefetcher.AfterStorageCommitBeforeWorkNotifications(PrefetchingUser.Indexer, documents);
});
if (addDocumentResult.Updated)
Database.Prefetcher.AfterUpdate(key, addDocumentResult.PrevEtag);
Database.PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, null));
TransactionalStorage
.ExecuteImmediatelyOrRegisterForSynchronization(() =>
{
Database.PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag));
var newDocumentChangeNotification =
new DocumentChangeNotification
{
Id = key,
Type = DocumentChangeTypes.Put,
TypeName = metadata.Value<string>(Constants.RavenClrType),
CollectionName = metadata.Value<string>(Constants.RavenEntityName),
Etag = newEtag
};
Database.Notifications.RaiseNotifications(newDocumentChangeNotification, metadata);
});
WorkContext.ShouldNotifyAboutWork(() => "PUT " + key);
}
else
{
var doc = actions.Documents.DocumentMetadataByKey(key);
newEtag = Database.InFlightTransactionalState.AddDocumentInTransaction(key, etag, document, metadata,
transactionInformation,
doc == null
? Etag.Empty
: doc.Etag,
UuidGenerator);
}
});
Log.Debug("Put document {0} with etag {1}", key, newEtag);
return new PutResult
{
Key = key,
ETag = newEtag
};
}
}
示例5: Put
public PutResult Put(string key, Guid? etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
workContext.DocsPerSecIncreaseBy(1);
key = string.IsNullOrWhiteSpace(key) ? Guid.NewGuid().ToString() : key.Trim();
RemoveReservedProperties(document);
RemoveReservedProperties(metadata);
Guid newEtag = Guid.Empty;
lock (putSerialLock)
{
TransactionalStorage.Batch(actions =>
{
if (key.EndsWith("/"))
{
key += GetNextIdentityValueWithoutOverwritingOnExistingDocuments(key, actions, transactionInformation);
}
AssertPutOperationNotVetoed(key, metadata, document, transactionInformation);
if (transactionInformation == null)
{
PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, null));
var addDocumentResult = actions.Documents.AddDocument(key, etag, document, metadata);
newEtag = addDocumentResult.Etag;
PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, null));
metadata.EnsureSnapshot();
document.EnsureSnapshot();
actions.AfterCommit(new JsonDocument
{
Metadata = metadata,
Key = key,
DataAsJson = document,
Etag = newEtag,
LastModified = addDocumentResult.SavedAt,
SkipDeleteFromIndex = addDocumentResult.Updated == false
}, indexingExecuter.AfterCommit);
TransactionalStorage
.ExecuteImmediatelyOrRegisterForSyncronization(() =>
{
PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag));
RaiseNotifications(new DocumentChangeNotification
{
Name = key,
Type = DocumentChangeTypes.Put,
Etag = newEtag,
});
});
}
else
{
newEtag = actions.Transactions.AddDocumentInTransaction(key, etag,
document, metadata, transactionInformation);
}
workContext.ShouldNotifyAboutWork(() => "PUT " + key);
});
}
log.Debug("Put document {0} with etag {1}", key, newEtag);
return new PutResult
{
Key = key,
ETag = newEtag
};
}