Skip to content

Commit 652aef2

Browse files
pyjarrettrzikm
andauthored
Adds F# IPStatus snippet for System.Net.NetworkInformation (#8934)
* Adds F# IPStatus snippet for System.Net.NetworkInformation * Fix snippet paths. Co-authored-by: Radek Zikmund <[email protected]> * Add error message and fix remaining snippet strings. --------- Co-authored-by: Radek Zikmund <[email protected]>
1 parent d604210 commit 652aef2

File tree

6 files changed

+58
-0
lines changed

6 files changed

+58
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net6.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Compile Include="syncping.fs" />
9+
</ItemGroup>
10+
</Project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module Examples.System.Net.NetworkInformation.PingTest
2+
3+
//NCLPingSync
4+
//<snippet1>
5+
open System.Net.NetworkInformation
6+
open System.Text
7+
8+
// args[0] can be an IPaddress or host name.
9+
[<EntryPoint>]
10+
let main args =
11+
//<snippet3>
12+
//<snippet2>
13+
let pingSender = new Ping()
14+
15+
// Use the default Ttl value which is 128,
16+
// but change the fragmentation behavior.
17+
let options = PingOptions()
18+
options.DontFragment <- true
19+
20+
//</snippet2>
21+
// Create a buffer of 32 bytes of data to be transmitted.
22+
let data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
23+
let buffer = Encoding.ASCII.GetBytes data
24+
let timeout = 120
25+
let reply: PingReply = pingSender.Send(args.[0], timeout, buffer, options)
26+
//</snippet3>
27+
//<snippet4>
28+
29+
match reply.Status with
30+
| IPStatus.Success ->
31+
printfn "Address: %O" reply.Address
32+
printfn "RoundTrip time: %d" reply.RoundtripTime
33+
printfn "Time to live: %d" reply.Options.Ttl
34+
printfn "Don't fragment: %b" reply.Options.DontFragment
35+
printfn "Buffer size: %d" reply.Buffer.Length
36+
0
37+
| _ ->
38+
eprintfn "Error sending ping: %O" reply
39+
eprintfn "Error was: %O" reply.Status
40+
1
41+
//</snippet4>
42+
//</snippet1>

xml/System.Net.NetworkInformation/IPStatus.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
5555
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/NclPingSync/CPP/syncping.cpp" id="Snippet1":::
5656
:::code language="csharp" source="~/snippets/csharp/System.Net.NetworkInformation/IPStatus/Overview/syncping.cs" id="Snippet1":::
57+
:::code language="fsharp" source="~/snippets/fsharp/System.Net.NetworkInformation/IPStatus/Overview/syncping.fs" id="Snippet1":::
5758
5859
]]></format>
5960
</remarks>

xml/System.Net.NetworkInformation/Ping.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
102102
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/NclPingSync/CPP/syncping.cpp" id="Snippet1":::
103103
:::code language="csharp" source="~/snippets/csharp/System.Net.NetworkInformation/IPStatus/Overview/syncping.cs" id="Snippet1":::
104+
:::code language="fsharp" source="~/snippets/fsharp/System.Net.NetworkInformation/IPStatus/Overview/syncping.fs" id="Snippet1":::
104105
105106
The following code example demonstrates using the <xref:System.Net.NetworkInformation.Ping> class asynchronously.
106107

xml/System.Net.NetworkInformation/PingOptions.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
6161
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/NclPingSync/CPP/syncping.cpp" id="Snippet1":::
6262
:::code language="csharp" source="~/snippets/csharp/System.Net.NetworkInformation/IPStatus/Overview/syncping.cs" id="Snippet1":::
63+
:::code language="fsharp" source="~/snippets/fsharp/System.Net.NetworkInformation/IPStatus/Overview/syncping.fs" id="Snippet1":::
6364
6465
]]></format>
6566
</remarks>
@@ -127,6 +128,7 @@
127128
128129
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/NclPingSync/CPP/syncping.cpp" id="Snippet2":::
129130
:::code language="csharp" source="~/snippets/csharp/System.Net.NetworkInformation/IPStatus/Overview/syncping.cs" id="Snippet2":::
131+
:::code language="fsharp" source="~/snippets/fsharp/System.Net.NetworkInformation/IPStatus/Overview/syncping.fs" id="Snippet2":::
130132
131133
]]></format>
132134
</remarks>

xml/System.Net.NetworkInformation/PingReply.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
5757
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/NclPingSync/CPP/syncping.cpp" id="Snippet1":::
5858
:::code language="csharp" source="~/snippets/csharp/System.Net.NetworkInformation/IPStatus/Overview/syncping.cs" id="Snippet1":::
59+
:::code language="fsharp" source="~/snippets/fsharp/System.Net.NetworkInformation/IPStatus/Overview/syncping.fs" id="Snippet1":::
5960
6061
]]></format>
6162
</remarks>
@@ -355,6 +356,7 @@
355356
356357
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/NclPingSync/CPP/syncping.cpp" id="Snippet1":::
357358
:::code language="csharp" source="~/snippets/csharp/System.Net.NetworkInformation/IPStatus/Overview/syncping.cs" id="Snippet1":::
359+
:::code language="fsharp" source="~/snippets/fsharp/System.Net.NetworkInformation/IPStatus/Overview/syncping.fs" id="Snippet1":::
358360
359361
]]></format>
360362
</remarks>

0 commit comments

Comments
 (0)