From 20cf28ee9ff7df0919d424628c16f52fa3ef2362 Mon Sep 17 00:00:00 2001 From: XuanThuLab Date: Sun, 30 Aug 2020 14:40:23 +0700 Subject: [PATCH] LIB --- .../htmlhelper/.vscode/tasks.json | 42 +++++ .../htmlhelperlib/htmlhelper/HtmlHelper.cs | 143 ++++++++++++++++++ .../htmlhelper/htmlhelper.csproj | 16 ++ .../htmltestcode/.vscode/launch.json | 27 ++++ .../htmltestcode/.vscode/tasks.json | 42 +++++ .../htmlhelperlib/htmltestcode/Program.cs | 14 ++ .../htmltestcode/htmltestcode.csproj | 12 ++ ASP_NET_CORE/htmlhelperlib/readme.md | 3 + .../htmlhelperlib/test/.vscode/launch.json | 27 ++++ .../htmlhelperlib/test/.vscode/tasks.json | 42 +++++ ASP_NET_CORE/htmlhelperlib/test/Program.cs | 13 ++ ASP_NET_CORE/htmlhelperlib/test/test.csproj | 12 ++ 12 files changed, 393 insertions(+) create mode 100644 ASP_NET_CORE/htmlhelperlib/htmlhelper/.vscode/tasks.json create mode 100644 ASP_NET_CORE/htmlhelperlib/htmlhelper/HtmlHelper.cs create mode 100644 ASP_NET_CORE/htmlhelperlib/htmlhelper/htmlhelper.csproj create mode 100644 ASP_NET_CORE/htmlhelperlib/htmltestcode/.vscode/launch.json create mode 100644 ASP_NET_CORE/htmlhelperlib/htmltestcode/.vscode/tasks.json create mode 100644 ASP_NET_CORE/htmlhelperlib/htmltestcode/Program.cs create mode 100644 ASP_NET_CORE/htmlhelperlib/htmltestcode/htmltestcode.csproj create mode 100644 ASP_NET_CORE/htmlhelperlib/readme.md create mode 100644 ASP_NET_CORE/htmlhelperlib/test/.vscode/launch.json create mode 100644 ASP_NET_CORE/htmlhelperlib/test/.vscode/tasks.json create mode 100644 ASP_NET_CORE/htmlhelperlib/test/Program.cs create mode 100644 ASP_NET_CORE/htmlhelperlib/test/test.csproj diff --git a/ASP_NET_CORE/htmlhelperlib/htmlhelper/.vscode/tasks.json b/ASP_NET_CORE/htmlhelperlib/htmlhelper/.vscode/tasks.json new file mode 100644 index 0000000..6a5ce58 --- /dev/null +++ b/ASP_NET_CORE/htmlhelperlib/htmlhelper/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/htmlhelper.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/htmlhelper.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/htmlhelper.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/ASP_NET_CORE/htmlhelperlib/htmlhelper/HtmlHelper.cs b/ASP_NET_CORE/htmlhelperlib/htmlhelper/HtmlHelper.cs new file mode 100644 index 0000000..5f6e4dc --- /dev/null +++ b/ASP_NET_CORE/htmlhelperlib/htmlhelper/HtmlHelper.cs @@ -0,0 +1,143 @@ +using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Http; + +namespace XTLAB.HtmlHelper { + + public static class HtmlHelper { + /// + /// Phát sinh trang HTML + /// + /// Tiêu đề trang + /// Nội dung trong thẻ body + /// Trang HTML + public static string HtmlDocument (string title, string content) { + return $@" + + + + + {title} + + + + + {content} + + "; + } + + /// + /// Phát sinh HTML thanh menu trên, menu nào active phụ thuộc vào URL mà request gủi đến + /// + /// Mảng các menu item, mỗi item có cấu trúc {url, lable} + /// HttpRequest + /// + + public static string MenuTop (object[] menus, HttpRequest request) { + + var menubuilder = new StringBuilder (); + menubuilder.Append ("\n"); + + string menuhtml = $@" +
+
"; + + return menuhtml; + } + + /// + /// Những menu item mặc định cho trang + /// + /// Mảng các menuitem + public static object[] DefaultMenuTopItems () { + return new object[] { + new { + url = "/RequestInfo", + label = "Request" + }, + new { + url = "/Form", + label = "Form" + }, + new { + url = "/Encoding", + label = "Encoding" + }, + new { + url = "/Cookies", + label = "Cookies" + }, + new { + url = "/Json", + label = "JSON" + } + }; + } + + public static string HtmlTrangchu () { + return $@" +
+
+

Đây là một trang Web .NET Core

+

Trang Web này xây dựng trên nền tảng .NET Core, + chưa sử dụng kỹ thuật MVC - nhằm mục đích học tập. + Mã nguồn trang này tại + Mã nguồn Ví dụ + +

+ + +
+

.NET Core là một hệ thống chạy đa nền tảng (Windows, Linux, macOS)

+ Xem thêm +
+
+ "; + + } + + // Mở rộng String, phát sinh thẻ HTML với nội dụng là String + // Ví dụ: + // "content".HtmlTag() =>

content

+ // "content".HtmlTag("div", "text-danger") =>
content
+ public static string HtmlTag (this string content, string tag = "p", string _class = null) { + string cls = (_class != null) ? $" class=\"{_class}\"" : null; + return $"<{tag + cls}>{content}"; + } + public static string td (this string content, string _class = null) { + return content.HtmlTag ("td", _class); + } + public static string tr (this string content, string _class = null) { + return content.HtmlTag ("tr", _class); + } + public static string table (this string content, string _class = null) { + return content.HtmlTag ("table", _class); + } + + } +} \ No newline at end of file diff --git a/ASP_NET_CORE/htmlhelperlib/htmlhelper/htmlhelper.csproj b/ASP_NET_CORE/htmlhelperlib/htmlhelper/htmlhelper.csproj new file mode 100644 index 0000000..d857adc --- /dev/null +++ b/ASP_NET_CORE/htmlhelperlib/htmlhelper/htmlhelper.csproj @@ -0,0 +1,16 @@ + + + + netcoreapp3.1 + XTL.HtmlHelper + 1.0.0 + xuanthulab + XUANTHULAB.NET + false + + + + + + + diff --git a/ASP_NET_CORE/htmlhelperlib/htmltestcode/.vscode/launch.json b/ASP_NET_CORE/htmlhelperlib/htmltestcode/.vscode/launch.json new file mode 100644 index 0000000..b64a261 --- /dev/null +++ b/ASP_NET_CORE/htmlhelperlib/htmltestcode/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/htmltestcode.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/ASP_NET_CORE/htmlhelperlib/htmltestcode/.vscode/tasks.json b/ASP_NET_CORE/htmlhelperlib/htmltestcode/.vscode/tasks.json new file mode 100644 index 0000000..478df0d --- /dev/null +++ b/ASP_NET_CORE/htmlhelperlib/htmltestcode/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/htmltestcode.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/htmltestcode.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/htmltestcode.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/ASP_NET_CORE/htmlhelperlib/htmltestcode/Program.cs b/ASP_NET_CORE/htmlhelperlib/htmltestcode/Program.cs new file mode 100644 index 0000000..9097474 --- /dev/null +++ b/ASP_NET_CORE/htmlhelperlib/htmltestcode/Program.cs @@ -0,0 +1,14 @@ +using System; +using XTLAB.HtmlHelper; + +namespace htmltestcode +{ + class Program + { + static void Main(string[] args) + { + String html = "Ví dụ sử dụng HtmlHelper".HtmlTag("div", "text-danger"); + Console.WriteLine(html); + } + } +} diff --git a/ASP_NET_CORE/htmlhelperlib/htmltestcode/htmltestcode.csproj b/ASP_NET_CORE/htmlhelperlib/htmltestcode/htmltestcode.csproj new file mode 100644 index 0000000..eab6c26 --- /dev/null +++ b/ASP_NET_CORE/htmlhelperlib/htmltestcode/htmltestcode.csproj @@ -0,0 +1,12 @@ + + + + + + + + Exe + netcoreapp3.1 + + + diff --git a/ASP_NET_CORE/htmlhelperlib/readme.md b/ASP_NET_CORE/htmlhelperlib/readme.md new file mode 100644 index 0000000..993540a --- /dev/null +++ b/ASP_NET_CORE/htmlhelperlib/readme.md @@ -0,0 +1,3 @@ +# Tạo thư viện C# NET Core và chia sẻ lên nuget.org + +https://xuanthulab.net/tao-thu-vien-c-net-core-va-chia-se-len-nuget-org.html diff --git a/ASP_NET_CORE/htmlhelperlib/test/.vscode/launch.json b/ASP_NET_CORE/htmlhelperlib/test/.vscode/launch.json new file mode 100644 index 0000000..bb74f8c --- /dev/null +++ b/ASP_NET_CORE/htmlhelperlib/test/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/test.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/ASP_NET_CORE/htmlhelperlib/test/.vscode/tasks.json b/ASP_NET_CORE/htmlhelperlib/test/.vscode/tasks.json new file mode 100644 index 0000000..7263f86 --- /dev/null +++ b/ASP_NET_CORE/htmlhelperlib/test/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/test.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/test.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/test.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/ASP_NET_CORE/htmlhelperlib/test/Program.cs b/ASP_NET_CORE/htmlhelperlib/test/Program.cs new file mode 100644 index 0000000..52223d0 --- /dev/null +++ b/ASP_NET_CORE/htmlhelperlib/test/Program.cs @@ -0,0 +1,13 @@ +using System; +using XTLAB; +namespace test +{ + class Program + { + static void Main(string[] args) + { + "abc".HtmlTag("p"); + Console.WriteLine("Hello World!"); + } + } +} diff --git a/ASP_NET_CORE/htmlhelperlib/test/test.csproj b/ASP_NET_CORE/htmlhelperlib/test/test.csproj new file mode 100644 index 0000000..6314c24 --- /dev/null +++ b/ASP_NET_CORE/htmlhelperlib/test/test.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + +