/// <summary> /// Gets a document containing all of the temporal metadata for every revision of a document. /// </summary> /// <param name="session">The advanced session.</param> /// <param name="id">The non-temporal document id.</param> /// <returns>A TemporalHistory document.</returns> public static TemporalHistory GetTemporalHistoryFor(this IAdvancedDocumentSessionOperations session, string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } if (id.IndexOf(TemporalConstants.TemporalKeySeparator, StringComparison.OrdinalIgnoreCase) != -1) { throw new ArgumentException("Pass the non-temporal id, not a temporal revisions key."); } if (id.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException("Raven system docs can not be versioned."); } var key = TemporalHistory.GetKeyFor(id); var history = ((IDocumentSession)session).Load <TemporalHistory>(key); if (history != null) { // don't track this in the session session.Evict(history); } return(history); }
public static void SaveTemporalHistoryFor(this DocumentDatabase database, string key, TemporalHistory history, TransactionInformation transactionInformation, Etag etag) { using (database.DisableAllTriggersForCurrentThread()) { var document = RavenJObject.FromObject(history); var metadata = new RavenJObject(); database.Put(TemporalHistory.GetKeyFor(key), etag, document, metadata, transactionInformation); } }
public static TemporalHistory GetTemporalHistoryFor(this DocumentDatabase database, string key, TransactionInformation transactionInformation, out Etag etag) { using (database.DisableAllTriggersForCurrentThread()) { var doc = database.Get(TemporalHistory.GetKeyFor(key), transactionInformation); if (doc == null) { etag = null; return(new TemporalHistory()); } etag = doc.Etag; return(doc.DataAsJson.JsonDeserialization <TemporalHistory>()); } }