-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
188 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Threading; | ||
using log4net; | ||
using Sherpa.Library.SiteHierarchy; | ||
|
||
namespace Sherpa.Library | ||
{ | ||
public class FileListenerAndUploader | ||
{ | ||
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
public SiteSetupManager SetupManager { get; set; } | ||
public ManualResetEvent ResetEvent { get; set; } | ||
public List<string> ChangedFilesInIteration { get; set; } | ||
|
||
public void CreateFileWatcher(string path, SiteSetupManager setupManager) | ||
{ | ||
SetupManager = setupManager; | ||
|
||
FileSystemWatcher watcher = new FileSystemWatcher(); | ||
ResetEvent = new ManualResetEvent(false); | ||
|
||
watcher.Path = path; | ||
/* Watch for changes in LastAccess and LastWrite times, and | ||
the renaming of files or directories. */ | ||
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | ||
| NotifyFilters.FileName | NotifyFilters.DirectoryName; | ||
|
||
watcher.IncludeSubdirectories = true; | ||
|
||
// Add event handlers. | ||
watcher.Changed += new FileSystemEventHandler(FileChange); | ||
watcher.Created += new FileSystemEventHandler(FileChange); | ||
|
||
// Begin watching. | ||
watcher.EnableRaisingEvents = true; | ||
|
||
ChangedFilesInIteration = new List<string>(); | ||
while (true) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Green; | ||
Console.WriteLine("Watching for changes to files in Sherpa content directory..."); | ||
Console.ResetColor(); | ||
|
||
if (ResetEvent.WaitOne()) | ||
{ | ||
SetupManager.UploadChangedFiles(); | ||
ChangedFilesInIteration.Clear(); | ||
ResetEvent.Reset(); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Waiting timed-out"); | ||
} | ||
} | ||
//watcher.WaitForChanged(WatcherChangeTypes.Changed | WatcherChangeTypes.Created | WatcherChangeTypes.Renamed, -1); | ||
} | ||
|
||
// Define the event handlers. | ||
private void FileChange(object source, FileSystemEventArgs e) | ||
{ | ||
if (e.FullPath.EndsWith(".js") || e.FullPath.EndsWith(".css") || e.FullPath.EndsWith(".txt") || | ||
e.FullPath.EndsWith(".html") || e.FullPath.EndsWith(".webpart") || e.FullPath.EndsWith(".png")) | ||
{ | ||
if (!ChangedFilesInIteration.Contains(e.FullPath)) | ||
{ | ||
Log.InfoFormat("File {0} changed and a new upload is starting", e.Name); | ||
ChangedFilesInIteration.Add(e.FullPath); | ||
ResetEvent.Set(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters