Esempio n. 1
0
        /// <summary>
        /// Called when [put].
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="document">The document.</param>
        /// <param name="metadata">The metadata.</param>
        /// <param name="transactionInformation">The transaction information.</param>
        public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
        {
            if (key.StartsWith("Raven/", true, CultureInfo.InvariantCulture)) // we don't deal with system documents
            {
                return;
            }

            if (TriggerContext.IsInTriggerContext)
            {
                return;
            }

            using (TriggerContext.Enter()) {
                var meta = document["MetaData"] as RavenJObject;
                if (meta != null)
                {
                    var         slug = meta.Value <string>("Slug");
                    RavenJToken parent;
                    if (document.TryGetValue("Parent", out parent) && parent.Type != JTokenType.Null)
                    {
                        var parentId       = parent.Value <string>("Id");
                        var parentDocument = Database.Get(parentId, transactionInformation);
                        var parentUrl      = parentDocument.DataAsJson.Value <JObject>("Metadata").Value <string>("Url");
                        if (parentUrl != null)
                        {
                            meta["Url"] = string.Format("{0}/{1}", parentUrl, slug);
                            base.OnPut(key, document, metadata, transactionInformation);
                            return;
                        }
                    }
                    meta["Url"] = slug;
                }
            }
            base.OnPut(key, document, metadata, transactionInformation);
        }
Esempio n. 2
0
        /// <summary>
        /// Afters the put.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="document">The document.</param>
        /// <param name="metadata">The metadata.</param>
        /// <param name="etag">The etag.</param>
        /// <param name="transactionInformation">The transaction information.</param>
        public override void AfterPut(string key, RavenJObject document, RavenJObject metadata, Guid etag, TransactionInformation transactionInformation)
        {
            if (key.StartsWith("Raven/", true, CultureInfo.InvariantCulture)) // we don't deal with system documents
            {
                return;
            }

            if (TriggerContext.IsInTriggerContext)
            {
                return;
            }

            using (TriggerContext.Enter()) {
                UpdateChildren(key, document, transactionInformation);
            }

            base.AfterPut(key, document, metadata, etag, transactionInformation);
        }