Skip to content

Commit

Permalink
Import load http async
Browse files Browse the repository at this point in the history
  • Loading branch information
webprofusion-chrisc committed Dec 7, 2023
1 parent 78bd0e6 commit de41086
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Import/OCM.Import.Common/ImportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ public async Task<ImportReport> PerformImport(ImportProcessSettings settings, AP
}
else if (p is ImportProvider_Sitronics)
{
(p as ImportProvider_Sitronics).AuthHeaderValue = "Token openchargemapDkxXXliO4542YWQzY2M0NGQyCgn";
(p as ImportProvider_Sitronics).AuthHeaderValue = "Token";
}

if (p.ImportInitialisationRequired && p is IImportProviderWithInit)
Expand All @@ -869,7 +869,7 @@ public async Task<ImportReport> PerformImport(ImportProcessSettings settings, AP
{
Log("Loading input data from URL..");
var sw = Stopwatch.StartNew();
loadOK = provider.LoadInputFromURL(p.AutoRefreshURL);
loadOK = await provider.LoadInputFromURL(p.AutoRefreshURL);
sw.Stop();
Log($"Data downloaded in {sw.Elapsed.TotalSeconds}s.");
}
Expand All @@ -879,7 +879,7 @@ public async Task<ImportReport> PerformImport(ImportProcessSettings settings, AP
{
Log("Loading input data from file..");

loadOK = provider.LoadInputFromURL(p.InputPath);
loadOK = await provider.LoadInputFromURL(p.InputPath);
}
else
{
Expand Down
7 changes: 5 additions & 2 deletions Import/OCM.Import.Common/Providers/BaseImportProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;


namespace OCM.Import.Providers
Expand Down Expand Up @@ -230,14 +232,15 @@ public string CalculateMD5Hash(string input)
return sb.ToString();
}

public bool LoadInputFromURL(string url)
public async Task<bool> LoadInputFromURL(string url)
{
HttpClient client = new HttpClient();
try
{
if (String.IsNullOrEmpty(HTTPPostVariables))
{
//get
InputData = webClient.DownloadString(url);
InputData = await client.GetStringAsync(url);
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion Import/OCM.Import.Common/Providers/IImportProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using OCM.API.Common.Model;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OCM.Import.Providers
{
Expand All @@ -8,7 +9,7 @@ public interface IImportProvider
string GetProviderName();
List<ChargePoint> Process(CoreReferenceData coreRefData);

bool LoadInputFromURL(string url);
Task<bool> LoadInputFromURL(string url);
}

public interface IImportProviderWithInit : IImportProvider
Expand Down

0 comments on commit de41086

Please sign in to comment.