Last ...
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
@@ -107,6 +108,7 @@ namespace xIdentityService.Interfaces
|
||||
/// Access a Get Request Stream as AsyncEnumerable ...
|
||||
/// </summary>
|
||||
/// <param name="endpoint"></param>
|
||||
/// <param name="bufferLength"></param>
|
||||
/// <param name="addXPoweredValue"></param>
|
||||
/// <param name="tokens"></param>
|
||||
/// <param name="@params"></param>
|
||||
@@ -115,8 +117,9 @@ namespace xIdentityService.Interfaces
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
IAsyncEnumerable<T> StreamData<T>(
|
||||
Task<Stream> StreamData(
|
||||
Enum endpoint,
|
||||
int bufferLength = 8194,
|
||||
bool addXPoweredValue = true,
|
||||
XTokenResponse tokens = null,
|
||||
IDictionary<string, string> @params = null,
|
||||
@@ -168,11 +171,13 @@ namespace xIdentityService.Interfaces
|
||||
/// and Query Strings Attach ...
|
||||
/// </summary>
|
||||
/// <param name="endpoint"></param>
|
||||
/// <param name="attachBaseUrl"></param>
|
||||
/// <param name="@params"></param>
|
||||
/// <param name="queryStrings"></param>
|
||||
/// <returns></returns>
|
||||
string PrepareUrl(
|
||||
Enum endpoint,
|
||||
bool attachBaseUrl = false,
|
||||
IDictionary<string, string> @params = null,
|
||||
IDictionary<string, string> queryStrings = null
|
||||
);
|
||||
@@ -182,11 +187,13 @@ namespace xIdentityService.Interfaces
|
||||
/// and Query Strings Attach ...
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="attachBaseUrl"></param>
|
||||
/// <param name="@params"></param>
|
||||
/// <param name="queryStrings"></param>
|
||||
/// <returns></returns>
|
||||
string PrepareUrl(
|
||||
string url,
|
||||
bool attachBaseUrl = false,
|
||||
IDictionary<string, string> @params = null,
|
||||
IDictionary<string, string> queryStrings = null
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
@@ -19,6 +20,8 @@ using xIdentityService.Constants;
|
||||
using xIdentityService.Interfaces;
|
||||
using xIdentityService.Models;
|
||||
using xIdentityService.Extensions;
|
||||
using System.Diagnostics.Tracing;
|
||||
using MySqlX.XDevAPI.Common;
|
||||
|
||||
namespace xIdentityService.Providers
|
||||
{
|
||||
@@ -132,7 +135,7 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
httpClient.DefaultRequestHeaders
|
||||
.Add(
|
||||
XAuthorization.AccessToken,
|
||||
XAuthorization.Header,
|
||||
$"{XAuthentication.BEARER} {tokens.AccessToken}");
|
||||
}
|
||||
|
||||
@@ -257,9 +260,9 @@ namespace xIdentityService.Providers
|
||||
{
|
||||
//
|
||||
var url = PrepareUrl(
|
||||
endpoint,
|
||||
@params,
|
||||
queryStrings
|
||||
@params: @params,
|
||||
endpoint: endpoint,
|
||||
queryStrings: queryStrings
|
||||
);
|
||||
|
||||
//
|
||||
@@ -456,6 +459,7 @@ namespace xIdentityService.Providers
|
||||
/// Access a Get Request Stream as AsyncEnumerable ...
|
||||
/// </summary>
|
||||
/// <param name="endpoint"></param>
|
||||
/// <param name="bufferLength"></param>
|
||||
/// <param name="addXPoweredValue"></param>
|
||||
/// <param name="tokens"></param>
|
||||
/// <param name="@params"></param>
|
||||
@@ -464,8 +468,9 @@ namespace xIdentityService.Providers
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public async IAsyncEnumerable<T> StreamData<T>(
|
||||
public async Task<Stream> StreamData(
|
||||
Enum endpoint,
|
||||
int bufferLength = 8194,
|
||||
bool addXPoweredValue = true,
|
||||
XTokenResponse tokens = null,
|
||||
IDictionary<string, string> @params = null,
|
||||
@@ -477,9 +482,10 @@ namespace xIdentityService.Providers
|
||||
{
|
||||
//
|
||||
var url = PrepareUrl(
|
||||
endpoint,
|
||||
@params,
|
||||
queryStrings
|
||||
@params: @params,
|
||||
endpoint: endpoint,
|
||||
attachBaseUrl: true,
|
||||
queryStrings: queryStrings
|
||||
);
|
||||
var client = GetHttpClient(tokens);
|
||||
if (addXPoweredValue)
|
||||
@@ -488,7 +494,8 @@ namespace xIdentityService.Providers
|
||||
client.DefaultRequestHeaders
|
||||
.Add(
|
||||
XAuthorization.XPoweredBy,
|
||||
XPoweredValue);
|
||||
XPoweredValue
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -499,16 +506,92 @@ namespace xIdentityService.Providers
|
||||
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/event-stream"));
|
||||
|
||||
//
|
||||
using (var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken))
|
||||
{
|
||||
//
|
||||
response.EnsureSuccessStatusCode();
|
||||
var stream = await response.Content.ReadAsStreamAsync();
|
||||
await foreach (var item in stream.ToAsyncEnumerable<T>(cancellationToken: cancellationToken))
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
//
|
||||
var stream = await response.Content.ReadAsStreamAsync();
|
||||
|
||||
//
|
||||
return stream;
|
||||
|
||||
// using (var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken))
|
||||
// {
|
||||
// //
|
||||
// int readedBuffers = 0;
|
||||
// response.EnsureSuccessStatusCode();
|
||||
// var buffer = new byte[bufferLength];
|
||||
// var stream = await response.Content.ReadAsStreamAsync();
|
||||
|
||||
// //
|
||||
// while ((readedBuffers = await stream.ReadAsync(buffer, 0, buffer.Length)) > 0)
|
||||
// {
|
||||
// //
|
||||
// var content = buffer.FromBytes();
|
||||
// Console.WriteLine(content);
|
||||
// }
|
||||
|
||||
// // await foreach (var message in stream) {
|
||||
// // Console.WriteLine(message);
|
||||
// // }
|
||||
|
||||
// // await foreach (var item in stream.ToAsyncEnumerable<byte[]>(cancellationToken: cancellationToken))
|
||||
// // {
|
||||
// // //
|
||||
// // Console.WriteLine(item);
|
||||
|
||||
// // // T value = item.IsNull()
|
||||
// // // ? default(T)
|
||||
// // // : item.FromBytes().FromJSON<T>();
|
||||
|
||||
// // // //
|
||||
// // // yield return value;
|
||||
// // }
|
||||
// }
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
///
|
||||
|
||||
//
|
||||
// var eventSource = new EventSource(url);
|
||||
// // eventSource.
|
||||
|
||||
// // var client = GetHttpClient(tokens);
|
||||
// // if (addXPoweredValue)
|
||||
// // {
|
||||
// // //
|
||||
// // client.DefaultRequestHeaders
|
||||
// // .Add(
|
||||
// // XAuthorization.XPoweredBy,
|
||||
// // XPoweredValue);
|
||||
// // }
|
||||
|
||||
// // //
|
||||
// // // For SSE, you might want to set the Accept header, though not strictly necessary for just streaming
|
||||
// // client.DefaultRequestHeaders.Accept.Clear();
|
||||
// // client.DefaultRequestHeaders.Accept
|
||||
// // .Add(
|
||||
// // new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/event-stream"));
|
||||
|
||||
// // //
|
||||
// // using (var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken))
|
||||
// // {
|
||||
// // //
|
||||
// // response.EnsureSuccessStatusCode();
|
||||
// // var stream = await response.Content.ReadAsStreamAsync();
|
||||
// // await foreach (var item in stream.ToAsyncEnumerable<byte[]>(cancellationToken: cancellationToken))
|
||||
// // {
|
||||
// // //
|
||||
// // T value = item.IsNull()
|
||||
// // ? default(T)
|
||||
// // : item.FromBytes().FromJSON<T>();
|
||||
|
||||
// // //
|
||||
// // yield return value;
|
||||
// // }
|
||||
// // }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -748,11 +831,13 @@ namespace xIdentityService.Providers
|
||||
/// and Query Strings Attach ...
|
||||
/// </summary>
|
||||
/// <param name="endpoint"></param>
|
||||
/// <param name="attachBaseUrl"></param>
|
||||
/// <param name="@params"></param>
|
||||
/// <param name="queryStrings"></param>
|
||||
/// <returns></returns>
|
||||
public string PrepareUrl(
|
||||
Enum endpoint,
|
||||
bool attachBaseUrl = false,
|
||||
IDictionary<string, string> @params = null,
|
||||
IDictionary<string, string> queryStrings = null
|
||||
)
|
||||
@@ -764,9 +849,10 @@ namespace xIdentityService.Providers
|
||||
//
|
||||
// Filling Parmas and Query Strings of Url ...
|
||||
url = PrepareUrl(
|
||||
url,
|
||||
@params,
|
||||
queryStrings
|
||||
url: url,
|
||||
@params: @params,
|
||||
queryStrings: queryStrings,
|
||||
attachBaseUrl: attachBaseUrl
|
||||
);
|
||||
|
||||
//
|
||||
@@ -778,15 +864,31 @@ namespace xIdentityService.Providers
|
||||
/// and Query Strings Attach ...
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="attachBaseUrl"></param>
|
||||
/// <param name="@params"></param>
|
||||
/// <param name="queryStrings"></param>
|
||||
/// <returns></returns>
|
||||
public string PrepareUrl(
|
||||
string url,
|
||||
bool attachBaseUrl = false,
|
||||
IDictionary<string, string> @params = null,
|
||||
IDictionary<string, string> queryStrings = null
|
||||
)
|
||||
{
|
||||
//
|
||||
if (attachBaseUrl)
|
||||
{
|
||||
//
|
||||
var baseUrl = BaseUrl;
|
||||
if (!baseUrl.EndsWith("/"))
|
||||
{
|
||||
baseUrl = $"{baseUrl}/";
|
||||
}
|
||||
|
||||
//
|
||||
url = $"{baseUrl}{url}";
|
||||
}
|
||||
|
||||
//
|
||||
// Add Route Payloads ...
|
||||
if (!@params.IsNull() && @params.Count > 0)
|
||||
|
||||
Reference in New Issue
Block a user