Skip to content

Commit

Permalink
Merge pull request #6 from JeringTech/Misc_Refactorings
Browse files Browse the repository at this point in the history
Made misc refactorings
  • Loading branch information
JeremyTCD committed Nov 16, 2018
2 parents c213afa + bdb79a7 commit fb66f5b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 7 deletions.
11 changes: 11 additions & 0 deletions src/NodeJS/InvocationData/InvocationException.cs
@@ -1,10 +1,12 @@
using System;
using System.Runtime.Serialization;

namespace Jering.Javascript.NodeJS
{
/// <summary>
/// Represents an exception caused by an error caught in NodeJS.
/// </summary>
[Serializable]
public class InvocationException : Exception
{
/// <summary>
Expand All @@ -24,5 +26,14 @@ public InvocationException(string message, string stack)
: base(message + Environment.NewLine + stack)
{
}

/// <summary>
/// Creates a <see cref="InvocationException"/> instance.
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
protected InvocationException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
Expand Up @@ -245,7 +245,7 @@ function patchLStat() {
throw ex;
}
}
};
}

// It's only necessary to apply this workaround on Windows
let appRootDirLong: string = null;
Expand Down
Expand Up @@ -151,7 +151,6 @@ protected override void OnConnectionEstablishedMessageReceived(string connection

// Skip over "Port - "
i += 7;
continue;
}
else if (currentChar == ']')
{
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class InvocationContent : HttpContent
//private static readonly Encoding UTF8NoBOM = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true);

// Arbitrary boundary
internal static byte[] BOUNDARY_BYTES = Encoding.UTF8.GetBytes("--Uiw6+hXl3k+5ia0cUYGhjA==");
internal static readonly byte[] BOUNDARY_BYTES = Encoding.UTF8.GetBytes("--Uiw6+hXl3k+5ia0cUYGhjA==");

private readonly IJsonService _jsonService;
private readonly InvocationRequest _invocationRequest;
Expand Down
Expand Up @@ -82,8 +82,6 @@ private Process CreateProcess(ProcessStartInfo startInfo)
}
}

// TODO verify that this escaping works for non-windows platforms
// https://www.appveyor.com/docs/getting-started-with-appveyor-for-linux/
internal string EscapeCommandLineArg(string arg)
{
var stringBuilder = new StringBuilder();
Expand Down
Expand Up @@ -174,7 +174,7 @@ internal async Task<(bool, T)> TryInvokeCoreAsync<T>(InvocationRequest invocatio
{
if (Logger?.IsEnabled(LogLevel.Debug) == true)
{
Logger.LogDebug($"Before first semaphore wait, count: {_processSemaphore.CurrentCount}. Thread ID: {Thread.CurrentThread.ManagedThreadId.ToString()}");
Logger.LogDebug(string.Format(Strings.LogDebug_OutOfProcessNodeJSService_BeforeFirstSemaphore, _processSemaphore.CurrentCount, Thread.CurrentThread.ManagedThreadId.ToString()));
}

await _processSemaphore.WaitAsync().ConfigureAwait(false);
Expand All @@ -190,7 +190,7 @@ internal async Task<(bool, T)> TryInvokeCoreAsync<T>(InvocationRequest invocatio

if (Logger?.IsEnabled(LogLevel.Debug) == true)
{
Logger.LogDebug($"Before second semaphore wait, count: {_processSemaphore.CurrentCount}. Thread ID: {Thread.CurrentThread.ManagedThreadId.ToString()}");
Logger.LogDebug(string.Format(Strings.LogDebug_OutOfProcessNodeJSService_BeforeSecondSemaphore, _processSemaphore.CurrentCount, Thread.CurrentThread.ManagedThreadId.ToString()));
}

await _processSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
Expand Down
18 changes: 18 additions & 0 deletions src/NodeJS/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/NodeJS/Strings.resx
Expand Up @@ -142,4 +142,10 @@
<data name="InvocationException_OutOfProcessNodeJSService_InvocationTimedOut" xml:space="preserve">
<value>The Node invocation timed out after {0}ms. You can change the timeout duration by setting the {1} property on {2}. Do ensure that your NodeJS function always invokes the callback (or throws an exception synchronously), even if it encounters an error.</value>
</data>
<data name="LogDebug_OutOfProcessNodeJSService_BeforeFirstSemaphore" xml:space="preserve">
<value>Before first semaphore wait, count: {0}. Thread ID: {1}.</value>
</data>
<data name="LogDebug_OutOfProcessNodeJSService_BeforeSecondSemaphore" xml:space="preserve">
<value>Before second semaphore wait, count: {0}. Thread ID: {1}.</value>
</data>
</root>

0 comments on commit fb66f5b

Please sign in to comment.