void ContentService_Moving(IContentService sender, MoveEventArgs <IContent> e)
        {
            IContent content = e.Entity;

#if !DEBUG
            try
#endif
            {
                if (content != null)
                {
                    Node node = new Node(content.Id);

                    if (node != null && !string.IsNullOrEmpty(node.NiceUrl) && !content.Path.StartsWith("-1,-20")) // -1,-20 == Recycle bin | Not moved to recycle bin
                    {
                        UrlTrackerRepository.AddUrlMapping(content, node.GetDomainRootNode().Id, node.NiceUrl, AutoTrackingTypes.Moved);
                    }
                }
            }
#if !DEBUG
            catch (Exception ex)
            {
                ex.LogException();
            }
#endif
        }
        void Document_BeforeMove(object sender, MoveEventArgs e)
        {
#if !DEBUG
            try
#endif
            {
                Document doc = sender as Document;
#if !DEBUG
                try
#endif
                {
                    if (doc != null)
                    {
                        Node node = new Node(doc.Id);

                        if (node != null && !string.IsNullOrEmpty(node.NiceUrl) && !doc.Path.StartsWith("-1,-20")) // -1,-20 == Recycle bin | Not moved to recycle bin
                        {
                            UrlTrackerRepository.AddUrlMapping(doc, node.GetDomainRootNode().Id, node.NiceUrl, AutoTrackingTypes.Moved);
                        }
                    }
                }
#if !DEBUG
                catch (Exception ex)
                {
                    ex.LogException(doc.Id);
                }
#endif
            }
#if !DEBUG
            catch (Exception ex)
            {
                ex.LogException();
            }
#endif
        }
        void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            // When content is renamed or 'umbracoUrlName' property value is added/updated
            foreach (IContent content in e.PublishedEntities)
            {
#if !DEBUG
                try
#endif
                {
                    Node node = new Node(content.Id);
                    if (node.Name != content.Name && !string.IsNullOrEmpty(node.Name)) // If name is null, it's a new document
                    {
                        // Rename occurred
                        UrlTrackerRepository.AddUrlMapping(content, node.GetDomainRootNode().Id, node.NiceUrl, AutoTrackingTypes.Renamed);

                        if (ClientTools != null)
                        {
                            ClientTools.ChangeContentFrameUrl(string.Concat("/umbraco/editContent.aspx?id=", content.Id));
                        }
                    }
                    if (content.HasProperty("umbracoUrlName"))
                    {
                        string contentUmbracoUrlNameValue = content.GetValue("umbracoUrlName") != null?content.GetValue("umbracoUrlName").ToString() : string.Empty;

                        string nodeUmbracoUrlNameValue = node.GetProperty("umbracoUrlName") != null?node.GetProperty("umbracoUrlName").Value : string.Empty;

                        if (contentUmbracoUrlNameValue != nodeUmbracoUrlNameValue)
                        {
                            // 'umbracoUrlName' property value added/changed
                            UrlTrackerRepository.AddUrlMapping(content, node.GetDomainRootNode().Id, node.NiceUrl, AutoTrackingTypes.UrlOverwritten);

                            if (ClientTools != null)
                            {
                                ClientTools.ChangeContentFrameUrl(string.Concat("/umbraco/editContent.aspx?id=", content.Id));
                            }
                        }
                    }
                }
#if !DEBUG
                catch (Exception ex)
                {
                    ex.LogException();
                }
#endif
            }
        }
        void Document_BeforePublish(Document doc, PublishEventArgs e)
        {
            // When document is renamed or 'umbracoUrlName' property value is added/updated
#if !DEBUG
            try
#endif
            {
                Node node = new Node(doc.Id);
                if (node.Name != doc.Text && !string.IsNullOrEmpty(node.Name)) // If name is null, it's a new document
                {
                    // Rename occurred
                    UrlTrackerRepository.AddUrlMapping(doc, node.GetDomainRootNode().Id, node.NiceUrl, AutoTrackingTypes.Renamed);

                    if (BasePage.Current != null)
                    {
                        BasePage.Current.ClientTools.ChangeContentFrameUrl(string.Concat("/umbraco/editContent.aspx?id=", doc.Id));
                    }
                }
                if (doc.getProperty("umbracoUrlName") != null && node.GetProperty("umbracoUrlName") != null && node.GetProperty("umbracoUrlName").Value != doc.getProperty("umbracoUrlName").Value.ToString())
                {
                    // 'umbracoUrlName' property value added/changed
                    UrlTrackerRepository.AddUrlMapping(doc, node.GetDomainRootNode().Id, node.NiceUrl, AutoTrackingTypes.UrlOverwritten);

                    if (BasePage.Current != null)
                    {
                        BasePage.Current.ClientTools.ChangeContentFrameUrl(string.Concat("/umbraco/editContent.aspx?id=", doc.Id));
                    }
                }
            }
#if !DEBUG
            catch (Exception ex)
            {
                ex.LogException(doc.Id);
            }
#endif
        }