-
Notifications
You must be signed in to change notification settings - Fork 1
/
sidekickapp.cs
86 lines (78 loc) · 3.13 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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 string[] fileExtensionsWhiteList = new string[]
{
".cs",
".coffee",
".rb",
".html",
".cshtml",
".js",
".css",
".fs"
};
static void Main(string[] args)
{
path = Directory.GetCurrentDirectory();
watcher = new FileSystemWatcher(path, "*.*");
watcher.IncludeSubdirectories = true;
watcher.EnableRaisingEvents = true;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
watcher.Created += new FileSystemEventHandler(watcher_Changed);
watcher.Renamed += watcher_Renamed;
Console.WriteLine("Watching for changes to the following file types: " + string.Join(", ", fileExtensionsWhiteList));
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_Renamed(object source, RenamedEventArgs e)
{
CallWatcher(e.FullPath);
}
static void watcher_Changed(object sender, FileSystemEventArgs e)
{
CallWatcher(e.FullPath);
}
static void CallWatcher(string path)
{
if (fileExtensionsWhiteList.Contains(Path.GetExtension(path)) && System.IO.File.Exists(path))
{
watcher.EnableRaisingEvents = false;
var relativeFile = path.Replace(Directory.GetCurrentDirectory(), "");
System.Console.WriteLine("Changed: " + relativeFile);
Shell("file_changed", relativeFile);
watcher.EnableRaisingEvents = true;
}
}
}
}