Skip to content

Commit 87c98a0

Browse files
committed
Fix package hintpaths in the project file. Remove <Deterministic>true</Deterministic> flag from the project file.
1 parent e2eff40 commit 87c98a0

File tree

3 files changed

+29
-35
lines changed

3 files changed

+29
-35
lines changed

AsyncToSyncCodeRoundtripSynchroniserMonitorNet.csproj

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14-
<Deterministic>true</Deterministic>
1514
<TargetFrameworkProfile />
1615
</PropertyGroup>
1716
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -46,7 +45,7 @@
4645
</PropertyGroup>
4746
<ItemGroup>
4847
<Reference Include="AsyncEnumerable, Version=4.0.2.0, Culture=neutral, PublicKeyToken=0426b068161bd1d1, processorArchitecture=MSIL">
49-
<HintPath>..\..\FolderSync\FolderSyncNet\packages\AsyncEnumerator.4.0.2\lib\net45\AsyncEnumerable.dll</HintPath>
48+
<HintPath>packages\AsyncEnumerator.4.0.2\lib\net45\AsyncEnumerable.dll</HintPath>
5049
</Reference>
5150
<Reference Include="Microsoft.Extensions.Configuration, Version=1.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
5251
<HintPath>packages\Microsoft.Extensions.Configuration.1.1.2\lib\netstandard1.1\Microsoft.Extensions.Configuration.dll</HintPath>
@@ -76,16 +75,16 @@
7675
<HintPath>packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
7776
</Reference>
7877
<Reference Include="MyOddWeb.DirectoryWatcher, Version=0.1.9.0, Culture=neutral, PublicKeyToken=b044eb2621106c1f, processorArchitecture=MSIL">
79-
<HintPath>..\..\FolderSync\FolderSyncNet\packages\MyOddWeb.DirectoryWatcher.0.1.9\lib\net452\MyOddWeb.DirectoryWatcher.dll</HintPath>
78+
<HintPath>packages\MyOddWeb.DirectoryWatcher.0.1.9\lib\net452\MyOddWeb.DirectoryWatcher.dll</HintPath>
8079
</Reference>
8180
<Reference Include="MyOddWeb.DirectoryWatcher.Interfaces, Version=0.1.9.0, Culture=neutral, PublicKeyToken=b044eb2621106c1f, processorArchitecture=MSIL">
82-
<HintPath>..\..\FolderSync\FolderSyncNet\packages\MyOddWeb.DirectoryWatcher.0.1.9\lib\net452\MyOddWeb.DirectoryWatcher.Interfaces.dll</HintPath>
81+
<HintPath>packages\MyOddWeb.DirectoryWatcher.0.1.9\lib\net452\MyOddWeb.DirectoryWatcher.Interfaces.dll</HintPath>
8382
</Reference>
8483
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
8584
<HintPath>packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
8685
</Reference>
8786
<Reference Include="Nito.AspNetBackgroundTasks, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
88-
<HintPath>..\..\FolderSync\FolderSyncNet\packages\Nito.AspNetBackgroundTasks.1.0.0\lib\net45\Nito.AspNetBackgroundTasks.dll</HintPath>
87+
<HintPath>packages\Nito.AspNetBackgroundTasks.1.0.0\lib\net45\Nito.AspNetBackgroundTasks.dll</HintPath>
8988
</Reference>
9089
<Reference Include="Nito.AsyncEx.Coordination, Version=5.0.0.0, Culture=neutral, processorArchitecture=MSIL">
9190
<HintPath>packages\Nito.AsyncEx.Coordination.5.0.0\lib\netstandard1.3\Nito.AsyncEx.Coordination.dll</HintPath>
@@ -100,7 +99,7 @@
10099
<HintPath>packages\Nito.Disposables.2.0.0\lib\netstandard1.0\Nito.Disposables.dll</HintPath>
101100
</Reference>
102101
<Reference Include="NReco.Text.AhoCorasickDoubleArrayTrie, Version=1.0.2.0, Culture=neutral, PublicKeyToken=70ca172a68680917, processorArchitecture=MSIL">
103-
<HintPath>..\..\FolderSync\FolderSyncNet\packages\NReco.Text.AhoCorasickDoubleArrayTrie.1.0.2\lib\net40\NReco.Text.AhoCorasickDoubleArrayTrie.dll</HintPath>
102+
<HintPath>packages\NReco.Text.AhoCorasickDoubleArrayTrie.1.0.2\lib\net40\NReco.Text.AhoCorasickDoubleArrayTrie.dll</HintPath>
104103
</Reference>
105104
<Reference Include="System" />
106105
<Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
@@ -140,7 +139,7 @@
140139
<HintPath>packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll</HintPath>
141140
</Reference>
142141
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
143-
<HintPath>..\..\FolderSync\FolderSyncNet\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
142+
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
144143
</Reference>
145144
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
146145
<HintPath>packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
@@ -158,7 +157,7 @@
158157
<HintPath>packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net46\System.Security.Cryptography.X509Certificates.dll</HintPath>
159158
</Reference>
160159
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
161-
<HintPath>..\..\FolderSync\FolderSyncNet\packages\System.Threading.Tasks.Extensions.4.5.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
160+
<HintPath>packages\System.Threading.Tasks.Extensions.4.5.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
162161
</Reference>
163162
<Reference Include="System.Windows.Forms" />
164163
<Reference Include="System.IO.Compression.FileSystem" />

FileExtensions.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//
66

77
#define ASYNC
8-
#define MS_IO_REDIST
98
using System;
109
#if NETSTANDARD
1110
using System.Buffers;
@@ -57,7 +56,7 @@ private static StreamReader AsyncStreamReader(string path, Encoding encoding)
5756

5857

5958
retryCount = Math.Max(0, retryCount);
60-
for (int i = -1; i < retryCount; i++) //roland
59+
for (int tryIndex = -1; tryIndex < retryCount; tryIndex++) //roland
6160
{
6261
try //roland
6362
{
@@ -72,7 +71,7 @@ ex is IOException
7271
{
7372
//retry after delay
7473

75-
if (i + 1 < retryCount) //do not sleep after last try
74+
if (tryIndex + 1 < retryCount) //do not sleep after last try
7675
{
7776
#if !NOASYNC
7877
await Task.Delay(1000, cancellationToken); //TODO: config file?
@@ -118,11 +117,7 @@ private static async Task<string> InternalReadAllTextAsync(string path, Encoding
118117
StringBuilder sb = new StringBuilder();
119118
while (true)
120119
{
121-
#if MS_IO_REDIST
122120
int read = await sr.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
123-
#else
124-
int read = await sr.ReadAsync(new Memory<char>(buffer), cancellationToken).ConfigureAwait(false);
125-
#endif
126121
if (read == 0)
127122
{
128123
return sb.ToString();
@@ -226,21 +221,17 @@ private static async Task InternalWriteAllTextAsync(StreamWriter sw, string cont
226221
buffer = new char[DefaultBufferSize];
227222
#endif
228223
int count = contents.Length;
229-
int index = 0;
230-
while (index < count)
224+
int sourceOffset = 0;
225+
while (sourceOffset < count)
231226
{
232-
int batchSize = Math.Min(DefaultBufferSize, count - index);
233-
contents.CopyTo(index, buffer, 0, batchSize);
234-
#if MS_IO_REDIST
235-
await sw.WriteAsync(buffer, 0, batchSize).ConfigureAwait(false);
236-
#else
237-
await sw.WriteAsync(new ReadOnlyMemory<char>(buffer, 0, batchSize), cancellationToken).ConfigureAwait(false);
238-
#endif
239-
index += batchSize;
227+
int batchSize = Math.Min(DefaultBufferSize, count - sourceOffset);
228+
contents.CopyTo(sourceOffset, buffer, 0, batchSize);
229+
await sw.WriteAsync(buffer, 0, batchSize);
230+
sourceOffset += batchSize;
240231
}
241232

242233
cancellationToken.ThrowIfCancellationRequested();
243-
await sw.FlushAsync().ConfigureAwait(false);
234+
await sw.FlushAsync();
244235
}
245236
finally
246237
{

Program.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,12 @@ private static async Task WriteException(Exception ex_in)
484484

485485
message.AppendLine("");
486486

487-
await FileExtensions.AppendAllTextAsync("UnhandledExceptions.log", message.ToString(), Global.CancellationToken.Token);
488-
489487

488+
using (await ConsoleWatch.Lock.LockAsync(Global.CancellationToken.Token))
489+
{
490+
await FileExtensions.AppendAllTextAsync("UnhandledExceptions.log", message.ToString(), Global.CancellationToken.Token);
491+
}
492+
490493

491494
//Console.WriteLine(ex.Message);
492495
message.Clear(); //TODO: refactor to shared function
@@ -501,16 +504,15 @@ private static async Task WriteException(Exception ex_in)
501504

502505

503506
var time = DateTime.Now;
504-
var msg = $"[{time:yyyy.MM.dd HH:mm:ss.ffff}]:{message}";
507+
var msg = $"[{time:yyyy.MM.dd HH:mm:ss.ffff}] : {message}";
505508
await AddMessage(ConsoleColor.Red, msg, time, showAlert: true);
506509
}
507510

508511
private static async Task AddMessage(ConsoleColor color, string message, DateTime time, bool showAlert = false)
509512
{
510513
//await Task.Run(() =>
511514
{
512-
//NB! using synchronous lock here since the MessageBox.Show and Console.WriteLine are synchronous
513-
lock (ConsoleWatch.Lock)
515+
using (await ConsoleWatch.Lock.LockAsync(Global.CancellationToken.Token))
514516
{
515517
try
516518
{
@@ -616,7 +618,7 @@ internal class ConsoleWatch
616618
/// <summary>
617619
/// We need a static lock so it is shared by all.
618620
/// </summary>
619-
internal static readonly object Lock = new object();
621+
internal static readonly AsyncLock Lock = new AsyncLock();
620622

621623
internal static DateTime PrevAlertTime;
622624
internal static string PrevAlertMessage;
@@ -703,8 +705,11 @@ public static async Task WriteException(Exception ex_in, Context context)
703705

704706
message.AppendLine("");
705707

706-
await FileExtensions.AppendAllTextAsync("UnhandledExceptions.log", message.ToString(), context.Token);
707708

709+
using (await ConsoleWatch.Lock.LockAsync(context.Token))
710+
{
711+
await FileExtensions.AppendAllTextAsync("UnhandledExceptions.log", message.ToString(), context.Token);
712+
}
708713

709714

710715
//Console.WriteLine(ex.Message);
@@ -1289,8 +1294,7 @@ public static async Task AddMessage(ConsoleColor color, string message, Context
12891294
{
12901295
//await Task.Run(() =>
12911296
{
1292-
//NB! using synchronous lock here since the MessageBox.Show and Console.WriteLine are synchronous
1293-
lock (Lock)
1297+
using (await ConsoleWatch.Lock.LockAsync(context.Token))
12941298
{
12951299
try
12961300
{

0 commit comments

Comments
 (0)