120 lines
2.9 KiB
C#
120 lines
2.9 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Oqtane.Shared
|
|
{
|
|
public class Interop
|
|
{
|
|
private readonly IJSRuntime jsRuntime;
|
|
|
|
public Interop(IJSRuntime jsRuntime)
|
|
{
|
|
this.jsRuntime = jsRuntime;
|
|
}
|
|
|
|
public Task SetCookie(string name, string value, int days)
|
|
{
|
|
try
|
|
{
|
|
jsRuntime.InvokeAsync<string>(
|
|
"interop.setCookie",
|
|
name, value, days);
|
|
return Task.CompletedTask;
|
|
}
|
|
catch
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
public ValueTask<string> GetCookie(string name)
|
|
{
|
|
try
|
|
{
|
|
return jsRuntime.InvokeAsync<string>(
|
|
"interop.getCookie",
|
|
name);
|
|
}
|
|
catch
|
|
{
|
|
return new ValueTask<string>(Task.FromResult(string.Empty));
|
|
}
|
|
}
|
|
|
|
public Task IncludeCSS(string id, string url)
|
|
{
|
|
try
|
|
{
|
|
jsRuntime.InvokeAsync<string>(
|
|
"interop.includeCSS",
|
|
id, url);
|
|
return Task.CompletedTask;
|
|
}
|
|
catch
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
public ValueTask<string> GetElementByName(string name)
|
|
{
|
|
try
|
|
{
|
|
return jsRuntime.InvokeAsync<string>(
|
|
"interop.getElementByName",
|
|
name);
|
|
}
|
|
catch
|
|
{
|
|
return new ValueTask<string>(Task.FromResult(string.Empty));
|
|
}
|
|
}
|
|
|
|
public Task SubmitForm(string path, object fields)
|
|
{
|
|
try
|
|
{
|
|
jsRuntime.InvokeAsync<string>(
|
|
"interop.submitForm",
|
|
path, fields);
|
|
return Task.CompletedTask;
|
|
}
|
|
catch
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
public ValueTask<string[]> GetFiles(string id)
|
|
{
|
|
try
|
|
{
|
|
return jsRuntime.InvokeAsync<string[]>(
|
|
"interop.getFiles",
|
|
id);
|
|
}
|
|
catch
|
|
{
|
|
return new ValueTask<string[]>(Task.FromResult(new string[0]));
|
|
}
|
|
}
|
|
|
|
public Task UploadFiles(string posturl, string folder, string id)
|
|
{
|
|
try
|
|
{
|
|
jsRuntime.InvokeAsync<string>(
|
|
"interop.uploadFiles",
|
|
posturl, folder, id);
|
|
return Task.CompletedTask;
|
|
}
|
|
catch
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|
|
}
|