Skip to content

Commit

Permalink
Added conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
manishtiwari25 committed Jan 9, 2024
1 parent 35d7a83 commit d2f4a81
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/EdmxTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer"
Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="8.0.1" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.5.0" />
<PackageReference Include="Radzen.Blazor" Version="4.23.7" />
</ItemGroup>
</Project>
38 changes: 38 additions & 0 deletions src/Helpers/OpenApiHelper.cs
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;
});
}
}
17 changes: 11 additions & 6 deletions src/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@inherits LayoutComponentBase
@inject IJSRuntime JSRuntime
@inject NavigationManager _nav

@inject TooltipService tooltipService
<RadzenComponents />
<RadzenLayout>
<RadzenHeader>
Expand Down Expand Up @@ -48,10 +48,14 @@
ShowArrow="false">
<RadzenPanelMenuItem Text="Home" Icon="home" Path="/" />
<RadzenPanelMenuItem Text="Tools" Icon="build" Expanded="true">
<RadzenPanelMenuItem Text="Trim" Path="trim" Icon="content_cut" />
<RadzenPanelMenuItem Text="Explore" Path="explore" Icon="explore" />
<RadzenPanelMenuItem Text="OpenApi - JSON" Path="convert?type=open-api-json" Icon="sync" />
<RadzenPanelMenuItem Text="OpenApi - YML" Path="convert?type=open-api-yml" Icon="sync" />
<RadzenPanelMenuItem Text="Trim" Path="trim" Icon="content_cut"
MouseEnter="@(args => ShowTooltip(args,"Trim Edmx", new TooltipOptions(){ Position = TooltipPosition.Right }))" />
<RadzenPanelMenuItem Text="Explore" Path="explore" Icon="explore"
MouseEnter="@(args => ShowTooltip(args,"Explore Edmx", new TooltipOptions(){ Position = TooltipPosition.Right }))" />
<RadzenPanelMenuItem Text="OpenApi - JSON" Path="convert?type=open-api-json" Icon="settings"
MouseEnter="@(args => ShowTooltip(args,"Edmx to Open Api JSON", new TooltipOptions(){ Position = TooltipPosition.Right }))" />
<RadzenPanelMenuItem Text="OpenApi - YML" Path="convert?type=open-api-yml" Icon="settings"
MouseEnter="@(args => ShowTooltip(args,"Edmx to Open Api YML", new TooltipOptions(){ Position = TooltipPosition.Right }))" />
</RadzenPanelMenuItem>
</RadzenPanelMenu>
</RadzenSidebar>
Expand Down Expand Up @@ -82,7 +86,8 @@
@code {
bool sidebarExpanded = false;
string modeIcon = "dark_mode";

void ShowTooltip(ElementReference elementReference, string content, TooltipOptions options = null) =>
tooltipService.Open(elementReference, content, options);
async Task ToggleMode()
{
if (modeIcon == "light_mode")
Expand Down
91 changes: 88 additions & 3 deletions src/Pages/Convert.razor
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);
}
3 changes: 2 additions & 1 deletion src/Pages/Upload.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<RadzenText TextStyle="TextStyle.H6" Text="Upload Edmx File" />
<InputFile OnChange="@SingleUpload" />
</RadzenCard>

<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid"
data-ad-client="ca-pub-2889277787752693" data-ad-slot="2242644635"></ins>

@code {
[Parameter]
Expand Down
1 change: 1 addition & 0 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddScoped<DialogService>();
builder.Services.AddScoped<TooltipService>();
builder.Services.AddScoped<NotificationService>();
builder.Services.AddRadzenComponents();
await builder.Build().RunAsync();
1 change: 1 addition & 0 deletions src/wwwroot/ads.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
google.com, pub-2889277787752693, DIRECT, f08c47fec0942fa0
22 changes: 22 additions & 0 deletions src/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
</head>

<body>
<amp-ad width="100vw" height="320"
type="adsense"
data-ad-client="ca-pub-2889277787752693"
data-ad-slot="9551132288"
data-auto-format="rspv"
data-full-width="">
<div overflow=""></div>
</amp-ad>
<div id="app" style="margin: 0 auto; width: 100vw; height: 100vh">
<div class="text-center pt-3" style="color: purple; font-size: 16pt">
Loading...
Expand Down Expand Up @@ -69,6 +77,20 @@
</script>
<script src="_framework/blazor.webassembly.js"></script>
<script src="_content/Radzen.Blazor/Radzen.Blazor.js"></script>
<script async custom-element="amp-ad" src="https://cdn.ampproject.org/v0/amp-ad-0.1.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-F9EC1KWJNY"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());

gtag('config', 'G-F9EC1KWJNY');
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2889277787752693"
crossorigin="anonymous"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</body>

</html>

0 comments on commit d2f4a81

Please sign in to comment.