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
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public async Task Invoke(HttpContext context)
IHttpHandler handler=null;
string url = string.Empty;
try
{
//context.Request.EnableBuffering(); does not work in 3.1
{
context.NewSessionCheck();
url = context.Request.Path.Value;

Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/dotnetframework/GxClasses/Core/gxconfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ public static string getTMP_MEDIA_PATH()
}
if (!String.IsNullOrEmpty(mediaPath))
defaultPath = false;
if (GXServices.Instance == null || GXServices.Instance.Get(GXServices.STORAGE_SERVICE) == null)
if (ServiceFactory.GetExternalProvider() == null)
{
if (defaultPath || !Path.IsPathRooted(mediaPath))
mediaPath = Path.Combine(GxContext.StaticPhysicalPath(), mediaPath) + Path.DirectorySeparatorChar;
Expand Down Expand Up @@ -1228,7 +1228,7 @@ public static string getBLOB_PATH()
if (String.IsNullOrEmpty(blobPath) || !Path.IsPathRooted(blobPath))
{
blobPathFolderName = String.IsNullOrEmpty(blobPath) ? blobPath : blobPath.TrimEnd('/', '\\').TrimStart('/', '\\');
if (GXServices.Instance == null || GXServices.Instance.Get(GXServices.STORAGE_SERVICE) == null)
if (ServiceFactory.GetExternalProvider() == null)
{
blobPath = Path.Combine(GxContext.StaticPhysicalPath(), blobPath);
if (blobPath[blobPath.Length - 1] != Path.DirectorySeparatorChar)
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/dotnetframework/GxClasses/Data/GXDataCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ protected static byte[] GetBinary(string fileNameParm, bool dbBlob)
{
Uri uri;
string fileName = fileNameParm;
bool inLocalStorage = dbBlob || GXServices.Instance == null || GXServices.Instance.Get(GXServices.STORAGE_SERVICE) == null;
bool inLocalStorage = dbBlob || ServiceFactory.GetExternalProvider() == null;
bool validFileName = !String.IsNullOrEmpty(fileName) && !String.IsNullOrEmpty(fileName.Trim()) && String.Compare(fileName, "about:blank", false) != 0;
byte[] binary = Array.Empty<byte>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public void SetParameterMultimedia(int id, string parm, string multimediaParm)
public void SetParameterMultimedia(int id, string image_gxi, string image, string tableName, string fieldName)
{
GXLogging.Debug(log, "SetParameterMultimedia image_gxi:", image_gxi + " image:" + image);
bool storageServiceEnabled = !string.IsNullOrEmpty(tableName) && !string.IsNullOrEmpty(fieldName) && (GXServices.Instance != null && GXServices.Instance.Get(GXServices.STORAGE_SERVICE) != null);
bool storageServiceEnabled = !string.IsNullOrEmpty(tableName) && !string.IsNullOrEmpty(fieldName) && (ServiceFactory.GetExternalProvider() != null);
string imageUploadName=image;
if (GxUploadHelper.IsUpload(image))
{
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/dotnetframework/GxClasses/Domain/GXFileIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ public GxFile(string baseDirectory, string fileName, GxFileType fileType = GxFil
fileName = GxUploadHelper.UploadPath(fileName);
}
fileName = fileName.Trim();
if ((GXServices.Instance != null && GXServices.Instance.Get(GXServices.STORAGE_SERVICE) != null) && !Path.IsPathRooted(fileName))
if ((ServiceFactory.GetExternalProvider() != null) && !Path.IsPathRooted(fileName))
_file = new GxExternalFileInfo(fileName, ServiceFactory.GetExternalProvider(), fileType);
else
_file = new GxFileInfo(fileName, baseDirectory);
Expand Down Expand Up @@ -1577,7 +1577,7 @@ public class GxDirectory
string _baseDirectory;
int _lastError;
string _lastErrorDescription;
bool _externalStorage = GXServices.Instance != null && GXServices.Instance.Get(GXServices.STORAGE_SERVICE) != null;
bool _externalStorage = ServiceFactory.GetExternalProvider() != null;

public GxDirectory(string baseDirectory)
{
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/dotnetframework/GxClasses/Helpers/HttpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,10 @@ public static string GetRawBodyString(this HttpRequest request, Encoding encodin
#endif
public static string GetRawUrl(this HttpRequest request)
{
#if NETCORE
#if NETCORE
var httpContext = request.HttpContext;
var requestFeature = httpContext.Features.Get<IHttpRequestFeature>();
return requestFeature.RawTarget;
return !string.IsNullOrEmpty(requestFeature.RawTarget) ? requestFeature.RawTarget: request.GetEncodedPathAndQuery();
#else
return request.RawUrl;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ public GXObjectUploadServices()
public GXObjectUploadServices(IGxContext ctx)
{
this.context = ctx;
#if NETCORE
localHttpContext.Request.EnableBuffering();
#endif
}

public override void webExecute()
Expand Down Expand Up @@ -329,8 +332,12 @@ public override void webExecute()
localHttpContext.Response.Write(jsonObj);
}
else
{
WcfExecute(localHttpContext.Request.GetInputStream(), localHttpContext.Request.ContentType, (long)localHttpContext.Request.ContentLength);
{
#if NETCORE
WcfExecute(localHttpContext.Request.Body, localHttpContext.Request.ContentType, (long)localHttpContext.Request.ContentLength);
#else
WcfExecute(localHttpContext.Request.GetBufferedInputStream(), localHttpContext.Request.ContentType, (long)localHttpContext.Request.ContentLength);
#endif
}
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public static GXServices Instance
}
return s_instance;
}
set { }
}

public void AddService(string name, GXService service)
{
services[name] = service;
}

public static void LoadFromFile(string fileName, ref GXServices services)
Expand Down Expand Up @@ -121,9 +127,9 @@ private void ProcessService(GXXMLReader reader)
service.Properties = properties;
service.AllowMultiple = string.IsNullOrEmpty(allowMultiple) ? false : bool.Parse(allowMultiple);
if (service.AllowMultiple)
services[$"{service.Type}:{service.Name}"] = service;
AddService($"{service.Type}:{service.Name}", service);
else
services[type] = service;
AddService(type, service);

}

Expand Down Expand Up @@ -196,6 +202,11 @@ public static ExternalProvider GetExternalProvider()
return externalProvider;
}

public static void SetExternalProvider(ExternalProvider provider)
{
externalProvider = provider;
}

public static ExternalProvider GetExternalProviderImpl(string service)
{
ExternalProvider externalProviderImpl = null;
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/dotnetframework/GxExcel/GxExcelI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public String Template
}
set
{
bool storageEnabled = GXServices.Instance != null && GXServices.Instance.Get(GXServices.STORAGE_SERVICE) != null;
bool storageEnabled = ServiceFactory.GetExternalProvider() != null;
template = value;
if (storageEnabled)
{
Expand Down Expand Up @@ -231,7 +231,7 @@ public short Open(String xlName)
closed = false;
try
{
if (GXServices.Instance == null || GXServices.Instance.Get(GXServices.STORAGE_SERVICE) == null)
if (ServiceFactory.GetExternalProvider() == null)
{
if (!Path.IsPathRooted(this.fileName))
this.fileName = Path.Combine(GxContext.StaticPhysicalPath(), this.fileName);
Expand Down
6 changes: 6 additions & 0 deletions dotnet/test/DotNetCoreUnitTest/DotNetCoreUnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
<None Update="apps\append.svc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="apps\saveimage.svc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="confmapping.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -149,6 +152,9 @@
<None Update="resources\text.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="uruguay.flag.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>


Expand Down
83 changes: 79 additions & 4 deletions dotnet/test/DotNetCoreUnitTest/Middleware/RestServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Text.Json;
using System.Threading.Tasks;
using GeneXus.Http;
using GeneXus.Metadata;
using GeneXus.Services;
using GeneXus.Storage.GXAmazonS3;
using GeneXus.Utils;
using Microsoft.AspNetCore.Http;
using Xunit;
namespace xUnitTesting
{
public class RestServiceTest : MiddlewareTest
{
public RestServiceTest():base()
public RestServiceTest() : base()
{
ClassLoader.FindType("apps.append", "GeneXus.Programs.apps", "append", Assembly.GetExecutingAssembly(), true);//Force loading assembly for append procedure
server.AllowSynchronousIO=true;
ClassLoader.FindType("apps.saveimage", "GeneXus.Programs.apps", "saveimage", Assembly.GetExecutingAssembly(), true);//Force loading assembly for saveimage procedure
server.AllowSynchronousIO = true;
}

[Fact]
public async Task TestMultiCall()
{
Expand All @@ -28,7 +35,75 @@ public async Task TestMultiCall()
string responseBody = await response.Content.ReadAsStringAsync();
Assert.Empty(responseBody);
}
[Fact(Skip="Non deterministic")]

[Fact]
public async Task TestSimpleRestPost()
{
server.AllowSynchronousIO = true;
HttpClient client = server.CreateClient();
StringContent body = new StringContent("{\"Image\":\"imageName\",\"ImageDescription\":\"imageDescription\"}");
HttpResponseMessage response = await client.PostAsync("rest/apps/saveimage", body);
response.EnsureSuccessStatusCode();
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
string responseBody = await response.Content.ReadAsStringAsync();
Assert.Equal("{}", responseBody);
}

[Fact(Skip = "Non deterministic")]
public async Task TestGxObjectUploads()
{
server.AllowSynchronousIO = true;
HttpClient client = server.CreateClient();
using (Stream s = System.IO.File.Open(@"uruguay.flag.png", FileMode.Open))
{
StreamContent streamContent = new StreamContent(s);
HttpResponseMessage response = await client.PutAsync("rest/apps/saveimage/gxobject", streamContent);
response.EnsureSuccessStatusCode();
string uploadPath = await GetObjectIdToken(response);
Assert.True(System.IO.File.Exists(uploadPath));
}
}

[SkippableFact]
public async Task TestGxObjectUploadsWithS3Storage()
{
bool testEnabled = Environment.GetEnvironmentVariable("AWSS3" + "_TEST_ENABLED") == "true";
Skip.IfNot(testEnabled, "Environment variables not set");

server.AllowSynchronousIO = true;
HttpClient client = server.CreateClient();

ExternalProviderS3 s3Provider = new ExternalProviderS3();
ServiceFactory.SetExternalProvider(s3Provider);

using (Stream s = System.IO.File.Open(@"uruguay.flag.png", FileMode.Open))
{
StreamContent streamContent = new StreamContent(s);
HttpResponseMessage response = await client.PutAsync("rest/apps/saveimage/gxobject", streamContent);
response.EnsureSuccessStatusCode();

string uploadUrl = await GetObjectIdToken(response);
response = await new HttpClient().GetAsync(uploadUrl);
response.EnsureSuccessStatusCode();
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
}
}

private static async Task<string> GetObjectIdToken(HttpResponseMessage response)
{

Assert.Equal(System.Net.HttpStatusCode.Created, response.StatusCode);
string responseBody = await response.Content.ReadAsStringAsync();
Dictionary<string, string> jsonObj = JsonSerializer.Deserialize<Dictionary<string, string>>(responseBody);

Assert.True(jsonObj.ContainsKey("object_id"));
string objId = jsonObj["object_id"];
Assert.NotEmpty(objId);
string uploadUrl = GxUploadHelper.UploadPath(objId);
return uploadUrl;
}

[Fact(Skip = "Non deterministic")]
public async Task MultithreadRestServiceAccess_ContextDisposed()
{
HttpClient client = server.CreateClient();
Expand All @@ -38,7 +113,7 @@ public async Task MultithreadRestServiceAccess_ContextDisposed()
{
tasks.Add(RunController(client));
}

await Task.WhenAll(tasks);
}

Expand Down
39 changes: 39 additions & 0 deletions dotnet/test/DotNetCoreUnitTest/apps/saveimage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using GeneXus.Application;
using GeneXus.Data.NTier;

using GeneXus.Procedure;
namespace GeneXus.Programs.apps
{
public class saveimage : GXProcedure
{
public saveimage()
{
context = new GxContext();
DataStoreUtil.LoadDataStores(context);
IsMain = true;
}

public saveimage(IGxContext context)
{
this.context = context;
IsMain = false;
}

public void execute(string aP0_ImageDescription, string aP1_Image)
{
System.Console.WriteLine("SaveImage executed:" + aP0_ImageDescription);
}

public override bool UploadEnabled()
{
return true;
}


public override void initialize()
{

}
}

}
1 change: 1 addition & 0 deletions dotnet/test/DotNetCoreUnitTest/apps/saveimage.svc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%@ServiceHost Service= "GeneXus.Programs.apps.saveimage, apps.saveimage" %>
Binary file added dotnet/test/DotNetCoreUnitTest/uruguay.flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.