-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
291 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Editor configuration, see http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 3 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
max_line_length = 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,4 +337,7 @@ ASALocalRun/ | |
.localhistory/ | ||
|
||
# BeatPulse healthcheck temp database | ||
healthchecksdb | ||
healthchecksdb | ||
|
||
|
||
nuget.config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,83 @@ | ||
using Newtonsoft.Json; | ||
using Senstate.CSharp_Client; | ||
using Senstate.CSharp_Client.Tests; | ||
using Senstate.NetStandard; | ||
using System; | ||
using System.Linq; | ||
using System.Net.WebSockets; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Senstate_ExampleApp | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
SenstateContext.AppName = "C# Console Log"; | ||
SenstateContext.SerializerInstance = new DummySerializer(); | ||
SenstateContext.WebSocketInstance = new DotNetWebSocket(); | ||
SenstateContext.RegisterApp(); | ||
|
||
var stringWatcher = new Watcher( | ||
new WatcherMeta | ||
{ | ||
Tag = "Some Label", | ||
Type = WatcherType.String, | ||
Group = "Example Group 1" | ||
} | ||
); | ||
|
||
var numberWatcher = new Watcher( | ||
new WatcherMeta | ||
{ | ||
Tag = "Number", | ||
Type = WatcherType.Number, | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var webSocket = new NetStandardWebSocketImplementation(); | ||
webSocket.ExceptionThrown += (sender, e) => | ||
{ | ||
throw e.Exception; | ||
}; | ||
|
||
SenstateContext.SerializerInstance = new NetStandardJsonNetImplementation(); | ||
SenstateContext.WebSocketInstance = webSocket; | ||
SenstateContext.RegisterApp("C# Console Log"); | ||
|
||
var stringWatcher = new Watcher( | ||
new WatcherMeta | ||
{ | ||
Tag = "Some Label", | ||
Type = WatcherType.String, | ||
Group = "Example Group 1" | ||
} | ||
); | ||
|
||
var objectWatcher = new Watcher( | ||
new WatcherMeta | ||
{ | ||
Tag = "Object", | ||
Type = WatcherType.Json, | ||
Group = "Special" | ||
} | ||
); | ||
|
||
try | ||
{ | ||
throw new NullReferenceException(); | ||
} | ||
catch(Exception ex) | ||
{ | ||
ErrorSender.Send(ex); | ||
} | ||
|
||
for (var i = 0; i<10000; i++) { | ||
|
||
Thread.Sleep(500); | ||
} | ||
); | ||
|
||
var numberWatcher = new Watcher( | ||
new WatcherMeta | ||
{ | ||
Tag = "Number", | ||
Type = WatcherType.Number, | ||
Group = "Example Group 1" | ||
} | ||
); | ||
|
||
var objectWatcher = new Watcher( | ||
new WatcherMeta | ||
{ | ||
Tag = "Object", | ||
Type = WatcherType.Json, | ||
Group = "Special" | ||
} | ||
); | ||
|
||
try | ||
{ | ||
throw new NullReferenceException(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
ErrorSender.Send(ex); | ||
} | ||
|
||
for (var i = 0; i < 10000; i++) | ||
{ | ||
|
||
Thread.Sleep(500); | ||
stringWatcher.SendData($"This an example Text {i}"); | ||
numberWatcher.SendData(i); | ||
|
||
var someObject = new | ||
{ | ||
example = true, | ||
sub = new | ||
{ | ||
data = i | ||
} | ||
}; | ||
|
||
Logger.SendLog(LoggerType.Debug, $"Debug {i}", someObject); | ||
Logger.SendLog(LoggerType.Info, $"Info {i}"); | ||
|
||
|
||
objectWatcher.SendData(someObject); | ||
} | ||
|
||
|
||
Console.ReadKey(); | ||
} | ||
numberWatcher.SendData(i); | ||
|
||
|
||
|
||
private class DummyWebSocket : ISenstateWebSocket | ||
{ | ||
public void CreateSocket(Uri targetEndpoint) | ||
{ | ||
Console.WriteLine("Created a Dummy Socket"); | ||
} | ||
|
||
public void SendToSocket(string jsonData) | ||
{ | ||
Console.WriteLine($"{jsonData}"); | ||
} | ||
} | ||
|
||
|
||
private class DotNetWebSocket : ISenstateWebSocket | ||
{ | ||
ClientWebSocket m_socket = new ClientWebSocket(); | ||
private Task connectionTask = null; | ||
|
||
public void CreateSocket(Uri targetEndpoint) | ||
var someObject = new | ||
{ | ||
CancellationTokenSource source = new CancellationTokenSource(); | ||
CancellationToken token = source.Token; | ||
|
||
connectionTask = m_socket.ConnectAsync(targetEndpoint, token); | ||
} | ||
|
||
public async void SendToSocket(string jsonData) | ||
{ | ||
if (!connectionTask.IsCompleted) | ||
{ | ||
await connectionTask; | ||
} | ||
|
||
if (m_socket.State == WebSocketState.Open) | ||
{ | ||
CancellationTokenSource source = new CancellationTokenSource(); | ||
CancellationToken token = source.Token; | ||
|
||
var utf8Array = Encoding.UTF8.GetBytes(jsonData).AsMemory(); | ||
|
||
|
||
Console.WriteLine($"Sending to Hub {jsonData}"); | ||
await m_socket.SendAsync(utf8Array, WebSocketMessageType.Text, true, token); | ||
} | ||
} | ||
} | ||
} | ||
example = true, | ||
sub = new | ||
{ | ||
data = i | ||
} | ||
}; | ||
|
||
Logger.SendLog(LoggerType.Debug, $"Debug {i}", someObject); | ||
Logger.SendLog(LoggerType.Info, $"Info {i}"); | ||
|
||
objectWatcher.SendData(someObject); | ||
} | ||
|
||
Console.ReadKey(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace Senstate.CSharp_Client | ||
{ | ||
public interface ISenstateJson | ||
{ | ||
string ConvertToString(object data); | ||
} | ||
|
||
public interface ISenstateWebSocket | ||
{ | ||
void CreateSocket(Uri targetEndpoint); | ||
void SendToSocket(string jsonData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.