Skip to content

Commit

Permalink
Merge pull request #5 from gccornejo441/development
Browse files Browse the repository at this point in the history
updating appsplash
  • Loading branch information
gccornejo441 authored Feb 28, 2024
2 parents 7bee2b8 + 7cdef47 commit 6b66359
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 80 deletions.
4 changes: 4 additions & 0 deletions src/InsightBytes.BlackBoxk/InsightBytes.BlackBox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\InsightBytes.Services\InsightBytes.Services.csproj" />
<ProjectReference Include="..\InsightBytes.Utilities\InsightBytes.Utilities.csproj" />
Expand Down
130 changes: 59 additions & 71 deletions src/InsightBytes.BlackBoxk/Program.cs
Original file line number Diff line number Diff line change
@@ -1,92 +1,80 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using InsightBytes.Utilities.Endpoints;

namespace InsightBytes.BlackBox
using Newtonsoft.Json;

namespace InsightBytes.BlackBox;

internal class Program
{
internal class Program
{
static async Task Main(string[] args)
{
Program p = new Program();
await p.StartServerAndRequestData();
}
private readonly HttpClient _httpClient;

async Task StartServerAndRequestData()
{
// Start the Go server process
var process = ProcessStarter();
try
{
// Request data from the Go server
var users = await GetAllUsers();
public Program() { _httpClient = new HttpClient(); }

foreach (var user in users)
{
Console.WriteLine($"ID: {user.ID}, Name: {user.Name}, Age: {user.Age}");
}
}
finally
{
// Ensure to kill the process when done
if (!process.HasExited)
{
process.Kill();
}
}
}
static async Task Main(string[] args)
{
var program = new Program();

Process ProcessStarter()
{
string goServerExePath = @"C:\Users\gabriel.cornejo\source\repos\VSCodeApps\Golang\gin-quickstart\goServerExecutable.exe";

ProcessStartInfo startInfo = new ProcessStartInfo()
{
FileName = goServerExePath,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
};
var sdpOffer = @"v=0
o=- 5841829617509545627 1709000931 IN IP4 0.0.0.0
s=-
t=0 0
a=fingerprint:sha-256 52:74:14:CD:57:F7:20:26:D1:1E:C0:CC:5C:D4:61:A0:AF:16:61:BB:70:BE:70:5C:F8:B9:C4:D7:76:10:70:9D
a=extmap-allow-mixed
a=group:BUNDLE 0
m=application 9 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 0.0.0.0
a=setup:actpass
a=mid:0
a=sendrecv
a=sctp-port:5000
a=ice-ufrag:xqpbWsfYSDiUJdbC
a=ice-pwd:MFTlHpwBEyxmFmcLFctEXCflyLUaaljX";

Process process = new Process()
{
StartInfo = startInfo
};
await program.SendOfferAsync(sdpOffer);
}

process.Start();
public async Task SendOfferAsync(string offer)
{
var requestUri = "http://localhost:8080/offer";
var offerData = new { sdp = offer }; // Assuming offer is your SDP string
var jsonContent = JsonConvert.SerializeObject(offerData);
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");

return process;
HttpResponseMessage response = await _httpClient.PostAsync(requestUri, content);
if(response.IsSuccessStatusCode)
{
Console.WriteLine("Offer sent successfully.");
// Optionally, read the response
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
} else
{
Console.WriteLine("Failed to send offer.");
}
}

async Task<List<User>> GetAllUsers()
public async Task<string> GetOfferOrAnswerAsync(string sessionId)
{
var requestUri = $"http://localhost:8080/offer/{sessionId}";
HttpResponseMessage response = await _httpClient.GetAsync(requestUri);
if(response.IsSuccessStatusCode)
{
List<User> userList = new List<User>();
Console.WriteLine("Getting users from Go service...");
Console.WriteLine("##############################\n");

var httpClient = new HttpClient();
var golangService = new GolangService(httpClient);

try
{
var users = await golangService.GetUserDataAsync();
userList.AddRange(users);
}
catch (Exception e)
{
Console.WriteLine($"Error getting users: {e.Message}");
}
finally
{
Console.WriteLine("##############################\n");
}

return userList;
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine("Received response: " + responseBody);
return responseBody;
} else
{
Console.WriteLine("Failed to receive offer/answer.");
return null;
}
}
}

1 change: 1 addition & 0 deletions src/InsightBytes/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public class MainWindowViewModel : ViewModelBase
{

}
27 changes: 18 additions & 9 deletions src/InsightBytes/Views/AppSplash.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="400"
d:DesignWidth="600"
xmlns:vm="using:InsightBytes.ViewModels"
x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d">
<Border Background="{DynamicResource BackgroundDark}">
<Grid RowDefinitions="*,Auto,150">
<Image
Width="128"
Height="128"
Width="100"
Height="100"
IsHitTestVisible="False"
Source="/Assets/report-repo.ico" />
<ProgressBar
Grid.Row="1"
Width="45"
Height="45"
Classes="Circle"
IsIndeterminate="True" />
</Grid>
<Grid
Grid.Row="2"
RowDefinitions="*,15,5">
<TextBlock
Grid.Row="1"
FontSize="10"
FontWeight="SemiBold"
Foreground="{DynamicResource NormalGreenDark}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="Loading..." />
<ProgressBar Grid.Row="3" IsIndeterminate="True" Foreground="{DynamicResource NormalGreenDark}" />
</Grid>
</Grid>
</Border>
</UserControl>

0 comments on commit 6b66359

Please sign in to comment.