Fixed some small usage issues
- Simplify waiting for changes - Fixed project dependencies
This commit is contained in:
parent
3f40980d02
commit
22d13c4b34
|
|
@ -182,41 +182,36 @@ namespace Microsoft.Dnx.Watcher.Core
|
||||||
|
|
||||||
foreach (var projFile in project.ProjectDependencies)
|
foreach (var projFile in project.ProjectDependencies)
|
||||||
{
|
{
|
||||||
//var fullProjectFilePath = Path.Combine(Path.GetDirectoryName(project.ProjectFile), projFile);
|
|
||||||
|
|
||||||
AddProjectAndDependeciesToWatcher(projFile, fileWatcher);
|
AddProjectAndDependeciesToWatcher(projFile, fileWatcher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task<string> WatchForFileChangeAsync(IFileWatcher fileWatcher, CancellationToken cancellationToken)
|
private async Task<string> WatchForFileChangeAsync(IFileWatcher fileWatcher, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return Task.Run(() =>
|
var tcs = new TaskCompletionSource<string>();
|
||||||
|
|
||||||
|
cancellationToken.Register(() => tcs.TrySetResult(null));
|
||||||
|
|
||||||
|
Action<string> callback = path =>
|
||||||
{
|
{
|
||||||
using (var fileChangeEvent = new ManualResetEvent(false))
|
tcs.TrySetResult(path);
|
||||||
{
|
};
|
||||||
string changedFile = null;
|
|
||||||
|
|
||||||
fileWatcher.OnChanged += path =>
|
fileWatcher.OnChanged += callback;
|
||||||
{
|
|
||||||
changedFile = path;
|
|
||||||
fileChangeEvent.Set();
|
|
||||||
};
|
|
||||||
|
|
||||||
while (!cancellationToken.IsCancellationRequested &&
|
var changedPath = await tcs.Task;
|
||||||
!fileChangeEvent.WaitOne(500))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return changedFile;
|
// Don't need to listen anymore
|
||||||
}
|
fileWatcher.OnChanged -= callback;
|
||||||
});
|
|
||||||
|
return changedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DnxWatcher CreateDefault(ILoggerFactory loggerFactory)
|
public static DnxWatcher CreateDefault(ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
return new DnxWatcher(
|
return new DnxWatcher(
|
||||||
fileWatcherFactory: root => { return new FileWatcher(root); },
|
fileWatcherFactory: root => new FileWatcher(root),
|
||||||
processWatcherFactory: () => { return new ProcessWatcher(); },
|
processWatcherFactory: () => new ProcessWatcher(),
|
||||||
projectProvider: new ProjectProvider(),
|
projectProvider: new ProjectProvider(),
|
||||||
loggerFactory: loggerFactory);
|
loggerFactory: loggerFactory);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,33 +37,19 @@ namespace Microsoft.Dnx.Watcher.Core
|
||||||
return _runningProcess.Id;
|
return _runningProcess.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> WaitForExitAsync(CancellationToken cancellationToken)
|
public Task<int> WaitForExitAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
try
|
cancellationToken.Register(() => _runningProcess?.Kill());
|
||||||
|
|
||||||
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
await Task.Run(() =>
|
_runningProcess.WaitForExit();
|
||||||
{
|
|
||||||
while (!cancellationToken.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
if (_runningProcess.WaitForExit(500))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_runningProcess.HasExited)
|
var exitCode = _runningProcess.ExitCode;
|
||||||
{
|
|
||||||
_runningProcess.Kill();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
return _runningProcess.ExitCode;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_runningProcess = null;
|
_runningProcess = null;
|
||||||
}
|
|
||||||
|
return exitCode;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RemoveCompilationPortEnvironmentVariable(ProcessStartInfo procStartInfo)
|
private static void RemoveCompilationPortEnvironmentVariable(ProcessStartInfo procStartInfo)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ namespace Microsoft.Dnx.Watcher.Core
|
||||||
public Project(Runtime.Project runtimeProject)
|
public Project(Runtime.Project runtimeProject)
|
||||||
{
|
{
|
||||||
ProjectFile = runtimeProject.ProjectFilePath;
|
ProjectFile = runtimeProject.ProjectFilePath;
|
||||||
|
ProjectDirectory = runtimeProject.ProjectDirectory;
|
||||||
|
|
||||||
Files = runtimeProject.Files.SourceFiles.Concat(
|
Files = runtimeProject.Files.SourceFiles.Concat(
|
||||||
runtimeProject.Files.ResourceFiles.Values.Concat(
|
runtimeProject.Files.ResourceFiles.Values.Concat(
|
||||||
|
|
@ -28,7 +29,7 @@ namespace Microsoft.Dnx.Watcher.Core
|
||||||
if (File.Exists(projectLockJsonPath))
|
if (File.Exists(projectLockJsonPath))
|
||||||
{
|
{
|
||||||
var lockFile = lockFileReader.Read(projectLockJsonPath);
|
var lockFile = lockFileReader.Read(projectLockJsonPath);
|
||||||
ProjectDependencies = lockFile.ProjectLibraries.Select(dep => dep.Path).ToList();
|
ProjectDependencies = lockFile.ProjectLibraries.Select(dep => GetProjectRelativeFullPath(dep.Path)).ToList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -41,5 +42,12 @@ namespace Microsoft.Dnx.Watcher.Core
|
||||||
public IEnumerable<string> Files { get; private set; }
|
public IEnumerable<string> Files { get; private set; }
|
||||||
|
|
||||||
public string ProjectFile { get; private set; }
|
public string ProjectFile { get; private set; }
|
||||||
|
|
||||||
|
public string ProjectDirectory { get; private set; }
|
||||||
|
|
||||||
|
private string GetProjectRelativeFullPath(string path)
|
||||||
|
{
|
||||||
|
return Path.GetFullPath(Path.Combine(ProjectDirectory, path));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue