public static StatusLine CreateNew(string statusLineString) { try { var parts = GetParts(statusLineString); var protocolString = parts[0]; var codeString = parts[1]; var reason = parts[2]; var protocol = new HttpProtocol(protocolString); var code = int.Parse(codeString); if (!HttpStatusCodeHelper.IsValidCode(code)) { throw new NotSupportedException($"Invalid HTTP status code: {code}."); } var statusCode = (HttpStatusCode)code; // https://tools.ietf.org/html/rfc7230#section-3.1.2 // The reason-phrase element exists for the sole purpose of providing a // textual description associated with the numeric status code, mostly // out of deference to earlier Internet application protocols that were // more frequently used with interactive text clients.A client SHOULD // ignore the reason - phrase content. return(new StatusLine(protocol, statusCode)); } catch (Exception ex) { Logger.LogDebug <StatusLine>(ex); throw new NotSupportedException($"Invalid {nameof(StatusLine)}: {statusLineString}.", ex); } }
/// <summary> /// Delete the record for the given parameters /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tableName"></param> /// <param name="partitionKey"></param> /// <param name="rowKey"></param> /// <returns></returns> public async Task <bool> DeleteSingleAsync <T>(string tableName, string partitionKey, string rowKey) where T : ITableEntity, new() { // Create the CloudTable object that represents the "tableName" table. table = tableClient.GetTableReference(tableName); // Create a retrieve operation that takes a "tableName" entity. TableOperation retrieveOperation = TableOperation.Retrieve <T>(partitionKey, rowKey); // Execute the retrieve operation. TableResult retrievedResult = await table.ExecuteAsync(retrieveOperation); if (retrievedResult.Result != null) { var data = ((T)retrievedResult.Result); TableOperation dOperation = TableOperation.Delete(data); var result = await table.ExecuteAsync(dOperation); return(HttpStatusCodeHelper.GetResultFromTableResult(result)); } else { return(false); } }
/// <summary> /// carries out InsertOrReplace for the given object /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tableName"></param> /// <param name="partitionKey"></param> /// <param name="rowKey"></param> /// <param name="updateData"></param> /// <param name="updateData"></param> /// <returns></returns> public async Task <bool> InsertOrReplaceSingleAsync <T>(string tableName, string partitionKey, string rowKey, T updateData, List <string> propertiesToUpdate) where T : ITableEntity, new() { // Create the CloudTable object that represents the "tableName" table. table = tableClient.GetTableReference(tableName); // Create a retrieve operation that takes a "tableName" entity. TableOperation retrieveOperation = TableOperation.Retrieve <T>(partitionKey, rowKey); // Execute the retrieve operation. TableResult retrievedResult = await table.ExecuteAsync(retrieveOperation); T resultObject = (T)retrievedResult.Result; //Update if (resultObject != null) { resultObject = ReflectionPropertyMatcher.SetPropertyValues <T>(updateData, resultObject, propertiesToUpdate); // Create the InsertOrReplace TableOperation TableOperation updateOperation = TableOperation.InsertOrReplace(resultObject); // Execute the operation. var returnData = await table.ExecuteAsync(updateOperation); return(HttpStatusCodeHelper.GetResultFromTableResult(returnData)); } else { return(false); } }
public void CodeVerificationTest() { Assert.True(HttpStatusCodeHelper.IsInformational(HttpStatusCode.Processing)); Assert.False(HttpStatusCodeHelper.IsInformational(HttpStatusCode.OK)); Assert.True(HttpStatusCodeHelper.IsSuccessful(HttpStatusCode.OK)); Assert.False(HttpStatusCodeHelper.IsSuccessful(HttpStatusCode.Redirect)); }
/// <summary> /// inserts the given T to the given tablename /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tableModel"></param> /// <param name="tableName"></param> /// <returns></returns> public async Task <bool> InsertAsync <T>(T tableModel, string tableName) { // Create the table if it doesn't exist. table = tableClient.GetTableReference(tableName); TableOperation insertOperation = TableOperation.Insert(tableModel as ITableEntity); var result = await table.ExecuteAsync(insertOperation); return(HttpStatusCodeHelper.GetResultFromTableResult(result)); }
private async Task OpenProgressiveMp4Async(DmcSessionResponse session) { Assert.IsTrue(HttpStatusCodeHelper.IsSuccessStatusCode(session.Meta.Status)); Debug.WriteLineIf(session.Meta.Message is not null, session.Meta.Message); Assert.IsNotNull(session.Data.Session.ContentUri); // Try open media using (var mediaSource = MediaSource.CreateFromUri(session.Data.Session.ContentUri)) { await mediaSource.OpenAsync(); } }
/// <summary> /// Inserts batch records of type T to the given table name /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tableModel"></param> /// <param name="tableName"></param> /// <returns></returns> public async Task <bool> InsertBatchAsync <T>(List <T> tableModel, string tableName) { //declare TableBatchOperation TableBatchOperation tableBatchOperation = new TableBatchOperation(); // Create the table if it doesn't exist. table = tableClient.GetTableReference(tableName); foreach (var item in tableModel) { tableBatchOperation.Insert(tableModel as ITableEntity); } var result = await table.ExecuteBatchAsync(tableBatchOperation); return(HttpStatusCodeHelper.GetResultFromTableListResult(result)); }
private async Task OpenHlsAsync(DmcSessionResponse session) { Assert.IsTrue(HttpStatusCodeHelper.IsSuccessStatusCode(session.Meta.Status)); Debug.WriteLineIf(session.Meta.Message is not null, session.Meta.Message); Assert.IsNotNull(session.Data.Session.ContentUri); Assert.AreEqual("mpeg2ts", session.Data.Session.Protocol.Parameters.HttpParameters.Parameters.HlsParameters.MediaSegmentFormat); // Try open media var ams = await AdaptiveMediaSource.CreateFromUriAsync(session.Data.Session.ContentUri, _context.HttpClient); Assert.AreEqual(ams.Status, AdaptiveMediaSourceCreationStatus.Success); using (var mediaSource = MediaSource.CreateFromAdaptiveMediaSource(ams.MediaSource)) { await mediaSource.OpenAsync(); } }
public static async Task <HttpContent> GetContentAsync(Stream stream, HttpResponseContentHeaders headerStruct, HttpMethod requestMethod, StatusLine statusLine, CancellationToken ctsToken = default) { // https://tools.ietf.org/html/rfc7230#section-3.3.3 // The length of a message body is determined by one of the following // (in order of precedence): // 1.Any response to a HEAD request and any response with a 1xx // (Informational), 204(No Content), or 304(Not Modified) status // code is always terminated by the first empty line after the // header fields, regardless of the header fields present in the // message, and thus cannot contain a message body. if (requestMethod == HttpMethod.Head || HttpStatusCodeHelper.IsInformational(statusLine.StatusCode) || statusLine.StatusCode == HttpStatusCode.NoContent || statusLine.StatusCode == HttpStatusCode.NotModified) { return(GetDummyOrNullContent(headerStruct.ContentHeaders)); } // https://tools.ietf.org/html/rfc7230#section-3.3.3 // 2.Any 2xx(Successful) response to a CONNECT request implies that // the connection will become a tunnel immediately after the empty // line that concludes the header fields.A client MUST ignore any // Content - Length or Transfer-Encoding header fields received in // such a message. else if (requestMethod == new HttpMethod("CONNECT")) { if (HttpStatusCodeHelper.IsSuccessful(statusLine.StatusCode)) { return(null); } } // https://tools.ietf.org/html/rfc7230#section-3.3.3 // 3.If a Transfer-Encoding header field is present and the chunked // transfer coding(Section 4.1) is the final encoding, the message // body length is determined by reading and decoding the chunked // data until the transfer coding indicates the data is complete. if (headerStruct.ResponseHeaders != null && headerStruct.ResponseHeaders.Contains("Transfer-Encoding")) { // https://tools.ietf.org/html/rfc7230#section-4 // All transfer-coding names are case-insensitive if ("chunked".Equals(headerStruct.ResponseHeaders.TransferEncoding.Last().Value, StringComparison.OrdinalIgnoreCase)) { return(await GetDecodedChunkedContentAsync(stream, headerStruct, ctsToken)); } // https://tools.ietf.org/html/rfc7230#section-3.3.3 // If a Transfer - Encoding header field is present in a response and // the chunked transfer coding is not the final encoding, the // message body length is determined by reading the connection until // it is closed by the server. If a Transfer - Encoding header field // is present in a request and the chunked transfer coding is not // the final encoding, the message body length cannot be determined // reliably; the server MUST respond with the 400(Bad Request) // status code and then close the connection. else { return(await GetContentTillEndAsync(stream, ctsToken)); } } // https://tools.ietf.org/html/rfc7230#section-3.3.3 // 5.If a valid Content - Length header field is present without // Transfer - Encoding, its decimal value defines the expected message // body length in octets.If the sender closes the connection or // the recipient times out before the indicated number of octets are // received, the recipient MUST consider the message to be // incomplete and close the connection. else if (headerStruct.ContentHeaders.Contains("Content-Length")) { long?contentLength = headerStruct.ContentHeaders?.ContentLength; return(await GetContentTillLengthAsync(stream, contentLength, ctsToken)); } // https://tools.ietf.org/html/rfc7230#section-3.3.3 // 6.If this is a request message and none of the above are true, then // the message body length is zero (no message body is present). // 7. Otherwise, this is a response message without a declared message // body length, so the message body length is determined by the // number of octets received prior to the server closing the // connection. return(await GetContentTillEndAsync(stream, ctsToken)); }