public void SetContents(string path, HttpStatusCode status, string contentType, string etag, DateTime?modified, byte[] contents) { if (contents.Length == 0) { Console.Error.WriteLine("{0} - {1} (Content is empty)", (int)status, path); } ContentRecord rec = _data[path]; ITransactable pendingUpdate = null; try { ContentRecord.Builder builder = rec.ToBuilder() .SetContentUri(path) .SetLastCrawled(CrawlTime) .SetLastValid(CrawlTime) .SetHttpStatus((uint)status) ; builder.ClearContentRedirect(); builder.SetContentType(contentType); builder.SetContentLength((uint)contents.Length); if (!String.IsNullOrEmpty(etag)) { builder.SetETag(etag); } string hash = Hash.SHA256(contents).ToString(); if (hash != builder.HashOriginal) { Modified = true; builder.SetHashOriginal(hash); builder.SetDateModified(CrawlTime); pendingUpdate = _data.WriteContent(builder, contents); } if (_data.AddOrUpdate(path, rec = builder.Build())) { if (pendingUpdate != null) { pendingUpdate.Commit(); pendingUpdate.Dispose(); pendingUpdate = null; } } } finally { if (pendingUpdate != null) { pendingUpdate.Rollback(); pendingUpdate.Dispose(); } } ProcessFileContent(rec, contents); }
public ITransactable WriteContent(ContentRecord.Builder builder, byte[] contents) { byte[] compressed; builder.SetContentLength((uint)contents.Length); if (contents.TryCompress(out compressed)) { builder.SetHashContents(Hash.SHA256(compressed).ToString()); builder.SetCompressedLength((uint)compressed.Length); return(WriteBytes(builder, compressed)); } else { builder.SetHashContents(Hash.SHA256(contents).ToString()); builder.ClearCompressedLength(); return(WriteBytes(builder, contents)); } }