Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/BulkLocationImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task ImportFromCsv(string csvFilePath)
var locations = LoadLocationsFromCsv(csvFilePath);
Console.WriteLine($"Loaded {locations.Count} locations");

await ImportLocationsInBatches(locations);
await ImportLocationsInBatches(locations).ConfigureAwait(false);

Console.WriteLine("\n✓ Import completed successfully!");
}
Expand Down Expand Up @@ -173,7 +173,7 @@ private async Task ImportLocationsInBatches(List<object> locations)

foreach (var location in batch)
{
var success = await SendLocation(location);
var success = await SendLocation(location).ConfigureAwait(false);
if (success)
{
successCount++;
Expand All @@ -186,7 +186,7 @@ private async Task ImportLocationsInBatches(List<object> locations)

if (i < batches.Count - 1)
{
await Task.Delay(500); // Rate limiting between batches
await Task.Delay(500).ConfigureAwait(false); // Rate limiting between batches
}
}

Expand All @@ -206,7 +206,7 @@ private async Task<bool> SendLocation(object location)
var content = new StringContent(json, Encoding.UTF8, "application/json");
content.Headers.Add("X-API-Key", _apiKey);

var response = await _httpClient.PostAsync($"{_baseUrl}/api/v1/locations", content);
var response = await _httpClient.PostAsync($"{_baseUrl}/api/v1/locations", content).ConfigureAwait(false);
return response.IsSuccessStatusCode;
}
catch
Expand Down Expand Up @@ -274,6 +274,6 @@ public static async Task Main(string[] args)
var csvFile = args[2];

var importer = new BulkLocationImporter(baseUrl, apiKey);
await importer.ImportFromCsv(csvFile);
await importer.ImportFromCsv(csvFile).ConfigureAwait(false);
}
}
14 changes: 7 additions & 7 deletions examples/GeofenceAlertsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ public async Task Connect()
{
try
{
await _connection.StartAsync();
await _connection.StartAsync().ConfigureAwait(false);
Console.WriteLine("✓ Connected to SignalR hub");

await _connection.InvokeAsync("SubscribeToVehicle", _vehicleId);
await _connection.InvokeAsync("SubscribeToVehicle", _vehicleId).ConfigureAwait(false);
Console.WriteLine($"✓ Subscribed to vehicle: {_vehicleId}");
}
catch (Exception ex)
Expand All @@ -223,8 +223,8 @@ public async Task Disconnect()
{
try
{
await _connection.InvokeAsync("UnsubscribeFromVehicle", _vehicleId);
await _connection.StopAsync();
await _connection.InvokeAsync("UnsubscribeFromVehicle", _vehicleId).ConfigureAwait(false);
await _connection.StopAsync().ConfigureAwait(false);
Console.WriteLine("✓ Disconnected from hub");
}
catch (Exception ex)
Expand All @@ -240,7 +240,7 @@ public async Task RunExample()
{
Console.WriteLine("=== Geofence Alerts Client ===\n");

await Connect();
await Connect().ConfigureAwait(false);

AddGeofence("Warehouse", 40.7128, -74.0060, 1.0);
AddGeofence("Office", 40.7489, -73.9680, 0.5);
Expand All @@ -249,7 +249,7 @@ public async Task RunExample()
Console.WriteLine("\n✓ Listening for geofence alerts (press Enter to exit)...\n");
Console.ReadLine();

await Disconnect();
await Disconnect().ConfigureAwait(false);
}

private class Alert
Expand All @@ -275,6 +275,6 @@ public static async Task Main(string[] args)
var vehicleId = args.Length > 1 ? args[1] : Guid.NewGuid().ToString();

var client = new GeofenceAlertsClient(hubUrl, vehicleId);
await client.RunExample();
await client.RunExample().ConfigureAwait(false);
}
}
16 changes: 8 additions & 8 deletions examples/LocationUpdateSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public async Task RunSimulation(int vehicleCount = 5, int durationSeconds = 60)

try
{
vehicleIds = await CreateVehicles(vehicleCount);
await SimulateMovement(vehicleIds, durationSeconds);
vehicleIds = await CreateVehicles(vehicleCount).ConfigureAwait(false);
await SimulateMovement(vehicleIds, durationSeconds).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -86,11 +86,11 @@ private async Task<List<string>> CreateVehicles(int count)
var content = new StringContent(json, Encoding.UTF8, "application/json");
content.Headers.Add("X-API-Key", _apiKey);

var response = await _httpClient.PostAsync($"{_baseUrl}/api/v1/vehicles", content);
var response = await _httpClient.PostAsync($"{_baseUrl}/api/v1/vehicles", content).ConfigureAwait(false);

if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsStringAsync();
var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var doc = JsonDocument.Parse(result);
var vehicleId = doc.RootElement.GetProperty("id").GetString();

Expand Down Expand Up @@ -120,7 +120,7 @@ private async Task SimulateMovement(List<string> vehicleIds, int durationSeconds
foreach (var vehicleId in vehicleIds)
{
var location = GenerateLocation(vehicleId);
var success = await SendLocation(location);
var success = await SendLocation(location).ConfigureAwait(false);

if (success)
{
Expand All @@ -132,7 +132,7 @@ private async Task SimulateMovement(List<string> vehicleIds, int durationSeconds
var remaining = Math.Max(0, durationSeconds - elapsed);
Console.WriteLine($"[{elapsed:F0}s] Sent {locationCount} updates (remaining: {remaining:F0}s)");

await Task.Delay(2000); // Update every 2 seconds
await Task.Delay(2000).ConfigureAwait(false); // Update every 2 seconds
}

Console.WriteLine($"\n✓ Simulation completed: {locationCount} total location updates sent");
Expand Down Expand Up @@ -175,7 +175,7 @@ private async Task<bool> SendLocation(object location)
var content = new StringContent(json, Encoding.UTF8, "application/json");
content.Headers.Add("X-API-Key", _apiKey);

var response = await _httpClient.PostAsync($"{_baseUrl}/api/v1/locations", content);
var response = await _httpClient.PostAsync($"{_baseUrl}/api/v1/locations", content).ConfigureAwait(false);
return response.IsSuccessStatusCode;
}
catch
Expand All @@ -196,6 +196,6 @@ public static async Task Main(string[] args)
var durationSeconds = args.Length > 3 ? int.Parse(args[3]) : 60;

var simulator = new LocationUpdateSimulator(baseUrl, apiKey);
await simulator.RunSimulation(vehicleCount, durationSeconds);
await simulator.RunSimulation(vehicleCount, durationSeconds).ConfigureAwait(false);
}
}
16 changes: 8 additions & 8 deletions examples/RouteOptimizationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ public async Task CreateDeliveryRoute(string vehicleId)
var content = new StringContent(json, Encoding.UTF8, "application/json");
content.Headers.Add("X-API-Key", _apiKey);

var response = await _httpClient.PostAsync($"{_baseUrl}/api/v1/routes", content);
var response = await _httpClient.PostAsync($"{_baseUrl}/api/v1/routes", content).ConfigureAwait(false);

if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsStringAsync();
var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var doc = JsonDocument.Parse(result);
var routeId = doc.RootElement.GetProperty("id").GetString();

Console.WriteLine($"\n✓ Route created: {routeId}");
Console.WriteLine($" Total Distance: {totalDistance:F2} km");
Console.WriteLine($" Estimated Duration: {route.estimatedDuration} minutes");

await GetRouteDetails(routeId ?? "");
await GetRouteDetails(routeId ?? "").ConfigureAwait(false);
}
else
{
Expand All @@ -108,12 +108,12 @@ private async Task GetRouteDetails(string routeId)
var request = new HttpRequestMessage(HttpMethod.Get, $"{_baseUrl}/api/v1/routes/{routeId}");
request.Headers.Add("X-API-Key", _apiKey);

var response = await _httpClient.SendAsync(request);
var response = await _httpClient.SendAsync(request).ConfigureAwait(false);

if (!response.IsSuccessStatusCode)
return;

var result = await response.Content.ReadAsStringAsync();
var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var doc = JsonDocument.Parse(result);
var route = doc.RootElement;

Expand Down Expand Up @@ -202,7 +202,7 @@ public async Task SimulateRouteExecution(string routeId)
for (int i = 0; i < steps.Length; i++)
{
Console.WriteLine($" [{steps[i]}%] {statuses[i]}");
await Task.Delay(1000);
await Task.Delay(1000).ConfigureAwait(false);
}

Console.WriteLine("\n✓ Route execution simulation completed");
Expand All @@ -215,7 +215,7 @@ public async Task RunExample(string vehicleId)
{
try
{
await CreateDeliveryRoute(vehicleId);
await CreateDeliveryRoute(vehicleId).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand All @@ -233,6 +233,6 @@ public static async Task Main(string[] args)
var vehicleId = args.Length > 2 ? args[2] : Guid.NewGuid().ToString();

var client = new RouteOptimizationClient(baseUrl, apiKey);
await client.RunExample(vehicleId);
await client.RunExample(vehicleId).ConfigureAwait(false);
}
}
8 changes: 4 additions & 4 deletions examples/SessionAnalyticsReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task GenerateVehicleAnalyticsReport(string vehicleId)

try
{
var sessions = await GetVehicleSessions(vehicleId);
var sessions = await GetVehicleSessions(vehicleId).ConfigureAwait(false);
if (sessions.Count == 0)
{
Console.WriteLine("No tracking sessions found for this vehicle.");
Expand Down Expand Up @@ -214,7 +214,7 @@ public async Task ExportAnalyticsToCsv(string vehicleId, string outputPath)
{
Console.WriteLine($"Exporting analytics to: {outputPath}");

var sessions = await GetVehicleSessions(vehicleId);
var sessions = await GetVehicleSessions(vehicleId).ConfigureAwait(false);

using (var writer = new StreamWriter(outputPath))
{
Expand All @@ -239,7 +239,7 @@ public async Task ExportAnalyticsToCsv(string vehicleId, string outputPath)
/// </summary>
public async Task RunExample(string vehicleId)
{
await GenerateVehicleAnalyticsReport(vehicleId);
await GenerateVehicleAnalyticsReport(vehicleId).ConfigureAwait(false);
}

private class SessionData
Expand Down Expand Up @@ -277,6 +277,6 @@ public static async Task Main(string[] args)
var vehicleId = args.Length > 2 ? args[2] : Guid.NewGuid().ToString();

var reporter = new SessionAnalyticsReporter(baseUrl, apiKey);
await reporter.RunExample(vehicleId);
await reporter.RunExample(vehicleId).ConfigureAwait(false);
}
}
28 changes: 14 additions & 14 deletions examples/VehicleTrackerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public async Task RunExample()

try
{
var vehicleId = await CreateVehicle();
await RecordLocations(vehicleId);
await RetrieveLocationHistory(vehicleId);
await GetVehicleDetails(vehicleId);
var vehicleId = await CreateVehicle().ConfigureAwait(false);
await RecordLocations(vehicleId).ConfigureAwait(false);
await RetrieveLocationHistory(vehicleId).ConfigureAwait(false);
await GetVehicleDetails(vehicleId).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -66,15 +66,15 @@ private async Task<string> CreateVehicle()
var content = new StringContent(json, Encoding.UTF8, "application/json");
content.Headers.Add("X-API-Key", _apiKey);

var response = await _httpClient.PostAsync($"{_baseUrl}/api/v1/vehicles", content);
var response = await _httpClient.PostAsync($"{_baseUrl}/api/v1/vehicles", content).ConfigureAwait(false);

if (!response.IsSuccessStatusCode)
{
var error = await response.Content.ReadAsStringAsync();
var error = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new Exception($"Failed to create vehicle: {error}");
}

var result = await response.Content.ReadAsStringAsync();
var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var doc = JsonDocument.Parse(result);
var vehicleId = doc.RootElement.GetProperty("id").GetString();

Expand Down Expand Up @@ -115,14 +115,14 @@ private async Task RecordLocations(string vehicleId)
var content = new StringContent(json, Encoding.UTF8, "application/json");
content.Headers.Add("X-API-Key", _apiKey);

var response = await _httpClient.PostAsync($"{_baseUrl}/api/v1/locations", content);
var response = await _httpClient.PostAsync($"{_baseUrl}/api/v1/locations", content).ConfigureAwait(false);

if (response.IsSuccessStatusCode)
{
Console.WriteLine($" ✓ Location recorded: ({lat}, {lon})");
}

await Task.Delay(500); // Small delay between updates
await Task.Delay(500).ConfigureAwait(false); // Small delay between updates
}

Console.WriteLine();
Expand All @@ -141,15 +141,15 @@ private async Task RetrieveLocationHistory(string vehicleId)
);
request.Headers.Add("X-API-Key", _apiKey);

var response = await _httpClient.SendAsync(request);
var response = await _httpClient.SendAsync(request).ConfigureAwait(false);

if (!response.IsSuccessStatusCode)
{
Console.WriteLine("Failed to retrieve locations");
return;
}

var result = await response.Content.ReadAsStringAsync();
var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var doc = JsonDocument.Parse(result);
var data = doc.RootElement.GetProperty("data");

Expand All @@ -175,15 +175,15 @@ private async Task GetVehicleDetails(string vehicleId)
var request = new HttpRequestMessage(HttpMethod.Get, $"{_baseUrl}/api/v1/vehicles/{vehicleId}");
request.Headers.Add("X-API-Key", _apiKey);

var response = await _httpClient.SendAsync(request);
var response = await _httpClient.SendAsync(request).ConfigureAwait(false);

if (!response.IsSuccessStatusCode)
{
Console.WriteLine("Failed to retrieve vehicle details");
return;
}

var result = await response.Content.ReadAsStringAsync();
var result = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var doc = JsonDocument.Parse(result);
var vehicle = doc.RootElement;

Expand All @@ -204,6 +204,6 @@ public static async Task Main(string[] args)
var apiKey = args.Length > 1 ? args[1] : "default-api-key";

var client = new VehicleTrackerClient(baseUrl, apiKey);
await client.RunExample();
await client.RunExample().ConfigureAwait(false);
}
}
Loading
Loading