This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<CollectionResult<PackageDto>> GetPackages(PackageSearchQuery query) | |
{ | |
if (!IsSearchServiceConfigured()) | |
{ | |
return CollectionResult<PackageDto>.Empty(); | |
} | |
SearchClient searchClient = GetSearchClient(); | |
string searchText = GetSearchText(query); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<bool> AddOrUpdatePackage(PackageDto packageDto) | |
{ | |
if (!IsSearchServiceConfigured()) | |
{ | |
_logger.LogWarning($"Package with Id {packageDto.PackageId} failed to index with Azure search as the search service is not configured."); | |
return false; | |
} | |
SearchIndexClient indexClient = GetIndexClient(); | |
await CreateIndexIfNotExists(indexClient); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task CreateIndex(SearchIndexClient indexClient) | |
{ | |
var fieldBuilder = new FieldBuilder(); | |
IList<SearchField> searchFields = fieldBuilder.Build(typeof(PackageModel)); | |
var definition = new SearchIndex(_searchSettings.IndexName, searchFields); | |
// Add a scoring profile to boost text matches on more relevent fields. | |
const string DefaultScoringProfileName = "PackageSearch"; | |
var scoringProfile = new ScoringProfile(DefaultScoringProfileName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<bool> AddOrUpdatePackage(PackageDto packageDto) | |
{ | |
if (!IsSearchServiceConfigured()) | |
{ | |
_logger.LogWarning($"Package with Id {packageDto.PackageId} failed to index with Azure search as the search service is not configured."); | |
return false; | |
} | |
SearchIndexClient indexClient = GetIndexClient(); | |
await CreateIndexIfNotExists(indexClient); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PackageModel | |
{ | |
private const string DateFormat = "yyyy-MM-dd"; | |
public PackageModel() | |
{ | |
} | |
public PackageModel(Guid id) => Id = id.ToString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DistributedCacheExtensions | |
{ | |
public static async Task RemoveWithPrefixAsync(this IDistributedCache cache, string keyPrefix) | |
{ | |
if (cache is RedisCache redisCache) | |
{ | |
ConnectionMultiplexer connection = await redisCache.GetConnectionAsync(); | |
IDatabase db = connection.GetDatabase(); | |
foreach (EndPoint? endpoint in connection.GetEndPoints()) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DistributedCacheExtensions | |
{ | |
public static async Task<T?> GetAsync<T>(this IDistributedCache cache, string key) | |
{ | |
var val = await cache.GetAsync(key); | |
if (val == null || val.Length == 0) | |
{ | |
return default; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cacheKey = string.Format(ApplicationServices.Constants.DistributedCache.CacheKeyFormats.CategoryById, id); | |
CategoryDto? categoryDto = await _distributedCache.GetAsync<CategoryDto>(cacheKey); | |
if (categoryDto is not null) | |
{ | |
return categoryDto; | |
} | |
categoryDto = await _categoryService.GetCategoryById(id); | |
if (categoryDto is null) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
public Startup(IConfiguration configuration) => Configuration = configuration; | |
public IConfiguration Configuration { get; } | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
IConfigurationSection apiSettingsSection = Configuration.GetSection(Constants.ConfigurationKeys.ApiSettingsKeyName); | |
services.Configure<ApiSettings>(apiSettingsSection); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Mvc; | |
using Umbraco.Cms.Web.Common.Controllers; | |
using Umbraco.Forms.Core.Models; | |
using Umbraco.Forms.Core.Persistence.Dtos; | |
using Umbraco.Forms.Core.Services; | |
namespace Umbraco.Forms.Testsite.Controllers | |
{ | |
public class SubmitFormTestController : UmbracoApiController | |
{ |