Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 95cba7f

Browse filesBrowse files
refactor: apply default vs transform to xproj
refactor(spa-services): clean code refactor(node-services): clean code, extract classes nto separate files refactor(angular-services): prime cache cleanup
1 parent 2c35945 commit 95cba7f
Copy full SHA for 95cba7f
Expand file treeCollapse file tree

32 files changed

+575
-402
lines changed
Open diff view settings
Collapse file

‎samples/angular/MusicStore/MusicStore.xproj‎

Copy file name to clipboardExpand all lines: samples/angular/MusicStore/MusicStore.xproj
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<ProjectGuid>1a74148f-9dc0-435d-b5ac-7d1b0d3d5e0b</ProjectGuid>
1111
<RootNamespace>MusicStore</RootNamespace>
1212
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
13-
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
1414
</PropertyGroup>
1515
<PropertyGroup>
1616
<SchemaVersion>2.0</SchemaVersion>
1717
<DevelopmentServerPort>5068</DevelopmentServerPort>
1818
</PropertyGroup>
1919
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
20-
</Project>
20+
</Project>
Collapse file

‎samples/misc/ES2015Transpilation/ES2015Transpilation.xproj‎

Copy file name to clipboardExpand all lines: samples/misc/ES2015Transpilation/ES2015Transpilation.xproj
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<ProjectGuid>6d4bcdd6-7951-449b-be55-cb7f014b7430</ProjectGuid>
1111
<RootNamespace>ES2015Transpilation</RootNamespace>
1212
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\JavaScriptServices.sln\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
13-
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\JavaScriptServices.sln\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
1414
</PropertyGroup>
1515
<PropertyGroup>
1616
<SchemaVersion>2.0</SchemaVersion>
1717
<DevelopmentServerPort>2018</DevelopmentServerPort>
1818
</PropertyGroup>
1919
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
20-
</Project>
20+
</Project>
Collapse file

‎samples/react/ReactGrid/ReactGrid.xproj‎

Copy file name to clipboardExpand all lines: samples/react/ReactGrid/ReactGrid.xproj
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<ProjectGuid>abf90a5b-f4e0-438c-a6e4-9549fb43690b</ProjectGuid>
1111
<RootNamespace>ReactGrid</RootNamespace>
1212
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
13-
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
1414
</PropertyGroup>
1515
<PropertyGroup>
1616
<SchemaVersion>2.0</SchemaVersion>
1717
<DevelopmentServerPort>2311</DevelopmentServerPort>
1818
</PropertyGroup>
1919
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
20-
</Project>
20+
</Project>
Collapse file

‎src/Microsoft.AspNetCore.AngularServices/Microsoft.AspNetCore.AngularServices.xproj‎

Copy file name to clipboardExpand all lines: src/Microsoft.AspNetCore.AngularServices/Microsoft.AspNetCore.AngularServices.xproj
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
<ProjectGuid>421807e6-b62c-417b-b901-46c5dedaa8f1</ProjectGuid>
1010
<RootNamespace>Microsoft.AspNetCore.AngularServices</RootNamespace>
1111
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
12-
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
1313
</PropertyGroup>
14-
1514
<PropertyGroup>
1615
<SchemaVersion>2.0</SchemaVersion>
1716
</PropertyGroup>
1817
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
19-
</Project>
18+
</Project>
Collapse file

‎src/Microsoft.AspNetCore.AngularServices/PrimeCacheHelper.cs‎

Copy file name to clipboardExpand all lines: src/Microsoft.AspNetCore.AngularServices/PrimeCacheHelper.cs
+27-18Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,51 @@
33
using System.Net.Http;
44
using System.Threading.Tasks;
55
using Microsoft.AspNetCore.Mvc.Rendering;
6+
using Microsoft.AspNetCore.Html;
67
using Microsoft.Extensions.Logging;
78
using Newtonsoft.Json;
89

9-
namespace Microsoft.AspNetCore.AngularServices {
10-
public static class PrimeCacheHelper {
11-
public static async Task<HtmlString> PrimeCache(this IHtmlHelper html, string url) {
10+
namespace Microsoft.AspNetCore.AngularServices
11+
{
12+
public static class PrimeCacheHelper
13+
{
14+
public static async Task<HtmlString> PrimeCache(this IHtmlHelper html, string url)
15+
{
1216
// TODO: Consider deduplicating the PrimeCache calls (that is, if there are multiple requests to precache
1317
// the same URL, only return nonempty for one of them). This will make it easier to auto-prime-cache any
1418
// HTTP requests made during server-side rendering, without risking unnecessary duplicate requests.
1519

16-
if (string.IsNullOrEmpty(url)) {
20+
if (string.IsNullOrEmpty(url))
21+
{
1722
throw new ArgumentException("Value cannot be null or empty", nameof(url));
1823
}
1924

20-
try {
25+
try
26+
{
2127
var request = html.ViewContext.HttpContext.Request;
22-
var baseUri = new Uri(string.Concat(request.Scheme, "://", request.Host.ToUriComponent(), request.PathBase.ToUriComponent(), request.Path.ToUriComponent(), request.QueryString.ToUriComponent()));
28+
var baseUri =
29+
new Uri(string.Concat(request.Scheme, "://", request.Host.ToUriComponent(),
30+
request.PathBase.ToUriComponent(), request.Path.ToUriComponent(),
31+
request.QueryString.ToUriComponent()));
2332
var fullUri = new Uri(baseUri, url);
2433
var response = await new HttpClient().GetAsync(fullUri.ToString());
2534
var responseBody = await response.Content.ReadAsStringAsync();
2635
return new HtmlString(FormatAsScript(url, response.StatusCode, responseBody));
27-
} catch (Exception ex) {
28-
var logger = (ILogger)html.ViewContext.HttpContext.RequestServices.GetService(typeof (ILogger));
29-
if (logger != null) {
30-
logger.LogWarning("Error priming cache for URL: " + url, ex);
31-
}
36+
}
37+
catch (Exception ex)
38+
{
39+
var logger = (ILogger)html.ViewContext.HttpContext.RequestServices.GetService(typeof(ILogger));
40+
logger?.LogWarning("Error priming cache for URL: " + url, ex);
3241
return new HtmlString(string.Empty);
3342
}
3443
}
3544

3645
private static string FormatAsScript(string url, HttpStatusCode responseStatusCode, string responseBody)
37-
{
38-
return string.Format(@"<script>window.__preCachedResponses = window.__preCachedResponses || {{}}; window.__preCachedResponses[{0}] = {1};</script>",
39-
JsonConvert.SerializeObject(url),
40-
JsonConvert.SerializeObject(new { statusCode = responseStatusCode, body = responseBody })
41-
);
42-
}
46+
=>
47+
"<script>" +
48+
"window.__preCachedResponses = window.__preCachedResponses || {{}}; " +
49+
$"window.__preCachedResponses[{JsonConvert.SerializeObject(url)}] " +
50+
$"= {JsonConvert.SerializeObject(new { statusCode = responseStatusCode, body = responseBody })};" +
51+
"</script>";
4352
}
44-
}
53+
}
Collapse file

‎src/Microsoft.AspNetCore.NodeServices/Configuration.cs‎

Copy file name to clipboardExpand all lines: src/Microsoft.AspNetCore.NodeServices/Configuration.cs
+21-25Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,46 @@
22
using Microsoft.Extensions.PlatformAbstractions;
33
using Microsoft.AspNetCore.Hosting;
44

5-
namespace Microsoft.AspNetCore.NodeServices {
6-
public static class Configuration {
7-
private readonly static string[] defaultWatchFileExtensions = new[] { ".js", ".jsx", ".ts", ".tsx", ".json", ".html" };
8-
private readonly static NodeServicesOptions defaultOptions = new NodeServicesOptions {
5+
namespace Microsoft.AspNetCore.NodeServices
6+
{
7+
using System;
8+
9+
public static class Configuration
10+
{
11+
private static readonly string[] DefaultWatchFileExtensions = {".js", ".jsx", ".ts", ".tsx", ".json", ".html"};
12+
13+
private static readonly NodeServicesOptions DefaultOptions = new NodeServicesOptions
14+
{
915
HostingModel = NodeHostingModel.Http,
10-
WatchFileExtensions = defaultWatchFileExtensions
16+
WatchFileExtensions = DefaultWatchFileExtensions
1117
};
1218

13-
public static void AddNodeServices(this IServiceCollection serviceCollection) {
14-
AddNodeServices(serviceCollection, defaultOptions);
15-
}
19+
public static void AddNodeServices(this IServiceCollection serviceCollection)
20+
=> AddNodeServices(serviceCollection, DefaultOptions);
1621

17-
public static void AddNodeServices(this IServiceCollection serviceCollection, NodeServicesOptions options) {
18-
serviceCollection.AddSingleton(typeof(INodeServices), (serviceProvider) => {
22+
public static void AddNodeServices(this IServiceCollection serviceCollection, NodeServicesOptions options)
23+
=> serviceCollection.AddSingleton(typeof(INodeServices), serviceProvider =>
24+
{
1925
var hostEnv = serviceProvider.GetRequiredService<IHostingEnvironment>();
20-
if (string.IsNullOrEmpty(options.ProjectPath)) {
26+
if (string.IsNullOrEmpty(options.ProjectPath))
27+
{
2128
options.ProjectPath = hostEnv.ContentRootPath;
2229
}
2330
return CreateNodeServices(options);
2431
});
25-
}
2632

2733
public static INodeServices CreateNodeServices(NodeServicesOptions options)
2834
{
29-
var watchFileExtensions = options.WatchFileExtensions ?? defaultWatchFileExtensions;
35+
var watchFileExtensions = options.WatchFileExtensions ?? DefaultWatchFileExtensions;
3036
switch (options.HostingModel)
3137
{
3238
case NodeHostingModel.Http:
3339
return new HttpNodeInstance(options.ProjectPath, /* port */ 0, watchFileExtensions);
3440
case NodeHostingModel.InputOutputStream:
3541
return new InputOutputStreamNodeInstance(options.ProjectPath);
3642
default:
37-
throw new System.ArgumentException("Unknown hosting model: " + options.HostingModel.ToString());
43+
throw new ArgumentException("Unknown hosting model: " + options.HostingModel);
3844
}
3945
}
4046
}
41-
42-
public class NodeServicesOptions {
43-
public NodeHostingModel HostingModel { get; set; }
44-
public string ProjectPath { get; set; }
45-
public string[] WatchFileExtensions { get; set; }
46-
47-
public NodeServicesOptions() {
48-
this.HostingModel = NodeHostingModel.Http;
49-
}
50-
}
51-
}
47+
}
Collapse file

‎src/Microsoft.AspNetCore.NodeServices/HostingModels/HttpNodeInstance.cs‎

Copy file name to clipboardExpand all lines: src/Microsoft.AspNetCore.NodeServices/HostingModels/HttpNodeInstance.cs
+53-29Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,90 @@
77
using Newtonsoft.Json;
88
using Newtonsoft.Json.Serialization;
99

10-
namespace Microsoft.AspNetCore.NodeServices {
11-
internal class HttpNodeInstance : OutOfProcessNodeInstance {
12-
private readonly static Regex PortMessageRegex = new Regex(@"^\[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on port (\d+)\]$");
10+
namespace Microsoft.AspNetCore.NodeServices
11+
{
12+
internal class HttpNodeInstance : OutOfProcessNodeInstance
13+
{
14+
private static readonly Regex PortMessageRegex =
15+
new Regex(@"^\[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on port (\d+)\]$");
1316

14-
private readonly static JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings {
17+
private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
18+
{
1519
ContractResolver = new CamelCasePropertyNamesContractResolver()
1620
};
1721

1822
private int _portNumber;
1923

20-
public HttpNodeInstance(string projectPath, int port = 0, string[] watchFileExtensions = null)
21-
: base(EmbeddedResourceReader.Read(typeof(HttpNodeInstance), "/Content/Node/entrypoint-http.js"), projectPath, MakeCommandLineOptions(port, watchFileExtensions))
24+
public HttpNodeInstance(string projectPath, int port = 0, string[] watchFileExtensions = null)
25+
: base(
26+
EmbeddedResourceReader.Read(
27+
typeof(HttpNodeInstance),
28+
"/Content/Node/entrypoint-http.js"),
29+
projectPath,
30+
MakeCommandLineOptions(port, watchFileExtensions))
2231
{
23-
}
32+
}
2433

25-
private static string MakeCommandLineOptions(int port, string[] watchFileExtensions) {
26-
var result = "--port " + port.ToString();
27-
if (watchFileExtensions != null && watchFileExtensions.Length > 0) {
34+
private static string MakeCommandLineOptions(int port, string[] watchFileExtensions)
35+
{
36+
var result = "--port " + port;
37+
if (watchFileExtensions != null && watchFileExtensions.Length > 0)
38+
{
2839
result += " --watch " + string.Join(",", watchFileExtensions);
2940
}
41+
3042
return result;
3143
}
3244

33-
public override async Task<T> Invoke<T>(NodeInvocationInfo invocationInfo) {
34-
await this.EnsureReady();
45+
public override async Task<T> Invoke<T>(NodeInvocationInfo invocationInfo)
46+
{
47+
await EnsureReady();
3548

36-
using (var client = new HttpClient()) {
49+
using (var client = new HttpClient())
50+
{
3751
// TODO: Use System.Net.Http.Formatting (PostAsJsonAsync etc.)
38-
var payloadJson = JsonConvert.SerializeObject(invocationInfo, jsonSerializerSettings);
52+
var payloadJson = JsonConvert.SerializeObject(invocationInfo, JsonSerializerSettings);
3953
var payload = new StringContent(payloadJson, Encoding.UTF8, "application/json");
40-
var response = await client.PostAsync("http://localhost:" + this._portNumber, payload);
54+
var response = await client.PostAsync("http://localhost:" + _portNumber, payload);
4155
var responseString = await response.Content.ReadAsStringAsync();
4256

43-
if (!response.IsSuccessStatusCode) {
57+
if (!response.IsSuccessStatusCode)
58+
{
4459
throw new Exception("Call to Node module failed with error: " + responseString);
4560
}
4661

4762
var responseIsJson = response.Content.Headers.ContentType.MediaType == "application/json";
48-
if (responseIsJson) {
63+
if (responseIsJson)
64+
{
4965
return JsonConvert.DeserializeObject<T>(responseString);
50-
} else if (typeof(T) != typeof(string)) {
51-
throw new System.ArgumentException("Node module responded with non-JSON string. This cannot be converted to the requested generic type: " + typeof(T).FullName);
52-
} else {
53-
return (T)(object)responseString;
5466
}
67+
if (typeof(T) != typeof(string))
68+
{
69+
throw new ArgumentException(
70+
"Node module responded with non-JSON string. This cannot be converted to the requested generic type: " +
71+
typeof(T).FullName);
72+
}
73+
return (T)(object)responseString;
5574
}
5675
}
5776

58-
protected override void OnOutputDataReceived(string outputData) {
59-
var match = this._portNumber != 0 ? null : PortMessageRegex.Match(outputData);
60-
if (match != null && match.Success) {
61-
this._portNumber = int.Parse(match.Groups[1].Captures[0].Value);
62-
} else {
77+
protected override void OnOutputDataReceived(string outputData)
78+
{
79+
var match = _portNumber != 0 ? null : PortMessageRegex.Match(outputData);
80+
if (match != null && match.Success)
81+
{
82+
_portNumber = int.Parse(match.Groups[1].Captures[0].Value);
83+
}
84+
else
85+
{
6386
base.OnOutputDataReceived(outputData);
6487
}
6588
}
6689

67-
protected override void OnBeforeLaunchProcess() {
90+
protected override void OnBeforeLaunchProcess()
91+
{
6892
// Prepare to receive a new port number
69-
this._portNumber = 0;
93+
_portNumber = 0;
7094
}
7195
}
72-
}
96+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.