diff --git a/serialize-linq/.dockerignore b/serialize-linq/.dockerignore new file mode 100644 index 00000000..af50df1a --- /dev/null +++ b/serialize-linq/.dockerignore @@ -0,0 +1,25 @@ +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.idea +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/serialize-linq/.gitignore b/serialize-linq/.gitignore new file mode 100644 index 00000000..2cb90536 --- /dev/null +++ b/serialize-linq/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +*.sln.iml +.idea/**/* +**/.idea/* \ No newline at end of file diff --git a/serialize-linq/Apps/HelloApp.cs b/serialize-linq/Apps/HelloApp.cs new file mode 100644 index 00000000..667d1ace --- /dev/null +++ b/serialize-linq/Apps/HelloApp.cs @@ -0,0 +1,22 @@ +//namespace SerializeLinq.Apps; + +//[App(icon:Icons.PartyPopper, title:"Hello")] +//public class HelloApp : ViewBase +//{ +// public override object? Build() +// { +// var nameState = this.UseState(); + +// return Layout.Center() +// | (new Card( +// Layout.Vertical().Gap(6).Padding(2) +// | new Confetti(new IvyLogo()) +// | Text.H2("Hello " + (string.IsNullOrEmpty(nameState.Value) ? "there" : nameState.Value) + "!") +// | Text.Block("Welcome to the fantastic world of Ivy. Let's build something amazing together!") +// | nameState.ToInput(placeholder: "What is your name?") +// | new Separator() +// | Text.Markdown("You'd be a hero to us if you could ⭐ us on [Github](https://github.com/Ivy-Interactive/Ivy-Framework)") +// ) +// .Width(Size.Units(120).Max(500))); +// } +//} \ No newline at end of file diff --git a/serialize-linq/Apps/SerializeLinqApp.cs b/serialize-linq/Apps/SerializeLinqApp.cs new file mode 100644 index 00000000..8b54de78 --- /dev/null +++ b/serialize-linq/Apps/SerializeLinqApp.cs @@ -0,0 +1,89 @@ +using Serialize.Linq.Serializers; +using System.Linq.Expressions; + +namespace SerializeLinq.Apps; + +[App(icon: Icons.Pencil, title: "Serialize Linq")] +public class SerializeLinqApp : ViewBase +{ + public override object? Build() + { + //Input states + var value1State = this.UseState(); + var value2State = this.UseState(); + var operatorState = this.UseState(); + + //Serialization state + var jsonState = this.UseState(); + + //Deserialization states + var expressionState = this.UseState(); + var comparisonResultState = this.UseState(); + + return Layout.Vertical() + | Text.Block("Hello world!") + //Inputs + | (Layout.Horizontal() + | value1State.ToNumberInput().Width(Size.Grow()) + | operatorState.ToSelectInput(new string[] { "=", "<", "<=", ">", ">=", "!=" }.ToOptions()).Width(Size.Third()) + | value2State.ToNumberInput().Width(Size.Grow())) + //Serialize button + | new Button("Serialize", () => + { + Expression> expression = null; + switch (operatorState.Value) + { + case "=": + expression = val => value1State.Value == val; + break; + case "<": + expression = val => value1State.Value < val; + break; + case "<=": + expression = val => value1State.Value <= val; + break; + case ">": + expression = val => value1State.Value > val; + break; + case ">=": + expression = val => value1State.Value >= val; + break; + case "!=": + expression = val => value1State.Value != val; + break; + } + if (expression != null) + { + var serializer = new ExpressionSerializer(new JsonSerializer()); + + //The result is a json representation of the expression + jsonState.Set(serializer.SerializeText(expression)); + } + else + { + jsonState.Set("Invalid expression"); + } + }) + //Serialization result + | Text.Block(jsonState) + //Deserialize button (only works with serialization result, works like a validation for the json result) + | new Button("Deserialize Result", () => + { + try + { + var serializer = new ExpressionSerializer(new JsonSerializer()); + Expression> expression = (Expression>)serializer.DeserializeText(jsonState.Value); + + //Expression definition (value1 + operator) + expressionState.Set($"Expression: {expression}"); + + //Result of the expresion when using value2 + comparisonResultState.Set($"The comparison is {expression.Compile()(value2State.Value).ToString().ToLower()}"); + } + catch { } + }) + //Deserialization results + | Text.Block(expressionState.Value) + | Text.Block(comparisonResultState); + } +} \ No newline at end of file diff --git a/serialize-linq/Dockerfile b/serialize-linq/Dockerfile new file mode 100644 index 00000000..f9034b4d --- /dev/null +++ b/serialize-linq/Dockerfile @@ -0,0 +1,34 @@ +# Base runtime image +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base +WORKDIR /app +EXPOSE 80 + +# Build stage +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src + +# Copy and restore +COPY ["SerializeLinq.csproj", "./"] +RUN dotnet restore "SerializeLinq.csproj" + +# Copy everything and build +COPY . . +RUN dotnet build "SerializeLinq.csproj" -c $BUILD_CONFIGURATION -o /app/build + +# Publish stage +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "SerializeLinq.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=true + +# Final runtime image +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . + +# Set environment variables +ENV PORT=80 +ENV ASPNETCORE_URLS="http://+:80" + +# Run the executable +ENTRYPOINT ["dotnet","./SerializeLinq.dll"] \ No newline at end of file diff --git a/serialize-linq/GlobalUsings.cs b/serialize-linq/GlobalUsings.cs new file mode 100644 index 00000000..19330b91 --- /dev/null +++ b/serialize-linq/GlobalUsings.cs @@ -0,0 +1,28 @@ +global using Ivy; +global using Ivy.Apps; +global using Ivy.Auth; +global using Ivy.Chrome; +global using Ivy.Client; +global using Ivy.Core; +global using Ivy.Core.Hooks; +global using Ivy.Helpers; +global using Ivy.Hooks; +global using Ivy.Shared; +global using Ivy.Views; +global using Ivy.Views.Alerts; +global using Ivy.Views.Blades; +global using Ivy.Views.Builders; +global using Ivy.Views.Charts; +global using Ivy.Views.Dashboards; +global using Ivy.Views.Forms; +global using Ivy.Views.Tables; +global using Ivy.Widgets.Inputs; +global using Microsoft.Extensions.Configuration; +global using Microsoft.Extensions.DependencyInjection; +global using Microsoft.Extensions.Logging; +global using System.Collections.Immutable; +global using System.ComponentModel.DataAnnotations; +global using System.Globalization; +global using System.Reactive.Linq; + +namespace SerializeLinq; diff --git a/serialize-linq/Program.cs b/serialize-linq/Program.cs new file mode 100644 index 00000000..b77b3943 --- /dev/null +++ b/serialize-linq/Program.cs @@ -0,0 +1,11 @@ +using SerializeLinq.Apps; +CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US"); +var server = new Server(); +#if DEBUG +server.UseHotReload(); +#endif +server.AddAppsFromAssembly(); +server.AddConnectionsFromAssembly(); +var chromeSettings = new ChromeSettings().DefaultApp().UseTabs(preventDuplicates: true); +server.UseChrome(chromeSettings); +await server.RunAsync(); diff --git a/serialize-linq/README.md b/serialize-linq/README.md new file mode 100644 index 00000000..37a05000 --- /dev/null +++ b/serialize-linq/README.md @@ -0,0 +1,17 @@ +# Hello + +Web application created using [Ivy](https://github.com/Ivy-Interactive/Ivy). + +Ivy is a web framework for building interactive web applications using C# and .NET. + +## Run + +``` +dotnet watch +``` + +## Deploy + +``` +ivy deploy +``` \ No newline at end of file diff --git a/serialize-linq/SerializeLinq.csproj b/serialize-linq/SerializeLinq.csproj new file mode 100644 index 00000000..cd66ae95 --- /dev/null +++ b/serialize-linq/SerializeLinq.csproj @@ -0,0 +1,23 @@ + + + + Exe + net9.0 + enable + enable + CS8618;CS8603;CS8602;CS8604;CS9113 + SerializeLinq + + + + + + + + + + + + + + diff --git a/serialize-linq/SerializeLinq.sln b/serialize-linq/SerializeLinq.sln new file mode 100644 index 00000000..895275e8 --- /dev/null +++ b/serialize-linq/SerializeLinq.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.2.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hello", "SerializeLinq.csproj", "{039638F3-A6D7-FB67-E733-27BD896EFDC4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {039638F3-A6D7-FB67-E733-27BD896EFDC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {039638F3-A6D7-FB67-E733-27BD896EFDC4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {039638F3-A6D7-FB67-E733-27BD896EFDC4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {039638F3-A6D7-FB67-E733-27BD896EFDC4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5F74B1AD-6C2E-4FDA-9DAF-9F7D8053687B} + EndGlobalSection +EndGlobal