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;
4using Waher.Content;
6using Waher.Events;
9
11{
16 {
20 public DeleteExport()
21 : base("/DeleteExport")
22 {
23 }
24
28 public override bool HandlesSubPaths => false;
29
33 public override bool UserSessions => true;
34
38 public bool AllowsPOST => true;
39
46 public async Task POST(HttpRequest Request, HttpResponse Response)
47 {
48 Gateway.AssertUserAuthenticated(Request, "Admin.Data.Backup");
49
50 if (!Request.HasData)
51 {
52 await Response.SendResponse(new BadRequestException());
53 return;
54 }
55
56 ContentResponse Content = await Request.DecodeDataAsync();
57 if (Content.HasError || !(Content.Decoded is string FileName))
58 {
59 await Response.SendResponse(new BadRequestException());
60 return;
61 }
62
63 string Dir;
64
65 if (FileName.EndsWith(".key", StringComparison.CurrentCultureIgnoreCase))
67 else
68 Dir = await Export.GetFullExportFolderAsync();
69
70 if (!Directory.Exists(Dir))
71 {
72 await Response.SendResponse(new NotFoundException("Folder not found: " + Dir));
73 return;
74 }
75
76 string FullFileName = Dir + Path.DirectorySeparatorChar + FileName;
77 if (!File.Exists(FullFileName))
78 {
79 await Response.SendResponse(new NotFoundException("File not found: " + FullFileName));
80 return;
81 }
82
83 File.Delete(FullFileName);
84
85 Log.Informational("Export deleted.", FileName);
86
87 Response.StatusCode = 200;
88 Response.StatusMessage = "OK";
89 Response.ContentType = PlainTextCodec.DefaultContentType;
90 await Response.Write("1");
91
93 }
94
95 }
96}
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
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:14
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:344
Static class managing data export.
Definition: Export.cs:18
static async Task< string > GetFullExportFolderAsync()
Full path to export folder.
Definition: Export.cs:22
static async Task< string > GetFullKeyExportFolderAsync()
Full path to key folder.
Definition: Export.cs:35
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:147
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:3868
override bool UserSessions
If the resource uses user sessions.
Definition: DeleteExport.cs:33
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
Definition: DeleteExport.cs:46
bool AllowsPOST
If the POST method is allowed.
Definition: DeleteExport.cs:38
override bool HandlesSubPaths
If the resource handles sub-paths.
Definition: DeleteExport.cs:28
DeleteExport()
Deletes an exported file.
Definition: DeleteExport.cs:20
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:22
bool HasData
If the request has data.
Definition: HttpRequest.cs:113
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
Definition: HttpRequest.cs:139
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:23
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
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.