-
Notifications
You must be signed in to change notification settings - Fork 3
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
9 changed files
with
376 additions
and
159 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Imposter.Fiddler.Helpers | ||
{ | ||
public class FileWatcher : IDisposable | ||
{ | ||
private FileSystemWatcher _watcher; | ||
|
||
public bool EnableRaisingEvents | ||
{ | ||
get { return _watcher.EnableRaisingEvents; } | ||
set { _watcher.EnableRaisingEvents = value; } | ||
} | ||
|
||
public FileSystemEventHandler Handler | ||
{ | ||
set | ||
{ | ||
_watcher.Changed += value; | ||
_watcher.Created += value; | ||
_watcher.Deleted += value; | ||
} | ||
} | ||
|
||
public FileWatcher(string path, bool enabled) | ||
{ | ||
if (_watcher == null) | ||
{ | ||
_watcher = new FileSystemWatcher(); | ||
_watcher.IncludeSubdirectories = true; | ||
_watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.DirectoryName | NotifyFilters.CreationTime; | ||
_watcher.Filter = "*.*"; | ||
} | ||
_watcher.Path = path; | ||
_watcher.EnableRaisingEvents = enabled; | ||
} | ||
|
||
public void Start() | ||
{ | ||
_watcher.EnableRaisingEvents = true; | ||
} | ||
|
||
public void Stop() | ||
{ | ||
_watcher.EnableRaisingEvents = false; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (_watcher != null) | ||
{ | ||
_watcher.Dispose(); | ||
} | ||
} | ||
} | ||
} |
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,53 @@ | ||
using Imposter.Fiddler.Model; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Windows; | ||
|
||
namespace Imposter.Fiddler.Helpers | ||
{ | ||
public static class PathHelper | ||
{ | ||
public static string GetStringAfterSubString(string fullString, string subString) | ||
{ | ||
int index = fullString.IndexOf(subString); | ||
return fullString.Substring(index + subString.Length); | ||
} | ||
|
||
public static string GetLocalFilePath(string urlFragment, string localDirectory, List<Override> overrides) | ||
{ | ||
var path = localDirectory + @"\" + urlFragment.Replace("/", @"\"); | ||
|
||
if (File.Exists(path)) | ||
{ | ||
return path; | ||
} | ||
|
||
foreach (var ovr in overrides) | ||
{ | ||
if (urlFragment.Contains(ovr.RemoteFile.ToLower()) && CheckIfFileExists(ovr.LocalFile)) | ||
{ | ||
return ovr.LocalFile; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static bool CheckIfFileExists(string file) | ||
{ | ||
var result = true; | ||
|
||
result = result && File.Exists(file); | ||
|
||
if (!result) | ||
{ | ||
MessageBox.Show(string.Format("Imposter says: Override file \"{0}\" does not appear to exist on disk.", file)); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.