())
21 | {
22 | Start(portal);
23 | }
24 | }
25 |
26 | public void Start(PortalInfo portalInfo)
27 | {
28 | var cache = DataCache.GetCache("InspectorIT.FileMonitor." + portalInfo.PortalID);
29 |
30 | if (cache == null)
31 | {
32 |
33 | FileSystemWatcher fileWatcher = new FileSystemWatcher();
34 | fileWatcher.Path = portalInfo.HomeDirectoryMapPath;
35 | fileWatcher.IncludeSubdirectories = true;
36 | fileWatcher.EnableRaisingEvents = true;
37 | fileWatcher.NotifyFilter = NotifyFilters.FileName;
38 | fileWatcher.Created += (s, e) => onFileChanged(s, e, portalInfo);
39 | fileWatcher.Deleted += (s, e) => onFileDeleted(s, e, portalInfo);
40 | fileWatcher.Renamed += (s, e) => onFileRenamed(s, e, portalInfo);
41 |
42 | FileSystemWatcher folderWatcher = new FileSystemWatcher();
43 | folderWatcher.Path = portalInfo.HomeDirectoryMapPath;
44 | folderWatcher.IncludeSubdirectories = true;
45 | folderWatcher.EnableRaisingEvents = true;
46 | folderWatcher.NotifyFilter = NotifyFilters.DirectoryName;
47 | folderWatcher.Created += (s, e) => onFolderChanged(s, e, portalInfo);
48 | folderWatcher.Deleted += (s, e) => onFolderDeleted(s, e, portalInfo);
49 | folderWatcher.Renamed += (s, e) => onFolderRenamed(s, e, portalInfo);
50 |
51 |
52 | DataCache.SetCache("InspectorIT.FileMonitor." + portalInfo.PortalID, true);
53 | }
54 | }
55 |
56 |
57 | #region Files
58 |
59 | private void onFileRenamed(object sender, RenamedEventArgs e, PortalInfo portalInfo)
60 | {
61 | try
62 | {
63 | var oldRelativeFilePath = Utils.GetRelativePath(portalInfo.HomeDirectoryMapPath, e.OldFullPath);
64 | var oldFileInfo = FileManager.Instance.GetFile(portalInfo.PortalID, oldRelativeFilePath);
65 | if (oldFileInfo != null)
66 | {
67 | var newRelativeFilePath = Utils.GetRelativePath(portalInfo.HomeDirectoryMapPath, e.FullPath);
68 | var newFileInfo = FileManager.Instance.GetFile(portalInfo.PortalID, newRelativeFilePath);
69 | if (newFileInfo == null)
70 | {
71 | oldFileInfo.FileName = Path.GetFileName(e.Name);
72 | FileManager.Instance.UpdateFile(oldFileInfo);
73 | }
74 | }
75 | }
76 | catch (Exception ex)
77 | {
78 |
79 | DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
80 | }
81 |
82 | }
83 |
84 | private void onFileDeleted(object sender, FileSystemEventArgs e, PortalInfo portalInfo)
85 | {
86 | try
87 | {
88 | var relativeFilePath = Utils.GetRelativePath(portalInfo.HomeDirectoryMapPath, e.FullPath);
89 | var fileInfo = FileManager.Instance.GetFile(portalInfo.PortalID, relativeFilePath);
90 | if (fileInfo != null)
91 | {
92 | FileManager.Instance.DeleteFile(fileInfo);
93 | }
94 | }
95 | catch (Exception ex)
96 | {
97 | DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
98 | }
99 | }
100 |
101 | private void onFileChanged(object sender, FileSystemEventArgs e, PortalInfo portalInfo)
102 | {
103 | try
104 | {
105 | var relativeFilePath = Utils.GetRelativePath(portalInfo.HomeDirectoryMapPath, e.FullPath);
106 | string fileName = Path.GetFileName(e.Name);
107 | var fileInfo = FileManager.Instance.GetFile(0, relativeFilePath);
108 | if (fileInfo == null)
109 | {
110 | //Get Folder
111 | string folderPath = relativeFilePath.Replace(fileName, "");
112 | var folderInfo = FolderManager.Instance.GetFolder(portalInfo.PortalID, folderPath);
113 | if (folderInfo == null)
114 | {
115 | folderInfo = FolderManager.Instance.AddFolder(portalInfo.PortalID, folderPath);
116 | }
117 | FileManager.Instance.AddFile(folderInfo, fileName, null, false);
118 | }
119 | }
120 | catch (Exception ex)
121 | {
122 | DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
123 | }
124 | }
125 |
126 | #endregion
127 |
128 | #region Folders
129 |
130 | private void onFolderRenamed(object sender, RenamedEventArgs e, PortalInfo portalInfo)
131 | {
132 | try
133 | {
134 | string relativeFolderPath = Utils.GetRelativePath(portalInfo.HomeDirectoryMapPath, e.OldFullPath);
135 | var oldFolderInfo = FolderManager.Instance.GetFolder(portalInfo.PortalID, relativeFolderPath);
136 | if (oldFolderInfo != null || e.OldFullPath.Contains("New folder"))
137 | {
138 | var newFolderInfo = FolderManager.Instance.GetFolder(portalInfo.PortalID, e.FullPath);
139 | if (newFolderInfo == null)
140 | {
141 | if (e.OldFullPath.Contains("New folder"))
142 | {
143 | FolderManager.Instance.AddFolder(portalInfo.PortalID, Utils.GetRelativePath(portalInfo.HomeDirectoryMapPath, e.FullPath));
144 | }
145 | else
146 | {
147 | new CustomFolderManager().MoveFolder(oldFolderInfo, Utils.GetRelativePath(portalInfo.HomeDirectoryMapPath, e.FullPath));
148 | }
149 |
150 |
151 | }
152 | }
153 | }
154 | catch (Exception ex)
155 | {
156 |
157 | DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
158 | }
159 | }
160 |
161 | private void onFolderDeleted(object sender, FileSystemEventArgs e, PortalInfo portalInfo)
162 | {
163 | try
164 | {
165 | string relativeFolderPath = Utils.GetRelativePath(portalInfo.HomeDirectoryMapPath, e.FullPath);
166 | var folderInfo = FolderManager.Instance.GetFolder(portalInfo.PortalID, relativeFolderPath);
167 | if (folderInfo != null)
168 | {
169 | var folderInfos = FolderManager.Instance.GetFolders(folderInfo.PortalID).Where(f => f.FolderPath != string.Empty && f.FolderPath.StartsWith(folderInfo.FolderPath)).ToList();
170 | foreach (IFolderInfo folder in folderInfos)
171 | {
172 | FolderManager.Instance.DeleteFolder(folder);
173 | }
174 | }
175 | }
176 | catch (Exception ex)
177 | {
178 | DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
179 | }
180 | }
181 |
182 | private void onFolderChanged(object sender, FileSystemEventArgs e, PortalInfo portalInfo)
183 | {
184 | try
185 | {
186 | string relativeFolderPath = Utils.GetRelativePath(portalInfo.HomeDirectoryMapPath, e.FullPath);
187 | var folderInfo = FolderManager.Instance.GetFolder(portalInfo.PortalID, relativeFolderPath);
188 | if (folderInfo == null && !e.Name.Contains("New folder"))
189 | {
190 | FolderManager.Instance.AddFolder(portalInfo.PortalID, relativeFolderPath);
191 | }
192 | }
193 | catch (Exception ex)
194 | {
195 | DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
196 | }
197 | }
198 |
199 | #endregion
200 | }
201 | }
--------------------------------------------------------------------------------
/Documentation/License.htm:
--------------------------------------------------------------------------------
1 | New BSD License (BSD)
2 | Copyright (c) 2013, Jonathan Sheely
All rights reserved.
3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
6 | * Neither the name of Jonathan Sheely nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
7 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8 |
--------------------------------------------------------------------------------
/Documentation/ReleaseNotes.htm:
--------------------------------------------------------------------------------
1 | Version 1.0.0.0
2 |
--------------------------------------------------------------------------------
/FileWatcher.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 |
8 |
9 | 2.0
10 | {D302CF97-1C02-406E-9C39-F3B1838B9674}
11 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
12 | Library
13 | Properties
14 | InspectorIT.FileWatcher
15 | InspectorIT.FileWatcher
16 | v4.5
17 | true
18 |
19 |
20 |
21 |
22 |
23 |
24 | true
25 | full
26 | false
27 | ..\..\..\..\Website\bin\
28 | DEBUG;TRACE
29 | prompt
30 | 4
31 |
32 |
33 | pdbonly
34 | true
35 | ..\..\..\..\Website\bin\
36 | TRACE
37 | prompt
38 | 4
39 |
40 |
41 |
42 | ..\..\..\..\Website\bin\ClientDependency.Core.dll
43 |
44 |
45 | ..\..\..\..\Website\bin\DotNetNuke.dll
46 |
47 |
48 | ..\..\..\..\Website\bin\DotNetNuke.Instrumentation.dll
49 |
50 |
51 | ..\..\..\..\Website\bin\DotNetNuke.Web.Client.dll
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 | {8DA31B98-5E8E-4243-8967-D4CF7DC622CB}
89 | DotNetNuke.Web
90 |
91 |
92 |
93 |
94 |
95 |
96 | 10.0
97 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | True
107 | True
108 | 64171
109 | /
110 | http://localhost:51123/
111 | False
112 | False
113 |
114 |
115 | False
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/InspectorIT.FileWatcher.dnn:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | File Watcher
6 | Monitors the files in your portals folder and instantly adds or removes them from the database. This is useful if you FTP or use explorer to copy files to your website.
7 | DesktopModules/InspectorIT/FileWatcher/images/icon.png
8 |
9 | Jonathan Sheely
10 | InspectorIT
11 | http://inspectorit.com
12 | jsheely@inspectorit.com
13 |
14 |
15 |
16 |
17 |
18 |
19 | bin
20 |
21 | InspectorIT.FileWatcher.dll
22 |
23 |
24 |
25 |
26 |
27 | DesktopModules\InspectorIT\FileWatcher
28 |
29 | Resources.zip
30 | Resources.zip
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("FileWatcher")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("FileWatcher")]
13 | [assembly: AssemblyCopyright("Copyright ? 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("0d9fbdc6-f041-42b2-aad9-3b99ee9d61f9")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Revision and Build Numbers
33 | // by using the '*' as shown below:
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | DotNetNuke-FileWatcher
2 | ======================
3 |
4 | Monitors the files in your portals folder and instantly adds or removes them from the database. This is useful if you FTP or use explorer to copy files to your website.
5 |
6 | ## How it works
7 |
8 | Utilizes .NET FileSystemWatcher in order to monitor the portals folder for any changes in order to keep the database in sync.
9 |
10 | ## What it solves
11 |
12 | - If you add a file to your portals directory through any means except though the DotNetNuke interface that file won't be picked up by DotNetNuke until the scheduler system runs. *Assuming you have the auto sync enabled*
13 | - You no longer have the performance hit of running the fully recursive auto sync on every file in your portal.
14 | - Instantly have access to any file that is in your portal no matter how it got there.
15 |
16 | ## Fun Facts
17 |
18 | - Utilizes the IServiceRouteMapper
interface in order to have DotNetNuke enable the file system watcher code at application start.
19 | - Is a DotNetNuke library project.
20 |
21 | ## Requirements
22 |
23 | - DotNetNuke 7.0.6
24 | - Full Trust Environment. *Will not work on shared hosting like GoDaddy*
25 |
26 |
--------------------------------------------------------------------------------
/Resources.zip.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Documentation/
5 | License.htm
6 |
7 |
8 | Documentation/
9 | ReleaseNotes.htm
10 |
11 |
12 |
--------------------------------------------------------------------------------
/install/InspectorIT.FileWatcher_1.0.0.0_Install.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxiomtech/DotNetNuke-FileWatcher/72585e5f7f869aa628172440caed21367886b564/install/InspectorIT.FileWatcher_1.0.0.0_Install.zip
--------------------------------------------------------------------------------
/install/InspectorIT.FileWatcher_1.0.0.0_Source.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maxiomtech/DotNetNuke-FileWatcher/72585e5f7f869aa628172440caed21367886b564/install/InspectorIT.FileWatcher_1.0.0.0_Source.zip
--------------------------------------------------------------------------------
/version.txt:
--------------------------------------------------------------------------------
1 | 1.0.0.0
--------------------------------------------------------------------------------