/// <summary> /// Releases server resources for a session termination caused by either: /// Close-Session or Cancel-Session /// </summary> async Task <HttpResponseMessage> ReleaseResources(HttpRequestMessage request, CancellationToken cancellationToken, bool deleteFile = false) { HttpStatusCode status_code = HttpStatusCode.OK; HttpResponseMessage response = request.CreateResponse(); response.Headers.Add(Bits.K_BITS_PACKET_TYPE, Bits.V_ACK); //response.Headers.Add(Bits.K_CONTENT_LENGTH, "0"); try { string session_id = request.Headers.GetValues(Bits.K_BITS_SESSION_ID)?.First(); if (string.IsNullOrEmpty(session_id)) { throw new NotSupportedException(); } _traceManager.TraceDebug($"Closing BITS-Session-Id: {session_id}"); if (Sessions.ContainsKey(session_id)) { await Sessions[session_id].Close(deleteFile); } else { FileInfo fileInfo = new FileInfo(Path.Combine(BITSUploadSession.VideoBufferDirectory, session_id)); if (fileInfo.Exists) { fileInfo.Delete(); } else { await _fileProvider.Delete(session_id, DirectoryEnum.Uploaded); } } if (Sessions.ContainsKey(session_id) && Sessions[session_id].Move) { if (Sessions[session_id].IsTranscoding) { Progress <double> progress = new Progress <double>(); CancellationToken ct = CancellationToken.None; var transcodeSession = new TaskProgressObservable <bool> { Task = TranscodeFileToFileProvider(Sessions[session_id], progress, ct), Progress = progress, CancellationToken = ct }; TranscodingSessions.Add($"TRANSCODED_{Path.GetFileName(Sessions[session_id].FileName)}", transcodeSession); } else { await _fileProvider.Complete(Sessions[session_id].FileName); } } if (Sessions.ContainsKey(session_id)) { Sessions.Remove(session_id); } status_code = HttpStatusCode.OK; } catch (NotSupportedException) { return(SendResponse(response, HttpStatusCode.BadRequest)); } catch (Exception e) { throw new Bits.ServerInternalError(e); } return(SendResponse(response, status_code)); }