Halfbax
Halfbax
CC#
Created by Halfbax on 6/12/2024 in #help
Pipe is being closed. Trying to pass request body to php process
I found the main issue. The script sets the header location and this is not supported. I have removed the php script and replaced it with html/js + api. Thanks for help. Even we havnt found a solution I have learned few new things. The solution (havnt tried yet) is to call the fastcgi service e.g. php-fpm, but there is no active maintained wrapper for .net
13 replies
CC#
Created by Halfbax on 6/12/2024 in #help
Pipe is being closed. Trying to pass request body to php process
Process.Start() returned true. I have moved over to CliWrap. Thats my code. Sadly same result, blank screen while executing a script with a body
private async Task ExecutePhpFileAsync(HttpContext context, string filePath)
{
try
{
Dictionary<string, string?> environmentVariables = new()
{
["REQUEST_METHOD"] = context.Request.Method,
["QUERY_STRING"] = context.Request.QueryString.ToString(),
["SCRIPT_FILENAME"] = filePath,
["SCRIPT_NAME"] = context.Request.Path,
["REQUEST_URI"] = context.Request.Path + context.Request.QueryString,
["DOCUMENT_ROOT"] = _rootPath,
["REMOTE_ADDR"] = context.Connection.RemoteIpAddress?.ToString() ?? string.Empty,
["REMOTE_PORT"] = context.Connection.RemotePort.ToString(),
["SERVER_PROTOCOL"] = context.Request.Protocol
};

PipeSource inputPipe = PipeSource.FromStream(context.Request.Body);

Command cmd = Cli.Wrap(_phpInterpreterPath)
.WithArguments(args => args.Add(filePath))
.WithStandardInputPipe(inputPipe)
.WithEnvironmentVariables(environmentVariables);

BufferedCommandResult result = await cmd.ExecuteBufferedAsync();

if (result.StandardError != string.Empty)
{
_logger.LogError(result.StandardError);
}

if (!context.Response.HasStarted)
{
context.Response.ContentType = "text/html";
await context.Response.WriteAsync(result.StandardOutput);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "An error occurred while executing the PHP file.");

if (!context.Response.HasStarted)
{
context.Response.StatusCode = 500;
await context.Response.WriteAsync("An internal server error occurred.");
}
}
}
private async Task ExecutePhpFileAsync(HttpContext context, string filePath)
{
try
{
Dictionary<string, string?> environmentVariables = new()
{
["REQUEST_METHOD"] = context.Request.Method,
["QUERY_STRING"] = context.Request.QueryString.ToString(),
["SCRIPT_FILENAME"] = filePath,
["SCRIPT_NAME"] = context.Request.Path,
["REQUEST_URI"] = context.Request.Path + context.Request.QueryString,
["DOCUMENT_ROOT"] = _rootPath,
["REMOTE_ADDR"] = context.Connection.RemoteIpAddress?.ToString() ?? string.Empty,
["REMOTE_PORT"] = context.Connection.RemotePort.ToString(),
["SERVER_PROTOCOL"] = context.Request.Protocol
};

PipeSource inputPipe = PipeSource.FromStream(context.Request.Body);

Command cmd = Cli.Wrap(_phpInterpreterPath)
.WithArguments(args => args.Add(filePath))
.WithStandardInputPipe(inputPipe)
.WithEnvironmentVariables(environmentVariables);

BufferedCommandResult result = await cmd.ExecuteBufferedAsync();

if (result.StandardError != string.Empty)
{
_logger.LogError(result.StandardError);
}

if (!context.Response.HasStarted)
{
context.Response.ContentType = "text/html";
await context.Response.WriteAsync(result.StandardOutput);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "An error occurred while executing the PHP file.");

if (!context.Response.HasStarted)
{
context.Response.StatusCode = 500;
await context.Response.WriteAsync("An internal server error occurred.");
}
}
}
13 replies
CC#
Created by Halfbax on 6/12/2024 in #help
Pipe is being closed. Trying to pass request body to php process
HasExited is true. That seems to be the problem. Now I have to check how can I let the process wait for my inputs
13 replies
CC#
Created by Halfbax on 6/12/2024 in #help
Pipe is being closed. Trying to pass request body to php process
using StreamReader reader = new(context.Request.Body, Encoding.UTF8);
string requestBody = await reader.ReadToEndAsync();
await phpProcess.StandardInput.WriteAsync(requestBody);
// await phpProcess.StandardInput.FlushAsync();
using StreamReader reader = new(context.Request.Body, Encoding.UTF8);
string requestBody = await reader.ReadToEndAsync();
await phpProcess.StandardInput.WriteAsync(requestBody);
// await phpProcess.StandardInput.FlushAsync();
13 replies
CC#
Created by Halfbax on 6/12/2024 in #help
Pipe is being closed. Trying to pass request body to php process
My fault, but hasnt changed anything. The exception occurs on the write method. Same for this one:
13 replies
CC#
Created by Halfbax on 6/12/2024 in #help
Pipe is being closed. Trying to pass request body to php process
@occluder Like this?
if (context.Request.ContentLength > 0 || context.Request.ContentType != null)
{
using MemoryStream memoryStream = new();
await context.Request.Body.CopyToAsync(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);

await phpProcess.StandardInput.BaseStream.WriteAsync(memoryStream.ToArray(), 0, (int)memoryStream.Length);
await phpProcess.StandardInput.FlushAsync();
}
if (context.Request.ContentLength > 0 || context.Request.ContentType != null)
{
using MemoryStream memoryStream = new();
await context.Request.Body.CopyToAsync(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);

await phpProcess.StandardInput.BaseStream.WriteAsync(memoryStream.ToArray(), 0, (int)memoryStream.Length);
await phpProcess.StandardInput.FlushAsync();
}
Same exception
The pipe is being closed.

at System.IO.RandomAccess.WriteAtOffset(SafeFileHandle handle, ReadOnlySpan`1 buffer, Int64 fileOffset)
at System.IO.RandomAccess.<>c.<WriteAtOffsetAsync>b__21_0(ValueTuple`4 state)
at System.Threading.AsyncOverSyncWithIoCancellation.InvokeAsync[TState](Action`1 action, TState state, CancellationToken cancellationToken)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.IO.Strategies.BufferedFileStreamStrategy.WriteToNonSeekableAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)
at ProjectName.ReverseProxy.Middlewares.PhpMiddleware.ExecutePhpFileAsync(HttpContext context, String filePath)
The pipe is being closed.

at System.IO.RandomAccess.WriteAtOffset(SafeFileHandle handle, ReadOnlySpan`1 buffer, Int64 fileOffset)
at System.IO.RandomAccess.<>c.<WriteAtOffsetAsync>b__21_0(ValueTuple`4 state)
at System.Threading.AsyncOverSyncWithIoCancellation.InvokeAsync[TState](Action`1 action, TState state, CancellationToken cancellationToken)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.IO.Strategies.BufferedFileStreamStrategy.WriteToNonSeekableAsync(ReadOnlyMemory`1 source, CancellationToken cancellationToken)
at ProjectName.ReverseProxy.Middlewares.PhpMiddleware.ExecutePhpFileAsync(HttpContext context, String filePath)
13 replies
CC#
Created by Halfbax on 5/3/2024 in #help
Publish Failure of Class Library with WinAppSdk dependency
I added the flag to publish WinAppSdk in self-contained mode in the .csproj of the class library. Now I'm encountering the error:
error : The platform 'AnyCPU' is not supported for Self Contained mode.
error : The platform 'AnyCPU' is not supported for Self Contained mode.
This issue is puzzling because the platform is indeed set to win-x64.
2 replies
CC#
Created by Halfbax on 9/15/2023 in #help
❔ Mapperly | How to map a property?
Yea it's specific to Mapperly
5 replies
CC#
Created by EsoEnjoyer on 6/30/2023 in #help
❔ guys who can help me with run on .net service
ora-01017 seems to be wrong username/password. Can you check that? Verify the connection string
3 replies
CC#
Created by Halfbax on 6/30/2023 in #help
❔ Calculating estimated time is inaccurate
The new class works great but the code smells imo. Any suggestions for improvement?
public class WorkerTime
{
/// <summary>
/// Total amount of jobs
/// </summary>
public int Total { get; }

/// <summary>
/// Amount of jobs done
/// </summary>
public int Done { get; private set; }

/// <summary>
/// Estimated remaining time
/// </summary>
public TimeSpan TimeRemaining { get; private set; } = TimeSpan.Zero;

private readonly Stopwatch _totalWatch = new();
private readonly Stopwatch _taskWatch = new();

public WorkerTime(int jobs)
{
Total = jobs;
_totalWatch.Start();
_taskWatch.Start();
}

public void CalculateRemainingTime()
{
Done++;

long timeRemaining = _taskWatch.ElapsedMilliseconds * (Total - Done);
TimeRemaining = TimeSpan.FromMilliseconds(timeRemaining);

_taskWatch.Restart();
}

public TimeSpan Stop()
{
_totalWatch.Stop();
_taskWatch.Stop();

return _totalWatch.Elapsed;
}
}
public class WorkerTime
{
/// <summary>
/// Total amount of jobs
/// </summary>
public int Total { get; }

/// <summary>
/// Amount of jobs done
/// </summary>
public int Done { get; private set; }

/// <summary>
/// Estimated remaining time
/// </summary>
public TimeSpan TimeRemaining { get; private set; } = TimeSpan.Zero;

private readonly Stopwatch _totalWatch = new();
private readonly Stopwatch _taskWatch = new();

public WorkerTime(int jobs)
{
Total = jobs;
_totalWatch.Start();
_taskWatch.Start();
}

public void CalculateRemainingTime()
{
Done++;

long timeRemaining = _taskWatch.ElapsedMilliseconds * (Total - Done);
TimeRemaining = TimeSpan.FromMilliseconds(timeRemaining);

_taskWatch.Restart();
}

public TimeSpan Stop()
{
_totalWatch.Stop();
_taskWatch.Stop();

return _totalWatch.Elapsed;
}
}
10 replies
CC#
Created by Halfbax on 6/30/2023 in #help
❔ Calculating estimated time is inaccurate
Thanks. I will change that.
10 replies
CC#
Created by Halfbax on 5/26/2023 in #help
❔ JSON serialization fails
🙂
8 replies
CC#
Created by Halfbax on 5/26/2023 in #help
❔ JSON serialization fails
Thanks. That's works
8 replies
CC#
Created by Halfbax on 5/26/2023 in #help
❔ JSON serialization fails
Sadly I am unable to change the json.
8 replies
CC#
Created by Halfbax on 2/23/2023 in #help
❔ Unpackaged WinUI 3 app raises 0xc000027b after publish
In the csproj I do use this line to public to succeed the publish
<!--Workaround-->
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
<!--Workaround-->
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
3 replies
CC#
Created by Halfbax on 2/7/2023 in #help
❔ Does Grpc works with net7 on IIS?
Do you have an idea how to debug it on the server?
11 replies
CC#
Created by Halfbax on 2/7/2023 in #help
❔ Does Grpc works with net7 on IIS?
I was trying to implement cors but that was dumb. The 500 isnt occuring anymore, but I dont get any result now
11 replies
CC#
Created by Halfbax on 2/7/2023 in #help
❔ Does Grpc works with net7 on IIS?
Any ideas why the grpc service isnt working after publishing?
11 replies
CC#
Created by Halfbax on 2/7/2023 in #help
❔ Does Grpc works with net7 on IIS?
Good to know
11 replies
CC#
Created by Halfbax on 2/7/2023 in #help
❔ Does Grpc works with net7 on IIS?
oops
11 replies