public PSNotebookCell(NotebookCell notebookCell)
 {
     this.CellType             = notebookCell?.CellType;
     this.Metadata             = notebookCell?.Metadata;
     this.Source               = notebookCell?.Source;
     this.Attachments          = notebookCell?.Attachments;
     this.Outputs              = notebookCell?.Outputs?.Select(element => new PSNotebookCellOutputItem(element)).ToList();
     this.AdditionalProperties = notebookCell?.AdditionalProperties;
 }
Example #2
0
        public async Task CreateAndUploadNotebook()
        {
            #region Snippet:CreateNotebookClient
#if SNIPPET
            // Replace the string below with your actual endpoint url.
            string endpoint = "<my-endpoint-url>";
#else
            string endpoint = TestEnvironment.EndpointUrl;
#endif
            var client = new NotebookClient(endpoint: new Uri(endpoint), credential: new DefaultAzureCredential());
            #endregion

            #region Snippet:ConfigureNotebookResource
            string notebookName = "Test-Notebook";
            var    cell         = new NotebookCell("code", new NotebookMetadata(), new string[] {
                "from azureml.opendatasets import NycTlcYellow\n",
                "\n",
                "data = NycTlcYellow()\n",
                "df = data.to_spark_dataframe()\n",
                "# Display 10 rows\n",
                "display(df.limit(10))"
            });
            var newNotebook      = new Notebook(new NotebookMetadata(), 4, 2, new NotebookCell[] { cell });
            var notebookResource = new NotebookResource(notebookName, newNotebook);
            #endregion

            #region Snippet:CreateNotebook
            NotebookCreateOrUpdateNotebookOperation operation = await client.StartCreateOrUpdateNotebookAsync(notebookName, notebookResource);

            await operation.WaitForCompletionAsync();

            Console.WriteLine("The notebook is created");
            #endregion

            #region Snippet:RetrieveNotebook
            NotebookResource retrievedNotebook = client.GetNotebook(notebookName);
            #endregion

            #region Snippet:ListNotebooks
            Pageable <NotebookResource> notebooks = client.GetNotebooksByWorkspace();
            foreach (NotebookResource notebook in notebooks)
            {
                Console.WriteLine(notebook.Name);
            }
            #endregion

            #region Snippet:DeleteNotebook
            NotebookDeleteNotebookOperation deleteNotebookOperation = client.StartDeleteNotebook(notebookName);
            await deleteNotebookOperation.WaitForCompletionResponseAsync();

            #endregion
        }
        public NotebookCell ToSdkObject()
        {
            if (this.Metadata == null)
            {
                this.Metadata = new System.Collections.Generic.Dictionary <string, object>();
            }
            var cell = new NotebookCell(this.CellType, this.Metadata, this.Source)
            {
                Attachments = this.Attachments,
            };

            this.Outputs?.ForEach(item => cell.Outputs.Add(item?.ToSdkObject()));
            this.AdditionalProperties?.ForEach(item => cell.Add(item.Key, item.Value));
            return(cell);
        }
Example #4
0
        public PSNotebookCell(NotebookCell notebookCell)
        {
            this.CellType    = notebookCell?.CellType;
            this.Metadata    = notebookCell?.Metadata;
            this.Source      = notebookCell?.Source;
            this.Attachments = notebookCell?.Attachments;
            this.Outputs     = notebookCell?.Outputs?.Select(element => new PSNotebookCellOutputItem(element)).ToList();
            var propertiesEnum = notebookCell?.GetEnumerator();

            if (propertiesEnum != null)
            {
                this.AdditionalProperties = new Dictionary <string, object>();
                while (propertiesEnum.MoveNext())
                {
                    this.AdditionalProperties.Add(propertiesEnum.Current);
                }
            }
        }
Example #5
0
        public async Task CreateAndUploadNotebook()
        {
            string notebookName = "demo_notebook";
            string endpoint     = TestEnvironment.EndpointUrl;

            var client = new NotebookClient(endpoint: new Uri(endpoint), credential: new DefaultAzureCredential());

            var cell = new NotebookCell("code", new NotebookMetadata(), new string[] {
                "from azureml.opendatasets import NycTlcYellow\n",
                "\n",
                "data = NycTlcYellow()\n",
                "df = data.to_spark_dataframe()\n",
                "# Display 10 rows\n",
                "display(df.limit(10))"
            });
            var notebook         = new Notebook(new NotebookMetadata(), 4, 2, new NotebookCell[] { cell });
            var notebookResource = new NotebookResource(notebookName, notebook);

            NotebookCreateOrUpdateNotebookOperation operation = await client.StartCreateOrUpdateNotebookAsync(notebookName, notebookResource);

            await operation.WaitForCompletionAsync();

            Console.WriteLine("Notebook is created");
        }