-
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
1 parent
2e75cce
commit 7cdef47
Showing
4 changed files
with
82 additions
and
80 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
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,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; | ||
} | ||
} | ||
} | ||
|
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
|
||
public class MainWindowViewModel : ViewModelBase | ||
{ | ||
|
||
} |
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