forked from kipusoep/UrlTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUrlTrackerApplicationBase.cs
149 lines (138 loc) · 4.67 KB
/
UrlTrackerApplicationBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using InfoCaster.Umbraco.UrlTracker.Extensions;
using InfoCaster.Umbraco.UrlTracker.Helpers;
using InfoCaster.Umbraco.UrlTracker.Models;
using InfoCaster.Umbraco.UrlTracker.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using umbraco;
using umbraco.BasePages;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
using umbraco.cms.businesslogic.web;
using umbraco.DataLayer;
using umbraco.NodeFactory;
namespace InfoCaster.Umbraco.UrlTracker
{
public class UrlTrackerApplicationBase : ApplicationBase
{
public UrlTrackerApplicationBase()
{
if (!UrlTrackerSettings.IsDisabled && !UrlTrackerSettings.IsTrackingDisabled)
{
Document.BeforeMove += Document_BeforeMove;
Document.BeforePublish += Document_BeforePublish;
content.BeforeClearDocumentCache += content_BeforeClearDocumentCache;
Document.BeforeDelete += Document_BeforeDelete;
Domain.AfterDelete += Domain_AfterDelete;
Domain.AfterSave += Domain_AfterSave;
Domain.New += Domain_New;
}
}
void Domain_New(Domain sender, NewEventArgs e)
{
UmbracoHelper.ClearDomains();
}
void Domain_AfterSave(Domain sender, SaveEventArgs e)
{
UmbracoHelper.ClearDomains();
}
void Domain_AfterDelete(Domain sender, DeleteEventArgs e)
{
UmbracoHelper.ClearDomains();
}
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
}
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 content_BeforeClearDocumentCache(Document doc, DocumentCacheEventArgs e)
{
#if !DEBUG
try
#endif
{
UrlTrackerRepository.AddGoneEntryByNodeId(doc.Id);
}
#if !DEBUG
catch (Exception ex)
{
ex.LogException(doc.Id);
}
#endif
}
void Document_BeforeDelete(Document doc, DeleteEventArgs e)
{
#if !DEBUG
try
#endif
{
UrlTrackerRepository.DeleteUrlTrackerEntriesByNodeId(doc.Id);
}
#if !DEBUG
catch (Exception ex)
{
ex.LogException(doc.Id);
}
#endif
}
}
}