예제 #1
0
    	public JsonDocument ProcessReadVetoes(JsonDocument document, TransactionInformation transactionInformation, ReadOperation operation)
        {
            if (document == null)
                return document;
            foreach (var readTrigger in triggers)
            {
                var readVetoResult = readTrigger.AllowRead(document.Key, document.DataAsJson ?? document.Projection, document.Metadata, operation, transactionInformation);
                switch (readVetoResult.Veto)
                {
                    case ReadVetoResult.ReadAllow.Allow:
                        break;
                    case ReadVetoResult.ReadAllow.Deny:
                        return new JsonDocument
                        {
                            DataAsJson = new JObject(),
                            Metadata = new JObject(
                                new JProperty("Raven-Read-Veto", new JObject(new JProperty("Reason", readVetoResult.Reason),
                                                                             new JProperty("Trigger", readTrigger.ToString())
                                                                    ))
                                )
                        };
                    case ReadVetoResult.ReadAllow.Ignore:
                        return null;
                    default:
                        throw new ArgumentOutOfRangeException(readVetoResult.Veto.ToString());
                }
            }

            return document;
        }
예제 #2
0
        public DocumentViewModel(JsonDocument inner)
        {
            this.inner = inner;
            Id = inner.Metadata.IfPresent<string>("@id");
            LastModified = inner.LastModified;
			ClrType = inner.Metadata.IfPresent<string>(Raven.Abstractions.Data.Constants.RavenClrType);
            CollectionType = DetermineCollectionType();
        }
예제 #3
0
		public DocumentViewModel(JsonDocument inner)
		{
			this.inner = inner;
			Id = inner.Metadata.IfPresent<string>("@id");
			LastModified = inner.Metadata.IfPresent<DateTime>("Last-Modified");
			ClrType = inner.Metadata.IfPresent<string>("Raven-Clr-Type");
			CollectionType = DetermineCollectionType();
		}
예제 #4
0
		public EditDocumentViewModel(IEventAggregator events)
		{
			metadata = new Dictionary<string, JToken>();

			Id = "";
			document = new JsonDocument();
			JsonData = InitialJsonData();
			events.Subscribe(this);
		}
예제 #5
0
 public Document(JsonDocument jsonDocument)
 {
     data = new Dictionary<string, JToken>();
     metadata = new Dictionary<string, JToken>();
     
     this.jsonDocument = jsonDocument;
     Id = jsonDocument.Key;
     data = ParseJsonToDictionary(jsonDocument.DataAsJson);
     metadata = ParseJsonToDictionary(jsonDocument.Metadata);
 }
예제 #6
0
        private JsonDocument ExecuteReadTriggersOnRead(JsonDocument resultingDocument, TransactionInformation transactionInformation, ReadOperation operation)
        {
            if (resultingDocument == null)
                return null;

            foreach (var readTrigger in triggers)
            {
                readTrigger.OnRead(resultingDocument.Key, resultingDocument.DataAsJson, resultingDocument.Metadata, operation, transactionInformation);
            }
            return resultingDocument;
        }
예제 #7
0
		public EditDocumentViewModel(IEventAggregator events, IKeyboardShortcutBinder keys)
		{
			metadata = new Dictionary<string, JToken>();

			Id = "";
			document = new JsonDocument();
			JsonData = InitialJsonData();
			events.Subscribe(this);
		    this.keys = keys;

            keys.Register<SaveDocument>(Key.S, ModifierKeys.Control, x => x.Execute(this), this);
		}
예제 #8
0
		public void Initialize(JsonDocument doc)
		{
			document = doc;

			Id = document.Key;
			JsonData = PrepareRawJsonString(document.DataAsJson);

			IsProjection = string.IsNullOrEmpty(Id) && (document.Metadata == null);

			if (IsProjection) return;

			JsonMetadata = PrepareRawJsonString(document.Metadata);

			metadata = ParseJsonToDictionary(document.Metadata);

			LastModified = metadata.IfPresent<DateTime>("Last-Modified");
			CollectionType = DocumentViewModel.DetermineCollectionType(document.Metadata);
			ClrType = metadata.IfPresent<string>("Raven-Clr-Type");
		}
 private static bool IsDirectChildOfCurrentDocument(JsonDocument existingDoc, JObject metadata)
 {
     return JToken.DeepEquals(existingDoc.Metadata[ReplicationConstants.RavenReplicationVersion],
                              metadata[ReplicationConstants.RavenReplicationParentVersion]) && 
            JToken.DeepEquals(existingDoc.Metadata[ReplicationConstants.RavenReplicationSource],
                              metadata[ReplicationConstants.RavenReplicationParentSource]);
 }
예제 #10
0
 public JsonDocument ExecuteReadTriggers(JsonDocument document, TransactionInformation transactionInformation, ReadOperation operation)
 {
     return ExecuteReadTriggersOnRead(ProcessReadVetoes(document, transactionInformation, operation),
                                      transactionInformation, operation);
 }
예제 #11
0
		public void GetDocumentAfterAnEtagWhileAddingDocsFromMultipleThreadsEnumeratesAllDocs()
		{
			var numberOfDocsAdded = 0;
			var threads = new List<Thread>();
			try
			{
				for (var i = 0; i < 10; i++)
				{
                    var thread = new Thread(() =>
                    {
                    	var cmds = new List<ICommandData>();
                         for (var k = 0; k < 100; k++)
                         {
							var newId = Interlocked.Increment(ref numberOfDocsAdded);
                            cmds.Add(new PutCommandData
                            {
                            	Document = new JObject(),
								Metadata = new JObject(),
								Key = newId.ToString()
                            });
                        };
                    	db.Batch(cmds);
                    });
					threads.Add(thread);
					thread.Start();
				}

				var docs = new List<string>();
				var lastEtag = Guid.Empty;
				var total = 0;
			    var stop = false;
			    do
			    {
					var etag = lastEtag;
			        var jsonDocuments = new JsonDocument[0];
			        db.TransactionalStorage.Batch(actions =>
			        {
			            jsonDocuments = actions.Documents.GetDocumentsAfter(etag).Where(x => x != null).ToArray();
			        });
					docs.AddRange(jsonDocuments.Select(x=>x.Key));
			        total += jsonDocuments.Length;
			    	if (jsonDocuments.Length > 0)
			    		lastEtag = jsonDocuments.Last().Etag;
			    	if (stop)
                        break;
                    if (threads.All(x => !x.IsAlive))
                        stop = true;
			    } while (true);

                Assert.Equal(numberOfDocsAdded, total);
			}
			finally
			{
				foreach (var thread in threads)
				{
					thread.Join();
				}
			}
		}
예제 #12
0
		public void Initialize(JsonDocument doc)
		{
			document = doc;

			UpdateDocumentFromJsonDocument();
		}
예제 #13
0
		public IEnumerable<Tuple<JsonDocument, int>> DocumentsById(int startId, int endId)
		{
			Api.JetSetCurrentIndex(session, Documents, "by_id");
			Api.MakeKey(session, Documents, startId, MakeKeyGrbit.NewKey);
			// this sholdn't really happen, it means that the doc is missing
			// probably deleted before we can get it?
			if (Api.TrySeek(session, Documents, SeekGrbit.SeekGE) == false)
			{
				logger.DebugFormat("Document with id {0} or higher was not found", startId);
				yield break;
			}
			do
			{
				var id = Api.RetrieveColumnAsInt32(session, Documents, tableColumnsCache.DocumentsColumns["id"],
												   RetrieveColumnGrbit.RetrieveFromIndex).Value;
				if (id > endId)
					break;

				var data = Api.RetrieveColumn(session, Documents, tableColumnsCache.DocumentsColumns["data"]);
				logger.DebugFormat("Document with id '{0}' was found, doc length: {1}", id, data.Length);
				var etag = Api.RetrieveColumn(session, Documents, tableColumnsCache.DocumentsColumns["etag"]).TransfromToGuidWithProperSorting();
				var metadata = Api.RetrieveColumn(session, Documents, tableColumnsCache.DocumentsColumns["metadata"]).ToJObject();
				var key = Api.RetrieveColumnAsString(session, Documents, tableColumnsCache.DocumentsColumns["key"], Encoding.Unicode);
				var modified = Api.RetrieveColumnAsDateTime(session, Documents, tableColumnsCache.DocumentsColumns["last_modified"]);
				data = documentCodecs.Aggregate(data, (bytes, codec) => codec.Decode(key, metadata, bytes));

				var doc = new JsonDocument
				{
					Key = key,
					DataAsJson = data.ToJObject(),
					NonAuthoritiveInformation = IsDocumentModifiedInsideTransaction(key),
					Etag = etag,
					LastModified = modified.Value,
					Metadata = metadata
				};
				yield return new Tuple<JsonDocument, int>(doc, id);
			} while (Api.TryMoveNext(session, Documents));
		}
예제 #14
0
 public DocumentTestClass(JsonDocument document)
 {
     Document = document;
     Id = document.Key;
 }
예제 #15
0
		private JsonDocument ProcessReadVetoes(JsonDocument document, TransactionInformation transactionInformation, ReadOperation operation)
		{
			if (document == null)
				return document;
			foreach (var readTrigger in ReadTriggers)
			{
				var readVetoResult = readTrigger.AllowRead(document.Key, document.DataAsJson, document.Metadata, operation, transactionInformation);
				switch (readVetoResult.Veto)
				{
					case ReadVetoResult.ReadAllow.Allow:
						break;
					case ReadVetoResult.ReadAllow.Deny:
						return new JsonDocument
						{
							DataAsJson = 
								JObject.FromObject(new
								{
									Message = "The document exists, but it is hidden by a read trigger",
									DocumentHidden = true,
									readVetoResult.Reason
								}),
							Metadata = JObject.FromObject(
								new
								{
									ReadVeto = true,
									VetoingTrigger = readTrigger.ToString()
								}
								)
						};
					case ReadVetoResult.ReadAllow.Ignore:
						return null;
					default:
						throw new ArgumentOutOfRangeException(readVetoResult.Veto.ToString());
				}
			}

			return document;
		}