Skip to content

Commit

Permalink
Multiple Profile Support
Browse files Browse the repository at this point in the history
  • Loading branch information
gotdibbs committed Jun 17, 2015
1 parent 2f0892a commit dbe8d65
Show file tree
Hide file tree
Showing 9 changed files with 376 additions and 159 deletions.
60 changes: 60 additions & 0 deletions Imposter.Fiddler/Helpers/FileWatcher.cs
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();
}
}
}
}
53 changes: 53 additions & 0 deletions Imposter.Fiddler/Helpers/PathHelper.cs
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;
}
}
}
2 changes: 2 additions & 0 deletions Imposter.Fiddler/Imposter.Fiddler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Helpers\FileWatcher.cs" />
<Compile Include="Helpers\PathHelper.cs" />
<Compile Include="Imposter.cs" />
<Compile Include="Models\Override.cs" />
<Compile Include="Models\Profile.cs" />
Expand Down
Loading

0 comments on commit dbe8d65

Please sign in to comment.