-
Notifications
You must be signed in to change notification settings - Fork 18
/
sidekickapp.cs
61 lines (54 loc) · 2.29 KB
/
sidekickapp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
namespace SyncDeploy
{
class Program
{
static string path = null;
static FileSystemWatcher watcher;
static void Main(string[] args)
{
path = Directory.GetCurrentDirectory();
watcher = new FileSystemWatcher(path, "*.*");
watcher.IncludeSubdirectories = true;
watcher.EnableRaisingEvents = true;
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
watcher.Created += new FileSystemEventHandler(watcher_Changed);
Console.WriteLine("Watching " + path + " for changes, press Enter to stop...");
Shell("tutorial");
Console.ReadLine();
}
static void Shell(params string[] args)
{
ProcessStartInfo processStartInfo = new ProcessStartInfo("ruby", "dotnet.watchr.rb " + string.Join(" ", args));
processStartInfo.UseShellExecute = false;
processStartInfo.ErrorDialog = false;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
Process process = new Process();
process.EnableRaisingEvents = true;
process.StartInfo = processStartInfo;
process.OutputDataReceived += (sender, args1) => System.Console.WriteLine(args1.Data);
process.ErrorDataReceived += (sender, args2) => System.Console.WriteLine(args2.Data);
bool processStarted = process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
System.Console.WriteLine("---");
}
static void watcher_Changed(object sender, FileSystemEventArgs e)
{
watcher.EnableRaisingEvents = false;
var relativeFile = e.FullPath.Replace(Directory.GetCurrentDirectory(), "");
System.Console.WriteLine("Changed: " + relativeFile);
Shell("file_changed", relativeFile);
watcher.EnableRaisingEvents = true;
}
}
}