Working with notebook in VS Code using the "dotnet interactive" extension

Screenshot of notebook from VS Code
Screenshot of notebook from VS Code

Today I want to tell you about such a wonderful tool as "dotnet interactive". I will show by my example how and why I started using it, and briefly describe where to start.





Problem

, . , , . ยซ ยป ยซ ยป , .





, . , , , , "dotnet-interactive" notebook'a " "-""-""-"", .





notebook'a

, .net5 sdk VS Code. , ".NET Interactive Notebooks". "Preview", .





, , , . VS Code ".NET Interactive: Create new blank notebook" notebook.





:





#load "Load.fsx"

open Load

let Experiment = loadSep "2021.02.03_15.55.58_gen.sep"
      
      



F# , xml-:





#r "nuget: System.Text.Encoding.CodePages"
#r "AKIM.Protocol.dll"

open System.IO
open AKIM.Protocol
open System.Xml.Serialization
open System.Text

let loadSep path=
    
    let deserializeXml (xml : string) =
        let toBytes (x : string) = Encoding.UTF8.GetBytes x
        let xmlSerializer = XmlSerializer(typeof<Experiment>)
        use stream = new MemoryStream(toBytes xml)
        xmlSerializer.Deserialize stream :?> Experiment

    Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)    
    deserializeXml (File.ReadAllText(path, Encoding.GetEncoding(1251)))
      
      



nuget dto-, C#.





notebook'a c#-intaractive # f#,





#r "AKIM.Protocol.dll"

using AKIM.Protocol;
using AKIM.Protocol.Events;
using AKIM.Protocol.Events.OperatorSvn;
using AKIM.Protocol.Events.OperSb;
using AKIM.Protocol.Events.RespUnits;
using AKIM.Protocol.Events.Intruders;
using AKIM.Protocol.Events.Sens;
using AKIM.Protocol.Events.System;

#!share --from fsharp Experiment
      
      



, . ,





var allTests = Experiment.Tests.Count;

var penetrations = Experiment.Tests.Where(t => t.Events.Last() is PenetrationEvent).Count();
var nonPenetrations = Experiment.Tests.Where(t => t.Events.Last() is NonPenetEvent).Count();

var eve = Experiment.Tests.First().Events.FirstOrDefault(t => t is VisContactEvent);

Console.WriteLine(eve?.GetDescription());

Console.WriteLine($"  {penetrations}  {allTests}")
      
      



:





, :





#r "nuget: XPlot.Plotly"

#!share --from csharp penetrations 
#!share --from csharp nonPenetrations
#!share --from csharp allTests

open XPlot.Plotly

Chart.Pie(seq {("- ",penetrations);
               ("",allTests- penetrations-nonPenetrations);
               ("  ",nonPenetrations)}) |> Chart.Show
      
      



, , (upd: XPlot.Plotly.Interactive. c# f# ( )).





Summary chart

, F# , , , . , , notebook , .





?

# "*.csx" #-interactive. , . , , . markdown $$...$$. (upd: , , markdown )





, .net . : , - , F# C#, , , manage' - . , , , , , ( ).





, Arkadiy Kuznetsov, .





. notebook' VS Code.





.





The official turnip, which also has

.NET Interactive + ML.NET documentation

New features f # (uses dotnet-intaractive at the beginning of the video)








All Articles