Skip to content

Commit 8fabe65

Browse files
committed
Add option to turn off bidirectional conversion. When bidirectional conversion is turned off, only sync->async conversion is performed
1 parent f41a7c5 commit 8fabe65

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

Program.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ internal static class Global
3434
public static List<string> ExcludedExtensions = new List<string>() { "*~", "tmp" };
3535
public static List<string> IgnorePathsStartingWith = new List<string>();
3636
public static List<string> IgnorePathsContaining = new List<string>();
37-
38-
37+
3938
public static string AsyncPath = "";
4039
public static string SyncPath = "";
4140

41+
public static bool Bidirectional = true;
42+
4243

4344

4445
internal static readonly AsyncLockQueueDictionary FileOperationLocks = new AsyncLockQueueDictionary();
@@ -109,6 +110,8 @@ private static void Main()
109110

110111
var fileConfig = config.GetSection("Files");
111112

113+
Global.Bidirectional = fileConfig["Bidirectional"]?.ToUpperInvariant() != "FALSE"; //default is true
114+
112115
Global.AsyncPath = fileConfig["AsyncPath"];
113116
Global.SyncPath = fileConfig["SyncPath"];
114117

@@ -160,10 +163,13 @@ private static async Task MainTask()
160163
// }
161164
//}
162165

163-
164-
watch.Add(new Request(Global.AsyncPath, recursive: true));
165166
watch.Add(new Request(Global.SyncPath, recursive: true));
166167

168+
if (Global.Bidirectional)
169+
{
170+
watch.Add(new Request(Global.AsyncPath, recursive: true));
171+
}
172+
167173

168174
// prepare the console watcher so we can output pretty messages.
169175
var consoleWatch = new ConsoleWatch(watch);
@@ -199,15 +205,18 @@ await ConsoleWatch.OnAddedAsync
199205
}
200206
}
201207

202-
//2. Do initial synchronisation from async to sync folder //TODO: config for enabling and ordering of this operation
203-
foreach (var fileInfo in new DirectoryInfo(Global.AsyncPath)
204-
.GetFiles("*." + Global.WatchedCodeExtension, SearchOption.AllDirectories))
208+
if (Global.Bidirectional)
205209
{
206-
await ConsoleWatch.OnAddedAsync
207-
(
208-
new DummyFileSystemEvent(fileInfo),
209-
new CancellationToken()
210-
);
210+
//2. Do initial synchronisation from async to sync folder //TODO: config for enabling and ordering of this operation
211+
foreach (var fileInfo in new DirectoryInfo(Global.AsyncPath)
212+
.GetFiles("*." + Global.WatchedCodeExtension, SearchOption.AllDirectories))
213+
{
214+
await ConsoleWatch.OnAddedAsync
215+
(
216+
new DummyFileSystemEvent(fileInfo),
217+
new CancellationToken()
218+
);
219+
}
211220
}
212221

213222

appsettings.example.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"Files": {
33

4-
"AsyncPath": "C:\\yourpath\\yourproject\\",
4+
"Bidirectional": true,
5+
6+
57
"SyncPath": "C:\\yourpath\\yourproject-debug\\",
8+
"AsyncPath": "C:\\yourpath\\yourproject\\",
69

710

811
"WatchedCodeExtension": "cs",

0 commit comments

Comments
 (0)