completed client state invalidation in multi-user environment
This commit is contained in:
119
Oqtane.Client/UI/Interop.cs
Normal file
119
Oqtane.Client/UI/Interop.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.JSInterop;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Oqtane.UI
|
||||
{
|
||||
public class Interop
|
||||
{
|
||||
private readonly IJSRuntime _jsRuntime;
|
||||
|
||||
public Interop(IJSRuntime jsRuntime)
|
||||
{
|
||||
_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user