public bool FilterAttachments(AttachmentInformation attachment, string destinationInstanceId) { if (attachment.Key.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase) || // don't replicate system attachments attachment.Key.StartsWith("transactions/recoveryInformation", StringComparison.OrdinalIgnoreCase)) // don't replicate transaction recovery information return false; // explicitly marked to skip if (attachment.Metadata.ContainsKey(Constants.NotForReplication) && attachment.Metadata.Value<bool>(Constants.NotForReplication)) return false; if (attachment.Metadata.ContainsKey(Constants.RavenReplicationConflict))// don't replicate conflicted documents, that just propagate the conflict return false; // we don't replicate stuff that was created there if (attachment.Metadata.Value<string>(Constants.RavenReplicationSource) == destinationInstanceId) return false; switch (ReplicationOptionsBehavior) { case TransitiveReplicationOptions.None: return attachment.Metadata.Value<string>(Constants.RavenReplicationSource) == null || (attachment.Metadata.Value<string>(Constants.RavenReplicationSource) == CurrentDatabaseId); } return true; }
// This is fired when retrieving INFORMATION about the attachment public override void OnRead(AttachmentInformation information) { // Get the filename, and make sure its in the returned metadata var filename = AugmentMetadataWithFilename(information.Key, information.Metadata); // We can't do anything else without a filename if (filename == null) return; // Add a Raven-Attachment-Content-Type header var contentType = Utils.GetMimeType(filename); if (!string.IsNullOrEmpty(contentType)) information.Metadata["Raven-Attachment-Content-Type"] = contentType; }
public async Task<byte[]> GetAttachmentData(AttachmentInformation attachmentInformation) { var attachment = await Store.AsyncDatabaseCommands.GetAttachmentAsync(attachmentInformation.Key); if (attachment == null) return null; return attachment.Data().ReadData(); }
private void ExecuteAttachmentReadTriggers(AttachmentInformation information) { if (information == null) return; foreach (var attachmentReadTrigger in AttachmentReadTriggers) { attachmentReadTrigger.Value.OnRead(information); } }
private AttachmentInformation ProcessAttachmentReadVetoes(AttachmentInformation attachment) { if (attachment == null) return null; var foundResult = false; foreach (var attachmentReadTriggerLazy in AttachmentReadTriggers) { if (foundResult) break; var attachmentReadTrigger = attachmentReadTriggerLazy.Value; var readVetoResult = attachmentReadTrigger.AllowRead(attachment.Key, null, attachment.Metadata, ReadOperation.Load); switch (readVetoResult.Veto) { case ReadVetoResult.ReadAllow.Allow: break; case ReadVetoResult.ReadAllow.Deny: attachment.Size = 0; attachment.Metadata = new RavenJObject { { "Raven-Read-Veto", new RavenJObject { {"Reason", readVetoResult.Reason}, {"Trigger", attachmentReadTrigger.ToString()} } } }; foundResult = true; break; case ReadVetoResult.ReadAllow.Ignore: attachment = null; foundResult = true; break; default: throw new ArgumentOutOfRangeException(readVetoResult.Veto.ToString()); } } return attachment; }
public Task<byte[]> GetAttachmentData(AttachmentInformation attachmentInformation) { var attachment = database.Attachments.GetStatic(attachmentInformation.Key); if (attachment == null) return null; var data = attachment.Data; attachment.Data = () => { var memoryStream = new MemoryStream(); database.TransactionalStorage.Batch(accessor => data().CopyTo(memoryStream)); memoryStream.Position = 0; return memoryStream; }; return new CompletedTask<byte[]>(attachment.Data().ReadData()); }
private AttachmentInformation AttachmentInfoByKey(string key) { var attachment = GetAttachment(key); if (attachment == null) //precaution throw new InvalidDataException( "Tried to read attachment with key='{0}' but failed. Data mismatch between attachment indice and attachment data? (key by etag indice)"); var attachmentInfo = new AttachmentInformation { Etag = attachment.Etag, Key = attachment.Key, Metadata = attachment.Metadata, Size = attachment.Size }; return attachmentInfo; }
public virtual void OnRead(AttachmentInformation information) { }