Skip to content

Commit a2a73c6

Browse files
committed
Merge branch 'gateway'
2 parents 1d40e3b + 218657a commit a2a73c6

File tree

8 files changed

+44
-49
lines changed

8 files changed

+44
-49
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ permissions: write-all
1212
jobs:
1313
build-windows:
1414
runs-on: windows-2022
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-build
18+
cancel-in-progress: true
19+
1520
steps:
1621
- uses: actions/checkout@v2
1722

@@ -33,11 +38,11 @@ jobs:
3338
echo ("BUILD_VERSION=$v") >> $env:GITHUB_ENV
3439
echo $v
3540
36-
- uses: actions/cache@v2
41+
- uses: actions/cache@v4
3742
id: cache
3843
with:
3944
path: packages
40-
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
45+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
4146
restore-keys: |
4247
${{ runner.os }}-nuget-
4348

Snittlistan.Queue/LoggingHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public class LoggingHandler : DelegatingHandler
99
{
1010
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
1111

12-
public LoggingHandler(HttpMessageHandler innerHandler)
13-
: base(innerHandler)
12+
public LoggingHandler()
13+
: base(new HttpClientHandler())
1414
{
1515
}
1616

Snittlistan.Queue/TaskQueueListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Snittlistan.Queue;
77

88
public class TaskQueueListener : MessageQueueListenerBase
99
{
10-
private readonly HttpClient client = new(new LoggingHandler(new HttpClientHandler()))
10+
private readonly HttpClient client = new(new LoggingHandler())
1111
{
1212
Timeout = TimeSpan.FromSeconds(600)
1313
};

Snittlistan.Test/BitsGateway.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ namespace Snittlistan.Test;
1313
public static class BitsGateway
1414
{
1515
private static readonly IBitsClient Client = new BitsClient(
16-
Environment.GetEnvironmentVariable("ApiKey"),
17-
new HttpClient(),
16+
new HttpClient()
17+
{
18+
BaseAddress = new Uri(Environment.GetEnvironmentVariable("GatewayUrl"))
19+
},
1820
MemoryCache.Default);
1921

2022
public static async Task<HeadInfo> GetHeadInfo(int matchId)

Snittlistan.Tool/Tasks/CommandLineTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Snittlistan.Tool.Tasks;
88

99
public abstract class CommandLineTask : ICommandLineTask
1010
{
11-
private readonly HttpClient client = new(new LoggingHandler(new HttpClientHandler()))
11+
private readonly HttpClient client = new(new LoggingHandler())
1212
{
1313
Timeout = TimeSpan.FromSeconds(600)
1414
};

Snittlistan.Web/Global.asax.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,15 @@ protected void Application_BeginRequest()
111111
{
112112
Response.Clear();
113113
Response.Status = "301 Moved Permanently";
114-
Response.AddHeader("Location", Context.Request.Url.ToString().Insert(4, "s"));
114+
try
115+
{
116+
Response.AddHeader("Location", Context.Request.Url.ToString().Insert(4, "s"));
117+
}
118+
catch (Exception ex)
119+
{
120+
throw new Exception($"Failed to redirect to {Context.Request.Url}", ex);
121+
}
122+
115123
Response.End();
116124
}
117125
}
@@ -233,17 +241,19 @@ private static void InitializeContainer(
233241
}
234242

235243
Container.Kernel.AddHandlerSelector(new HostBasedComponentSelector());
236-
string apiKey = Environment.GetEnvironmentVariable("ApiKey");
237-
Log.Info($"ApiKey: {apiKey}");
244+
string gatewayUrl = Environment.GetEnvironmentVariable("GatewayUrl");
245+
Log.Info($"gatewayUrl: {gatewayUrl}");
238246
HttpClient httpClient = new(
239247
new RateHandler(rate: 1.0, per: 1.0, maxTries: 60,
240-
new LoggingHandler(
241-
new HttpClientHandler())));
248+
new LoggingHandler()))
249+
{
250+
BaseAddress = new Uri(gatewayUrl)
251+
};
242252
_ = Container
243253
.AddFacility<LoggingFacility>(f => f.LogUsing<NLogFactory>())
244254
.Install(
245255
new ApiControllerInstaller(),
246-
new BitsClientInstaller(apiKey, httpClient),
256+
new BitsClientInstaller(httpClient),
247257
CommandHandlerInstaller.PerWebRequest(),
248258
new ControllerInstaller(),
249259
new DatabaseContextInstaller(databasesFactory),

Snittlistan.Web/Infrastructure/Bits/BitsClient.cs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,49 @@
99

1010
namespace Snittlistan.Web.Infrastructure.Bits;
1111

12-
public class BitsClient : IBitsClient
12+
public class BitsClient(HttpClient client, MemoryCache memoryCache) : IBitsClient
1313
{
14-
private readonly string apiKey;
15-
private readonly HttpClient client;
16-
private readonly MemoryCache memoryCache;
17-
18-
public BitsClient(string apiKey, HttpClient client, MemoryCache memoryCache)
19-
{
20-
this.apiKey = apiKey;
21-
this.client = client;
22-
this.memoryCache = memoryCache;
23-
}
24-
2514
public ILogger Logger { get; set; } = NullLogger.Instance;
2615

2716
public async Task<HeadInfo> GetHeadInfo(int matchId)
2817
{
29-
HeadInfo result = await Get<HeadInfo>($"https://api.swebowl.se/api/v1/matchResult/GetHeadInfo?APIKey={apiKey}&id={matchId}");
18+
HeadInfo result = await Get<HeadInfo>($"/api/v1/matchResult/GetHeadInfo?id={matchId}");
3019
return result;
3120
}
3221

3322
public async Task<HeadResultInfo> GetHeadResultInfo(int matchId)
3423
{
35-
HeadResultInfo result = await Get<HeadResultInfo>($"https://api.swebowl.se/api/v1/matchResult/GetHeadResultInfo?APIKey={apiKey}&id={matchId}");
24+
HeadResultInfo result = await Get<HeadResultInfo>($"/api/v1/matchResult/GetHeadResultInfo?id={matchId}");
3625
return result;
3726
}
3827

3928
public async Task<MatchResults> GetMatchResults(int matchId)
4029
{
41-
MatchResults result = await Get<MatchResults>($"https://api.swebowl.se/api/v1/matchResult/GetMatchResults?APIKey={apiKey}&matchId={matchId}&matchSchemeId=8M8BA");
30+
MatchResults result = await Get<MatchResults>($"/api/v1/matchResult/GetMatchResults?matchId={matchId}&matchSchemeId=8M8BA");
4231
return result;
4332
}
4433

4534
public async Task<MatchScores> GetMatchScores(int matchId)
4635
{
47-
MatchScores result = await Get<MatchScores>($"https://api.swebowl.se/api/v1/matchResult/GetMatchScores?APIKey={apiKey}&matchId={matchId}&matchSchemeId=8M8BA");
36+
MatchScores result = await Get<MatchScores>($"/api/v1/matchResult/GetMatchScores?matchId={matchId}&matchSchemeId=8M8BA");
4837
return result;
4938
}
5039

5140
public async Task<TeamResult[]> GetTeam(int clubId, int seasonId)
5241
{
53-
TeamResult[] result = await Get<TeamResult[]>($"https://api.swebowl.se/api/v1/Team?APIKey={apiKey}&clubId={clubId}&seasonId={seasonId}");
42+
TeamResult[] result = await Get<TeamResult[]>($"/api/v1/Team?clubId={clubId}&seasonId={seasonId}");
5443
return result;
5544
}
5645

5746
public async Task<DivisionResult[]> GetDivisions(int teamId, int seasonId)
5847
{
59-
DivisionResult[] result = await Get<DivisionResult[]>($"https://api.swebowl.se/api/v1/Division?APIKey={apiKey}&teamId={teamId}&seasonId={seasonId}");
48+
DivisionResult[] result = await Get<DivisionResult[]>($"/api/v1/Division?teamId={teamId}&seasonId={seasonId}");
6049
return result;
6150
}
6251

6352
public async Task<MatchRound[]> GetMatchRounds(int teamId, int divisionId, int seasonId)
6453
{
65-
MatchRound[] result = await Get<MatchRound[]>($"https://api.swebowl.se/api/v1/Match/?APIKey={apiKey}&teamId={teamId}&divisionId={divisionId}&seasonId={seasonId}");
54+
MatchRound[] result = await Get<MatchRound[]>($"/api/v1/Match/?teamId={teamId}&divisionId={divisionId}&seasonId={seasonId}");
6655
return result;
6756
}
6857

@@ -79,7 +68,7 @@ public async Task<PlayerResult> GetPlayers(int clubId)
7968
pageSize = "250",
8069
sort = new object[0]
8170
},
82-
$"https://api.swebowl.se/api/v1/player/GetAll?APIKey={apiKey}");
71+
$"/api/v1/player/GetAll");
8372
return result;
8473
}
8574

@@ -163,7 +152,6 @@ private async Task<string> Request(HttpMethod method, string url, Action<HttpReq
163152
"Requesting {url}",
164153
url);
165154
HttpRequestMessage request = new(method, url);
166-
request.Headers.Referrer = new Uri("https://bits.swebowl.se");
167155
action.Invoke(request);
168156
HttpResponseMessage result = await client.SendAsync(request);
169157
string content = await result.EnsureSuccessStatusCode().Content.ReadAsStringAsync();

Snittlistan.Web/Infrastructure/Installers/BitsClientInstaller.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-

1+
#nullable enable
2+
23
using System.Net.Http;
34
using System.Runtime.Caching;
45
using Snittlistan.Web.Infrastructure.Bits;
56
using Castle.MicroKernel.Registration;
67
using Castle.MicroKernel.SubSystems.Configuration;
78
using Castle.Windsor;
89

9-
#nullable enable
10-
1110
namespace Snittlistan.Web.Infrastructure.Installers;
12-
public class BitsClientInstaller : IWindsorInstaller
13-
{
14-
private readonly string apiKey;
15-
private readonly HttpClient httpClient;
16-
17-
public BitsClientInstaller(string apiKey, HttpClient httpClient)
18-
{
19-
this.apiKey = apiKey;
20-
this.httpClient = httpClient;
21-
}
2211

12+
public class BitsClientInstaller(HttpClient httpClient) : IWindsorInstaller
13+
{
2314
public void Install(IWindsorContainer container, IConfigurationStore store)
2415
{
2516
BitsClient bitsClient = new(
26-
apiKey,
2717
httpClient,
2818
MemoryCache.Default);
2919
_ = container.Register(Component.For<IBitsClient>().Instance(bitsClient));

0 commit comments

Comments
 (0)