Exemplo n.º 1
0
        public async Task <bool> Exists(IDataStoreReadById aggregateQueriedById)
        {
            Raven.Abstractions.Data.JsonDocumentMetadata documentMetadata =
                await store.AsyncDatabaseCommands.HeadAsync(aggregateQueriedById.Id.ToString()).ConfigureAwait(false);

            return(documentMetadata != null);
        }
Exemplo n.º 2
0
		private List<OperationAllowedResult> GenerateAuthorizationResponse(JsonDocumentMetadata[] documents, string[] docIds, string operation, string userId)
		{
			var list = new List<OperationAllowedResult>();
			for (var index = 0; index < documents.Length; index++)
			{
				var document = documents[index];
				var docId = docIds[index];
				if (document == null)
				{
					list.Add(new OperationAllowedResult
					{
						IsAllowed = false,
						Reasons = new List<string>
						{
							"Document " + docId + " does not exists"
						}
					});
					continue;
				}
				var reasons = new List<string>();
				var authorizationDecisions = new AuthorizationDecisions(Database);
				var isAllowed = authorizationDecisions.IsAllowed(userId, operation, docId, document.Metadata, reasons.Add);

				list.Add(new OperationAllowedResult { IsAllowed = isAllowed, Reasons = reasons });
			}
			return list;
		}
Exemplo n.º 3
0
        //returns true if it was update operation
        private bool WriteDocumentMetadata(JsonDocumentMetadata metadata, Slice key, bool shouldIgnoreConcurrencyExceptions = false)
        {
            var metadataStream = CreateStream();

            metadataStream.Write(metadata.Etag);
            metadataStream.Write(metadata.Key);

            if (metadata.LastModified.HasValue)
                metadataStream.Write(metadata.LastModified.Value.ToBinary());
            else
                metadataStream.Write((long)0);

            metadata.Metadata.WriteTo(metadataStream);

            metadataStream.Position = 0;

            ushort? existingVersion;
            var isUpdate = metadataIndex.Contains(Snapshot, key, writeBatch.Value, out existingVersion);
            metadataIndex.Add(writeBatch.Value, key, metadataStream, existingVersion, shouldIgnoreConcurrencyExceptions);

            return isUpdate;
        }
Exemplo n.º 4
0
 public int GetStoredVersionOf(JsonDocumentMetadata head)
 {
     return head
         ?.Metadata[EmployeeEntityVersion]
         .Value<int>() ?? 0;
 }
 private void HandleDocument(JsonDocumentMetadata metadata)
 {
     deletedHistory.Value = new RavenJArray(ReplicationData.GetHistory(metadata.Metadata))
     {
         new RavenJObject
         {
             {Constants.RavenReplicationVersion, metadata.Metadata[Constants.RavenReplicationVersion]},
             {Constants.RavenReplicationSource, metadata.Metadata[Constants.RavenReplicationSource]}
         }
     };
 }
        public bool IsConflictDocument(JsonDocumentMetadata metadata, TransactionInformation transactionInformation, ref JsonDocument document)
        {
            var conflict = metadata.Metadata.Value<RavenJValue>(Constants.RavenReplicationConflict);
            if (conflict == null || conflict.Value<bool>() == false)
            {
                return false;
            }

            var keyParts = metadata.Key.Split('/');
            if (keyParts.Contains("conflicts") == false)
            {
                return false;
            }

            document = Database.Documents.Get(metadata.Key, transactionInformation);

            var conflicts = document.DataAsJson.Value<RavenJArray>("Conflicts");
            if (conflicts != null)
            {
                return false;
            }

            return true;
        }
        private bool HasConflict(JsonDocumentMetadata metadata, TransactionInformation transactionInformation, ref JsonDocument document)
        {
            var conflict = metadata.Metadata.Value<RavenJValue>(Constants.RavenReplicationConflict);

            if (conflict != null && conflict.Value<bool>())
            {
                document = document ?? Database.Documents.Get(metadata.Key, transactionInformation);
                return document.DataAsJson.Value<RavenJArray>("Conflicts") != null;
            }

            return false;
        }
 public override bool TryGet(string key, TransactionInformation transactionInformation, out JsonDocumentMetadata document)
 {
     document = null;
     return false;
 }