Halfbax
Halfbax
CC#
Created by Halfbax on 6/28/2024 in #help
Set animation class in blazor doesnt work.
Animations don't work if I set them as variables, see example. If I set them with JavaScript Interop, they work. Can someone explain why this happens?
private async Task SetTransitionStateAsync(TransitionState state, int animationDelay)
{
string translationPrefix = $"transition-opacity ease-linear duration-{animationDelay}";

CurrentState = state;
switch (CurrentState)
{
case TransitionState.Hidden:
TransitionClass = string.Empty;
IsVisible = false;
break;
case TransitionState.Open:
TransitionClass = string.Empty;
break;
case TransitionState.EnteringStart:
TransitionClass = $"{translationPrefix} -translate-x-full";
IsVisible = true;
break;
case TransitionState.EnteringEnd:
TransitionClass = $"{translationPrefix} translate-x-0";
break;
case TransitionState.LeavingStart:
TransitionClass = $"{translationPrefix} translate-x-0";
break;
case TransitionState.LeavingEnd:
TransitionClass = $"{translationPrefix} -translate-x-full";
break;
}

await InvokeAsync(StateHasChanged);
}
private async Task SetTransitionStateAsync(TransitionState state, int animationDelay)
{
string translationPrefix = $"transition-opacity ease-linear duration-{animationDelay}";

CurrentState = state;
switch (CurrentState)
{
case TransitionState.Hidden:
TransitionClass = string.Empty;
IsVisible = false;
break;
case TransitionState.Open:
TransitionClass = string.Empty;
break;
case TransitionState.EnteringStart:
TransitionClass = $"{translationPrefix} -translate-x-full";
IsVisible = true;
break;
case TransitionState.EnteringEnd:
TransitionClass = $"{translationPrefix} translate-x-0";
break;
case TransitionState.LeavingStart:
TransitionClass = $"{translationPrefix} translate-x-0";
break;
case TransitionState.LeavingEnd:
TransitionClass = $"{translationPrefix} -translate-x-full";
break;
}

await InvokeAsync(StateHasChanged);
}
1 replies
CC#
Created by Halfbax on 6/12/2024 in #help
Pipe is being closed. Trying to pass request body to php process
I am trying to open a php process in my kestrel middleware. Without body everything works fine, but sending a body throws the exception Pipe is being closed. Do you know why?
try
{
Process phpProcess = new()
{
StartInfo = new ProcessStartInfo
{
FileName = _phpInterpreterPath,
Arguments = $"\"{filePath}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
UseShellExecute = false,
CreateNoWindow = true,
Environment =
{
// ENV VARS
}
}
};

phpProcess.Start();

// Pass the request body to the PHP process
if (context.Request.ContentLength > 0 || context.Request.ContentType != null)
{
await using StreamWriter sw = new(phpProcess.StandardInput.BaseStream);
await context.Request.Body.CopyToAsync(sw.BaseStream);
await sw.FlushAsync(); // EXCEPTION IS BEING THROWN HERE
}

// Capture the output and errors
var outputTask = phpProcess.StandardOutput.ReadToEndAsync();
var errorTask = phpProcess.StandardError.ReadToEndAsync();

await phpProcess.WaitForExitAsync();

// RESPONSE HANDLING
}
catch (Exception ex)
{
// EXCEPTION HANDLING
}
try
{
Process phpProcess = new()
{
StartInfo = new ProcessStartInfo
{
FileName = _phpInterpreterPath,
Arguments = $"\"{filePath}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
UseShellExecute = false,
CreateNoWindow = true,
Environment =
{
// ENV VARS
}
}
};

phpProcess.Start();

// Pass the request body to the PHP process
if (context.Request.ContentLength > 0 || context.Request.ContentType != null)
{
await using StreamWriter sw = new(phpProcess.StandardInput.BaseStream);
await context.Request.Body.CopyToAsync(sw.BaseStream);
await sw.FlushAsync(); // EXCEPTION IS BEING THROWN HERE
}

// Capture the output and errors
var outputTask = phpProcess.StandardOutput.ReadToEndAsync();
var errorTask = phpProcess.StandardError.ReadToEndAsync();

await phpProcess.WaitForExitAsync();

// RESPONSE HANDLING
}
catch (Exception ex)
{
// EXCEPTION HANDLING
}
13 replies
CC#
Created by Halfbax on 5/3/2024 in #help
Publish Failure of Class Library with WinAppSdk dependency
I have added a class library that references WinAppSDK. Now I am unable to publish my program. I don't encounter any errors while building, only while publishing.
Cannot resolve Assembly or Windows Metadata file 'I:\projects\Name\Shared\Name.Core\bin\Debug\net8.0-windows10.0.22621\win-x64\Name.Windows.Core.dll'
Cannot resolve Assembly or Windows Metadata file 'I:\projects\Name\Shared\Name.Core\bin\Debug\net8.0-windows10.0.22621\win-x64\Name.Windows.Core.dll'
Does the class library require any specific files, such as an app.manifest, to run since I have referenced WinAppSdk?
2 replies
CC#
Created by Halfbax on 3/27/2024 in #help
Unable to publish WinUI due duplicated WebView2 package from MSIX tooling and nuget package
Hello, I am unable to publish my current software due duplicated packages. I do used a workaround in the past. But it isnt working anymore and I dont know why. WinAppSDK 1.5 Building works, publishing not. This is the workaround. https://github.com/unoplatform/uno/issues/14555#issuecomment-1876175425
1 replies
CC#
Created by Halfbax on 9/15/2023 in #help
❔ Mapperly | How to map a property?
How can I automatically map ExampleB when ExampleA getting mapped to InternalExampleA
[Mapper]
public class TestMapper
{
public partial InternalExampleA ToInternalA(ExampleA data);
public partial InternalExampleB ToInternalB(ExampleB data);
}

public class ExampleA
{
public Guid Id { get; set; }
public ExampleB B { get; set; }
}

public class InternalExampleA
{
public Guid Id { get; set; }
public ExampleB B { get; set; }
}

public class ExampleB
{
public Guid AnotherId { get; set; }
}

public class InternalExampleB
{
public Guid AnotherId { get; set; }
}
[Mapper]
public class TestMapper
{
public partial InternalExampleA ToInternalA(ExampleA data);
public partial InternalExampleB ToInternalB(ExampleB data);
}

public class ExampleA
{
public Guid Id { get; set; }
public ExampleB B { get; set; }
}

public class InternalExampleA
{
public Guid Id { get; set; }
public ExampleB B { get; set; }
}

public class ExampleB
{
public Guid AnotherId { get; set; }
}

public class InternalExampleB
{
public Guid AnotherId { get; set; }
}
5 replies
CC#
Created by Halfbax on 6/30/2023 in #help
❔ Calculating estimated time is inaccurate
Hello, I try to calculate the remaining time. The problem is that the estimated remaining time is pretty inaccurate. The class says that each job takes around 7 seconds, but it is around ~1 second. What might the problem here? Is it because I do use seconds over milliseconds?
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 DateTime Start { get; } = DateTime.UtcNow;

public WorkerTime(int jobs)
{
Total = jobs;
}

public void Execute()
{
Done++;

TimeSpan timeTaken = DateTime.UtcNow - Start;
int jobsLeft = Total - Done;

int totalSeconds = (int)timeTaken.TotalSeconds;

if (totalSeconds == 0)
return;

int timeRemaining = Done / totalSeconds * jobsLeft;
TimeRemaining = TimeSpan.FromSeconds(timeRemaining);
}

public TimeSpan Stop()
{
return DateTime.UtcNow - Start;
}
}
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 DateTime Start { get; } = DateTime.UtcNow;

public WorkerTime(int jobs)
{
Total = jobs;
}

public void Execute()
{
Done++;

TimeSpan timeTaken = DateTime.UtcNow - Start;
int jobsLeft = Total - Done;

int totalSeconds = (int)timeTaken.TotalSeconds;

if (totalSeconds == 0)
return;

int timeRemaining = Done / totalSeconds * jobsLeft;
TimeRemaining = TimeSpan.FromSeconds(timeRemaining);
}

public TimeSpan Stop()
{
return DateTime.UtcNow - Start;
}
}
10 replies
CC#
Created by Halfbax on 5/26/2023 in #help
❔ JSON serialization fails
After the serialization RiotChampionWrapper.Champions is null. The problem might be that each item has a different name. How can I fix it?
public class RiotChampionWrapper
{
[JsonPropertyName("data")]
private List<RiotChampion> Champions { get; set; }
}

public class RiotChampion
{
[JsonPropertyName("id")]
public string Id { get; set; }

[JsonPropertyName("key")]
public string Key { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }
}
public class RiotChampionWrapper
{
[JsonPropertyName("data")]
private List<RiotChampion> Champions { get; set; }
}

public class RiotChampion
{
[JsonPropertyName("id")]
public string Id { get; set; }

[JsonPropertyName("key")]
public string Key { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }
}
RiotChampionWrapper? items = JsonSerializer.Deserialize<RiotChampionWrapper>(data);
RiotChampionWrapper? items = JsonSerializer.Deserialize<RiotChampionWrapper>(data);
{
"type": "champion",
"format": "standAloneComplex",
"version": "13.10.1",
"data": {
"Aatrox": {
"id": "Aatrox",
"key": "266",
"name": "Aatrox"
},
"Ahri": {
"id": "Ahri",
"key": "103",
"name": "Ahri"
}
}
}
{
"type": "champion",
"format": "standAloneComplex",
"version": "13.10.1",
"data": {
"Aatrox": {
"id": "Aatrox",
"key": "266",
"name": "Aatrox"
},
"Ahri": {
"id": "Ahri",
"key": "103",
"name": "Ahri"
}
}
}
8 replies
CC#
Created by Halfbax on 2/23/2023 in #help
❔ Unpackaged WinUI 3 app raises 0xc000027b after publish
I do have a problem and I would like to use your help. My app is not starting after publishing it with following settings.
<?xml version="1.0" encoding="utf-8"?>

<Project>
<PropertyGroup>
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
<PublishDir>bin\Publish</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>

<Project>
<PropertyGroup>
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
<PublishDir>bin\Publish</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
</Project>
In the event viewer I can see that the exception 0xc000027b is raised.
3 replies
CC#
Created by Halfbax on 2/14/2023 in #help
❔ Data doesnt get set with DispatcherQueue.TryEnqueue()
I try to get my camera feed with opencv on a non UI thread in WinUI 3. It's weird the data gets pushed into the queue, but the function doesn't get fired. I start CaptureAsync with Task.Run() because when I start it with CaptureAsync().ConfigureAwait(false); the UI gets blocked even with Task.Yield.
private async Task CaptureAsync()
{
_cts.TryReset();

if (CurrentSource is null)
return;

DispatcherQueue? queue = DispatcherQueue.GetForCurrentThread();
try
{
_capture = VideoCapture.FromCamera(CurrentSource.Id);

byte[] data;
while (!_cts.IsCancellationRequested)
{
using Mat? image = _capture.RetrieveMat();

if (image.Height <= 0)
continue;

data = image.ToBytes();
queue?.TryEnqueue(() => SetData(data)); // data != null, checked

await Task.Yield();
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}

// doesnt get fired once
private void SetData(byte[] data)
=> CurrentFrame = data;
private async Task CaptureAsync()
{
_cts.TryReset();

if (CurrentSource is null)
return;

DispatcherQueue? queue = DispatcherQueue.GetForCurrentThread();
try
{
_capture = VideoCapture.FromCamera(CurrentSource.Id);

byte[] data;
while (!_cts.IsCancellationRequested)
{
using Mat? image = _capture.RetrieveMat();

if (image.Height <= 0)
continue;

data = image.ToBytes();
queue?.TryEnqueue(() => SetData(data)); // data != null, checked

await Task.Yield();
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}

// doesnt get fired once
private void SetData(byte[] data)
=> CurrentFrame = data;
I do have two options. Fix the Task.Yield() problem or let it run on a secondary thread and fix the queue data. What would you do?
2 replies
CC#
Created by Halfbax on 2/7/2023 in #help
❔ Does Grpc works with net7 on IIS?
11 replies
CC#
Created by Halfbax on 2/2/2023 in #help
❔ Custom "block" statement such as while..do
Hello, is it possible to build a custom block? For example
// usage
DoRequestAsync
{
Categories = await _stockBrowser.GetCategoriesAsync();
}

// code behind DoRequest
private async Task DoRequestAsync()
{
try
{
// children
}
catch (Exception e)
{
Console.WriteLine(e);
Error = true;
}
}
// usage
DoRequestAsync
{
Categories = await _stockBrowser.GetCategoriesAsync();
}

// code behind DoRequest
private async Task DoRequestAsync()
{
try
{
// children
}
catch (Exception e)
{
Console.WriteLine(e);
Error = true;
}
}
10 replies
CC#
Created by Halfbax on 2/1/2023 in #help
❔ Predicate in LINQ GroupBy
Hello, how can I replace item.Name with the predicate?
public static ObservableCollection<GroupInfo> Create<TData>(IEnumerable<TData> data, Expression<Func<TData, string>> predicate)
where TData : class
{
IEnumerable<GroupInfo> query = data
.GroupBy(item => item.Name.ToUpper())
.OrderBy(g => g.Key)
.Select(g => new GroupInfo(g.Key, g));

return new ObservableCollection<GroupInfo>(query);
}
public static ObservableCollection<GroupInfo> Create<TData>(IEnumerable<TData> data, Expression<Func<TData, string>> predicate)
where TData : class
{
IEnumerable<GroupInfo> query = data
.GroupBy(item => item.Name.ToUpper())
.OrderBy(g => g.Key)
.Select(g => new GroupInfo(g.Key, g));

return new ObservableCollection<GroupInfo>(query);
}
26 replies
CC#
Created by Halfbax on 11/16/2022 in #help
❔ Getting exe path of entry point
I do have a WinUI 3 project and I am unable to retrieve the exe path of my application. That's what I have tried. But I get the dll only.
string? target = Assembly.GetAssembly(typeof(App))?.GetName().CodeBase;
// returns the dll path instead of the exe
string? target = Assembly.GetAssembly(typeof(App))?.GetName().CodeBase;
// returns the dll path instead of the exe
18 replies
CC#
Created by Halfbax on 8/31/2022 in #help
XAML Binding error, cannot find source
Hello, I do get a binding error when trying to bind a string from codebehind as content of a ComboBoxItem in CompositeCollection.
<ComboBox.ItemsSource>
<CompositeCollection>
<ComboBoxItem Visibility="Collapsed" Content="{Binding Test, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MultiSelectionDropdown}}}"/>
<CollectionContainer Collection="{Binding Source={StaticResource ResourceKey=Pipeline}}"/>
</CompositeCollection>
</ComboBox.ItemsSource>
<ComboBox.ItemsSource>
<CompositeCollection>
<ComboBoxItem Visibility="Collapsed" Content="{Binding Test, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MultiSelectionDropdown}}}"/>
<CollectionContainer Collection="{Binding Source={StaticResource ResourceKey=Pipeline}}"/>
</CompositeCollection>
</ComboBox.ItemsSource>
I am trying to bind Test.
3 replies