Skip to content

Commit f2dd6d4

Browse files
committed
Add back DownloadFile.cs
Revert Razor.Runtime.Manual.cs and regenerate ref assemblies
1 parent b92f423 commit f2dd6d4

9 files changed

+216
-9
lines changed

eng/tools/RepoTasks/DownloadFile.cs

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.IO;
6+
using System.Net;
7+
using System.Net.Http;
8+
using System.Threading.Tasks;
9+
using System.Collections.Generic;
10+
using Microsoft.Build.Framework;
11+
using Microsoft.Build.Utilities;
12+
13+
namespace RepoTasks
14+
{
15+
public class DownloadFile : Microsoft.Build.Utilities.Task
16+
{
17+
[Required]
18+
public string Uri { get; set; }
19+
20+
/// <summary>
21+
/// If this field is set and the task fail to download the file from `Uri`, with a NotFound
22+
/// status, it will try to download the file from `PrivateUri`.
23+
/// </summary>
24+
public string PrivateUri { get; set; }
25+
26+
/// <summary>
27+
/// Suffix for the private URI in base64 form (for SAS compatibility)
28+
/// </summary>
29+
public string PrivateUriSuffix { get; set; }
30+
31+
public int MaxRetries { get; set; } = 5;
32+
33+
[Required]
34+
public string DestinationPath { get; set; }
35+
36+
public bool Overwrite { get; set; }
37+
38+
public override bool Execute()
39+
{
40+
return ExecuteAsync().GetAwaiter().GetResult();
41+
}
42+
43+
private async System.Threading.Tasks.Task<bool> ExecuteAsync()
44+
{
45+
string destinationDir = Path.GetDirectoryName(DestinationPath);
46+
if (!Directory.Exists(destinationDir))
47+
{
48+
Directory.CreateDirectory(destinationDir);
49+
}
50+
51+
if (File.Exists(DestinationPath) && !Overwrite)
52+
{
53+
return true;
54+
}
55+
56+
const string FileUriProtocol = "file://";
57+
58+
if (Uri.StartsWith(FileUriProtocol, StringComparison.Ordinal))
59+
{
60+
var filePath = Uri.Substring(FileUriProtocol.Length);
61+
Log.LogMessage($"Copying '{filePath}' to '{DestinationPath}'");
62+
File.Copy(filePath, DestinationPath);
63+
return true;
64+
}
65+
66+
List<string> errorMessages = new List<string>();
67+
bool? downloadStatus = await DownloadWithRetriesAsync(Uri, DestinationPath, errorMessages);
68+
69+
if (downloadStatus == false && !string.IsNullOrEmpty(PrivateUri))
70+
{
71+
string uriSuffix = "";
72+
if (!string.IsNullOrEmpty(PrivateUriSuffix))
73+
{
74+
var uriSuffixBytes = System.Convert.FromBase64String(PrivateUriSuffix);
75+
uriSuffix = System.Text.Encoding.UTF8.GetString(uriSuffixBytes);
76+
}
77+
downloadStatus = await DownloadWithRetriesAsync($"{PrivateUri}{uriSuffix}", DestinationPath, errorMessages);
78+
}
79+
80+
if (downloadStatus != true)
81+
{
82+
foreach (var error in errorMessages)
83+
{
84+
Log.LogError(error);
85+
}
86+
}
87+
88+
return downloadStatus == true;
89+
}
90+
91+
/// <summary>
92+
/// Attempt to download file from `source` with retries when response error is different of FileNotFound and Success.
93+
/// </summary>
94+
/// <param name="source">URL to the file to be downloaded.</param>
95+
/// <param name="target">Local path where to put the downloaded file.</param>
96+
/// <returns>true: Download Succeeded. false: Download failed with 404. null: Download failed but is retriable.</returns>
97+
private async Task<bool?> DownloadWithRetriesAsync(string source, string target, List<string> errorMessages)
98+
{
99+
Random rng = new Random();
100+
101+
Log.LogMessage(MessageImportance.High, $"Attempting download '{source}' to '{target}'");
102+
103+
using (var httpClient = new HttpClient())
104+
{
105+
for (int retryNumber = 0; retryNumber < MaxRetries; retryNumber++)
106+
{
107+
try
108+
{
109+
var httpResponse = await httpClient.GetAsync(source);
110+
111+
Log.LogMessage(MessageImportance.High, $"{source} -> {httpResponse.StatusCode}");
112+
113+
// The Azure Storage REST API returns '400 - Bad Request' in some cases
114+
// where the resource is not found on the storage.
115+
// https://docs.microsoft.com/en-us/rest/api/storageservices/common-rest-api-error-codes
116+
if (httpResponse.StatusCode == HttpStatusCode.NotFound ||
117+
httpResponse.ReasonPhrase.IndexOf("The requested URI does not represent any resource on the server.", StringComparison.OrdinalIgnoreCase) == 0)
118+
{
119+
errorMessages.Add($"Problems downloading file from '{source}'. Does the resource exist on the storage? {httpResponse.StatusCode} : {httpResponse.ReasonPhrase}");
120+
return false;
121+
}
122+
123+
httpResponse.EnsureSuccessStatusCode();
124+
125+
using (var outStream = File.Create(target))
126+
{
127+
await httpResponse.Content.CopyToAsync(outStream);
128+
}
129+
130+
Log.LogMessage(MessageImportance.High, $"returning true {source} -> {httpResponse.StatusCode}");
131+
return true;
132+
}
133+
catch (Exception e)
134+
{
135+
Log.LogMessage(MessageImportance.High, $"returning error in {source} ");
136+
errorMessages.Add($"Problems downloading file from '{source}'. {e.Message} {e.StackTrace}");
137+
File.Delete(target);
138+
}
139+
140+
await System.Threading.Tasks.Task.Delay(rng.Next(1000, 10000));
141+
}
142+
}
143+
144+
Log.LogMessage(MessageImportance.High, $"giving up {source} ");
145+
errorMessages.Add($"Giving up downloading the file from '{source}' after {MaxRetries} retries.");
146+
return null;
147+
}
148+
}
149+
}

eng/tools/RepoTasks/RepoTasks.tasks

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
<UsingTask TaskName="RepoTasks.GenerateSharedFrameworkDepsFile" AssemblyFile="$(_RepoTaskAssembly)" />
1111
<UsingTask TaskName="RepoTasks.CreateFrameworkListFile" AssemblyFile="$(_RepoTaskAssembly)" />
1212
<UsingTask TaskName="RepoTasks.RemoveSharedFrameworkDependencies" AssemblyFile="$(_RepoTaskAssembly)" />
13+
<UsingTask TaskName="RepoTasks.DownloadFile" AssemblyFile="$(_RepoTaskAssembly)" />
1314
</Project>

src/Components/Components/ref/Microsoft.AspNetCore.Components.netcoreapp.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ public readonly partial struct ElementReference
123123
public ElementReference(string id) { throw null; }
124124
public string Id { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
125125
}
126+
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
127+
public readonly partial struct EventCallback
128+
{
129+
private readonly object _dummy;
130+
private readonly int _dummyPrimitive;
131+
public static readonly Microsoft.AspNetCore.Components.EventCallback Empty;
132+
public static readonly Microsoft.AspNetCore.Components.EventCallbackFactory Factory;
133+
public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent receiver, System.MulticastDelegate @delegate) { throw null; }
134+
public bool HasDelegate { get { throw null; } }
135+
public System.Threading.Tasks.Task InvokeAsync(object arg) { throw null; }
136+
}
126137
public sealed partial class EventCallbackFactory
127138
{
128139
public EventCallbackFactory() { }
@@ -186,6 +197,16 @@ public readonly partial struct EventCallbackWorkItem
186197
public EventCallbackWorkItem(System.MulticastDelegate @delegate) { throw null; }
187198
public System.Threading.Tasks.Task InvokeAsync(object arg) { throw null; }
188199
}
200+
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
201+
public readonly partial struct EventCallback<TValue>
202+
{
203+
private readonly object _dummy;
204+
private readonly int _dummyPrimitive;
205+
public static readonly Microsoft.AspNetCore.Components.EventCallback<TValue> Empty;
206+
public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent receiver, System.MulticastDelegate @delegate) { throw null; }
207+
public bool HasDelegate { get { throw null; } }
208+
public System.Threading.Tasks.Task InvokeAsync(TValue arg) { throw null; }
209+
}
189210
[System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
190211
public sealed partial class EventHandlerAttribute : System.Attribute
191212
{

src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ public readonly partial struct ElementReference
123123
public ElementReference(string id) { throw null; }
124124
public string Id { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
125125
}
126+
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
127+
public readonly partial struct EventCallback
128+
{
129+
private readonly object _dummy;
130+
private readonly int _dummyPrimitive;
131+
public static readonly Microsoft.AspNetCore.Components.EventCallback Empty;
132+
public static readonly Microsoft.AspNetCore.Components.EventCallbackFactory Factory;
133+
public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent receiver, System.MulticastDelegate @delegate) { throw null; }
134+
public bool HasDelegate { get { throw null; } }
135+
public System.Threading.Tasks.Task InvokeAsync(object arg) { throw null; }
136+
}
126137
public sealed partial class EventCallbackFactory
127138
{
128139
public EventCallbackFactory() { }
@@ -186,6 +197,16 @@ public readonly partial struct EventCallbackWorkItem
186197
public EventCallbackWorkItem(System.MulticastDelegate @delegate) { throw null; }
187198
public System.Threading.Tasks.Task InvokeAsync(object arg) { throw null; }
188199
}
200+
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
201+
public readonly partial struct EventCallback<TValue>
202+
{
203+
private readonly object _dummy;
204+
private readonly int _dummyPrimitive;
205+
public static readonly Microsoft.AspNetCore.Components.EventCallback<TValue> Empty;
206+
public EventCallback(Microsoft.AspNetCore.Components.IHandleEvent receiver, System.MulticastDelegate @delegate) { throw null; }
207+
public bool HasDelegate { get { throw null; } }
208+
public System.Threading.Tasks.Task InvokeAsync(TValue arg) { throw null; }
209+
}
189210
[System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
190211
public sealed partial class EventHandlerAttribute : System.Attribute
191212
{

src/Http/Routing/ref/Microsoft.AspNetCore.Routing.netcoreapp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ public partial struct CandidateState
517517
private int _dummyPrimitive;
518518
public Microsoft.AspNetCore.Http.Endpoint Endpoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
519519
public int Score { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
520+
public Microsoft.AspNetCore.Routing.RouteValueDictionary Values { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
520521
}
521522
public sealed partial class EndpointMetadataComparer : System.Collections.Generic.IComparer<Microsoft.AspNetCore.Http.Endpoint>
522523
{

src/Mvc/Mvc.Razor/ref/Microsoft.AspNetCore.Mvc.Razor.netcoreapp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Infrastructure
297297
public sealed partial class TagHelperMemoryCacheProvider
298298
{
299299
public TagHelperMemoryCacheProvider() { }
300+
public Microsoft.Extensions.Caching.Memory.IMemoryCache Cache { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
300301
}
301302
}
302303
namespace Microsoft.AspNetCore.Mvc.Razor.Internal

src/Mvc/Mvc.RazorPages/ref/Microsoft.AspNetCore.Mvc.RazorPages.netcoreapp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ public PageResult() { }
637637
public partial class RazorPagesOptions : System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Infrastructure.ICompatibilitySwitch>, System.Collections.IEnumerable
638638
{
639639
public RazorPagesOptions() { }
640+
public Microsoft.AspNetCore.Mvc.ApplicationModels.PageConventionCollection Conventions { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
640641
public string RootDirectory { get { throw null; } set { } }
641642
System.Collections.Generic.IEnumerator<Microsoft.AspNetCore.Mvc.Infrastructure.ICompatibilitySwitch> System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Infrastructure.ICompatibilitySwitch>.GetEnumerator() { throw null; }
642643
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers
5-
{
6-
public partial class TagHelperExecutionContext
7-
{
8-
internal TagHelperExecutionContext(string tagName, Microsoft.AspNetCore.Razor.TagHelpers.TagMode tagMode) { }
9-
[System.Diagnostics.DebuggerStepThroughAttribute]
10-
internal System.Threading.Tasks.Task<Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContent> GetChildContentAsync(bool useCachedResult, System.Text.Encodings.Web.HtmlEncoder encoder) { throw null; }
11-
}
12-
}
4+
using System.Runtime.CompilerServices;
5+
using Microsoft.AspNetCore.Razor.TagHelpers;
6+
7+
[assembly: TypeForwardedTo(typeof(DefaultTagHelperContent))]
8+
[assembly: TypeForwardedTo(typeof(HtmlAttributeNameAttribute))]
9+
[assembly: TypeForwardedTo(typeof(HtmlAttributeNotBoundAttribute))]
10+
[assembly: TypeForwardedTo(typeof(HtmlTargetElementAttribute))]
11+
[assembly: TypeForwardedTo(typeof(ITagHelper))]
12+
[assembly: TypeForwardedTo(typeof(ITagHelperComponent))]
13+
[assembly: TypeForwardedTo(typeof(NullHtmlEncoder))]
14+
[assembly: TypeForwardedTo(typeof(OutputElementHintAttribute))]
15+
[assembly: TypeForwardedTo(typeof(ReadOnlyTagHelperAttributeList))]
16+
[assembly: TypeForwardedTo(typeof(RestrictChildrenAttribute))]
17+
[assembly: TypeForwardedTo(typeof(TagHelper))]
18+
[assembly: TypeForwardedTo(typeof(TagHelperAttribute))]
19+
[assembly: TypeForwardedTo(typeof(TagHelperAttributeList))]
20+
[assembly: TypeForwardedTo(typeof(TagHelperComponent))]
21+
[assembly: TypeForwardedTo(typeof(TagHelperContent))]
22+
[assembly: TypeForwardedTo(typeof(TagHelperContext))]
23+
[assembly: TypeForwardedTo(typeof(TagHelperOutput))]

src/Servers/Kestrel/Core/ref/Microsoft.AspNetCore.Server.Kestrel.Core.netcoreapp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ internal ListenOptions() { }
155155
public System.IServiceProvider ApplicationServices { get { throw null; } }
156156
public ulong FileHandle { get { throw null; } }
157157
public System.Net.IPEndPoint IPEndPoint { get { throw null; } }
158+
public Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions KestrelServerOptions { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } }
158159
public Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols Protocols { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
159160
public string SocketPath { get { throw null; } }
160161
public Microsoft.AspNetCore.Connections.ConnectionDelegate Build() { throw null; }

0 commit comments

Comments
 (0)