2using System.Collections.Generic;
3using System.Threading.Tasks;
15 internal static readonly Dictionary<string, UploadRec> packageFilePerSession =
new Dictionary<string, UploadRec>();
16 private static int expectedBlockPackage = 0;
19 : base(
"/UploadPackage")
23 internal class UploadRec
26 public bool MakeDownloadable;
29 public override bool HandlesSubPaths =>
false;
30 public override bool UserSessions =>
true;
35 KeyValuePair<bool, int> P = await Upload(Request, Response, expectedBlockPackage, packageFilePerSession,
"package",
true);
36 expectedBlockPackage = P.Value;
39 internal static void RemoveFile(
string Key, Dictionary<string, UploadRec> Files)
43 if (Files.TryGetValue(Key, out UploadRec Rec))
51 internal static async Task<KeyValuePair<bool, int>> Upload(
HttpRequest Request,
HttpResponse Response,
int ExpectedBlockNr,
52 Dictionary<string, UploadRec> Files,
string Name,
bool PushToClient)
74 GenerateSignature =
false;
82 Request.
Session[Name +
"FileName"] = F.Value;
87 FileName = v.ValueObject as string;
91 if (BlockNr != ExpectedBlockNr)
100 Rec =
new UploadRec()
103 MakeDownloadable = Downloadable
109 Rec.MakeDownloadable |= Downloadable;
114 await Request.
DataStream.CopyToAsync(Rec.File);
116 long FileLength = Rec.File.Length;
122 if (GenerateSignature)
124 Rec.File.Position = 0;
125 byte[] Signature = XmppServerModule.Legal.Sign(Rec.File);
127 await UploadSignature.CopyPackage(Rec, Signature, TabID, FileName, Request.
RemoteEndPoint);
140 Response.StatusCode = 200;
150 return new KeyValuePair<bool, int>(!More, ExpectedBlockNr);
Helps with parsing of commong data types.
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
static string JsonStringEncode(string s)
Encodes a string for inclusion in JSON.
The ClientEvents class allows applications to push information asynchronously to web clients connecte...
static Task< int > PushEvent(string[] TabIDs, string Type, object Data)
Puses an event to a set of Tabs, given their Tab IDs.
Static class managing data export.
static string FormatBytes(double Bytes)
Formats a file size using appropriate unit.
Static class managing the runtime environment of the IoT Gateway.
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Base class for all HTTP fields.
Represents an HTTP request.
Stream DataStream
Data stream, if data is available, or null if data is not available.
HttpRequestHeader Header
Request header.
string RemoteEndPoint
Remote end-point.
bool HasData
If the request has data.
Variables Session
Contains session states, if the resource requires sessions, or null otherwise.
static string GetSessionId(HttpRequest Request, HttpResponse Response)
Gets the session ID used for a request.
const string HttpSessionID
The Cookie Key for HTTP Session Identifiers: "HttpSessionID"
Represets a response of an HTTP client request.
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
Class managing the contents of a temporary file. When the class is disposed, the temporary file is de...
Contains information about a variable.
virtual bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
bool AllowsPOST
If the POST method is allowed.
POST Interface for HTTP resources.