-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35d7a83
commit d2f4a81
Showing
8 changed files
with
166 additions
and
12 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Xml; | ||
using System.Xml.Linq; | ||
using Microsoft.OData.Edm; | ||
using Microsoft.OData.Edm.Csdl; | ||
using Microsoft.OpenApi; | ||
using Microsoft.OpenApi.Extensions; | ||
using Microsoft.OpenApi.OData; | ||
|
||
namespace EdmxTools; | ||
|
||
public static class OpenApiHelper | ||
{ | ||
public static string Convert(string xml, OpenApiFormat openApiFormat) | ||
{ | ||
var settings = new OpenApiConvertSettings | ||
{ | ||
OpenApiSpecVersion = OpenApiSpecVersion.OpenApi3_0 | ||
}; | ||
return Generate(xml, openApiFormat, settings); | ||
} | ||
private static string Generate(string input, OpenApiFormat format, OpenApiConvertSettings settings) | ||
{ | ||
var edmModel = GetEdmModel(input); | ||
var document = edmModel.ConvertToOpenApi(settings); | ||
return document.Serialize(settings.OpenApiSpecVersion, format); | ||
} | ||
private static IEdmModel GetEdmModel(string input) | ||
{ | ||
var parsed = XElement.Parse(input); | ||
using XmlReader mainReader = parsed.CreateReader(); | ||
return CsdlReader.Parse(mainReader, u => | ||
{ | ||
var referenceParsed = XElement.Parse(input); | ||
var referenceReader = referenceParsed.CreateReader(); | ||
return referenceReader; | ||
}); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,93 @@ | ||
@page "/convert" | ||
@inject NavigationManager NavManager | ||
@inject TooltipService tooltipService | ||
@inject IJSRuntime JSRuntime | ||
|
||
@inject NotificationService NotificationService | ||
|
||
Coming soon.. | ||
<PageTitle>Convert Edmx to @ConvertType</PageTitle> | ||
<RadzenText TextStyle="TextStyle.H4">Convert To @ConvertType</RadzenText> | ||
<Upload @bind-XmlData=XmlData /> | ||
<RadzenButton Click="@HandleConvert" Variant="Variant.Filled" ButtonStyle="ButtonStyle.Primary" | ||
ButtonType="ButtonType.Button" | ||
MouseEnter="@(args => ShowTooltip(args,"Convert Edmx", new TooltipOptions(){ Position = TooltipPosition.Bottom }))"> | ||
Convert To @ConvertType</RadzenButton> | ||
<RadzenButton Click="@HandleDownload" Variant="Variant.Filled" Icon="file_download" ButtonStyle="ButtonStyle.Primary" | ||
ButtonType="ButtonType.Button" Disabled="@DownloadDisabled" Text="Download" | ||
MouseEnter="@(args => ShowTooltip(args,"Download The Converted Edmx", new TooltipOptions(){ Position = TooltipPosition.Bottom }))" /> | ||
@code { | ||
private string convertedValue = string.Empty; | ||
public string XmlData { get; set; } | ||
bool DownloadDisabled => string.IsNullOrEmpty(convertedValue); | ||
private string ConvertType | ||
{ | ||
get | ||
{ | ||
if (type == "open-api-yml") | ||
{ | ||
return "Open Api YML"; | ||
} | ||
else if (type == "open-api-json") | ||
{ | ||
return "Open Api JSON"; | ||
} | ||
return string.Empty; | ||
} | ||
} | ||
private string type = string.Empty; | ||
protected override void OnInitialized() | ||
{ | ||
NavManager.LocationChanged += OnLocationChanged; | ||
} | ||
protected override void OnParametersSet() | ||
{ | ||
SetType(); | ||
StateHasChanged(); | ||
} | ||
private void SetType() | ||
{ | ||
var uri = NavManager.ToAbsoluteUri(NavManager.Uri); | ||
|
||
var foundQueryParameter = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(uri.Query).TryGetValue("type", out | ||
var tempConverType); | ||
if (foundQueryParameter) | ||
{ | ||
type = tempConverType; | ||
} | ||
} | ||
private void OnLocationChanged(object sender, LocationChangedEventArgs e) | ||
{ | ||
SetType(); | ||
StateHasChanged(); | ||
convertedValue = string.Empty; | ||
} | ||
async Task HandleDownload() | ||
{ | ||
var fileName = type; ; | ||
if (type == "open-api-yml") | ||
{ | ||
fileName += ".yml"; | ||
} | ||
else if (type == "open-api-json") | ||
{ | ||
fileName += ".json"; | ||
} | ||
var byteArray = System.Text.Encoding.ASCII.GetBytes(convertedValue); | ||
var stream = new MemoryStream(byteArray); | ||
|
||
using var streamRef = new DotNetStreamReference(stream: stream); | ||
|
||
await JSRuntime.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef); | ||
} | ||
void HandleConvert() | ||
{ | ||
if (type == "open-api-yml") | ||
{ | ||
convertedValue = OpenApiHelper.Convert(XmlData, Microsoft.OpenApi.OpenApiFormat.Yaml); | ||
} | ||
else if (type == "open-api-json") | ||
{ | ||
convertedValue = OpenApiHelper.Convert(XmlData, Microsoft.OpenApi.OpenApiFormat.Json); | ||
} | ||
} | ||
void ShowTooltip(ElementReference elementReference, string content, TooltipOptions options = null) => | ||
tooltipService.Open(elementReference, content, options); | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
google.com, pub-2889277787752693, DIRECT, f08c47fec0942fa0 |
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