Skip to content

Commit 411d056

Browse files
author
Tomáš Bezouška
committed
Visual basic sample
Resolves step-up-labs#204 Resolves step-up-labs#186
1 parent b89fc58 commit 411d056

File tree

5 files changed

+102
-3
lines changed

5 files changed

+102
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<RootNamespace>ConsoleChat.VisualBasic</RootNamespace>
6+
<TargetFramework>netcoreapp3.0</TargetFramework>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="FirebaseDatabase.net" Version="4.0.1" />
11+
</ItemGroup>
12+
13+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Imports Newtonsoft.Json
2+
3+
Public Class MessageBase
4+
Property Author() As String
5+
Property Content As String
6+
End Class
7+
8+
Public Class OutboundMessage
9+
Inherits MessageBase
10+
11+
<JsonProperty("Timestamp")> Property TimestampPlaceholder() As ServerTimeStamp = New ServerTimeStamp()
12+
End Class
13+
14+
Public Class InboundMessage
15+
Inherits MessageBase
16+
17+
Property Timestamp() As Long
18+
End Class
19+
20+
21+
Public Class ServerTimeStamp
22+
<JsonProperty(".sv")> Property TimestampPlaceholder() As String = "timestamp"
23+
End Class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Imports System
2+
Imports System.Reactive.Linq
3+
Imports Firebase.Database
4+
Imports Firebase.Database.Query
5+
6+
Module Program
7+
Sub Main(args As String())
8+
Run().Wait()
9+
End Sub
10+
11+
Async Function Run() As Task
12+
Console.WriteLine("You can run this application multiple times to simulate chat between multiple users")
13+
Console.Write("What's your name? ")
14+
15+
Dim name = Console.ReadLine()
16+
17+
Console.WriteLine("*******************************************************")
18+
19+
Dim client = New FirebaseClient("https://torrid-inferno-3642.firebaseio.com/")
20+
Dim child = client.Child("messages")
21+
22+
Dim observable = child.AsObservable(Of InboundMessage)
23+
24+
' delete entire conversation list
25+
Await child.DeleteAsync()
26+
27+
Console.WriteLine("Start chatting")
28+
29+
' subscribe to messages comming in, ignoring the ones that are from me
30+
Dim subscription = observable _
31+
.Where(Function(f) Not String.IsNullOrEmpty(f.Key)) _ ' you Get empty Key When there are no data On the server For specified node
32+
.Where(Function(f) f.Object?.Author IsNot name) _
33+
.Subscribe(Sub(f) Console.WriteLine($"{f.Object.Author}: {f.Object.Content}"))
34+
35+
While (True)
36+
37+
Dim message = Console.ReadLine()
38+
39+
If (message?.ToLower() Is "q") Then
40+
Exit While
41+
Else
42+
Dim msg = New OutboundMessage
43+
msg.Author = name
44+
msg.Content = message
45+
Await child.PostAsync(msg)
46+
End If
47+
End While
48+
49+
subscription.Dispose()
50+
End Function
51+
52+
53+
End Module

samples/ConsoleChat/ConsoleChat/Program.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ private static async Task Run()
2222
var name = Console.ReadLine();
2323

2424
Console.WriteLine("*******************************************************");
25-
Console.WriteLine("Start chatting");
2625

2726
var client = new FirebaseClient("https://yourfirebase.firebaseio.com/");
2827
var child = client.Child("messages");
@@ -32,6 +31,8 @@ private static async Task Run()
3231
// delete entire conversation list
3332
await child.DeleteAsync();
3433

34+
Console.WriteLine("Start chatting");
35+
3536
// subscribe to messages comming in, ignoring the ones that are from me
3637
var subscription = observable
3738
.Where(f => !string.IsNullOrEmpty(f.Key)) // you get empty Key when there are no data on the server for specified node

samples/ConsoleChat/Firebase.ConsoleChat.sln

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25123.0
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29324.140
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleChat", "ConsoleChat\ConsoleChat.csproj", "{18224765-6438-4D4C-8432-D29ED0AA45B4}"
77
EndProject
8+
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ConsoleChat.VisualBasic", "ConsoleChat.VisualBasic\ConsoleChat.VisualBasic.vbproj", "{16665B21-1BE9-4D01-8DFC-D1909C4B3413}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,8 +17,15 @@ Global
1517
{18224765-6438-4D4C-8432-D29ED0AA45B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{18224765-6438-4D4C-8432-D29ED0AA45B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{18224765-6438-4D4C-8432-D29ED0AA45B4}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{16665B21-1BE9-4D01-8DFC-D1909C4B3413}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{16665B21-1BE9-4D01-8DFC-D1909C4B3413}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{16665B21-1BE9-4D01-8DFC-D1909C4B3413}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{16665B21-1BE9-4D01-8DFC-D1909C4B3413}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE
2127
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {2E712524-3A0A-4F17-9E96-264F64FE890A}
30+
EndGlobalSection
2231
EndGlobal

0 commit comments

Comments
 (0)