Skip to content

Commit

Permalink
Merge pull request #278 from Flexberry/fix-232024-remove-designer-bugs
Browse files Browse the repository at this point in the history
Исправление ошибок метаданных
  • Loading branch information
Anisimova2020 committed Apr 21, 2023
2 parents 2a1b18c + 0486e30 commit da84a8b
Show file tree
Hide file tree
Showing 19 changed files with 280 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added

### Changed
1. Updated `NewPlatform.Flexberry.ORM` up to `7.1.1-beta01`.

### Fixed
1. Fixed problem with metadata when inheritance and PublishName is used.

## [7.1.0] - 2023.04.12

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.0" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.1-beta01" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NewPlatform.Flexberry.LockService" Version="3.0.0" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.0" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.1-beta01" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
7 changes: 5 additions & 2 deletions NewPlatform.Flexberry.ORM.ODataService.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>NewPlatform.Flexberry.ORM.ODataService</id>
<version>7.1.0</version>
<version>7.1.1-beta02</version>
<title>Flexberry ORM ODataService</title>
<authors>New Platform Ltd.</authors>
<owners>New Platform Ltd.</owners>
Expand All @@ -13,7 +13,10 @@
<description>Flexberry ORM OData Service Package.</description>
<releaseNotes>
Changed
1. Updated `NewPlatform.Flexberry.ORM` up to `7.1.0`.
1. Updated `NewPlatform.Flexberry.ORM` up to `7.1.1-beta01`.

Fixed
1. Fixed problem with metadata when inheritance and PublishName is used.
</releaseNotes>
<copyright>Copyright New Platform Ltd 2023</copyright>
<tags>Flexberry ORM OData ODataService</tags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private static string EdmName(this Type clrType)

private static string EdmFullName(this Type clrType)
{
return string.IsNullOrEmpty(clrType.Namespace) ? clrType.EdmName() : string.Format(CultureInfo.InvariantCulture, "{0}.{1}", clrType.Namespace, clrType.EdmName());
return string.Format(CultureInfo.InvariantCulture, "{0}.{1}", clrType.Namespace, clrType.EdmName());
}

private static IEdmPrimitiveType GetPrimitiveType(EdmPrimitiveTypeKind primitiveKind)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#if NETSTANDARD
namespace NewPlatform.Flexberry.ORM.ODataService.Extensions
{
using System;
using System;
using System.IO;
using System.Net.Mime;
using System.Threading.Tasks;
using Microsoft.AspNet.OData;
using Microsoft.AspNet.OData.Common;
using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using NewPlatform.Flexberry.ORM.ODataService.Middleware;

Expand All @@ -30,6 +34,11 @@ public static IApplicationBuilder UseODataService(this IApplicationBuilder app,

VerifyODataServiceIsRegistered(app);

app.Use(async (context, next) =>
{
await RewriteResponse(context, next);
});

return app
.UseODataBatching()
.UseMiddleware<RequestHeadersHookMiddleware>()
Expand All @@ -48,6 +57,59 @@ private static void VerifyODataServiceIsRegistered(IApplicationBuilder app)
throw Error.InvalidOperation(SRResources.MissingODataServices, nameof(IPerRouteContainer));
}
}

/// <summary>
/// Removing of extra symbols from response.
/// </summary>
/// <param name="context">Context of request.</param>
/// <param name="next">Next middleware.</param>
/// <returns>Formed task.</returns>
public static async Task RewriteResponse(HttpContext context, Func<Task> next)
{
/* Same code for NETFRAMEWORK is placed on NewPlatform.Flexberry.ORM.ODataService.Handlers.PostPatchHandler.*/
using (var responseBodyStream = new MemoryStream())
{
Stream bodyStream = context.Response.Body;

try
{
context.Response.Body = responseBodyStream;

await next();

responseBodyStream.Seek(0, SeekOrigin.Begin);
var responseBody = new StreamReader(responseBodyStream).ReadToEnd();

//Modify the response in some way.
if (context.Response.ContentType != null &&
(context.Response.ContentType.Contains("application/json")
|| context.Response.ContentType.Contains("application/xml")
|| context.Response.ContentType.Contains("multipart/mixed")))
{
responseBody = responseBody
.Replace("(____.", "(")
.Replace("\"____.", "\"")
.Replace("____.", ".")
.Replace(" Namespace=\"____\"", " Namespace=\"\"");
}

using (MemoryStream newStream = new MemoryStream())
{
using StreamWriter sw = new StreamWriter(newStream);
sw.Write(responseBody);
sw.Flush();

newStream.Seek(0, SeekOrigin.Begin);

await newStream.CopyToAsync(bodyStream);
}
}
finally
{
context.Response.Body = bodyStream;
}
}
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#if NETFRAMEWORK
namespace NewPlatform.Flexberry.ORM.ODataService.Handlers
{
{
using Microsoft.AspNet.OData.Batch;
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -33,8 +37,13 @@ public class PostPatchHandler : DelegatingHandler
public const string AcceptApplicationMsExcel = "PostPatchHandler_AcceptApplicationMsExcel";

/// <inheritdoc/>
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request == null)
{
throw new ArgumentNullException(nameof(request));
}

foreach (var val in request.Headers.Accept)
{
if (val.MediaType == "application/ms-excel")
Expand Down Expand Up @@ -62,9 +71,54 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques
/// Исправление для Mono, взято из https://github.com/OData/odata.net/issues/165
*/
if (!request.Headers.Contains("Accept-Charset"))
request.Headers.Add("Accept-Charset", new[] { "utf-8" });
request.Headers.Add("Accept-Charset", new[] { "utf-8" });

HttpResponseMessage responseMessage = await base.SendAsync(request, cancellationToken);
await RewriteResponse(responseMessage);
return responseMessage;

}

return base.SendAsync(request, cancellationToken);
/// <summary>
/// Удаление некорректных символов в именах типов метаданных.
/// Данные символы добавляются специально, чтобы MS не бросало исключение на пустой Namespace у типов с PublishName.
/// </summary>
/// <param name="response">Текущее ответное сообщение, в котором могут быть заменены символы.</param>
/// <returns>Задача на обработку.</returns>
private static async Task RewriteResponse(HttpResponseMessage response)
{
/* Same code for NETSTANDARD is placed on NewPlatform.Flexberry.ORM.ODataService.Extensions.ODataApplicationBuilderExtensions.*/
string contentType = response?.Content?.Headers?.ContentType?.MediaType;
if (!string.IsNullOrEmpty(contentType) &&
(contentType.Contains("application/json")
|| contentType.Contains("application/xml")
|| contentType.Contains("multipart/mixed")))
{
HttpContent content = response.Content;
Stream contentStream = await content.ReadAsStreamAsync();
string responseStr = new StreamReader(contentStream).ReadToEnd();
if (!string.IsNullOrEmpty(responseStr) && responseStr.Length > 3)
{
responseStr = responseStr
.Replace("(____.", "(")
.Replace("\"____.", "\"")
.Replace("____.", ".")
.Replace(" Namespace=\"____\"", " Namespace=\"\"");

using (MemoryStream newStream = new MemoryStream())
{
using StreamWriter sw = new StreamWriter(newStream);
sw.Write(responseStr);
sw.Flush();
newStream.Seek(0, SeekOrigin.Begin);

contentStream.Position = 0;
contentStream.SetLength(responseStr.Length);

await newStream.CopyToAsync(contentStream);
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ private void BuildTypeHierarchy()
else
_typeHierarchy[baseDataObjectType].Add(dataObjectType);

string nameSpace = GetEntityTypeNamespace(dataObjectType);
string typeName = GetEntityTypeName(dataObjectType);

var typeFullName = string.IsNullOrEmpty(nameSpace) ? typeName : $"{nameSpace}.{typeName}";
var typeFullName = $"{GetEntityTypeNamespace(dataObjectType)}.{GetEntityTypeName(dataObjectType)}";
if (!_aliasesNameToProperty.ContainsKey(typeFullName))
{
_aliasesNameToProperty.Add(typeFullName, new Dictionary<string, PropertyInfo>());
Expand Down Expand Up @@ -724,7 +721,7 @@ private string GetEntityTypeName(Type type)
var nameSpace = GetEntityTypeNamespace(type);
if (type != typeof(DataObject) && EdmModelBuilder != null && EdmModelBuilder.EntityTypeNameBuilder != null)
name = EdmModelBuilder.EntityTypeNameBuilder(type);
var fullname = string.IsNullOrEmpty(nameSpace) ? name : $"{nameSpace}.{name}";
var fullname = $"{nameSpace}.{name}";
if (!_aliasesNameToType.ContainsKey(fullname))
_aliasesNameToType.Add(fullname, type);
if (!_aliasesTypeToName.ContainsKey(type))
Expand Down Expand Up @@ -762,9 +759,7 @@ private string GetEntityPropertyName(PropertyInfo prop)
var name = prop.Name;
if (name != KeyPropertyName && prop.DeclaringType != typeof(DataObject) && EdmModelBuilder != null && EdmModelBuilder.EntityPropertyNameBuilder != null)
name = EdmModelBuilder.EntityPropertyNameBuilder(prop);
string nameSpace = GetEntityTypeNamespace(prop.DeclaringType);
string typeName = GetEntityTypeName(prop.DeclaringType);
string typeFullName = string.IsNullOrEmpty(nameSpace) ? typeName : $"{nameSpace}.{typeName}";
var typeFullName = $"{GetEntityTypeNamespace(prop.DeclaringType)}.{GetEntityTypeName(prop.DeclaringType)}";
if (!_aliasesNameToProperty.ContainsKey(typeFullName))
{
_aliasesNameToProperty.Add(typeFullName, new Dictionary<string, PropertyInfo>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ private string BuildEntitySetName(Type dataObjectType)

string typeName = BuildEntityTypeName(dataObjectType);
string nameSpace = BuildEntityTypeNamespace(dataObjectType);
return string.Concat((_useNamespaceInEntitySetName && !string.IsNullOrEmpty(nameSpace)) ? $"{nameSpace}.{typeName}".Replace(".", string.Empty) : typeName, "s"/* "Aliases"*/).Replace("_", string.Empty);
//return string.Concat(_useNamespaceInEntitySetName ? dataObjectType.FullName.Replace(".", string.Empty) : dataObjectType.Name, "s"/* "Aliases"*/).Replace("_", string.Empty);
return string.Concat(_useNamespaceInEntitySetName ? $"{nameSpace}.{typeName}".Replace(".", string.Empty) : typeName, "s").Replace("_", string.Empty);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NewPlatform.Flexberry.LockService" Version="3.0.0" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.0" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.1-beta01" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.0" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.1-beta01" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.0" />
<PackageReference Include="NewPlatform.Flexberry.ORM.MSSQLDataService" Version="7.1.0" />
<PackageReference Include="NewPlatform.Flexberry.ORM.OracleDataService" Version="7.1.0" />
<PackageReference Include="NewPlatform.Flexberry.ORM.PostgresDataService" Version="7.1.0" />
<PackageReference Include="NewPlatform.Flexberry.ORM" Version="7.1.1-beta01" />
<PackageReference Include="NewPlatform.Flexberry.ORM.MSSQLDataService" Version="7.1.1-beta01" />
<PackageReference Include="NewPlatform.Flexberry.ORM.OracleDataService" Version="7.1.1-beta01" />
<PackageReference Include="NewPlatform.Flexberry.ORM.PostgresDataService" Version="7.1.1-beta01" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit da84a8b

Please sign in to comment.