Skip to content

Commit

Permalink
Merge pull request #23 from Ali-YousefiTelori/develop
Browse files Browse the repository at this point in the history
ResolveContentAllLanguage
  • Loading branch information
Ali-YousefiTelori authored Sep 27, 2023
2 parents 00af265 + 41a823c commit ecfb580
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async Task OnInitialize()
[Fact]
public async Task GetAllTestTest()

Check warning on line 46 in src/CSharp/EasyMicroservices.ContentsMicroservice.Clients.Tests/MicroserviceClientTest.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 46 in src/CSharp/EasyMicroservices.ContentsMicroservice.Clients.Tests/MicroserviceClientTest.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 46 in src/CSharp/EasyMicroservices.ContentsMicroservice.Clients.Tests/MicroserviceClientTest.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 46 in src/CSharp/EasyMicroservices.ContentsMicroservice.Clients.Tests/MicroserviceClientTest.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 46 in src/CSharp/EasyMicroservices.ContentsMicroservice.Clients.Tests/MicroserviceClientTest.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 46 in src/CSharp/EasyMicroservices.ContentsMicroservice.Clients.Tests/MicroserviceClientTest.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 46 in src/CSharp/EasyMicroservices.ContentsMicroservice.Clients.Tests/MicroserviceClientTest.cs

View workflow job for this annotation

GitHub Actions / build-test-prep-push

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 46 in src/CSharp/EasyMicroservices.ContentsMicroservice.Clients.Tests/MicroserviceClientTest.cs

View workflow job for this annotation

GitHub Actions / build-test-prep-push

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var instance = Activator.CreateInstance(typeof(List<string>));
//await OnInitialize();
//var microserviceClient = new Contents.GeneratedServices.MicroserviceClient(_routeAddress, HttpClient);
//var microservices = await microserviceClient.GetAllAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.12</Version>
<Version>0.0.0.13</Version>
<Description>client generated code.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>microservice,Content,Contents,client</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,54 @@ string GetUniqueIdentity(object contract)
return uniqueIdentity.GetValue(contract) as string;
}

/// <summary>
///
/// </summary>
/// <param name="contract"></param>
/// <returns></returns>
public async Task ResolveContentAllLanguage(object contract)
{
if (contract == null)
return;
string uniqueRecordId = default;

var uidProperty = contract.GetType().GetProperty("UniqueRecordId", BindingFlags.Instance | BindingFlags.Public);
if (uidProperty != null)
uniqueRecordId = uidProperty.GetValue(contract) as string;
foreach (var property in contract.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
{
if (property.GetCustomAttribute<ContentLanguageAttribute>() != null)
{
var instance = Activator.CreateInstance(property.PropertyType);
if (instance is IList list)
{
var genericType = property.PropertyType.GetGenericArguments()[0];
var contents = await _contentClient.GetAllByKeyAsync(new GetAllByKeyRequestContract
{
Key = $"{uniqueRecordId}-{property.Name}"
});
if (contents.IsSuccess)
{
foreach (var item in contents.Result)
{
var itemInstance = Activator.CreateInstance(genericType);
var languageProperty = itemInstance.GetType().GetProperty(nameof(LanguageDataContract.Language), BindingFlags.Public | BindingFlags.Instance);
if (languageProperty == null)
throw new Exception($"Property {nameof(LanguageDataContract.Language)} not found in type {itemInstance.GetType()}");
var dataProperty = itemInstance.GetType().GetProperty(nameof(LanguageDataContract.Data), BindingFlags.Public | BindingFlags.Instance);
if (dataProperty == null)
throw new Exception($"Property {nameof(LanguageDataContract.Data)} not found in type {itemInstance.GetType()}");
languageProperty.SetValue(itemInstance, item.Language.Name);
dataProperty.SetValue(itemInstance, item.Data);
list.Add(itemInstance);
}
}
}
property.SetValue(contract, instance);
}
}
}

/// <summary>
///
/// </summary>
Expand Down

0 comments on commit ecfb580

Please sign in to comment.