From 08d92e51d6558bcde34f13a91b7d934e3a0dbce0 Mon Sep 17 00:00:00 2001 From: bicijinlian Date: Tue, 4 Apr 2023 12:33:04 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=96=87=E4=BB=B6=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {assets => Docs/assets}/images/Logo.png | Bin {assets => Docs/assets}/images/UserInput.png | Bin {sqlite => Docs/sqlite}/SQLiteDemo.db | Bin .../多语言笔记.1.0.常见问题.ipynb | 2 +- .../多语言笔记.1.1.入门说明.ipynb | 171 ++++++- ...笔记.1.2.显示程序执行结果.ipynb | 378 ++++++++++++++++ .../多语言笔记.1.3.多语言.ipynb | 0 .../多语言笔记.100.1.测试.ipynb | 14 +- .../多语言笔记.2.1.连接数据库.ipynb | 87 +--- Docs/多语言笔记.2.2.连接SQLite.ipynb | 268 +++++++++++ .../多语言笔记.3.1.交互式 Razor.ipynb | 57 ++- .../多语言笔记.4.1.使用WebApi.ipynb | 0 .../多语言笔记.5.1.使用扩展库.ipynb | 0 .../多语言笔记.6.1.共享变量.ipynb | 0 ...笔记.7.1.运行xUnit单元测试.ipynb | 71 +++ ...记.8.1.运行Benchmark基准测试.ipynb | 71 +++ ...笔记.1.2.显示程序执行结果.ipynb | 209 --------- 多语言笔记.2.2.连接SQLite.ipynb | 427 ------------------ 18 files changed, 1005 insertions(+), 750 deletions(-) rename {assets => Docs/assets}/images/Logo.png (100%) rename {assets => Docs/assets}/images/UserInput.png (100%) rename {sqlite => Docs/sqlite}/SQLiteDemo.db (100%) rename 多语言笔记.1.0.常见问题.ipynb => Docs/多语言笔记.1.0.常见问题.ipynb (99%) rename 多语言笔记.1.1.入门说明.ipynb => Docs/多语言笔记.1.1.入门说明.ipynb (65%) create mode 100644 Docs/多语言笔记.1.2.显示程序执行结果.ipynb rename 多语言笔记.1.3.多语言.ipynb => Docs/多语言笔记.1.3.多语言.ipynb (100%) rename 多语言笔记.100.1.测试.ipynb => Docs/多语言笔记.100.1.测试.ipynb (95%) rename 多语言笔记.2.1.连接数据库.ipynb => Docs/多语言笔记.2.1.连接数据库.ipynb (75%) create mode 100644 Docs/多语言笔记.2.2.连接SQLite.ipynb rename 多语言笔记.3.1.交互式 Razor.ipynb => Docs/多语言笔记.3.1.交互式 Razor.ipynb (56%) rename 多语言笔记.4.1.使用WebApi.ipynb => Docs/多语言笔记.4.1.使用WebApi.ipynb (100%) rename 多语言笔记.5.1.使用扩展库.ipynb => Docs/多语言笔记.5.1.使用扩展库.ipynb (100%) rename 多语言笔记.6.1.共享变量.ipynb => Docs/多语言笔记.6.1.共享变量.ipynb (100%) create mode 100644 Docs/多语言笔记.7.1.运行xUnit单元测试.ipynb create mode 100644 Docs/多语言笔记.8.1.运行Benchmark基准测试.ipynb delete mode 100644 多语言笔记.1.2.显示程序执行结果.ipynb delete mode 100644 多语言笔记.2.2.连接SQLite.ipynb diff --git a/assets/images/Logo.png b/Docs/assets/images/Logo.png similarity index 100% rename from assets/images/Logo.png rename to Docs/assets/images/Logo.png diff --git a/assets/images/UserInput.png b/Docs/assets/images/UserInput.png similarity index 100% rename from assets/images/UserInput.png rename to Docs/assets/images/UserInput.png diff --git a/sqlite/SQLiteDemo.db b/Docs/sqlite/SQLiteDemo.db similarity index 100% rename from sqlite/SQLiteDemo.db rename to Docs/sqlite/SQLiteDemo.db diff --git a/多语言笔记.1.0.常见问题.ipynb b/Docs/多语言笔记.1.0.常见问题.ipynb similarity index 99% rename from 多语言笔记.1.0.常见问题.ipynb rename to Docs/多语言笔记.1.0.常见问题.ipynb index 93a4957..301c0ce 100644 --- a/多语言笔记.1.0.常见问题.ipynb +++ b/Docs/多语言笔记.1.0.常见问题.ipynb @@ -94,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": { "dotnet_interactive": { "language": "csharp" diff --git a/多语言笔记.1.1.入门说明.ipynb b/Docs/多语言笔记.1.1.入门说明.ipynb similarity index 65% rename from 多语言笔记.1.1.入门说明.ipynb rename to Docs/多语言笔记.1.1.入门说明.ipynb index 86ccfa1..39cef9c 100644 --- a/多语言笔记.1.1.入门说明.ipynb +++ b/Docs/多语言笔记.1.1.入门说明.ipynb @@ -70,7 +70,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -81,12 +81,12 @@ }, "outputs": [], "source": [ - "#! import \"./NotebookStudy.ConsoleApp/Persion.cs\"" + "#! import \"../NotebookStudy.ConsoleApp/Persion.cs\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -95,7 +95,16 @@ "kernelName": "csharp" } }, - "outputs": [], + "outputs": [ + { + "ename": "Error", + "evalue": "(2,13): error CS0246: 未能找到类型或命名空间名“Person”(是否缺少 using 指令或程序集引用?)", + "output_type": "error", + "traceback": [ + "(2,13): error CS0246: 未能找到类型或命名空间名“Person”(是否缺少 using 指令或程序集引用?)" + ] + } + ], "source": [ "//单纯引用.cs文件,不能直接使用,解决方法待查找\n", "var p = new Person()\n", @@ -114,7 +123,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -123,7 +132,48 @@ "kernelName": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
{ Name = xx, Agx = 33 }
Namexx
Agx
33
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "var x = new {Name=\"xx\",Agx=33};\n", "display(x);" @@ -140,7 +190,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -149,9 +199,52 @@ "kernelName": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
NotebookStudy.ConsoleApp.Person
Id
2
Name本山
Address
<null>
Age
55
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "#r \"./NotebookStudy.ConsoleApp/bin/Debug/net7.0/NotebookStudy.ConsoleApp.dll\"\n", + "//如果找不到文件,需要先生成 NotebookStudy.ConsoleApp 项目\n", + "\n", + "#r \"../NotebookStudy.ConsoleApp/bin/Debug/net7.0/NotebookStudy.ConsoleApp.dll\"\n", "\n", "using NotebookStudy.ConsoleApp;\n", "\n", @@ -175,7 +268,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -184,7 +277,26 @@ "kernelName": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
Installed Packages
  • newtonsoft.json, 13.0.3
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "{\"Id\":2,\"Name\":\"newtonsoft类库\",\"Age\":6}" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "//安装库的最新版本\n", "#r \"nuget:newtonsoft.json\"\n", @@ -197,7 +309,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -206,7 +318,26 @@ "kernelName": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
Installed Packages
  • newtonsoft.json, 13.0.3
  • System.Text.Json, 4.7.2
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "{\"Id\":2,\"Name\":\"System.Text.Json\\u7C7B\\u5E93\",\"Age\":6}" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "//安装库的指定版本\n", "#r \"nuget:System.Text.Json,4.7.2\"\n", @@ -219,7 +350,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -228,7 +359,17 @@ "kernelName": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
Installed Packages
  • xunit, 2.4.2
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "//安装最新的预览版库\n", "#r \"nuget:xunit,*-*\"\n", diff --git a/Docs/多语言笔记.1.2.显示程序执行结果.ipynb b/Docs/多语言笔记.1.2.显示程序执行结果.ipynb new file mode 100644 index 0000000..a41c194 --- /dev/null +++ b/Docs/多语言笔记.1.2.显示程序执行结果.ipynb @@ -0,0 +1,378 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 展示程序执行结果" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Console.WriteLine() 方法,输出字符串到结果区域" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + }, + "vscode": { + "languageId": "polyglot-notebook" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "将字符串输出到展示区!\r\n" + ] + } + ], + "source": [ + "Console.WriteLine(\"将字符串输出到展示区!\");" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 使用内置的 Display() 方法" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + }, + "vscode": { + "languageId": "polyglot-notebook" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
[ ab, cd, ef ]
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "//直接写变量:限制是必须是最后一行\n", + "var strList = new List(){\"ab\",\"cd\",\"ef\"};\n", + "strList" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + }, + "vscode": { + "languageId": "polyglot-notebook" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
{ Name = 张三, Age = 33, Adress = 河南周口 }
Name张三
Age
33
Adress河南周口
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
{ Name = 张三, Age = 33, Adress = 河南周口 }
Name张三
Age
33
Adress河南周口
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "// 使用Display()方法,可以多次调用。估计是 .Net InterActive 内容实现的扩展方法\n", + "\n", + "var obj = new {Name=\"张三\",Age=33,Adress=\"河南周口\"};\n", + "\n", + "obj.Display();\n", + "obj.Display();" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 更新Display()返回对象,实现动态展示效果" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + }, + "vscode": { + "languageId": "polyglot-notebook" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "倒计时:0" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "var displayObject1 = \"\".Display();\n", + "for(int i=10; i>=0; i--)\n", + "{\n", + " displayObject1.Update(\"倒计时:\" + i);\n", + " await Task.Delay(500);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + }, + "vscode": { + "languageId": "polyglot-notebook" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "动态添加:0123456789" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "var displayText = \"动态添加:\";\n", + "var displayObject = displayText.Display();\n", + "for(int i=0;i<10;i++)\n", + "{\n", + " displayText+=i;\n", + " displayObject.Update(displayText);\n", + " await Task.Delay(200);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + }, + "vscode": { + "languageId": "polyglot-notebook" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "开唱:你是我的小呀小苹果..." + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "var displayText3 = \"开唱:\";\n", + "var displayObject3 = displayText3.Display();\n", + "foreach(var c in \"你是我的小呀小苹果...\".ToCharArray())\n", + "{\n", + " displayText3+=c;\n", + " displayObject3.Update(displayText3);\n", + " await Task.Delay(500);\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + }, + "vscode": { + "languageId": "polyglot-notebook" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "2023-04-04 12:27:28Z" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "var displayObject4 = DateTime.Now.Display();\n", + "for(int i=0; i<10; i++)\n", + "{\n", + " displayObject4.Update(DateTime.Now);\n", + " await Task.Delay(1000);\n", + "}" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/多语言笔记.1.3.多语言.ipynb b/Docs/多语言笔记.1.3.多语言.ipynb similarity index 100% rename from 多语言笔记.1.3.多语言.ipynb rename to Docs/多语言笔记.1.3.多语言.ipynb diff --git a/多语言笔记.100.1.测试.ipynb b/Docs/多语言笔记.100.1.测试.ipynb similarity index 95% rename from 多语言笔记.100.1.测试.ipynb rename to Docs/多语言笔记.100.1.测试.ipynb index b68740b..bf00c75 100644 --- a/多语言笔记.100.1.测试.ipynb +++ b/Docs/多语言笔记.100.1.测试.ipynb @@ -163,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -172,17 +172,7 @@ "kernelName": "csharp" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "99" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "using Microsoft.DotNet.Interactive;\n", "\n", diff --git a/多语言笔记.2.1.连接数据库.ipynb b/Docs/多语言笔记.2.1.连接数据库.ipynb similarity index 75% rename from 多语言笔记.2.1.连接数据库.ipynb rename to Docs/多语言笔记.2.1.连接数据库.ipynb index 96f5a99..a955fd8 100644 --- a/多语言笔记.2.1.连接数据库.ipynb +++ b/Docs/多语言笔记.2.1.连接数据库.ipynb @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -36,37 +36,7 @@ "kernelName": "csharp" } }, - "outputs": [ - { - "data": { - "text/html": [ - "
Installed Packages
  • Microsoft.Dotnet.Interactive.SqlServer, 1.0.0-beta.23165.2
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "Loading extensions from `C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet.interactive.sqlserver\\1.0.0-beta.23165.2\\interactive-extensions\\dotnet\\Microsoft.DotNet.Interactive.SqlServer.dll`" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
Query Microsoft SQL Server databases.\r\n", - "

This extension adds support for connecting to Microsoft SQL Server databases using the #!connect mssql magic command. For more information, run a cell using the #!sql magic command.

\r\n", - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "#r \"nuget:Microsoft.Dotnet.Interactive.SqlServer,*-*\"" ] @@ -146,7 +116,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -155,17 +125,7 @@ "kernelName": "csharp" } }, - "outputs": [ - { - "data": { - "text/plain": [ - "Kernel added: #!sql-Demo" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "#!connect mssql \"server=.\\SQL2008;uid=sa;pwd=gly-bicijinlian;database=Study;Encrypt=True;TrustServerCertificate=True;\" --kernel-name Demo\n", "//重复执行会抛出错误,目前没有找到解决方法" @@ -254,7 +214,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -263,42 +223,7 @@ "kernelName": "csharp" } }, - "outputs": [ - { - "data": { - "text/markdown": [ - "Scaffolding a `DbContext` and initializing an instance of it called `DemoEF` in the C# kernel." - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
Installed Packages
  • Humanizer, 2.14.1
  • humanizer.core, 2.14.1
  • Microsoft.EntityFrameworkCore.Design, 7.0.0
  • microsoft.entityframeworkcore.sqlserver, 7.0.0
  • microsoft.identity.client, 4.48.1
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Security Warning: The negotiated TLS 1.0 is an insecure protocol and is supported for backward compatibility only. The recommended protocol version is TLS 1.2 and later.\r\n" - ] - }, - { - "data": { - "text/plain": [ - "Kernel added: #!sql-DemoEF" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "#!connect mssql \"server=.\\SQL2008;uid=sa;pwd=gly-bicijinlian;database=Study;Encrypt=True;TrustServerCertificate=True;\" --create-dbcontext --kernel-name DemoEF " ] diff --git a/Docs/多语言笔记.2.2.连接SQLite.ipynb b/Docs/多语言笔记.2.2.连接SQLite.ipynb new file mode 100644 index 0000000..aadb143 --- /dev/null +++ b/Docs/多语言笔记.2.2.连接SQLite.ipynb @@ -0,0 +1,268 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "连接到 SQLite 数据库\n", + "============================== " + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "连接到 SQLite 数据库,并操作数据。注意:此功能在 Microsoft.DotNet.Interactive.ExtensionLab 扩展库中,要先引用 Nuget 包。" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 设置Nuget包源" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "#i \"https://api.nuget.org/v3/index.json\"" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 引用 Nuget 包" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "#r \"nuget: Microsoft.DotNet.Interactive.ExtensionLab,*-*\"" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 连接到 SQLite 数据库" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "引用扩展库后,使用 #!connect sqlite 命令连接到SQLite数据库!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "#!connect sqlite --kernel-name MySQLiteDemo \"Data Source=sqlite\\\\SQLiteDemo.db\"\n", + "\n", + "/*\n", + " 相对目录位置\n", + " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=Database\\SQLiteDemo.db;\"\n", + " \n", + " 缓存共享\n", + " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=Database\\SQLiteDemo.db;Cache=Shared;\"\n", + "\n", + " 使用带密码\n", + " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=SQLiteDemo.db;Cache=Shared;Password=MyEncryptionKey;\"\n", + " \n", + " 只读模式\n", + " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=SQLiteDemo.db;Mode=ReadOnly\"\n", + "\n", + " 读写创建模式\n", + " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=SQLiteDemo.db;Mode=ReadWriteCreate\"\n", + "\n", + " 读写模式\n", + " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=SQLiteDemo.db;Mode=ReadWrite\"\n", + "\n", + " 私有内存模式\n", + " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=:memory:\"\n", + "\n", + " 共享内存模式\n", + " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=Sharable;Mode=Memory;Cache=Shared\"\n", + "*/" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 使用连接操作数据库" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "sql-MySQLiteDemo" + }, + "polyglot_notebook": { + "kernelName": "sql-MySQLiteDemo" + } + }, + "outputs": [], + "source": [ + "#!sql-MySQLiteDemo\n", + "\n", + "select * from person;" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## C#中使用" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "//直接引用包,使用类库操作就可以了,不需要使用 上下文连接" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "language_info": { + "name": "polyglot-notebook" + }, + "polyglot_notebook": { + "kernelInfo": { + "defaultKernelName": "csharp", + "items": [ + { + "aliases": [], + "name": ".NET" + }, + { + "aliases": [ + "C#", + "c#" + ], + "languageName": "C#", + "name": "csharp" + }, + { + "aliases": [ + "F#", + "f#" + ], + "languageName": "F#", + "name": "fsharp" + }, + { + "aliases": [], + "languageName": "HTML", + "name": "html" + }, + { + "aliases": [], + "languageName": "KQL", + "name": "kql" + }, + { + "aliases": [], + "languageName": "Mermaid", + "name": "mermaid" + }, + { + "aliases": [ + "powershell" + ], + "languageName": "PowerShell", + "name": "pwsh" + }, + { + "aliases": [], + "languageName": "SQL", + "name": "sql" + }, + { + "aliases": [], + "languageName": "T-SQL", + "name": "sql-Demo" + }, + { + "aliases": [], + "languageName": "T-SQL", + "name": "sql-DemoEF" + }, + { + "aliases": [], + "languageName": "SQLite", + "name": "sql-MySQLiteDemo" + }, + { + "aliases": [], + "name": "value" + }, + { + "aliases": [ + "frontend" + ], + "name": "vscode" + } + ] + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/多语言笔记.3.1.交互式 Razor.ipynb b/Docs/多语言笔记.3.1.交互式 Razor.ipynb similarity index 56% rename from 多语言笔记.3.1.交互式 Razor.ipynb rename to Docs/多语言笔记.3.1.交互式 Razor.ipynb index e6ebe25..6c9aebe 100644 --- a/多语言笔记.3.1.交互式 Razor.ipynb +++ b/Docs/多语言笔记.3.1.交互式 Razor.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -27,7 +27,39 @@ "kernelName": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
Installed Packages
  • RazorInteractive, 1.1.8
" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Loading extensions from `C:\\Users\\ruyu\\.nuget\\packages\\razorinteractive\\1.1.8\\interactive-extensions\\dotnet\\RazorInteractive.dll`" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
\n", + " Renders the code block as Razor markup in dotnet-interactive notebooks.\n", + "

This extension adds a new kernel that can render Razor markdown.

\n", + "

All C# and F# variables are available in the @Model property.

\n", + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "// 可以先添加包源\n", "\n", @@ -44,7 +76,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -68,7 +100,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -77,7 +109,22 @@ "kernelName": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "
    \n", + "
  1. red
  2. \n", + "
  3. green
  4. \n", + "
  5. blue
  6. \n", + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#!razor\n", "\n", diff --git a/多语言笔记.4.1.使用WebApi.ipynb b/Docs/多语言笔记.4.1.使用WebApi.ipynb similarity index 100% rename from 多语言笔记.4.1.使用WebApi.ipynb rename to Docs/多语言笔记.4.1.使用WebApi.ipynb diff --git a/多语言笔记.5.1.使用扩展库.ipynb b/Docs/多语言笔记.5.1.使用扩展库.ipynb similarity index 100% rename from 多语言笔记.5.1.使用扩展库.ipynb rename to Docs/多语言笔记.5.1.使用扩展库.ipynb diff --git a/多语言笔记.6.1.共享变量.ipynb b/Docs/多语言笔记.6.1.共享变量.ipynb similarity index 100% rename from 多语言笔记.6.1.共享变量.ipynb rename to Docs/多语言笔记.6.1.共享变量.ipynb diff --git a/Docs/多语言笔记.7.1.运行xUnit单元测试.ipynb b/Docs/多语言笔记.7.1.运行xUnit单元测试.ipynb new file mode 100644 index 0000000..1c4ccb2 --- /dev/null +++ b/Docs/多语言笔记.7.1.运行xUnit单元测试.ipynb @@ -0,0 +1,71 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "运行 xUnit 单元测试\n", + "=====================" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 全局设置" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "// 默认包源\n", + "#i \"https://api.nuget.org/v3/index.json\"\n", + "\n", + "//Nuget 包引用\n", + "//#r \"nuget: Microsoft.DotNet.Interactive.ExtensionLab,*-*\"\n", + "\n", + "//全局变量" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "language_info": { + "name": "polyglot-notebook" + }, + "orig_nbformat": 4, + "polyglot_notebook": { + "kernelInfo": { + "defaultKernelName": "csharp", + "items": [ + { + "aliases": [], + "name": "csharp" + }, + { + "aliases": [], + "name": "razor" + } + ] + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Docs/多语言笔记.8.1.运行Benchmark基准测试.ipynb b/Docs/多语言笔记.8.1.运行Benchmark基准测试.ipynb new file mode 100644 index 0000000..9ab015f --- /dev/null +++ b/Docs/多语言笔记.8.1.运行Benchmark基准测试.ipynb @@ -0,0 +1,71 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "运行 BenchmarkDotnet 基准测试\n", + "============================" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 全局设置" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "// 默认包源\n", + "#i \"https://api.nuget.org/v3/index.json\"\n", + "\n", + "//Nuget 包引用\n", + "//#r \"nuget: Microsoft.DotNet.Interactive.ExtensionLab,*-*\"\n", + "\n", + "//全局变量" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "language_info": { + "name": "polyglot-notebook" + }, + "orig_nbformat": 4, + "polyglot_notebook": { + "kernelInfo": { + "defaultKernelName": "csharp", + "items": [ + { + "aliases": [], + "name": "csharp" + }, + { + "aliases": [], + "name": "razor" + } + ] + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/多语言笔记.1.2.显示程序执行结果.ipynb b/多语言笔记.1.2.显示程序执行结果.ipynb deleted file mode 100644 index 9ad0b3b..0000000 --- a/多语言笔记.1.2.显示程序执行结果.ipynb +++ /dev/null @@ -1,209 +0,0 @@ -{ - "cells": [ - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 展示程序执行结果" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Console.WriteLine() 方法,输出字符串到结果区域" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "polyglot_notebook": { - "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" - } - }, - "outputs": [], - "source": [ - "Console.WriteLine(\"将字符串输出到展示区!\");" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 使用内置的 Display() 方法" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "polyglot_notebook": { - "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" - } - }, - "outputs": [], - "source": [ - "//直接写变量:限制是必须是最后一行\n", - "var strList = new List(){\"ab\",\"cd\",\"ef\"};\n", - "strList" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "polyglot_notebook": { - "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" - } - }, - "outputs": [], - "source": [ - "// 使用Display()方法,可以多次调用。估计是 .Net InterActive 内容实现的扩展方法\n", - "\n", - "var obj = new {Name=\"张三\",Age=33,Adress=\"河南周口\"};\n", - "\n", - "obj.Display();\n", - "obj.Display();" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 更新Display()返回对象,实现动态展示效果" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "polyglot_notebook": { - "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" - } - }, - "outputs": [], - "source": [ - "var displayObject1 = \"\".Display();\n", - "for(int i=10; i>=0; i--)\n", - "{\n", - " displayObject1.Update(\"倒计时:\" + i);\n", - " await Task.Delay(500);\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "polyglot_notebook": { - "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" - } - }, - "outputs": [], - "source": [ - "var displayText = \"动态添加:\";\n", - "var displayObject = displayText.Display();\n", - "for(int i=0;i<10;i++)\n", - "{\n", - " displayText+=i;\n", - " displayObject.Update(displayText);\n", - " await Task.Delay(200);\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "polyglot_notebook": { - "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" - } - }, - "outputs": [], - "source": [ - "\n", - "var displayText3 = \"开唱:\";\n", - "var displayObject3 = displayText3.Display();\n", - "foreach(var c in \"你是我的小呀小苹果...\".ToCharArray())\n", - "{\n", - " displayText3+=c;\n", - " displayObject3.Update(displayText3);\n", - " await Task.Delay(500);\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "polyglot_notebook": { - "kernelName": "csharp" - }, - "vscode": { - "languageId": "polyglot-notebook" - } - }, - "outputs": [], - "source": [ - "var displayObject4 = DateTime.Now.Display();\n", - "for(int i=0; i<10; i++)\n", - "{\n", - " displayObject4.Update(DateTime.Now);\n", - " await Task.Delay(1000);\n", - "}" - ] - } - ], - "metadata": { - "language_info": { - "name": "python" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/多语言笔记.2.2.连接SQLite.ipynb b/多语言笔记.2.2.连接SQLite.ipynb deleted file mode 100644 index 884dc43..0000000 --- a/多语言笔记.2.2.连接SQLite.ipynb +++ /dev/null @@ -1,427 +0,0 @@ -{ - "cells": [ - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "连接到 SQLite 数据库\n", - "============================== " - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "连接到 SQLite 数据库,并操作数据。注意:此功能在 Microsoft.DotNet.Interactive.ExtensionLab 扩展库中,要先引用 Nuget 包。" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 设置Nuget包源" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "polyglot_notebook": { - "kernelName": "csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
Restore sources
  • https://api.nuget.org/v3/index.json
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "#i \"https://api.nuget.org/v3/index.json\"" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 引用 Nuget 包" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "polyglot_notebook": { - "kernelName": "csharp" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "
Restore sources
  • https://api.nuget.org/v3/index.json
Installed Packages
  • Microsoft.DotNet.Interactive.ExtensionLab, 1.0.0-beta.23165.2
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "Loading extensions from `C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet.interactive.extensionlab\\1.0.0-beta.23165.2\\interactive-extensions\\dotnet\\Microsoft.DotNet.Interactive.ExtensionLab.dll`" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
Create strongly-typed dataframes using#!linqify.\r\n", - "

The #!linqify magic command replaces a Microsoft.Data.Analysis.DataFrame variable with a generated, strongly-typed data frame, allowing the use of LINQ operations over the contained data.

\r\n", - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
ExplainCode\r\n", - "

This extension generates Sequence diagrams from csharp code using Mermaid kernel.

\r\n", - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
Inspect code compilation details using the #!inspect magic command.\r\n", - "

The #!inspect magic command allows you to see the C# decompilation, IL, and JIT Asm for the code in a C# cell.

\r\n", - " \r\n", - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
Use the #!record magic command to keep a transcript of the code you run.\r\n", - "

Once you enable transcripts using #!record, each code submission (including re-running cells) is recorded in the specified file. The JSON format used is the same format recognized by the .NET Interactive stdio and http APIs and can be used to replay an interactive session via automation.

\r\n", - " \r\n", - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
Query SQLite databases.\r\n", - "

This extension adds support for connecting to SQLite databases using the #!connect sqlite magic command. For more information, run a cell using the #!sql magic command.

\r\n", - "
" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "Loading extensions from `C:\\Users\\ruyu\\.nuget\\packages\\microsoft.data.analysis\\0.20.0\\interactive-extensions\\dotnet\\Microsoft.Data.Analysis.Interactive.dll`" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "#r \"nuget: Microsoft.DotNet.Interactive.ExtensionLab,*-*\"" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 连接到 SQLite 数据库" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "引用扩展库后,使用 #!connect sqlite 命令连接到SQLite数据库!" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "polyglot_notebook": { - "kernelName": "csharp" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "Kernel added: #!sql-MySQLiteDemo" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "#!connect sqlite --kernel-name MySQLiteDemo \"Data Source=sqlite\\\\SQLiteDemo.db\"\n", - "\n", - "/*\n", - " 相对目录位置\n", - " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=Database\\SQLiteDemo.db;\"\n", - " \n", - " 缓存共享\n", - " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=Database\\SQLiteDemo.db;Cache=Shared;\"\n", - "\n", - " 使用带密码\n", - " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=SQLiteDemo.db;Cache=Shared;Password=MyEncryptionKey;\"\n", - " \n", - " 只读模式\n", - " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=SQLiteDemo.db;Mode=ReadOnly\"\n", - "\n", - " 读写创建模式\n", - " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=SQLiteDemo.db;Mode=ReadWriteCreate\"\n", - "\n", - " 读写模式\n", - " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=SQLiteDemo.db;Mode=ReadWrite\"\n", - "\n", - " 私有内存模式\n", - " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=:memory:\"\n", - "\n", - " 共享内存模式\n", - " #!connect sqlite --kernel-name MySQLiteDemo \"Data Source=Sharable;Mode=Memory;Cache=Shared\"\n", - "*/" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## 使用连接操作数据库" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "dotnet_interactive": { - "language": "sql-MySQLiteDemo" - }, - "polyglot_notebook": { - "kernelName": "sql-MySQLiteDemo" - } - }, - "outputs": [ - { - "data": { - "text/csv": [ - "Id,Name,Age\r\n", - "1,张三,66\r\n", - "2,李四,55\r\n" - ], - "text/html": [ - "
IdNameAge
1
张三
66
2
李四
55
" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "#!sql-MySQLiteDemo\n", - "\n", - "select * from person;" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## C#中使用" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": { - "dotnet_interactive": { - "language": "csharp" - }, - "polyglot_notebook": { - "kernelName": "csharp" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "xxxxxxxx\r\n" - ] - } - ], - "source": [ - "//直接引用包,使用类库操作就可以了,不需要使用 上下文连接" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": ".NET (C#)", - "language": "C#", - "name": ".net-csharp" - }, - "language_info": { - "name": "polyglot-notebook" - }, - "polyglot_notebook": { - "kernelInfo": { - "defaultKernelName": "csharp", - "items": [ - { - "aliases": [], - "name": ".NET" - }, - { - "aliases": [ - "C#", - "c#" - ], - "languageName": "C#", - "name": "csharp" - }, - { - "aliases": [ - "F#", - "f#" - ], - "languageName": "F#", - "name": "fsharp" - }, - { - "aliases": [], - "languageName": "HTML", - "name": "html" - }, - { - "aliases": [], - "languageName": "KQL", - "name": "kql" - }, - { - "aliases": [], - "languageName": "Mermaid", - "name": "mermaid" - }, - { - "aliases": [ - "powershell" - ], - "languageName": "PowerShell", - "name": "pwsh" - }, - { - "aliases": [], - "languageName": "SQL", - "name": "sql" - }, - { - "aliases": [], - "languageName": "T-SQL", - "name": "sql-Demo" - }, - { - "aliases": [], - "languageName": "T-SQL", - "name": "sql-DemoEF" - }, - { - "aliases": [], - "languageName": "SQLite", - "name": "sql-MySQLiteDemo" - }, - { - "aliases": [], - "name": "value" - }, - { - "aliases": [ - "frontend" - ], - "name": "vscode" - } - ] - } - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}