Skip to content

Commit

Permalink
Update to HttpClient.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Nov 29, 2023
1 parent 3595835 commit e3248fa
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Update `csproj`.
- Add `ApplicationPreviewUtils` to enable know if Revit application is preview.
- Enable run without `LoginUserId` when `IsPreviewRelease`.
- Update `ricaun.Revit.UI`
- Update `RibbonUtils` with updated `ricaun.Revit.UI`
### Shared
- Update `net6.0-windows` framework.
### Console
Expand All @@ -29,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Update `ResourceConsoleUtils`
- Update `RevitTestConsole` to remove `+` in FileInfo.
- Add `FileVersionInfoUtils` to remove `+` in FileInfo.
- Update to `HttpClient`.
### Warning
- Ignore `Newtonsoft.Json` warning in `Application` project.

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ flowchart LR
* [ricaun.NUnit](https://github.com/ricaun-io/ricaun.NUnit)
* [ricaun.Revit.UI](https://github.com/ricaun-io/ricaun.Revit.UI)
* [ricaun.Revit.Async](https://github.com/ricaun-io/ricaun.Revit.Async)
* [ricaun.Auth](https://github.com/ricaun-io/ricaun.Auth)
* [Revit.Busy](https://github.com/ricaun-io/Revit.Busy)
* [ricaun.RevitTest.Shared](ricaun.RevitTest.Shared)
#### Console
Expand Down
4 changes: 4 additions & 0 deletions ricaun.RevitTest.Application/Revit/Utils/RibbonUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public static class RibbonUtils
public static string TestSkip { get; } = GetComponentImage("test-skip");
public static string TestWait { get; } = GetComponentImage("test-wait");
public static string GetComponentImage(string imageName)
{
return string.Format("Images/{0}.png", imageName);
}
static string GetComponentImagePack(string imageName)
{
var assemblyName = Assembly.GetCallingAssembly().GetName().Name;
return string.Format("pack://application:,,,/{0};component/Images/{1}.png", assemblyName, imageName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<ItemGroup>
<PackageReference Include="Revit.Busy" Version="*" />
<PackageReference Include="ricaun.Auth.Aps.UI" Version="*" />
<PackageReference Include="ricaun.Revit.UI" Version="0.6.0-alpha" />
<PackageReference Include="ricaun.Revit.UI" Version="*-*" />
<PackageReference Include="ricaun.Revit.Async" Version="*" />
<PackageReference Include="ricaun.NUnit" Version="*" />
<PackageReference Include="NamedPipeWrapper.Json" Version="*" />
Expand Down
50 changes: 50 additions & 0 deletions ricaun.RevitTest.TestAdapter/Services/ApplicationUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace ricaun.RevitTest.TestAdapter.Services
Expand Down Expand Up @@ -89,6 +90,54 @@ public static async Task<bool> DownloadAsync(string applicationFolder, string ad
var zipPath = Path.Combine(applicationFolder, fileName);
var result = false;

using (var client = new HttpClient())
{
System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;
try
{
if (File.Exists(address))
{
File.Copy(address, zipPath, true);
}
else
{
client.DefaultRequestHeaders.Add("User-Agent", nameof(ApplicationUtils));
using (var s = await client.GetStreamAsync(address))
{
using (var fs = new FileStream(zipPath, FileMode.Create))
{
await s.CopyToAsync(fs);
}
}
}
ExtractZipToDirectory(zipPath, applicationFolder);
result = true;
}
catch (Exception ex)
{
downloadFileException?.Invoke(ex);
}
if (Path.GetExtension(zipPath) == ZIP_FILE_EXTENSION)
if (File.Exists(zipPath)) File.Delete(zipPath);
}

return result;
}

/// <summary>
/// Download and unzip Application Async
/// </summary>
/// <param name="applicationFolder">Folder of the Application</param>
/// <param name="address"></param>
/// <param name="downloadFileException"></param>
/// <returns></returns>
public static async Task<bool> DownloadAsyncWeb(string applicationFolder, string address, Action<Exception> downloadFileException = null)
{
var fileName = Path.GetFileName(address);
var zipPath = Path.Combine(applicationFolder, fileName);
var result = false;

#pragma warning disable SYSLIB0014 // Type or member is obsolete
using (var client = new WebClient())
{
System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;
Expand All @@ -106,6 +155,7 @@ public static async Task<bool> DownloadAsync(string applicationFolder, string ad
if (Path.GetExtension(zipPath) == ZIP_FILE_EXTENSION)
if (File.Exists(zipPath)) File.Delete(zipPath);
}
#pragma warning restore SYSLIB0014 // Type or member is obsolete

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System.Web.Extensions" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Net.Http" />
</ItemGroup>

<!-- Fody -->
Expand Down

0 comments on commit e3248fa

Please sign in to comment.