当前位置: 首页>>代码示例>>C#>>正文


C# RavenJObject.EnsureSnapshot方法代码示例

本文整理汇总了C#中RavenJObject.EnsureSnapshot方法的典型用法代码示例。如果您正苦于以下问题:C# RavenJObject.EnsureSnapshot方法的具体用法?C# RavenJObject.EnsureSnapshot怎么用?C# RavenJObject.EnsureSnapshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RavenJObject的用法示例。


在下文中一共展示了RavenJObject.EnsureSnapshot方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AfterPut

		public override void AfterPut(string key, RavenJObject document, RavenJObject metadata, System.Guid etag, TransactionInformation transactionInformation)
		{
			if (key.StartsWith("Raven/"))
			{
				return;
			}

			var entityName = metadata.Value<string>(Constants.RavenEntityName) + "/";

			var properties = metadata.Value<RavenJArray>(Constants.EnsureUniqueConstraints);

			if (properties == null || properties.Length <= 0) 
				return;

			var constraintMetaObject = new RavenJObject { { Constants.IsConstraintDocument, true } };
			constraintMetaObject.EnsureSnapshot();
			foreach (var property in properties)
			{
				var propName = ((RavenJValue)property).Value.ToString();
				var uniqueValue = document.Value<string>(propName);
				if(uniqueValue == null)
					continue;
				string documentName = "UniqueConstraints/" + entityName + propName + "/" +Util.EscapeUniqueValue(uniqueValue);
				Database.Put(
					documentName,
					null,
					RavenJObject.FromObject(new { RelatedId = key }),
					(RavenJObject)constraintMetaObject.CreateSnapshot(),
					transactionInformation);
			}
		}
开发者ID:remcoros,项目名称:ravendb,代码行数:31,代码来源:UniqueConstraintsPutTrigger.cs

示例2: Constants

		static Constants()
		{
			InDatabaseKeyVerificationDocumentContents = new RavenJObject
			{
				{"Text", "The encryption is correct."}
			};
			InDatabaseKeyVerificationDocumentContents.EnsureSnapshot();
		}
开发者ID:synhershko,项目名称:ravendb,代码行数:8,代码来源:Constants.cs

示例3: Put

		public PutResult Put(string key, Etag etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
		{
			workContext.DocsPerSecIncreaseBy(1);
			key = string.IsNullOrWhiteSpace(key) ? Guid.NewGuid().ToString() : key.Trim();
			RemoveReservedProperties(document);
			RemoveMetadataReservedProperties(metadata);
			Etag newEtag = Etag.Empty;
			lock (putSerialLock)
			{
				TransactionalStorage.Batch(actions =>
				{
					if (key.EndsWith("/"))
					{
						key += GetNextIdentityValueWithoutOverwritingOnExistingDocuments(key, actions, transactionInformation);
					}
					AssertPutOperationNotVetoed(key, metadata, document, transactionInformation);
					if (transactionInformation == null)
					{
						PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, null));

						var addDocumentResult = actions.Documents.AddDocument(key, etag, document, metadata);
						newEtag = addDocumentResult.Etag;

						CheckReferenceBecauseOfDocumentUpdate(key, actions);
						metadata[Constants.LastModified] = addDocumentResult.SavedAt;
						metadata.EnsureSnapshot("Metadata was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?");
						document.EnsureSnapshot("Document was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?");

						PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, null));

						actions.AfterStorageCommitBeforeWorkNotifications(new JsonDocument
						{
							Metadata = metadata,
							Key = key,
							DataAsJson = document,
							Etag = newEtag,
							LastModified = addDocumentResult.SavedAt,
							SkipDeleteFromIndex = addDocumentResult.Updated == false
						}, indexingExecuter.PrefetchingBehavior.AfterStorageCommitBeforeWorkNotifications);

						TransactionalStorage
							.ExecuteImmediatelyOrRegisterForSynchronization(() =>
							{
								PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag));
								RaiseNotifications(new DocumentChangeNotification
								{
									Id = key,
									Type = DocumentChangeTypes.Put,
									Etag = newEtag,
								});
							});
					}
					else
					{
						newEtag = actions.Transactions.AddDocumentInTransaction(key, etag,
																				document, metadata, transactionInformation);
					}
					workContext.ShouldNotifyAboutWork(() => "PUT " + key);
				});
			}

			log.Debug("Put document {0} with etag {1}", key, newEtag);
			return new PutResult
			{
				Key = key,
				ETag = newEtag
			};
		}
开发者ID:samueldjack,项目名称:ravendb,代码行数:68,代码来源:DocumentDatabase.cs

示例4: Put

        public PutResult Put(string key, Etag etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
        {
            WorkContext.MetricsCounters.DocsPerSecond.Mark();
            key = string.IsNullOrWhiteSpace(key) ? Guid.NewGuid().ToString() : key.Trim();
            RemoveReservedProperties(document);
            RemoveMetadataReservedProperties(metadata);
            Etag newEtag = Etag.Empty;

            using (Database.DocumentLock.Lock())
            {
                TransactionalStorage.Batch(actions =>
                {
                    if (key.EndsWith("/"))
                    {
                        key += GetNextIdentityValueWithoutOverwritingOnExistingDocuments(key, actions);
                    }
                    AssertPutOperationNotVetoed(key, metadata, document, transactionInformation);
                    if (transactionInformation == null)
                    {
                        if (Database.InFlightTransactionalState.IsModified(key))
                            throw new ConcurrencyException("PUT attempted on : " + key +
                                                           " while it is being locked by another transaction");

                        Database.PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, null));

                        var addDocumentResult = actions.Documents.AddDocument(key, etag, document, metadata);
                        newEtag = addDocumentResult.Etag;

                        Database.Indexes.CheckReferenceBecauseOfDocumentUpdate(key, actions);
                        metadata[Constants.LastModified] = addDocumentResult.SavedAt;
                        metadata.EnsureSnapshot(
                            "Metadata was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?");
                        document.EnsureSnapshot(
                            "Document was written to the database, cannot modify the document after it was written (changes won't show up in the db). Did you forget to call CreateSnapshot() to get a clean copy?");

                        actions.AfterStorageCommitBeforeWorkNotifications(new JsonDocument
                        {
                            Metadata = metadata,
                            Key = key,
                            DataAsJson = document,
                            Etag = newEtag,
                            LastModified = addDocumentResult.SavedAt,
                            SkipDeleteFromIndex = addDocumentResult.Updated == false
                        }, documents =>
                        {
							if(Database.IndexDefinitionStorage.IndexesCount == 0 || Database.WorkContext.RunIndexing == false)
								return;

	                        Database.Prefetcher.AfterStorageCommitBeforeWorkNotifications(PrefetchingUser.Indexer, documents);
                        });

                        if (addDocumentResult.Updated)
                            Database.Prefetcher.AfterUpdate(key, addDocumentResult.PrevEtag);

                        Database.PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, null));

                        TransactionalStorage
                            .ExecuteImmediatelyOrRegisterForSynchronization(() =>
                            {
                                Database.PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag));
	                            
								var newDocumentChangeNotification =
		                            new DocumentChangeNotification
		                            {
			                            Id = key,
			                            Type = DocumentChangeTypes.Put,
			                            TypeName = metadata.Value<string>(Constants.RavenClrType),
			                            CollectionName = metadata.Value<string>(Constants.RavenEntityName),
			                            Etag = newEtag
		                            };
	                            
								Database.Notifications.RaiseNotifications(newDocumentChangeNotification, metadata);
                            });

                        WorkContext.ShouldNotifyAboutWork(() => "PUT " + key);
                    }
                    else
                    {
                        var doc = actions.Documents.DocumentMetadataByKey(key);
                        newEtag = Database.InFlightTransactionalState.AddDocumentInTransaction(key, etag, document, metadata,
                                                                                      transactionInformation,
                                                                                      doc == null
                                                                                          ? Etag.Empty
                                                                                          : doc.Etag,
                                                                                      UuidGenerator);
                    }
                });

                Log.Debug("Put document {0} with etag {1}", key, newEtag);
                return new PutResult
                {
                    Key = key,
                    ETag = newEtag
                };
            }
        }
开发者ID:mdavis,项目名称:ravendb,代码行数:96,代码来源:DocumentActions.cs

示例5: Put

		public PutResult Put(string key, Guid? etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
		{
			workContext.DocsPerSecIncreaseBy(1);
			key = string.IsNullOrWhiteSpace(key) ? Guid.NewGuid().ToString() : key.Trim();
			RemoveReservedProperties(document);
			RemoveReservedProperties(metadata);
			Guid newEtag = Guid.Empty;
			lock (putSerialLock)
			{
				TransactionalStorage.Batch(actions =>
				{
					if (key.EndsWith("/"))
					{
						key += GetNextIdentityValueWithoutOverwritingOnExistingDocuments(key, actions, transactionInformation);
					}
					AssertPutOperationNotVetoed(key, metadata, document, transactionInformation);
					if (transactionInformation == null)
					{
						PutTriggers.Apply(trigger => trigger.OnPut(key, document, metadata, null));

						var addDocumentResult = actions.Documents.AddDocument(key, etag, document, metadata);
						newEtag = addDocumentResult.Etag;

						PutTriggers.Apply(trigger => trigger.AfterPut(key, document, metadata, newEtag, null));

						metadata.EnsureSnapshot();
						document.EnsureSnapshot();
						actions.AfterCommit(new JsonDocument
						{
							Metadata = metadata,
							Key = key,
							DataAsJson = document,
							Etag = newEtag,
							LastModified = addDocumentResult.SavedAt,
							SkipDeleteFromIndex = addDocumentResult.Updated == false
						}, indexingExecuter.AfterCommit);
						TransactionalStorage
							.ExecuteImmediatelyOrRegisterForSyncronization(() =>
							{
								PutTriggers.Apply(trigger => trigger.AfterCommit(key, document, metadata, newEtag));
								RaiseNotifications(new DocumentChangeNotification
								{
									Name = key,
									Type = DocumentChangeTypes.Put,
									Etag = newEtag,
								});
							});
					}
					else
					{
						newEtag = actions.Transactions.AddDocumentInTransaction(key, etag,
																				document, metadata, transactionInformation);
					}
					workContext.ShouldNotifyAboutWork(() => "PUT " + key);
				});
			}

			log.Debug("Put document {0} with etag {1}", key, newEtag);
			return new PutResult
			{
				Key = key,
				ETag = newEtag
			};
		}
开发者ID:denno-secqtinstien,项目名称:ravendb,代码行数:64,代码来源:DocumentDatabase.cs


注:本文中的RavenJObject.EnsureSnapshot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。