Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions dotnet/src/dotnetcore/GxPdfReportsCS/PDFReportItext8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.IO;
using System.Text;
using GeneXus;
using GeneXus.Http;
using GeneXus.Utils;
using iText.Barcodes;
using iText.Html2pdf;
using iText.Html2pdf.Resolver.Font;
Expand Down Expand Up @@ -481,16 +483,22 @@ public override void GxDrawBitMap(String bitmap, int left, int top, int right, i
{
if (!Path.IsPathRooted(bitmap))
{

image = new Image(ImageDataFactory.Create(defaultRelativePrepend + bitmap));
if (image == null)
if (PathUtil.IsAbsoluteUrl(bitmap))
{
bitmap = webAppDir + bitmap;
image = new Image(ImageDataFactory.Create(bitmap));
image = new Image(ImageDataFactory.Create(HttpHelper.DownloadFile(bitmap, out _)));
}
else
{
bitmap = defaultRelativePrepend + bitmap;
image = new Image(ImageDataFactory.Create(defaultRelativePrepend + bitmap));
if (image == null)
{
bitmap = webAppDir + bitmap;
image = new Image(ImageDataFactory.Create(bitmap));
}
else
{
bitmap = defaultRelativePrepend + bitmap;
}
}
}
else
Expand Down
45 changes: 27 additions & 18 deletions dotnet/src/dotnetcore/GxPdfReportsCS/PDFReportPDFPig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Font = System.Drawing.Font;
#endif
using System.IO;
using System.Net.Http;
using System.Text;
using GeneXus;
using UglyToad.PdfPig.Core;
Expand All @@ -27,6 +26,9 @@
using static UglyToad.PdfPig.Writer.PdfPageBuilder;
using PageSize = UglyToad.PdfPig.Content.PageSize;
using PdfRectangle = UglyToad.PdfPig.Core.PdfRectangle;
using System.Net;
using GeneXus.Http;
using GeneXus.Utils;

namespace GeneXus.Printer
{
Expand Down Expand Up @@ -227,24 +229,34 @@ public override void GxDrawBitMap(string bitmap, int left, int top, int right, i
{
try
{
byte[] imageBytes;
if (!Path.IsPathRooted(bitmap))
{

image = imageType == "jpeg" ? pageBuilder.AddJpeg(File.ReadAllBytes(defaultRelativePrepend + bitmap), position) : pageBuilder.AddPng(File.ReadAllBytes(defaultRelativePrepend + bitmap), position);
if (image == null)
if (PathUtil.IsAbsoluteUrl(bitmap))
{
bitmap = webAppDir + bitmap;
image = imageType == "jpeg" ? pageBuilder.AddJpeg(File.ReadAllBytes(bitmap), position) : pageBuilder.AddPng(File.ReadAllBytes(bitmap), position);
imageBytes = HttpHelper.DownloadFile(bitmap, out _);
}
else
{
bitmap = defaultRelativePrepend + bitmap;
string bitmapPath = Path.Combine(defaultRelativePrepend, bitmap);
if (File.Exists(bitmapPath))
{
imageBytes = File.ReadAllBytes(bitmapPath);
bitmap = bitmapPath;
}
else
{
bitmapPath = Path.Combine(webAppDir, bitmap);
imageBytes = File.ReadAllBytes(bitmapPath);
bitmap = bitmapPath;
}
}
}
else
{
image = imageType == "jpeg" ? pageBuilder.AddJpeg(File.ReadAllBytes(bitmap), position) : pageBuilder.AddPng(File.ReadAllBytes(bitmap), position);
imageBytes = File.ReadAllBytes(bitmap);
}
image = imageType == "jpeg" ? pageBuilder.AddJpeg(imageBytes, position) : pageBuilder.AddPng(imageBytes, position);
}
catch (Exception)
{
Expand Down Expand Up @@ -272,17 +284,14 @@ public override void GxDrawBitMap(string bitmap, int left, int top, int right, i
private AddedImage AddImageFromURL(string url, PdfRectangle position)
{
AddedImage image = null;
using (HttpClient httpClient = new HttpClient())
byte[] imageBytes = HttpHelper.DownloadFile(url, out HttpStatusCode statusCode);
try
{
byte[] imageBytes = httpClient.GetByteArrayAsync(url).Result;
try
{
image = pageBuilder.AddJpeg(imageBytes, position);
}
catch (Exception)
{
pageBuilder.AddPng(imageBytes, position);
}
image = pageBuilder.AddJpeg(imageBytes, position);
}
catch (Exception)
{
pageBuilder.AddPng(imageBytes, position);
}
if (image == null)
{
Expand Down
46 changes: 23 additions & 23 deletions dotnet/src/dotnetframework/GxClasses/Core/GXUtilsCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#if NETCORE
using Microsoft.AspNetCore.Http;
using GxClasses.Helpers;
using System.Net;
#endif
using System.Net;
using NodaTime;
using NUglify;
using NUglify.Html;
Expand All @@ -38,6 +38,11 @@
using GeneXus.Http;
using System.Security;
using System.Net.Http.Headers;
using System.Security.Policy;
using GeneXus.Http.Client;



#if NETCORE
using Image = GeneXus.Drawing.Image;
using GeneXus.Drawing;
Expand All @@ -51,6 +56,7 @@
#endif
using System.Net.Http;


namespace GeneXus.Utils
{
public class GxDefaultProps
Expand Down Expand Up @@ -5885,21 +5891,18 @@ private static Bitmap BitmapCreateFromStream(string filePathOrUrl)
Uri uri;
if (Uri.TryCreate(filePathOrUrl, UriKind.Absolute, out uri) && (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps))
{
using (HttpClient httpClient = new HttpClient())
try
{
try
byte[] data = HttpHelper.DownloadFile(uri.AbsoluteUri, out HttpStatusCode statusCode);
using (MemoryStream mem = new MemoryStream(data))
{
byte[] data = httpClient.GetByteArrayAsync(uri).Result;
using (MemoryStream mem = new MemoryStream(data))
{
return new Bitmap(mem);
}
}
catch
{
return null;
return new Bitmap(mem);
}
}
catch
{
return null;
}
}
else
{
Expand All @@ -5917,21 +5920,18 @@ private static Image ImageCreateFromStream(string filePathOrUrl)
Uri uri;
if (Uri.TryCreate(filePathOrUrl, UriKind.Absolute, out uri) && (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps))
{
using (HttpClient httpClient = new HttpClient())
try
{
try
{
byte[] data = httpClient.GetByteArrayAsync(uri).Result;
using (MemoryStream mem = new MemoryStream(data))
{
return Image.FromStream(mem);
}
}
catch
byte[] data = HttpHelper.DownloadFile(uri.AbsoluteUri, out HttpStatusCode statusCode);
using (MemoryStream mem = new MemoryStream(data))
{
return null;
return Image.FromStream(mem);
}
}
catch
{
return null;
}
}
else
{
Expand Down
12 changes: 12 additions & 0 deletions dotnet/src/dotnetframework/GxClasses/Core/gxconfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ public class Preferences
public static string DefaultRewriteFile = "rewrite.config";
const string USE_NAMED_PARAMETERS = "UseNamedParameters";
const string REST_DATES_WITH_MILLIS = "REST_DATES_WITH_MILLIS";
const string UserAgentHeader = "UserAgentHeader";
internal const string YES = "1";
internal const string NO = "0";
static string defaultDatastore;
Expand All @@ -875,6 +876,17 @@ internal static string AppMainNamespace
return nameSpace;
}
}
internal static string HttpClientUserAgent
{
get
{
if (Config.GetValueOrEnvironmentVarOf(UserAgentHeader, out string userAgent))
return userAgent;
else
return string.Empty;
}
}

internal static bool IsBeforeConnectEventConfigured()
{
return (Config.GetValueOf("EVENT_BEFORE_CONNECT", out string evtProcName) && !string.IsNullOrEmpty(evtProcName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2833,6 +2833,7 @@ static public object ConvertToExternal(Type to, Object i)
}
return o;
}
internal static bool IsNullOrEmpty(IList collection) => collection == null || collection.Count == 0;
}
public interface IGxCollectionConverter
{
Expand Down
40 changes: 26 additions & 14 deletions dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,50 +158,60 @@ private async Task<byte[]> ReceiveDataAsync()
}

private const int POOLED_CONNECTION_LIFETIME_MINUTES = 2;

internal static ConcurrentDictionary<string, HttpClient> _httpClientInstances = new ConcurrentDictionary<string, HttpClient>();
internal static HttpClient GetHttpClientInstance(Uri uri, out bool disposableInstance)
{
return GetHttpClientInstance(uri, 0, null, null, null, null, string.Empty, 0, out disposableInstance);
}
private static HttpClient GetHttpClientInstance(Uri URI, int timeout, ArrayList authCollection, ArrayList authProxyCollection, X509Certificate2Collection certificateCollection, List<string> fileCertificateCollection, string proxyHost, int proxyPort, out bool disposableInstance)
{
HttpClient client;
if (CacheableInstance(authCollection, authProxyCollection))
{
HttpClient value;
disposableInstance = false;
string key = HttpClientInstanceIdentifier(proxyHost, proxyPort, fileCertificateCollection, timeout);
if (_httpClientInstances.TryGetValue(key, out value))
if (_httpClientInstances.TryGetValue(key, out client))
{
GXLogging.Debug(log, $"Getting httpClient cached instance");
return value;
return client;
}
else
{
lock (syncRootHttpInstance)
{
if (_httpClientInstances.TryGetValue(key, out value))
if (_httpClientInstances.TryGetValue(key, out client))
{
GXLogging.Debug(log, $"Getting httpClient cached instance");
return value;
return client;
}
client = new HttpClient(GetHandler(URI, authCollection, authProxyCollection, certificateCollection, proxyHost, proxyPort));
if (timeout != 0)
{
client.Timeout = TimeSpan.FromMilliseconds(timeout);
}
value = new HttpClient(GetHandler(URI, authCollection, authProxyCollection, certificateCollection, proxyHost, proxyPort));
value.Timeout = TimeSpan.FromMilliseconds(timeout);
_httpClientInstances.TryAdd(key, value);
return value;
_httpClientInstances.TryAdd(key, client);
}
}
}
else
{
disposableInstance = true;
return new HttpClient(GetHandler(URI, authCollection, authProxyCollection, certificateCollection, proxyHost, proxyPort));
client = new HttpClient(GetHandler(URI, authCollection, authProxyCollection, certificateCollection, proxyHost, proxyPort));
}
if (!string.IsNullOrEmpty(Preferences.HttpClientUserAgent))
client.DefaultRequestHeaders.UserAgent.ParseAdd(Preferences.HttpClientUserAgent);
return client;
}

private static string HttpClientInstanceIdentifier(string proxyHost, int proxyPort, List<string> fileCertificateCollection, int timeout)
{
bool defaultSslOptions = ServicePointManager.ServerCertificateValidationCallback == null;
if (string.IsNullOrEmpty(proxyHost) && fileCertificateCollection.Count==0 && timeout== DEFAULT_TIMEOUT && defaultSslOptions)
if (string.IsNullOrEmpty(proxyHost) && CollectionUtils.IsNullOrEmpty(fileCertificateCollection) && timeout== DEFAULT_TIMEOUT && defaultSslOptions)
{
return string.Empty;
}
else if (fileCertificateCollection.Count==0)
else if (CollectionUtils.IsNullOrEmpty(fileCertificateCollection))
{
return $"{proxyHost}:{proxyPort}::{timeout}:{defaultSslOptions}";
}
Expand All @@ -213,7 +223,7 @@ private static string HttpClientInstanceIdentifier(string proxyHost, int proxyPo

private static bool CacheableInstance(ArrayList authCollection, ArrayList authProxyCollection)
{
return authCollection.Count == 0 && authProxyCollection.Count == 0 && Preferences.SingletonHttpClient();
return CollectionUtils.IsNullOrEmpty(authCollection) && CollectionUtils.IsNullOrEmpty(authProxyCollection) && Preferences.SingletonHttpClient();
}
private static SocketsHttpHandler GetHandler(Uri URI, ArrayList authCollection, ArrayList authProxyCollection, X509Certificate2Collection certificateCollection, string proxyHost, int proxyPort)
{
Expand All @@ -239,7 +249,7 @@ private static SocketsHttpHandler GetHandler(Uri URI, ArrayList authCollection,
{
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
}
if (certificateCollection.Count > 0)
if (!CollectionUtils.IsNullOrEmpty(certificateCollection))
{
if (handler.SslOptions.ClientCertificates == null)
{
Expand Down Expand Up @@ -1590,6 +1600,8 @@ static ICredentials getCredentialCache(Uri URI, ArrayList authenticationCollecti
string sScheme;
GxAuthScheme auth;
CredentialCache cc = null;
if (CollectionUtils.IsNullOrEmpty(authenticationCollection))
return null;

for (int i = 0; i < authenticationCollection.Count; i++)
{
Expand Down
Loading
Loading