Skip to content

Commit e102051

Browse files
Merge pull request #2 from DevExpress-Examples/update-projects
Update projects
2 parents 4a3addf + 80406bf commit e102051

33 files changed

+643
-776
lines changed

ASP.NET Core/Controllers/HomeController.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
using System.Threading.Tasks;
55
using Microsoft.AspNetCore.Mvc;
66

7-
namespace ASP_NET_Core.Controllers
8-
{
9-
public class HomeController : Controller
10-
{
11-
public IActionResult Index()
12-
{
7+
namespace ASP_NET_Core.Controllers {
8+
public class HomeController : Controller {
9+
public IActionResult Index() {
1310
return View();
1411
}
1512

ASP.NET Core/Program.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77
using Microsoft.Extensions.Hosting;
88
using Microsoft.Extensions.Logging;
99

10-
namespace ASP_NET_Core
11-
{
12-
public class Program
13-
{
14-
public static void Main(string[] args)
15-
{
10+
namespace ASP_NET_Core {
11+
public class Program {
12+
public static void Main(string[] args) {
1613
CreateHostBuilder(args).Build().Run();
1714
}
1815

ASP.NET Core/Startup.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,27 @@
88
using Microsoft.Extensions.DependencyInjection;
99
using Microsoft.Extensions.Hosting;
1010

11-
namespace ASP_NET_Core
12-
{
13-
public class Startup
14-
{
15-
public Startup(IConfiguration configuration)
16-
{
11+
namespace ASP_NET_Core {
12+
public class Startup {
13+
public Startup(IConfiguration configuration) {
1714
Configuration = configuration;
1815
}
1916

2017
public IConfiguration Configuration { get; }
2118

2219
// This method gets called by the runtime. Use this method to add services to the container.
23-
public void ConfigureServices(IServiceCollection services)
24-
{
20+
public void ConfigureServices(IServiceCollection services) {
2521
// Add framework services.
2622
services
2723
.AddControllersWithViews()
2824
.AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
2925
}
3026

3127
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
32-
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
33-
{
34-
if (env.IsDevelopment())
35-
{
28+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
29+
if (env.IsDevelopment()) {
3630
app.UseDeveloperExceptionPage();
37-
}
38-
else
39-
{
31+
} else {
4032
app.UseExceptionHandler("/Home/Error");
4133
}
4234
app.UseStaticFiles();

ASP.NET Core/Views/Home/Index.cshtml

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
@using ASP_NET_Core.Models
2-
<script type="text/javascript" src="~/services/amazon.filesystem.js"></script>
3-
<script type="text/javascript" src="~/services/amazon.gateway.js"></script>
2+
<script type="text/javascript" src="~/js/amazon.filesystem.js"></script>
3+
<script type="text/javascript" src="~/js/amazon.gateway.js"></script>
44

55
<div id="wrapper">
66
<div id="widget-area">
77
@(Html.DevExtreme().FileUploader()
88
.ID("file-uploader")
99
.ChunkSize(5242880)
1010
.UploadChunk("uploadChunk")
11+
.AbortUpload("abortUpload")
1112
.OnValueChanged("onValueChanged")
1213
.OnUploaded("onUploaded")
1314
)
@@ -25,67 +26,71 @@
2526
</div>
2627

2728
<script>
28-
$.ajax({
29-
url: 'https://localhost:52366/api/AmazonS3/getItems',
30-
success(result) {
31-
result.active = true;
32-
const className = result.active ? 'show-widget' : 'show-message';
33-
$('#wrapper').addClass(className);
34-
$("#load-panel").dxLoadPanel("hide");
35-
},
36-
error() {
37-
$("#load-panel").dxLoadPanel("hide");
38-
}
39-
});
29+
$.ajax({
30+
url: 'https://localhost:52366/api/AmazonS3/getItems',
31+
success(result) {
32+
result.active = true;
33+
const className = result.active ? 'show-widget' : 'show-message';
34+
$('#wrapper').addClass(className);
35+
$("#load-panel").dxLoadPanel("hide");
36+
},
37+
error() {
38+
$("#load-panel").dxLoadPanel("hide");
39+
}
40+
});
4041
4142
42-
const onUploaded = async function(e) {
43-
const url = await amazon.getPresignedDownloadUrl(e.file.name);
44-
showPresignedUrl(url, e.file.name);
45-
}
43+
async function onUploaded(e) {
44+
const url = await amazon.getPresignedDownloadUrl(e.file.name);
45+
showPresignedUrl(url, e.file.name);
46+
}
4647
47-
function onValueChanged(e) {
48-
hidePresignedUrl();
49-
}
48+
async function abortUpload(file, uploadInfo) {
49+
return amazon.abortUpload(file, uploadInfo);
50+
}
5051
51-
async function uploadChunk(file, uploadInfo) {
52-
return await amazon.uploadFileChunk(file, uploadInfo);
53-
};
52+
function onValueChanged(e) {
53+
hidePresignedUrl();
54+
}
5455
55-
function showPresignedUrl(url, fileName) {
56-
$('<div>')
57-
.attr('id', 'url-div')
58-
.append(
59-
$('<span>').text('Download uploaded file: '),
60-
$('<a>')
61-
.attr('href', url)
62-
.attr('target', '_blank')
63-
.text(fileName)
64-
)
65-
.appendTo('#download-panel');
66-
}
56+
async function uploadChunk(file, uploadInfo) {
57+
return amazon.uploadFileChunk(file, uploadInfo);
58+
};
6759
68-
function hidePresignedUrl() {
69-
$('#url-div').remove();
70-
}
60+
function showPresignedUrl(url, fileName) {
61+
$('<div>')
62+
.attr('id', 'url-div')
63+
.append(
64+
$('<span>').text('Download uploaded file: '),
65+
$('<a>')
66+
.attr('href', url)
67+
.attr('target', '_blank')
68+
.text(fileName)
69+
)
70+
.appendTo('#download-panel');
71+
}
7172
72-
function onRequestExecuted(e) {
73-
$("<div>").addClass("request-info").append(
74-
createParameterInfoDiv("Method:", e.method),
75-
createParameterInfoDiv("Url path:", e.urlPath),
76-
createParameterInfoDiv("Query string:", e.queryString),
77-
$("<br>")
78-
)
79-
.prependTo("#request-panel");
80-
}
73+
function hidePresignedUrl() {
74+
$('#url-div').remove();
75+
}
8176
82-
function createParameterInfoDiv(name, value) {
83-
return $("<div>").addClass("parameter-info").append(
84-
$("<div>").addClass("parameter-name").text(name),
85-
$("<div>").addClass("parameter-value dx-theme-accent-as-text-color").text(value).attr("title", value)
86-
);
87-
}
77+
function onRequestExecuted(e) {
78+
$("<div>").addClass("request-info").append(
79+
createParameterInfoDiv("Method:", e.method),
80+
createParameterInfoDiv("Url path:", e.urlPath),
81+
createParameterInfoDiv("Query string:", e.queryString),
82+
$("<br>")
83+
)
84+
.prependTo("#request-panel");
85+
}
86+
87+
function createParameterInfoDiv(name, value) {
88+
return $("<div>").addClass("parameter-info").append(
89+
$("<div>").addClass("parameter-name").text(name),
90+
$("<div>").addClass("parameter-value dx-theme-accent-as-text-color").text(value).attr("title", value)
91+
);
92+
}
8893
89-
const endpointUrl = 'https://localhost:52366/api/AmazonS3';
90-
const amazon = new AmazonFileSystem(endpointUrl, onRequestExecuted);
94+
const endpointUrl = 'https://localhost:52366/api/AmazonS3';
95+
const amazon = new AmazonFileSystem(endpointUrl, onRequestExecuted);
9196
</script>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
class AmazonFileSystem {
2+
gateway = null;
3+
4+
constructor(baseUrl, onRequestExecuted) {
5+
this.gateway = new AmazonGateway(baseUrl, onRequestExecuted);
6+
}
7+
8+
getItems(path) {
9+
return this.gateway.getItems(path);
10+
}
11+
12+
createDirectory(key, name) {
13+
return this.gateway.createDirectory(key, name);
14+
}
15+
16+
renameItem(key, parentPath, name) {
17+
return this.gateway.renameItem(key, `${parentPath}/`, name);
18+
}
19+
20+
deleteItem(key) {
21+
return this.gateway.deleteItem(key);
22+
}
23+
24+
copyItem(item, destinationDir) {
25+
return this.gateway.copyItem(item.key, `${destinationDir.key}${item.name}`);
26+
}
27+
28+
moveItem(item, destinationDir) {
29+
return this.gateway.moveItem(item.key, `${destinationDir.key}${item.name}`);
30+
}
31+
32+
async abortFileUpload(fileData, uploadInfo, destinationDirectory) {
33+
await this.gateway.abortFileUpload(fileData, uploadInfo, destinationDirectory);
34+
}
35+
36+
async uploadFileChunk(fileData, uploadInfo, destinationDirectory) {
37+
if (uploadInfo.chunkIndex === 0) {
38+
await this.gateway.initUpload(fileData, destinationDirectory);
39+
}
40+
// upload part even if a chunk is first or last
41+
await this.gateway.uploadPart(fileData, uploadInfo, destinationDirectory);
42+
43+
if (uploadInfo.chunkCount === uploadInfo.chunkIndex + 1) {
44+
await this.gateway.completeUpload(fileData, uploadInfo, destinationDirectory);
45+
}
46+
}
47+
48+
/* eslint-disable-next-line spellcheck/spell-checker */
49+
async getPresignedDownloadUrl(fileName) {
50+
/* eslint-disable-next-line spellcheck/spell-checker */
51+
return this.gateway.getPresignedDownloadUrl(fileName);
52+
}
53+
54+
getFileNameFromKey(key) {
55+
const index = key.lastIndexOf('/');
56+
if (index === -1) {
57+
return key;
58+
}
59+
return key.substring(index + 1);
60+
}
61+
62+
async downloadItems(items) {
63+
const keys = items.map((x) => x.key);
64+
const fileName = keys.length > 1 ? 'archive.zip' : this.getFileNameFromKey(keys[0]);
65+
const blob = await this.gateway.downloadItems(keys);
66+
saveAs(new Blob([blob], { type: 'application/octet-stream' }), fileName);
67+
}
68+
}

0 commit comments

Comments
 (0)