Skip to content

Commit

Permalink
Update PipeAndFilter Package to 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Cerqueira committed Nov 10, 2023
1 parent 8e7758b commit 087e6a6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Samples/PipelineSamples/PipelineSamples.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PipeAndFilter" Version="1.0.1" />
<PackageReference Include="PipeAndFilter" Version="1.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
84 changes: 39 additions & 45 deletions Samples/PipelineSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,41 +59,39 @@ static void Main(string[] args)

private static ValueTask<bool> TryAgain(EventPipe<MyClassPipeline> pipe, CancellationToken token)
{
string? value = pipe.SavedPipes
.Where(X => X.Alias == "Confirm")
.Select(X => X.Result)
.FirstOrDefault();
var confirm = false;
if (!string.IsNullOrEmpty(value))
if (pipe.TrySavedValue("Confirm", out var value))
{
confirm = JsonSerializer.Deserialize<bool>(value);
if (!string.IsNullOrEmpty(value))
{
confirm = JsonSerializer.Deserialize<bool>(value);
}
}
return new ValueTask<bool>(!confirm);
}

private static Task WriteResult(EventPipe<MyClassPipeline> pipe, CancellationToken token)
{
string? firstname = pipe.SavedPipes
.Where(X => X.Alias == "FistName")
.Select(X => X.Result)
.FirstOrDefault();
if (!string.IsNullOrEmpty(firstname))
if (pipe.TrySavedValue("FistName", out string? value))
{
firstname = JsonSerializer.Deserialize<string>(firstname);
if (!string.IsNullOrEmpty(value))
{
pipe.ThreadSafeAccess((Contract) =>
{
Contract.FirtName = JsonSerializer.Deserialize<string>(value) ?? string.Empty;
});
}
}
string? lastname = pipe.SavedPipes
.Where(X => X.Alias == "LastName")
.Select(X => X.Result)
.FirstOrDefault();
if (!string.IsNullOrEmpty(lastname))
if (pipe.TrySavedValue("LastName", out value))
{
lastname = JsonSerializer.Deserialize<string>(lastname);
if (!string.IsNullOrEmpty(value))
{
pipe.ThreadSafeAccess((Contract) =>
{
Contract.LastName = JsonSerializer.Deserialize<string>(value) ?? string.Empty;
});
}
}
pipe.ThreadSafeAccess((Contract) =>
{
Contract.FirtName = firstname ??string.Empty;
Contract.LastName = lastname ?? string.Empty;
});
return Task.CompletedTask;
}

Expand All @@ -103,7 +101,7 @@ private static Task Confirm(EventPipe<MyClassPipeline> pipe, CancellationToken t
.Run();
if (!result.IsAborted)
{
pipe.SaveValue(result.Value.IsYesResponseKey());
pipe.SaveValueAtEnd("Confirm", result.Value.IsYesResponseKey());
}
else
{
Expand All @@ -114,21 +112,20 @@ private static Task Confirm(EventPipe<MyClassPipeline> pipe, CancellationToken t

private static Task FistName(EventPipe<MyClassPipeline> pipe, CancellationToken token)
{
string? value = pipe.SavedPipes
.Where(X => X.Alias == "FistName")
.Select(X => X.Result)
.FirstOrDefault();
if (!string.IsNullOrEmpty(value))
if (pipe.TrySavedValue("FistName", out string? value))
{
value = JsonSerializer.Deserialize<string>(value);
if (!string.IsNullOrEmpty(value))
{
value = JsonSerializer.Deserialize<string>(value) ?? string.Empty;
}
}

var result = PromptPlus.Input("Your First Name", "If first name is empty not get lastname and not confim inputs")
.Default(value ?? string.Empty)
.Run();
if (!result.IsAborted)
{
pipe.SaveValue(result.Value);
pipe.SaveValueAtEnd("FistName", result.Value);
}
else
{
Expand All @@ -139,21 +136,19 @@ private static Task FistName(EventPipe<MyClassPipeline> pipe, CancellationToken

private static Task LastName(EventPipe<MyClassPipeline> pipe, CancellationToken token)
{
string? value = pipe.SavedPipes
.Where(X => X.Alias == "LastName")
.Select(X => X.Result)
.FirstOrDefault();
if (!string.IsNullOrEmpty(value))
if (pipe.TrySavedValue("LastName", out string? value))
{
value = JsonSerializer.Deserialize<string>(value);
if (!string.IsNullOrEmpty(value))
{
value = JsonSerializer.Deserialize<string>(value) ?? string.Empty;
}
}

var result = PromptPlus.Input("Your Last Name")
.Default(value ?? string.Empty)
.Run();
if (!result.IsAborted)
{
pipe.SaveValue(result.Value);
pipe.SaveValueAtEnd("LastName", result.Value);
}
else
{
Expand All @@ -164,13 +159,12 @@ private static Task LastName(EventPipe<MyClassPipeline> pipe, CancellationToken

private static ValueTask<bool> ExistFirstName(EventPipe<MyClassPipeline> pipe, CancellationToken token)
{
string? value = pipe.SavedPipes
.Where(X => X.Alias == "FistName")
.Select(X => X.Result)
.FirstOrDefault();
if (!string.IsNullOrEmpty(value))
if (pipe.TrySavedValue("FistName", out string? value))
{
value = JsonSerializer.Deserialize<string>(value);
if (!string.IsNullOrEmpty(value))
{
value = JsonSerializer.Deserialize<string>(value) ?? string.Empty;
}
}
return ValueTask.FromResult(!string.IsNullOrEmpty(value));
}
Expand Down

0 comments on commit 087e6a6

Please sign in to comment.