Skip to content

Commit

Permalink
Version 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
negue committed Jun 13, 2020
1 parent 0847282 commit 6c2f981
Show file tree
Hide file tree
Showing 21 changed files with 291 additions and 251 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,7 @@ ASALocalRun/
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb
healthchecksdb


nuget.config
195 changes: 72 additions & 123 deletions Senstate-ExampleApp/Program.cs
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();
}
}
}
1 change: 1 addition & 0 deletions Senstate-ExampleApp/Senstate-ExampleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ItemGroup>
<ProjectReference Include="..\Senstate.CSharp-Client.Tests\Senstate.CSharp-Client.Tests.csproj" />
<ProjectReference Include="..\Senstate.CSharp-Client\Senstate.CSharp-Client.csproj" />
<ProjectReference Include="..\Senstate.NetStandard\Senstate.NetStandard.csproj" />
</ItemGroup>

</Project>
15 changes: 0 additions & 15 deletions Senstate.CSharp-Client.Tests/DummySerializer.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<ItemGroup>
<ProjectReference Include="..\Senstate.CSharp-Client\Senstate.CSharp-Client.csproj" />
<ProjectReference Include="..\Senstate.NetStandard\Senstate.NetStandard.csproj" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions Senstate.CSharp-Client.Tests/TestContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Moq;
using Moq;
using Senstate.NetStandard;

namespace Senstate.CSharp_Client.Tests
{
Expand All @@ -9,12 +10,11 @@ public static Mock<ISenstateWebSocket> RegisterApp ()
var webSocketMock = new Mock<ISenstateWebSocket>();

SenstateContext.AppId = "1234";
SenstateContext.AppName = "Some Name";

SenstateContext.SerializerInstance = new DummySerializer();
SenstateContext.SerializerInstance = new NetStandardJsonNetImplementation();
SenstateContext.WebSocketInstance = webSocketMock.Object;

SenstateContext.RegisterApp();
SenstateContext.RegisterApp("Some Name");

return webSocketMock;
}
Expand Down
36 changes: 24 additions & 12 deletions Senstate.CSharp-Client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ VisualStudioVersion = 16.0.30002.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Senstate.CSharp-Client", "Senstate.CSharp-Client\Senstate.CSharp-Client.csproj", "{180EF5BB-810E-413F-9F17-AD8E3A118F8C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Senstate.Json", "Senstate.Json\Senstate.Json.csproj", "{4F8A6955-1D3E-4F60-964C-DC9DCB80DC46}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Senstate-ExampleApp", "Senstate-ExampleApp\Senstate-ExampleApp.csproj", "{5A78AEE3-3206-48DB-A09D-502CCA887BCD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Senstate.WebSocket", "Senstate.WebSocket\Senstate.WebSocket.csproj", "{759953ED-6402-4E19-B15F-8F4FAAA702F0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Senstate.CSharp-Client.Tests", "Senstate.CSharp-Client.Tests\Senstate.CSharp-Client.Tests.csproj", "{0C835DA8-5521-4D16-8F5C-00EF94DFFE82}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Senstate-ExampleApp", "Senstate-ExampleApp\Senstate-ExampleApp.csproj", "{5A78AEE3-3206-48DB-A09D-502CCA887BCD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorAppServerSide", "BlazorAppServerSide\BlazorAppServerSide.csproj", "{19C726F7-9950-4809-9635-5E242BC6541D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Senstate.CSharp-Client.Tests", "Senstate.CSharp-Client.Tests\Senstate.CSharp-Client.Tests.csproj", "{0C835DA8-5521-4D16-8F5C-00EF94DFFE82}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorWASM", "BlazorWASM\BlazorWASM.csproj", "{391B0753-FC37-4683-A4B9-39CC931B8F7E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Senstate.NetStandard", "Senstate.NetStandard\Senstate.NetStandard.csproj", "{743F3C4A-7FFA-476F-8223-9F8E89ED518F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5955506B-E0CD-4F4D-A174-37B27018DC83}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
build.bat = build.bat
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -23,14 +31,6 @@ Global
{180EF5BB-810E-413F-9F17-AD8E3A118F8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{180EF5BB-810E-413F-9F17-AD8E3A118F8C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{180EF5BB-810E-413F-9F17-AD8E3A118F8C}.Release|Any CPU.Build.0 = Release|Any CPU
{4F8A6955-1D3E-4F60-964C-DC9DCB80DC46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F8A6955-1D3E-4F60-964C-DC9DCB80DC46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F8A6955-1D3E-4F60-964C-DC9DCB80DC46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F8A6955-1D3E-4F60-964C-DC9DCB80DC46}.Release|Any CPU.Build.0 = Release|Any CPU
{759953ED-6402-4E19-B15F-8F4FAAA702F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{759953ED-6402-4E19-B15F-8F4FAAA702F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{759953ED-6402-4E19-B15F-8F4FAAA702F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{759953ED-6402-4E19-B15F-8F4FAAA702F0}.Release|Any CPU.Build.0 = Release|Any CPU
{5A78AEE3-3206-48DB-A09D-502CCA887BCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A78AEE3-3206-48DB-A09D-502CCA887BCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A78AEE3-3206-48DB-A09D-502CCA887BCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -39,6 +39,18 @@ Global
{0C835DA8-5521-4D16-8F5C-00EF94DFFE82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C835DA8-5521-4D16-8F5C-00EF94DFFE82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C835DA8-5521-4D16-8F5C-00EF94DFFE82}.Release|Any CPU.Build.0 = Release|Any CPU
{19C726F7-9950-4809-9635-5E242BC6541D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{19C726F7-9950-4809-9635-5E242BC6541D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19C726F7-9950-4809-9635-5E242BC6541D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19C726F7-9950-4809-9635-5E242BC6541D}.Release|Any CPU.Build.0 = Release|Any CPU
{391B0753-FC37-4683-A4B9-39CC931B8F7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{391B0753-FC37-4683-A4B9-39CC931B8F7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{391B0753-FC37-4683-A4B9-39CC931B8F7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{391B0753-FC37-4683-A4B9-39CC931B8F7E}.Release|Any CPU.Build.0 = Release|Any CPU
{743F3C4A-7FFA-476F-8223-9F8E89ED518F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{743F3C4A-7FFA-476F-8223-9F8E89ED518F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{743F3C4A-7FFA-476F-8223-9F8E89ED518F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{743F3C4A-7FFA-476F-8223-9F8E89ED518F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
15 changes: 15 additions & 0 deletions Senstate.CSharp-Client/Interfaces.cs
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);
}
}
3 changes: 1 addition & 2 deletions Senstate.CSharp-Client/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Senstate.CSharp_Client
namespace Senstate.CSharp_Client
{
public enum LoggerType
{
Expand Down Expand Up @@ -26,5 +26,4 @@ public static void SendLog(LoggerType logLevel, string log, object data = null)
});
}
}

}
2 changes: 2 additions & 0 deletions Senstate.CSharp-Client/Senstate.CSharp-Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Senstate.CSharp_Client</RootNamespace>
<Version>0.1.0</Version>
<Company />
</PropertyGroup>

</Project>
Loading

0 comments on commit 6c2f981

Please sign in to comment.