Skip to content

Commit

Permalink
item collection link
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed May 5, 2021
1 parent 576eb5c commit 95fecdf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
45 changes: 36 additions & 9 deletions notebooks/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [],
"outputs": [
{
"data": {
"text/html": "\r\n<div>\r\n <div id='dotnet-interactive-this-cell-573046.7669508812924a52b5f70fe456ee3845' style='display: none'>\r\n The below script needs to be able to find the current output cell; this is an easy method to get it.\r\n </div>\r\n <script type='text/javascript'>\r\n// ensure `require` is available globally\r\nif (typeof require !== typeof Function || typeof require.config !== typeof Function) {\r\n let require_script = document.createElement('script');\r\n require_script.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js');\r\n require_script.setAttribute('type', 'text/javascript');\r\n require_script.onload = function () {\r\n loadDotnetInteractiveApi();\r\n };\r\n\r\n document.getElementsByTagName('head')[0].appendChild(require_script);\r\n}\r\nelse {\r\n loadDotnetInteractiveApi();\r\n}\r\n\r\nasync function probeAddresses(probingAddresses) {\r\n function timeout(ms, promise) {\r\n return new Promise(function (resolve, reject) {\r\n setTimeout(function () {\r\n reject(new Error('timeout'))\r\n }, ms)\r\n promise.then(resolve, reject)\r\n })\r\n }\r\n\r\n if (Array.isArray(probingAddresses)) {\r\n for (let i = 0; i < probingAddresses.length; i++) {\r\n\r\n let rootUrl = probingAddresses[i];\r\n\r\n if (!rootUrl.endsWith('/')) {\r\n rootUrl = `${rootUrl}/`;\r\n }\r\n\r\n try {\r\n let response = await timeout(1000, fetch(`${rootUrl}discovery`, {\r\n method: 'POST',\r\n cache: 'no-cache',\r\n mode: 'cors',\r\n timeout: 1000,\r\n headers: {\r\n 'Content-Type': 'text/plain'\r\n },\r\n body: probingAddresses[i]\r\n }));\r\n\r\n if (response.status == 200) {\r\n return rootUrl;\r\n }\r\n }\r\n catch (e) { }\r\n }\r\n }\r\n}\r\n\r\nfunction loadDotnetInteractiveApi() {\r\n probeAddresses([\"http://192.168.0.15:1026/\", \"http://172.17.0.1:1026/\", \"http://127.0.0.1:1026/\"])\r\n .then((root) => {\r\n // use probing to find host url and api resources\r\n // load interactive helpers and language services\r\n let dotnetInteractiveRequire = require.config({\r\n context: '573046.7669508812924a52b5f70fe456ee3845',\r\n paths: {\r\n 'dotnet-interactive': `${root}resources`\r\n }\r\n }) || require;\r\n\r\n let dotnetInteractiveExtensionsRequire = require.config({\r\n context: '573046.7669508812924a52b5f70fe456ee3845',\r\n paths: {\r\n 'dotnet-interactive-extensions': `${root}extensions`\r\n }\r\n }) || require;\r\n\r\n if (!window.dotnetInteractiveRequire) {\r\n window.dotnetInteractiveRequire = dotnetInteractiveRequire;\r\n }\r\n\r\n if (!window.dotnetInteractiveExtensionsRequire) {\r\n window.dotnetInteractiveExtensionsRequire = dotnetInteractiveExtensionsRequire;\r\n }\r\n\r\n window.getExtensionRequire = function(extensionName, extensionCacheBuster) {\r\n let paths = {};\r\n paths[extensionName] = `${root}extensions/${extensionName}/resources/`;\r\n \r\n let internalRequire = require.config({\r\n context: extensionCacheBuster,\r\n paths: paths,\r\n urlArgs: `cacheBuster=${extensionCacheBuster}`\r\n }) || require;\r\n\r\n return internalRequire\r\n };\r\n \r\n dotnetInteractiveRequire([\r\n 'dotnet-interactive/dotnet-interactive'\r\n ],\r\n function (dotnet) {\r\n dotnet.init(window);\r\n },\r\n function (error) {\r\n console.log(error);\r\n }\r\n );\r\n })\r\n .catch(error => {console.log(error);});\r\n }\r\n </script>\r\n</div>"
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": "<div><strong>Restore sources</strong><ul><li><span>/home/emathot/Workspace/Terradue/Components/sugar/DotNetStac/src/DotNetStac/bin/Debug/netstandard2.0/publish/</span></li></ul></div>"
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"// Use built lib\n",
"#i \"/home/jovyan/src/DotNetStac/bin/Debug/netstandard2.0/publish/\"\n",
"#r \"/home/jovyan/src/DotNetStac/bin/Debug/netstandard2.0/publish/DotNetStac.dll\""
"#i \"/home/emathot/Workspace/Terradue/Components/sugar/DotNetStac/src/DotNetStac/bin/Debug/netstandard2.0/publish/\"\n",
"#r \"/home/emathot/Workspace/Terradue/Components/sugar/DotNetStac/src/DotNetStac/bin/Debug/netstandard2.0/publish/DotNetStac.dll\""
]
},
{
Expand All @@ -76,14 +91,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {
"slideshow": {
"slide_type": "slide"
},
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
": [VALID]\n",
"1.0.0-rc.2\n"
]
}
],
"source": [
"using Stac;\n",
"using Stac.Schemas;\n",
Expand All @@ -92,7 +116,7 @@
"using Newtonsoft.Json.Schema;\n",
"\n",
"var webc = new WebClient();\n",
"Uri catalogUri = new Uri(\"https://cbers-stac-1-0-rc.s3.amazonaws.com/catalog.json\");\n",
"Uri catalogUri = new Uri(\"https://franklin.nasa-hsi.azavea.com/collections\");\n",
"StacValidator stacValidator = new StacValidator(new JSchemaUrlResolver());\n",
"\n",
"// StacConvert.Deserialize is the helper to start loading any STAC document\n",
Expand Down Expand Up @@ -121,7 +145,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {
"slideshow": {
"slide_type": "slide"
Expand Down Expand Up @@ -543,8 +567,11 @@
"name": ".net-csharp"
},
"language_info": {
"file_extension": ".cs",
"mimetype": "text/x-csharp",
"name": "C#",
"version": ""
"pygments_lexer": "csharp",
"version": "8.0"
},
"metadata": {
"interpreter": {
Expand Down
7 changes: 5 additions & 2 deletions src/DotNetStac/Extensions/ItemCollection/ItemCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ internal static JSchema GenerateJSchema(string version)

jSchema.AllOf.Add(fcr);

JSchema itemSchema = GetSchema(new Uri("https://schemas.stacspec.org/v"+ version +"/item-spec/json-schema/item.json"));
JSchema linkSchema = JSchema.Parse(itemSchema.ExtensionData["definitions"]["link"].ToString());

jSchema.AllOf.Add(new JSchema()
{
Properties = {
Expand All @@ -77,12 +80,12 @@ internal static JSchema GenerateJSchema(string version)
{ "features", new JSchema(){
Title = "ItemCollection features",
Type = JSchemaType.Array,
Items = { new JSchema { Ref = GetSchema(new Uri("https://schemas.stacspec.org/v"+ version +"/item-spec/json-schema/item.json")) } }
Items = { new JSchema { Ref = itemSchema } }
}},
{ "links", new JSchema(){
Title = "Links",
Type = JSchemaType.Array,
Items = { new JSchema { Ref = GetSchema(new Uri("https://schemas.stacspec.org/v"+ version +"/item-spec/json-schema/item.json#/definitions/link")) } }
Items = { new JSchema { Ref = linkSchema } }
}},
}
});
Expand Down

0 comments on commit 95fecdf

Please sign in to comment.