예제 #1
0
		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;

		}
예제 #2
0
        // 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();
        }
예제 #4
0
		private void ExecuteAttachmentReadTriggers(AttachmentInformation information)
		{
			if (information == null)
				return;

			foreach (var attachmentReadTrigger in AttachmentReadTriggers)
			{
				attachmentReadTrigger.Value.OnRead(information);
			}
		}
예제 #5
0
		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());
        }
예제 #7
0
        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;
        }
예제 #8
0
파일: Index.cs 프로젝트: modulexcite/docs-8
			public virtual void OnRead(AttachmentInformation information)
			{
			}