Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DeleteExport.cs
1using System;
2using System.IO;
3using System.Threading.Tasks;
5using Waher.Events;
8
10{
15 {
19 public DeleteExport()
20 : base("/DeleteExport")
21 {
22 }
23
27 public override bool HandlesSubPaths
28 {
29 get
30 {
31 return false;
32 }
33 }
34
38 public override bool UserSessions
39 {
40 get
41 {
42 return true;
43 }
44 }
45
49 public bool AllowsPOST => true;
50
57 public async Task POST(HttpRequest Request, HttpResponse Response)
58 {
59 Gateway.AssertUserAuthenticated(Request, "Admin.Data.Backup");
60
61 if (!Request.HasData)
62 throw new BadRequestException();
63
64 if (!(await Request.DecodeDataAsync() is string FileName))
65 throw new BadRequestException();
66
67 string Dir;
68
69 if (FileName.EndsWith(".key", StringComparison.CurrentCultureIgnoreCase))
71 else
72 Dir = await Export.GetFullExportFolderAsync();
73
74 if (!Directory.Exists(Dir))
75 throw new NotFoundException("Folder not found: " + Dir);
76
77 string FullFileName = Dir + Path.DirectorySeparatorChar + FileName;
78 if (!File.Exists(FullFileName))
79 throw new NotFoundException("File not found: " + FullFileName);
80
81 File.Delete(FullFileName);
82
83 Log.Informational("Export deleted.", FileName);
84
85 Response.StatusCode = 200;
86 Response.ContentType = PlainTextCodec.DefaultContentType;
87 await Response.Write("1");
88
90 }
91
92 }
93}
Plain text encoder/decoder.
const string DefaultContentType
text/plain
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static void Informational(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an informational event.
Definition: Log.cs:334
Static class managing data export.
Definition: Export.cs:19
static async Task< string > GetFullExportFolderAsync()
Full path to export folder.
Definition: Export.cs:23
static async Task< string > GetFullKeyExportFolderAsync()
Full path to key folder.
Definition: Export.cs:36
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:126
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
Definition: Gateway.cs:3041
override bool UserSessions
If the resource uses user sessions.
Definition: DeleteExport.cs:39
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
Definition: DeleteExport.cs:57
bool AllowsPOST
If the POST method is allowed.
Definition: DeleteExport.cs:49
override bool HandlesSubPaths
If the resource handles sub-paths.
Definition: DeleteExport.cs:28
DeleteExport()
Deletes an exported file.
Definition: DeleteExport.cs:19
Abstract base class for export formats.
Definition: ExportFormat.cs:14
static void UpdateClientsFileDeleted(string FileName)
Removes a file from all pages viewing backup files
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
Definition: HttpRequest.cs:18
bool HasData
If the request has data.
Definition: HttpRequest.cs:74
async Task< object > DecodeDataAsync()
Decodes data sent in request.
Definition: HttpRequest.cs:95
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:21
async Task Write(byte[] Data)
Returns binary data in the response.
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The server has not found anything matching the Request-URI. No indication is given of whether the con...
POST Interface for HTTP resources.