Skip to content

Commit e711e71

Browse files
committed
new release with map
1 parent 5d31ae0 commit e711e71

5 files changed

Lines changed: 89 additions & 49 deletions

File tree

README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
# What it does
1212
NETCore2Blockly generates [Blockly](https://developers.google.com/blockly) blocks for each of your controller actions.
1313

14-
*Demo* at https://netcoreblockly.herokuapp.com/ ( play with the links from the bottom)
14+
*Demo* at https://netcoreblockly.herokuapp.com/
1515

1616
*Demo* Video at https://www.youtube.com/watch?v=GptkNWjmCzk
1717

1818
Sample Project is TestBlocklyHtml from this repository
1919

2020
*Contributors welcome!* - please send email to <img src='email.png' height='10px' title = "please write email from image" alt='email'></img> or see issues tab.
2121

22-
# How to install NETCore2Blockly in a .NET Core 5 WebAPI / MVC application in 3 steps + run application
22+
# How to install NETCore2Blockly in a .NET Core 5 WebAPI / MVC application in 2 steps + run application
2323

2424
## Step 1:
2525
Install https://www.nuget.org/packages/NetCore2Blockly/ by running the following command in the Package Manager Console:
@@ -46,14 +46,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4646
app.UseStaticFiles();
4747
app.UseSwagger();
4848
app.UseBlocklyUI(env);
49-
app.UseSwaggerUI(c =>
50-
{
51-
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
52-
});
53-
app.UseRouting();
54-
55-
app.UseAuthorization();
56-
49+
//code
5750
app.UseEndpoints(endpoints =>
5851
{
5952
endpoints.MapControllers();
@@ -62,11 +55,27 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
6255
}
6356
```
6457

58+
# How to install NETCore2Blockly in a .NET Core 6 WebAPI / MVC application in 2 steps + run application
59+
60+
## Step 1:
61+
Install https://www.nuget.org/packages/NetCore2Blockly/ by running the following command in the Package Manager Console:
62+
> Install-Package NetCore2Blockly
63+
64+
## Step 2:
65+
```csharp
66+
67+
app.UseBlocklyUI(app.Environment);
68+
//after app.MapControllers();
69+
app.UseBlocklyAutomation();
70+
71+
```
72+
73+
6574
## Run application
6675

6776
Run the application from VS and browse to /BlocklyAutomation/ or /BlocklyAutomation/index.html
6877

69-
## That's all !( 3 steps + run )
78+
## That's all !( 2 steps + run )
7079

7180

7281
## Advanced usage remote data

src/NetCore2Blockly/NetCore2BlocklyNew/Extensions.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,55 @@
11
using Microsoft.AspNetCore.Builder;
22
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.AspNetCore.Http.Extensions;
34
using Microsoft.AspNetCore.Routing;
45
using Microsoft.Extensions.FileProviders;
56
using MimeTypes;
67
using System;
78
using System.IO;
9+
using System.Linq;
810
using System.Reflection;
11+
using System.Threading;
12+
using System.Threading.Tasks;
913

1014
namespace NetCore2BlocklyNew
1115
{
1216
public static class Extensions
1317
{
1418
public static IEndpointRouteBuilder UseBlocklyAutomation(this IEndpointRouteBuilder endpoints)
1519
{
16-
endpoints.MapFallbackToFile("BlocklyAutomation/{*:nonfilename}", "BlocklyAutomation/index.html");
20+
//endpoints.MapFallbackToFile("BlocklyAutomation/{**:nonfile}", "BlocklyAutomation/index.html");
21+
endpoints.Map("BlocklyAutomation/{**:nonfile}", async ctx =>
22+
{
23+
var dir = FileProvider.GetDirectoryContents("BlocklyAutomation").ToArray();
24+
var file = dir.Where(it => it?.Name?.ToLower() == "index.html").FirstOrDefault();
25+
var response = ctx.Response;
26+
response.ContentType = contentFromExtension(file.Name);
27+
//in net 6 use sendfileasync
28+
using (var fileContent = file.CreateReadStream())
29+
{
30+
await StreamCopyOperation.CopyToAsync(fileContent, response.Body,file.Length, CancellationToken.None);
31+
}
32+
});
1733
return endpoints;
1834
}
35+
public static IFileProvider FileProvider { get; set; }
1936
public static void UseBlocklyUI(this IApplicationBuilder appBuilder, IWebHostEnvironment environment)
2037
{
21-
var manifestEmbeddedProvider =
22-
new ManifestEmbeddedFileProvider(Assembly.GetExecutingAssembly());
23-
var service = appBuilder.ApplicationServices;
24-
var physicalProvider = environment.ContentRootFileProvider;
25-
var compositeProvider =
26-
new CompositeFileProvider(physicalProvider, manifestEmbeddedProvider);
27-
mapFile("blocklyAutomation", compositeProvider, appBuilder);
38+
if (FileProvider == null)
39+
{
40+
var manifestEmbeddedProvider =
41+
new ManifestEmbeddedFileProvider(Assembly.GetExecutingAssembly());
42+
var service = appBuilder.ApplicationServices;
43+
FileProvider = manifestEmbeddedProvider;
44+
if (environment != null)
45+
{
46+
var physicalProvider = environment.ContentRootFileProvider;
47+
if (physicalProvider != null)
48+
FileProvider =
49+
new CompositeFileProvider(physicalProvider, manifestEmbeddedProvider);
50+
}
51+
}
52+
mapFile("BlocklyAutomation", FileProvider, appBuilder);
2853
}
2954
static string contentFromExtension(string file)
3055
{

src/NetCore2Blockly/NetCore2BlocklyNew/NetCore2BlocklyNew.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
<PropertyGroup>
44
<TargetFramework>net5.0</TargetFramework>
55
</PropertyGroup>
6+
<ItemGroup>
7+
8+
<None Include="..\..\..\README.md" Pack="true" PackagePath="\"/>
9+
10+
</ItemGroup>
611
<PropertyGroup>
712
<PackageId>NetCore2Blockly</PackageId>
813
<Version>5.2022.129.1019</Version>
@@ -14,8 +19,9 @@
1419
<Authors>Andrei Ignat</Authors>
1520
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1621
<PackageTags>WebAPI;ASP.NET Core;.NET Core;Blockly;OData;GraphQL;Swagger;OpenAPI</PackageTags>
17-
<Description>
18-
This program will generate ASP.NET Core WebAPI+ ODATA+GraphQL blockly blocks. And from other swagger files.
22+
23+
<Description>
24+
This program will generate ASP.NET Core WebAPI blockly blocks. And from other swagger files.
1925
Can be usefull for just making a demo, interacting or others.
2026
Please see https://github.com/ignatandrei/NETCoreBlockly for details
2127
</Description>

src/NetCore2Blockly/NetCore2BlocklyNew/readme.txt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,51 @@ Demo at https://netcoreblockly.herokuapp.com/blockly.html ( play with the links
88

99
Demo Video at https://www.youtube.com/watch?v=GptkNWjmCzk
1010

11-
How to install NETCore2Blockly in a .NET Core 3.1 WebAPI / MVC application
11+
How to install NETCore2Blockly in a .NET Core 5 WebAPI / MVC application
12+
1213
Step 1:
1314
Install https://www.nuget.org/packages/NetCore2Blockly/ by running the following command in the Package Manager Console:
1415

1516
Install-Package NetCore2Blockly
1617

1718
Step 2:
1819
Modify Startup.cs by adding
20+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
21+
{
22+
app.UseDefaultFiles();
23+
app.UseStaticFiles();
24+
//your code ...
25+
}
1926

20-
public void ConfigureServices(IServiceCollection services)
21-
{
22-
//last line
23-
services.AddBlockly();
24-
}
2527
public void Configure(IApplicationBuilder app, IWebHostEnvironment env){
26-
//if you plan to use as html, do not forget app.UseStaticFiles
27-
//last line
28-
app.UseBlockly();
29-
}
30-
Step 3:
28+
//should have swagger
29+
app.UseSwagger();
3130

32-
To see the UI , please add
3331

34-
public void Configure(IApplicationBuilder app, IWebHostEnvironment env){
35-
36-
app.UseBlocklyUI();
32+
app.UseBlocklyUI(env);
33+
app.UseEndpoints(endpoints =>
34+
{
3735
}
36+
endpoints.UseBlocklyAutomation();
37+
}
38+
3839

3940

40-
Step 4:
41-
Run the application and browse to /blockly.html
41+
# How to install NETCore2Blockly in a .NET Core 6 WebAPI / MVC application in 2 steps + run application
4242

43-
For WebAPI (local):
44-
app.UseBlocklyUI();
43+
## Step 1:
44+
Install https://www.nuget.org/packages/NetCore2Blockly/ by running the following command in the Package Manager Console:
45+
> Install-Package NetCore2Blockly
4546

46-
For Swagger ( local or remote )
47-
app.UseBlocklySwagger("petstore", "https://petstore.swagger.io/v2/swagger.json")
47+
## Step 2:
4848

49-
For ODATA ( local or remote)
50-
app.UseBlocklyOData("OdataV4", "https://services.odata.org/TripPinRESTierService/");
49+
app.UseBlocklyUI(app.Environment);
50+
//after app.MapControllers();
51+
app.UseBlocklyAutomation();
5152

52-
For GraphQL
53-
app.UseBlocklyGraphQL("localGraphql", "/graphql");
5453

55-
For authentication
56-
See links 22 for JWT and 31 for Auth0 from https://netcoreblockly.herokuapp.com/
54+
Step 3:
55+
Run the application and browse to /blocklyautomation or /blocklyautomation/index.html
56+
5757

5858
That's all!

src/NetCore2Blockly/TestBlocklyHtml/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
282282

283283
app.UseAuthentication();
284284
app.UseAuthorization();
285-
285+
app.UseBlocklyUI(env);
286286
app.UseGraphQLPlayground(new GraphQLPlaygroundOptions());
287287
app.UseGraphQL<DepartmentSchema>();
288288
//app.UseBlocklyRegisterMiddleware();

0 commit comments

Comments
 (0)