Skip to content

Commit cee09ae

Browse files
authored
Merge pull request #222 from pticostaricags/development
merge "development" into "main"
2 parents cfb712b + a1990de commit cee09ae

File tree

2,069 files changed

+13499
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,069 files changed

+13499
-37
lines changed

src/FairPlayCombinedSln/FairPlayCombined.Interfaces/FairPlayTube/IVideoInfoService.cs

+3
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@ Task<PaginationOfT<VideoInfoModel>> GetPaginatedCompletedVideoInfoAsync(
3030
Task<VideoInfoModel?> GetVideoInfoByVideoIdAsync(string videoId,
3131
CancellationToken cancellationToken);
3232
Task DeleteMyVideoAsync(long videoInfoId, CancellationToken cancellationToken);
33+
Task<PaginationOfT<VideoInfoModel>> GetSmallPaginatedCompletedVideoInfoAsync(
34+
PaginationRequest paginationRequest, string? searchTerm,
35+
CancellationToken cancellationToken);
3336
}
3437
}

src/FairPlayCombinedSln/FairPlayCombined.Services/FairPlayTube/VideoInfoService.cs

+46
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,52 @@ public async Task<PaginationOfT<VideoInfoModel>> GetPaginatedCompletedVideoInfob
187187
return result;
188188
}
189189

190+
public async Task<PaginationOfT<VideoInfoModel>> GetSmallPaginatedCompletedVideoInfoAsync(
191+
PaginationRequest paginationRequest, string? searchTerm,
192+
CancellationToken cancellationToken
193+
)
194+
{
195+
PaginationOfT<VideoInfoModel> result = new();
196+
var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
197+
string orderByString = string.Empty;
198+
if (paginationRequest.SortingItems?.Length > 0)
199+
orderByString =
200+
String.Join(",",
201+
paginationRequest.SortingItems.Select(p => $"{p.PropertyName} {GetSortTypeString(p.SortType)}"));
202+
var preQuery = dbContext.VideoInfo
203+
.AsNoTracking()
204+
.AsSplitQuery();
205+
if (!String.IsNullOrWhiteSpace(searchTerm))
206+
{
207+
preQuery =
208+
preQuery.Where(p => EF.Functions.FreeText(p.Description, searchTerm!));
209+
}
210+
var query = preQuery
211+
.Where(p =>
212+
p.VideoIndexStatusId == (short)FairPlayCombined.Common.FairPlayTube.Enums.VideoIndexStatus.Processed)
213+
.Select(p => new VideoInfoModel
214+
{
215+
VideoInfoId = p.VideoInfoId,
216+
VideoId = p.VideoId,
217+
Name = p.Name,
218+
Description = p.Description,
219+
LifetimeViewers = p.VideoWatchTime.Select(p => p.WatchedByApplicationUserId).Distinct().Count(),
220+
LifetimeSessions = p.VideoWatchTime.Count,
221+
LifetimeWatchTime = TimeSpan.FromSeconds(p.VideoWatchTime.Sum(p => p.WatchTime)),
222+
PublishedOnString = (DateTimeOffset.UtcNow.Subtract(p.RowCreationDateTime).TotalDays < 1 ? "Today" : $"{DateTimeOffset.UtcNow.Subtract(p.RowCreationDateTime).Days} {localizer![DaysAgoTextKey]}")
223+
});
224+
if (!String.IsNullOrEmpty(orderByString))
225+
query = query.OrderBy(orderByString);
226+
result.TotalItems = await query.CountAsync(cancellationToken);
227+
result.PageSize = paginationRequest.PageSize;
228+
result.TotalPages = (int)Math.Ceiling((decimal)result.TotalItems / result.PageSize);
229+
result.Items = await query
230+
.Skip(paginationRequest.StartIndex)
231+
.Take(paginationRequest.PageSize)
232+
.ToArrayAsync(cancellationToken);
233+
return result;
234+
}
235+
190236
public async Task<PaginationOfT<VideoInfoModel>> GetPaginatedCompletedVideoInfoAsync(
191237
PaginationRequest paginationRequest, string? searchTerm,
192238
CancellationToken cancellationToken

src/FairPlayCombinedSln/FairPlayTube.ClientServices/CustomLocalization/ApiLocalizer.cs

+27-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using Microsoft.Extensions.Caching.Memory;
44
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.Localization;
6+
using System.Diagnostics;
7+
using System.Globalization;
68

79
namespace FairPlayTube.ClientServices.CustomLocalization
810
{
@@ -11,6 +13,7 @@ public class ApiLocalizer(
1113
KiotaClient.ApiClient anonymousClient,
1214
IMemoryCache memoryCache) : IStringLocalizer
1315
{
16+
private readonly Lock _lock = new();
1417
public LocalizedString this[string name]
1518
{
1619
get
@@ -32,13 +35,14 @@ public LocalizedString this[string name]
3235

3336
public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures)
3437
{
35-
var response = memoryCache.GetOrCreate(
36-
$"{nameof(ApiLocalizer)}.{GetAllStrings}", (entry) =>
38+
string cacheKey = $"{nameof(GetAllStrings)} -{CultureInfo.CurrentCulture.Name}";
39+
var response = memoryCache.GetOrCreateAsync(
40+
cacheKey, (entry) =>
3741
{
3842
entry.SlidingExpiration = Constants.CacheConfiguration.LocalizationCacheDuration;
3943
var response = anonymousClient.Localization.GetAllResources.GetAsync().Result;
40-
return response!;
41-
});
44+
return Task.FromResult(response);
45+
}).Result;
4246
var result = response!.Select(p =>
4347
new LocalizedString(p.Key!, p.Value!))
4448
.ToArray();
@@ -47,8 +51,25 @@ public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures)
4751

4852
private string GetString(string name)
4953
{
50-
var allStrings = GetAllStrings(false);
51-
return allStrings.SingleOrDefault(p => p.Name == name)?.Name ?? name;
54+
try
55+
{
56+
using (this._lock.EnterScope())
57+
{
58+
var cacheKey = $"{name}-{CultureInfo.CurrentCulture.Name}";
59+
var result = memoryCache.GetOrCreate(cacheKey, cacheEntry =>
60+
{
61+
cacheEntry.SlidingExpiration = Constants.CacheConfiguration.LocalizationCacheDuration;
62+
var data = this.GetAllStrings().SingleOrDefault(p => p.Name == name)?.Name;
63+
return data ?? name;
64+
});
65+
return result!;
66+
}
67+
}
68+
catch (Exception ex)
69+
{
70+
Debug.WriteLine(ex);
71+
return name;
72+
}
5273
}
5374
}
5475
}

src/FairPlayCombinedSln/FairPlayTube.ClientServices/CustomLocalization/ApiLocalizerOfT.cs

+31-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using Microsoft.Extensions.Caching.Memory;
44
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.Localization;
6+
using System.Diagnostics;
7+
using System.Globalization;
68
using System.Reflection;
79

810
namespace FairPlayTube.ClientServices.CustomLocalization
@@ -13,6 +15,7 @@ public class ApiLocalizer<T>(
1315
IMemoryCache memoryCache
1416
) : IStringLocalizer<T>
1517
{
18+
private readonly Lock _lock=new();
1619
public LocalizedString this[string name]
1720
{
1821
get
@@ -34,22 +37,44 @@ public LocalizedString this[string name]
3437

3538
public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures)
3639
{
37-
var response = memoryCache.GetOrCreate(
38-
$"{nameof(ApiLocalizer<T>)}.{GetAllStrings}", (entry) =>
40+
var typeFullName = typeof(T).FullName;
41+
var cacheKey = $"{typeFullName}-{nameof(GetAllStrings)}-{CultureInfo.CurrentCulture.Name}";
42+
var response = memoryCache.GetOrCreateAsync(
43+
cacheKey, (entry) =>
3944
{
4045
entry.SlidingExpiration = Constants.CacheConfiguration.LocalizationCacheDuration;
4146
var response = anonymousClient.Localization.GetAllResources.GetAsync().Result;
42-
return response!;
43-
});
44-
var result = response!.Select(p =>
47+
return Task.FromResult(response);
48+
}).Result;
49+
var typeName = typeof(T).FullName;
50+
var result = response!.Where(p=>p.Type == typeName).Select(p =>
4551
new LocalizedString(p.Key!, p.Value!))
4652
.ToArray();
4753
return result;
4854
}
4955

5056
private string GetString(string name)
5157
{
52-
return name;
58+
try
59+
{
60+
using (this._lock.EnterScope())
61+
{
62+
var typeFullName = typeof(T).FullName;
63+
var cacheKey = $"{typeFullName}-{nameof(GetString)}-{name}-{CultureInfo.CurrentCulture.Name}";
64+
var result = memoryCache!.GetOrCreate(cacheKey, (cacheEntry) =>
65+
{
66+
cacheEntry.SlidingExpiration = Constants.CacheConfiguration.LocalizationCacheDuration;
67+
var data = this.GetAllStrings().FirstOrDefault(p => p.Name == name)?.Value;
68+
return data ?? name;
69+
});
70+
return result!;
71+
}
72+
}
73+
catch (Exception ex)
74+
{
75+
Debug.WriteLine(ex);
76+
return name;
77+
}
5378
}
5479
}
5580
}

src/FairPlayCombinedSln/FairPlayTube.ClientServices/CustomLocalization/LocalizationMessageHandler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ protected override HttpResponseMessage Send(HttpRequestMessage request, Cancella
1717
return base.Send(request, cancellationToken);
1818
}
1919

20-
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
20+
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2121
{
2222
var currentCulture = System.Globalization.CultureInfo.CurrentUICulture;
2323
request.Headers.AcceptLanguage.Clear();
2424
request.Headers.AcceptLanguage.Add(new StringWithQualityHeaderValue(currentCulture.Name));
25-
return await base.SendAsync(request, cancellationToken);
25+
return base.SendAsync(request, cancellationToken);
2626
}
2727
}
2828
}

src/FairPlayCombinedSln/FairPlayTube.ClientServices/FairPlayTube.ClientServices.csproj

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
<ItemGroup>
1818
<PackageReference Include="Azure.Identity" Version="1.13.1" />
19-
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.14.0" />
20-
<PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.14.0" />
21-
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.14.0" />
22-
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.14.0" />
23-
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.14.0" />
24-
<PackageReference Include="Microsoft.Kiota.Serialization.Multipart" Version="1.14.0" />
25-
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.14.0" />
19+
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.15.0" />
20+
<PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.15.0" />
21+
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.15.0" />
22+
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.15.0" />
23+
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.15.0" />
24+
<PackageReference Include="Microsoft.Kiota.Serialization.Multipart" Version="1.15.0" />
25+
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.15.0" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

src/FairPlayCombinedSln/FairPlayTube.MAUI/FairPlayTube.MAUI.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="9.0.0" />
5656
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="9.0.0" />
5757
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
58-
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.10.3" />
58+
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.10.4" />
5959
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Emoji" Version="4.6.0" />
60-
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.10.3" />
60+
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.10.4" />
6161
</ItemGroup>
6262
<ItemGroup>
6363
<ProjectReference Include="..\FairPlayTube.ClientServices\FairPlayTube.ClientServices.csproj" />

src/FairPlayCombinedSln/FairPlayTube.MAUI/MauiProgram.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,36 @@ public static MauiApp CreateMauiApp()
4747
builder.Services.AddOptions();
4848
builder.Services.TryAddScoped<AuthenticationStateProvider, CustomAuthenticationStateProvider>();
4949
builder.Services.AddAuthorizationCore();
50+
builder.Services.AddHttpClient("DefaultHttpClient", client =>
51+
{
52+
client.BaseAddress = new Uri(apiBaseUrl);
53+
}).AddHttpMessageHandler<LocalizationMessageHandler>(); ;
54+
builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("DefaultHttpClient"));
5055
builder.Services.AddScoped<LocalizationMessageHandler>();
5156
builder.Services.AddSingleton<IAccessTokenProvider, CustomAccessTokenAuthenticationProvider>();
5257
builder.Services.AddKeyedSingleton<ApiClient>("AnonymousApiClient",
5358
(sp, key) =>
5459
{
60+
var httpClientFactory = sp.GetRequiredService<IHttpClientFactory>();
61+
var httpClient = httpClientFactory.CreateClient("DefaultHttpClient");
5562
AnonymousAuthenticationProvider anonymousAuthenticationProvider = new();
56-
HttpClientRequestAdapter httpClientRequestAdapter = new(anonymousAuthenticationProvider);
63+
HttpClientRequestAdapter httpClientRequestAdapter = new(anonymousAuthenticationProvider,
64+
httpClient: httpClient);
5765
httpClientRequestAdapter.BaseUrl = apiBaseUrl;
5866
ApiClient apiClient = new(httpClientRequestAdapter);
5967
return apiClient;
6068
});
6169
builder.Services.AddKeyedSingleton<ApiClient>("AuthenticatedApiClient",
6270
(sp, key) =>
6371
{
72+
var httpClientFactory = sp.GetRequiredService<IHttpClientFactory>();
73+
var httpClient = httpClientFactory.CreateClient("DefaultHttpClient");
6474
var accesstokenProvider = sp.GetRequiredService<IAccessTokenProvider>();
6575
BaseBearerTokenAuthenticationProvider baseBearerTokenAuthenticationProvider =
6676
new(accesstokenProvider);
6777
HttpClientRequestAdapter httpClientRequestAdapter =
68-
new(baseBearerTokenAuthenticationProvider);
78+
new(baseBearerTokenAuthenticationProvider,
79+
httpClient: httpClient);
6980
httpClientRequestAdapter.BaseUrl = apiBaseUrl;
7081
ApiClient apiClient = new(httpClientRequestAdapter);
7182
return apiClient;
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)