Skip to content

Commit c01b6a9

Browse files
authored
Session 4 (#26)
1 parent eaf5393 commit c01b6a9

File tree

2 files changed

+940
-3
lines changed

2 files changed

+940
-3
lines changed

notebooks/0101-FirstSession.ipynb

Lines changed: 125 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,21 +631,143 @@
631631
},
632632
{
633633
"cell_type": "code",
634-
"execution_count": 18,
634+
"execution_count": 1,
635635
"metadata": {},
636636
"outputs": [
637637
{
638638
"data": {
639639
"text/html": [
640-
"True"
640+
"\r\n",
641+
"<div>\r\n",
642+
" <div id='dotnet-interactive-this-cell-10059.856a01ed7c9e4ddda1827b4f965ac287' style='display: none'>\r\n",
643+
" The below script needs to be able to find the current output cell; this is an easy method to get it.\r\n",
644+
" </div>\r\n",
645+
" <script type='text/javascript'>\r\n",
646+
"// ensure `require` is available globally\r\n",
647+
"if (typeof require !== typeof Function || typeof require.config !== typeof Function) {\r\n",
648+
" let require_script = document.createElement('script');\r\n",
649+
" require_script.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js');\r\n",
650+
" require_script.setAttribute('type', 'text/javascript');\r\n",
651+
" require_script.onload = function () {\r\n",
652+
" loadDotnetInteractiveApi();\r\n",
653+
" };\r\n",
654+
"\r\n",
655+
" document.getElementsByTagName('head')[0].appendChild(require_script);\r\n",
656+
"}\r\n",
657+
"else {\r\n",
658+
" loadDotnetInteractiveApi();\r\n",
659+
"}\r\n",
660+
"\r\n",
661+
"async function probeAddresses(probingAddresses) {\r\n",
662+
" function timeout(ms, promise) {\r\n",
663+
" return new Promise(function (resolve, reject) {\r\n",
664+
" setTimeout(function () {\r\n",
665+
" reject(new Error('timeout'))\r\n",
666+
" }, ms)\r\n",
667+
" promise.then(resolve, reject)\r\n",
668+
" })\r\n",
669+
" }\r\n",
670+
"\r\n",
671+
" if (Array.isArray(probingAddresses)) {\r\n",
672+
" for (let i = 0; i < probingAddresses.length; i++) {\r\n",
673+
"\r\n",
674+
" let rootUrl = probingAddresses[i];\r\n",
675+
"\r\n",
676+
" if (!rootUrl.endsWith('/')) {\r\n",
677+
" rootUrl = `${rootUrl}/`;\r\n",
678+
" }\r\n",
679+
"\r\n",
680+
" try {\r\n",
681+
" let response = await timeout(1000, fetch(`${rootUrl}discovery`, {\r\n",
682+
" method: 'POST',\r\n",
683+
" cache: 'no-cache',\r\n",
684+
" mode: 'cors',\r\n",
685+
" timeout: 1000,\r\n",
686+
" headers: {\r\n",
687+
" 'Content-Type': 'text/plain'\r\n",
688+
" },\r\n",
689+
" body: probingAddresses[i]\r\n",
690+
" }));\r\n",
691+
"\r\n",
692+
" if (response.status == 200) {\r\n",
693+
" return rootUrl;\r\n",
694+
" }\r\n",
695+
" }\r\n",
696+
" catch (e) { }\r\n",
697+
" }\r\n",
698+
" }\r\n",
699+
"}\r\n",
700+
"\r\n",
701+
"function loadDotnetInteractiveApi() {\r\n",
702+
" probeAddresses([\"http://192.168.1.151:1025/\", \"http://127.0.0.1:1025/\"])\r\n",
703+
" .then((root) => {\r\n",
704+
" // use probing to find host url and api resources\r\n",
705+
" // load interactive helpers and language services\r\n",
706+
" let dotnetInteractiveRequire = require.config({\r\n",
707+
" context: '10059.856a01ed7c9e4ddda1827b4f965ac287',\r\n",
708+
" paths: {\r\n",
709+
" 'dotnet-interactive': `${root}resources`\r\n",
710+
" }\r\n",
711+
" }) || require;\r\n",
712+
"\r\n",
713+
" let dotnetInteractiveExtensionsRequire = require.config({\r\n",
714+
" context: '10059.856a01ed7c9e4ddda1827b4f965ac287',\r\n",
715+
" paths: {\r\n",
716+
" 'dotnet-interactive-extensions': `${root}extensions`\r\n",
717+
" }\r\n",
718+
" }) || require;\r\n",
719+
" if (!window.dotnetInteractiveRequire) {\r\n",
720+
" window.dotnetInteractiveRequire = dotnetInteractiveRequire;\r\n",
721+
" }\r\n",
722+
"\r\n",
723+
" if (!window.dotnetInteractiveExtensionsRequire) {\r\n",
724+
" window.dotnetInteractiveExtensionsRequire = dotnetInteractiveExtensionsRequire;\r\n",
725+
" }\r\n",
726+
"\r\n",
727+
" window.getExtensionRequire = function(extensionName, extensionCacheBuster) {\r\n",
728+
" let paths = {};\r\n",
729+
" paths[extensionName] = `${root}extensions/${extensionName}/resources/`;\r\n",
730+
" \r\n",
731+
" let internalRequire = require.config({\r\n",
732+
" context: extensionCacheBuster,\r\n",
733+
" paths: paths,\r\n",
734+
" urlArgs: `cacheBuster=${extensionCacheBuster}`\r\n",
735+
" }) || require;\r\n",
736+
"\r\n",
737+
" return internalRequire\r\n",
738+
" };\r\n",
739+
" \r\n",
740+
" dotnetInteractiveRequire([\r\n",
741+
" 'dotnet-interactive/dotnet-interactive'\r\n",
742+
" ],\r\n",
743+
" function (dotnet) {\r\n",
744+
" dotnet.init(window);\r\n",
745+
" },\r\n",
746+
" function (error) {\r\n",
747+
" console.log(error);\r\n",
748+
" }\r\n",
749+
" );\r\n",
750+
" })\r\n",
751+
" .catch(error => {console.log(error);});\r\n",
752+
" }\r\n",
753+
" </script>\r\n",
754+
"</div>"
641755
]
642756
},
643757
"metadata": {},
644758
"output_type": "display_data"
759+
},
760+
{
761+
"ename": "Unhandled exception",
762+
"evalue": "(1,9): error CS0103: The name 'apples' does not exist in the current context\n(1,19): error CS0103: The name 'oranges' does not exist in the current context",
763+
"output_type": "error",
764+
"traceback": [
765+
"(1,9): error CS0103: The name 'apples' does not exist in the current context\n(1,19): error CS0103: The name 'oranges' does not exist in the current context"
766+
]
645767
}
646768
],
647769
"source": [
648-
"display(apples != oranges);"
770+
"display(apples != oranges); // The not-equals operator"
649771
]
650772
},
651773
{

0 commit comments

Comments
 (0)