Normalise trailing whitespace and line endings everywhere

This commit is contained in:
SteveSandersonMS
2016-03-01 01:10:43 +00:00
parent c425137423
commit 74cac774f8
174 changed files with 782 additions and 783 deletions

View File

@@ -8,11 +8,11 @@ namespace Microsoft.AspNet.NodeServices {
HostingModel = NodeHostingModel.Http,
WatchFileExtensions = defaultWatchFileExtensions
};
public static void AddNodeServices(this IServiceCollection serviceCollection) {
AddNodeServices(serviceCollection, defaultOptions);
}
public static void AddNodeServices(this IServiceCollection serviceCollection, NodeServicesOptions options) {
serviceCollection.AddSingleton(typeof(INodeServices), (serviceProvider) => {
var appEnv = serviceProvider.GetRequiredService<IApplicationEnvironment>();
@@ -42,7 +42,7 @@ namespace Microsoft.AspNet.NodeServices {
public NodeHostingModel HostingModel { get; set; }
public string ProjectPath { get; set; }
public string[] WatchFileExtensions { get; set; }
public NodeServicesOptions() {
this.HostingModel = NodeHostingModel.Http;
}

View File

@@ -24,7 +24,7 @@ var server = http.createServer(function(req, res) {
hasSentResult = true;
if (errorValue) {
res.statusCode = 500;
if (errorValue.stack) {
res.end(errorValue.stack);
} else {
@@ -41,19 +41,19 @@ var server = http.createServer(function(req, res) {
}
}
};
try {
func.apply(null, [callback].concat(bodyJson.args));
} catch (synchronousException) {
callback(synchronousException, null);
}
}
});
});
server.listen(requestedPortOrZero, 'localhost', function () {
// Signal to HttpNodeHost which port it should make its HTTP connections on
console.log('[Microsoft.AspNet.NodeServices.HttpNodeHost:Listening on port ' + server.address().port + '\]');
// Signal to the NodeServices base class that we're ready to accept invocations
console.log('[Microsoft.AspNet.NodeServices:Listening]');
});

View File

@@ -12,7 +12,7 @@ function invocationCallback(errorValue, successValue) {
}
readline.createInterface({ input: process.stdin }).on('line', function (message) {
if (message && message.substring(0, invocationPrefix.length) === invocationPrefix) {
if (message && message.substring(0, invocationPrefix.length) === invocationPrefix) {
var invocation = JSON.parse(message.substring(invocationPrefix.length));
var invokedModule = require(path.resolve(process.cwd(), invocation.moduleName));
var func = invocation.exportedFunctionName ? invokedModule[invocation.exportedFunctionName] : invokedModule;

View File

@@ -10,40 +10,40 @@ using Newtonsoft.Json.Serialization;
namespace Microsoft.AspNet.NodeServices {
internal class HttpNodeInstance : OutOfProcessNodeInstance {
private readonly static Regex PortMessageRegex = new Regex(@"^\[Microsoft.AspNet.NodeServices.HttpNodeHost:Listening on port (\d+)\]$");
private readonly static JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings {
ContractResolver = new CamelCasePropertyNamesContractResolver()
private readonly static JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings {
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
private int _portNumber;
public HttpNodeInstance(string projectPath, int port = 0, string[] watchFileExtensions = null)
: base(EmbeddedResourceReader.Read(typeof(HttpNodeInstance), "/Content/Node/entrypoint-http.js"), projectPath, MakeCommandLineOptions(port, watchFileExtensions))
{
}
private static string MakeCommandLineOptions(int port, string[] watchFileExtensions) {
var result = "--port " + port.ToString();
if (watchFileExtensions != null && watchFileExtensions.Length > 0) {
result += " --watch " + string.Join(",", watchFileExtensions);
}
}
return result;
}
public override async Task<T> Invoke<T>(NodeInvocationInfo invocationInfo) {
await this.EnsureReady();
using (var client = new HttpClient()) {
// TODO: Use System.Net.Http.Formatting (PostAsJsonAsync etc.)
var payloadJson = JsonConvert.SerializeObject(invocationInfo, jsonSerializerSettings);
var payload = new StringContent(payloadJson, Encoding.UTF8, "application/json");
var response = await client.PostAsync("http://localhost:" + this._portNumber, payload);
var responseString = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode) {
throw new Exception("Call to Node module failed with error: " + responseString);
}
var responseIsJson = response.Content.Headers.ContentType.MediaType == "application/json";
if (responseIsJson) {
return JsonConvert.DeserializeObject<T>(responseString);
@@ -54,7 +54,7 @@ namespace Microsoft.AspNet.NodeServices {
}
}
}
protected override void OnOutputDataReceived(string outputData) {
var match = this._portNumber != 0 ? null : PortMessageRegex.Match(outputData);
if (match != null && match.Success) {
@@ -63,7 +63,7 @@ namespace Microsoft.AspNet.NodeServices {
base.OnOutputDataReceived(outputData);
}
}
protected override void OnBeforeLaunchProcess() {
// Prepare to receive a new port number
this._portNumber = 0;

View File

@@ -19,21 +19,21 @@ namespace Microsoft.AspNet.NodeServices {
{
private SemaphoreSlim _invocationSemaphore = new SemaphoreSlim(1);
private TaskCompletionSource<string> _currentInvocationResult;
private readonly static JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings {
ContractResolver = new CamelCasePropertyNamesContractResolver()
private readonly static JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings {
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
public InputOutputStreamNodeInstance(string projectPath)
: base(EmbeddedResourceReader.Read(typeof(InputOutputStreamNodeInstance), "/Content/Node/entrypoint-stream.js"), projectPath)
{
}
public override async Task<T> Invoke<T>(NodeInvocationInfo invocationInfo) {
await this._invocationSemaphore.WaitAsync();
try {
await this.EnsureReady();
var payloadJson = JsonConvert.SerializeObject(invocationInfo, jsonSerializerSettings);
var nodeProcess = this.NodeProcess;
this._currentInvocationResult = new TaskCompletionSource<string>();
@@ -46,7 +46,7 @@ namespace Microsoft.AspNet.NodeServices {
this._currentInvocationResult = null;
}
}
protected override void OnOutputDataReceived(string outputData) {
if (this._currentInvocationResult != null) {
this._currentInvocationResult.SetResult(outputData);

View File

@@ -24,7 +24,7 @@ namespace Microsoft.AspNet.NodeServices {
return this._nodeProcess;
}
}
public OutOfProcessNodeInstance(string entryPointScript, string projectPath, string commandLineArguments = null)
{
this._childProcessLauncherLock = new object();
@@ -32,13 +32,13 @@ namespace Microsoft.AspNet.NodeServices {
this._projectPath = projectPath;
this._commandLineArguments = commandLineArguments ?? string.Empty;
}
public abstract Task<T> Invoke<T>(NodeInvocationInfo invocationInfo);
public Task<T> Invoke<T>(string moduleName, params object[] args) {
return this.InvokeExport<T>(moduleName, null, args);
}
public async Task<T> InvokeExport<T>(string moduleName, string exportedFunctionName, params object[] args) {
return await this.Invoke<T>(new NodeInvocationInfo {
ModuleName = moduleName,
@@ -56,7 +56,7 @@ namespace Microsoft.AspNet.NodeServices {
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
WorkingDirectory = this._projectPath
WorkingDirectory = this._projectPath
};
// Append projectPath to NODE_PATH so it can locate node_modules
@@ -149,4 +149,4 @@ namespace Microsoft.AspNet.NodeServices {
Dispose (false);
}
}
}
}

View File

@@ -2,9 +2,9 @@ using System;
using System.Threading.Tasks;
namespace Microsoft.AspNet.NodeServices {
public interface INodeServices : IDisposable {
public interface INodeServices : IDisposable {
Task<T> Invoke<T>(string moduleName, params object[] args);
Task<T> InvokeExport<T>(string moduleName, string exportedFunctionName, params object[] args);
}
}

View File

@@ -16,4 +16,4 @@
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
</Project>

View File

@@ -3,4 +3,4 @@ namespace Microsoft.AspNet.NodeServices {
Http,
InputOutputStream,
}
}
}

View File

@@ -4,14 +4,14 @@ using System.Reflection;
namespace Microsoft.AspNet.NodeServices {
public static class EmbeddedResourceReader {
public static string Read(Type assemblyContainingType, string path) {
public static string Read(Type assemblyContainingType, string path) {
var asm = assemblyContainingType.GetTypeInfo().Assembly;
var embeddedResourceName = asm.GetName().Name + path.Replace("/", ".");
using (var stream = asm.GetManifestResourceStream(embeddedResourceName))
using (var sr = new StreamReader(stream)) {
return sr.ReadToEnd();
}
}
}
}
}

View File

@@ -7,7 +7,7 @@ namespace Microsoft.AspNet.NodeServices {
public string FileName { get; private set; }
private bool _disposedValue;
public StringAsTempFile(string content) {
this.FileName = Path.GetTempFileName();
File.WriteAllText(this.FileName, content);