Skip to content

Commit

Permalink
Using record with positional parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mikescandy authored and PiotrJustyna committed Oct 19, 2021
1 parent 7f814c0 commit a9b1650
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 126 deletions.
9 changes: 3 additions & 6 deletions 2/SiloHost/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Program
public static Task Main()
{
var siloEndpointConfiguration = GetSiloEndpointConfiguration();

return new HostBuilder()
.UseOrleans(siloBuilder =>
{
Expand All @@ -42,13 +42,10 @@ public static Task Main()
.ConfigureLogging(logging => logging.AddConsole())
.RunConsoleAsync();
}

private static SiloEndpointConfiguration GetSiloEndpointConfiguration()
{
return new SiloEndpointConfiguration(
GetLocalIpAddress(),
2000,
3000);
return new(GetLocalIpAddress(), 2000, 3000);
}

private static IPAddress GetLocalIpAddress()
Expand Down
12 changes: 1 addition & 11 deletions 2/SiloHost/src/SiloEndpointConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,5 @@

namespace SiloHost
{
public record SiloEndpointConfiguration
{
public IPAddress Ip { get; }
public int SiloPort { get; }
public int GatewayPort { get; }

public SiloEndpointConfiguration(
IPAddress ip,
int siloPort,
int gatewayPort) => (Ip, SiloPort, GatewayPort) = (ip, siloPort, gatewayPort);
}
public record SiloEndpointConfiguration(IPAddress Ip, int SiloPort, int GatewayPort);
}
14 changes: 5 additions & 9 deletions 3/SiloHost/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static Task Main()
var advertisedIp = Environment.GetEnvironmentVariable("ADVERTISEDIP");
var advertisedIpAddress = advertisedIp == null ? GetLocalIpAddress() : IPAddress.Parse(advertisedIp);
var gatewayPort = int.Parse(Environment.GetEnvironmentVariable("GATEWAYPORT") ?? "3000");

var siloEndpointConfiguration = GetSiloEndpointConfiguration(advertisedIpAddress, gatewayPort);

return new HostBuilder()
Expand Down Expand Up @@ -52,11 +52,7 @@ private static SiloEndpointConfiguration GetSiloEndpointConfiguration(
IPAddress advertisedAddress,
int gatewayPort)
{

return new SiloEndpointConfiguration(
advertisedAddress,
2000,
gatewayPort);
return new(advertisedAddress, 2000, gatewayPort);
}

private static IPAddress GetLocalIpAddress()
Expand All @@ -66,11 +62,11 @@ private static IPAddress GetLocalIpAddress()
{
if (network.OperationalStatus != OperationalStatus.Up)
continue;

var properties = network.GetIPProperties();
if (properties.GatewayAddresses.Count == 0)
continue;

foreach (var address in properties.UnicastAddresses)
{
if (address.Address.AddressFamily == AddressFamily.InterNetwork &&
Expand All @@ -80,7 +76,7 @@ private static IPAddress GetLocalIpAddress()
}
}
}

return null;
}
}
Expand Down
12 changes: 1 addition & 11 deletions 3/SiloHost/src/SiloEndpointConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,5 @@

namespace SiloHost
{
public record SiloEndpointConfiguration
{
public IPAddress Ip { get; }
public int SiloPort { get; }
public int GatewayPort { get; }

public SiloEndpointConfiguration(
IPAddress ip,
int siloPort,
int gatewayPort) => (Ip, SiloPort, GatewayPort) = (ip, siloPort, gatewayPort);
}
public record SiloEndpointConfiguration(IPAddress Ip, int SiloPort, int GatewayPort);
}
14 changes: 5 additions & 9 deletions 3a/SiloHost/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static Task Main()
var advertisedIp = Environment.GetEnvironmentVariable("ADVERTISEDIP");
var advertisedIpAddress = advertisedIp == null ? GetLocalIpAddress() : IPAddress.Parse(advertisedIp);
var gatewayPort = int.Parse(Environment.GetEnvironmentVariable("GATEWAYPORT") ?? "3000");

var siloEndpointConfiguration = GetSiloEndpointConfiguration(advertisedIpAddress, gatewayPort);

return new HostBuilder()
Expand Down Expand Up @@ -64,11 +64,7 @@ private static SiloEndpointConfiguration GetSiloEndpointConfiguration(
IPAddress advertisedAddress,
int gatewayPort)
{

return new SiloEndpointConfiguration(
advertisedAddress,
2000,
gatewayPort);
return new(advertisedAddress, 2000, gatewayPort);
}

private static IPAddress GetLocalIpAddress()
Expand All @@ -78,11 +74,11 @@ private static IPAddress GetLocalIpAddress()
{
if (network.OperationalStatus != OperationalStatus.Up)
continue;

var properties = network.GetIPProperties();
if (properties.GatewayAddresses.Count == 0)
continue;

foreach (var address in properties.UnicastAddresses)
{
if (address.Address.AddressFamily == AddressFamily.InterNetwork &&
Expand All @@ -92,7 +88,7 @@ private static IPAddress GetLocalIpAddress()
}
}
}

return null;
}
}
Expand Down
12 changes: 1 addition & 11 deletions 3a/SiloHost/src/SiloEndpointConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,5 @@

namespace SiloHost
{
public record SiloEndpointConfiguration
{
public IPAddress Ip { get; }
public int SiloPort { get; }
public int GatewayPort { get; }

public SiloEndpointConfiguration(
IPAddress ip,
int siloPort,
int gatewayPort) => (Ip, SiloPort, GatewayPort) = (ip, siloPort, gatewayPort);
}
public record SiloEndpointConfiguration(IPAddress Ip, int SiloPort, int GatewayPort);
}
5 changes: 1 addition & 4 deletions 3b/SiloHost/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ private static SiloEndpointConfiguration GetSiloEndpointConfiguration(
IPAddress advertisedAddress,
int gatewayPort)
{
return new SiloEndpointConfiguration(
advertisedAddress,
2000,
gatewayPort);
return new(advertisedAddress, 2000, gatewayPort);
}

private static IPAddress GetLocalIpAddress()
Expand Down
12 changes: 1 addition & 11 deletions 3b/SiloHost/src/SiloEndpointConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,5 @@

namespace SiloHost
{
public record SiloEndpointConfiguration
{
public IPAddress Ip { get; }
public int SiloPort { get; }
public int GatewayPort { get; }

public SiloEndpointConfiguration(
IPAddress ip,
int siloPort,
int gatewayPort) => (Ip, SiloPort, GatewayPort) = (ip, siloPort, gatewayPort);
}
public record SiloEndpointConfiguration(IPAddress Ip, int SiloPort, int GatewayPort);
}
4 changes: 2 additions & 2 deletions 4/SiloHost/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static Task Main()
var advertisedIp = Environment.GetEnvironmentVariable("ADVERTISEDIP");
var advertisedIpAddress = advertisedIp == null ? GetLocalIpAddress() : IPAddress.Parse(advertisedIp);

var extractedGatewayPort = Environment.GetEnvironmentVariable("GATEWAYPORT")?? throw new Exception("Gateway port cannot be null");
var extractedGatewayPort = Environment.GetEnvironmentVariable("GATEWAYPORT") ?? throw new Exception("Gateway port cannot be null");
var extractedSiloPort = Environment.GetEnvironmentVariable("SILOPORT")
?? throw new Exception("Silo port cannot be null");
var extractDashboardPort = Environment.GetEnvironmentVariable("DASHBOARDPORT") ??
Expand All @@ -39,7 +39,7 @@ public static Task Main()

var primarySiloEndpoint = new IPEndPoint(primaryIp, developmentPeerPort);

var siloEndpointConfiguration = new SiloEndpointConfiguration(advertisedIpAddress, siloPort, gatewayPort);
var siloEndpointConfiguration = new(advertisedIpAddress, siloPort, gatewayPort);

return new HostBuilder()
.UseOrleans(siloBuilder =>
Expand Down
12 changes: 1 addition & 11 deletions 4/SiloHost/src/SiloEndpointConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,5 @@

namespace SiloHost
{
public record SiloEndpointConfiguration
{
public IPAddress Ip { get; }
public int SiloPort { get; }
public int GatewayPort { get; }

public SiloEndpointConfiguration(
IPAddress ip,
int siloPort,
int gatewayPort) => (Ip, SiloPort, GatewayPort) = (ip, siloPort, gatewayPort);
}
public record SiloEndpointConfiguration(IPAddress Ip, int SiloPort, int GatewayPort);
}
4 changes: 2 additions & 2 deletions 5/SiloHost/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static Task Main()
var advertisedIp = Environment.GetEnvironmentVariable("ADVERTISEDIP");
var advertisedIpAddress = advertisedIp == null ? GetLocalIpAddress() : IPAddress.Parse(advertisedIp);

var extractedGatewayPort = Environment.GetEnvironmentVariable("GATEWAYPORT")?? throw new Exception("Gateway port cannot be null");
var extractedGatewayPort = Environment.GetEnvironmentVariable("GATEWAYPORT") ?? throw new Exception("Gateway port cannot be null");
var extractedSiloPort = Environment.GetEnvironmentVariable("SILOPORT")
?? throw new Exception("Silo port cannot be null");
var extractDashboardPort = Environment.GetEnvironmentVariable("DASHBOARDPORT") ??
Expand All @@ -37,7 +37,7 @@ public static Task Main()

var primarySiloEndpoint = new IPEndPoint(primaryIp, primarySiloPort);

var siloEndpointConfiguration = new SiloEndpointConfiguration(advertisedIpAddress, siloPort, gatewayPort);
var siloEndpointConfiguration = new(advertisedIpAddress, siloPort, gatewayPort);

return new HostBuilder()
.UseOrleans(siloBuilder =>
Expand Down
12 changes: 1 addition & 11 deletions 5/SiloHost/src/SiloEndpointConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,5 @@

namespace SiloHost
{
public record SiloEndpointConfiguration
{
public IPAddress Ip { get; }
public int SiloPort { get; }
public int GatewayPort { get; }

public SiloEndpointConfiguration(
IPAddress ip,
int siloPort,
int gatewayPort) => (Ip, SiloPort, GatewayPort) = (ip, siloPort, gatewayPort);
}
public record SiloEndpointConfiguration(IPAddress Ip, int SiloPort, int GatewayPort);
}
4 changes: 2 additions & 2 deletions 6/SiloHost/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static Task Main()
var advertisedIp = Environment.GetEnvironmentVariable("ADVERTISEDIP");
var advertisedIpAddress = advertisedIp == null ? GetLocalIpAddress() : IPAddress.Parse(advertisedIp);

var extractedGatewayPort = Environment.GetEnvironmentVariable("GATEWAYPORT")?? throw new Exception("Gateway port cannot be null");
var extractedGatewayPort = Environment.GetEnvironmentVariable("GATEWAYPORT") ?? throw new Exception("Gateway port cannot be null");
var extractedSiloPort = Environment.GetEnvironmentVariable("SILOPORT")
?? throw new Exception("Silo port cannot be null");
var extractDashboardPort = Environment.GetEnvironmentVariable("DASHBOARDPORT") ??
Expand All @@ -37,7 +37,7 @@ public static Task Main()

var primarySiloEndpoint = new IPEndPoint(primaryIp, primarySiloPort);

var siloEndpointConfiguration = new SiloEndpointConfiguration(advertisedIpAddress, siloPort, gatewayPort);
var siloEndpointConfiguration = new(advertisedIpAddress, siloPort, gatewayPort);

return new HostBuilder()
.UseOrleans(siloBuilder =>
Expand Down
12 changes: 1 addition & 11 deletions 6/SiloHost/src/SiloEndpointConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,5 @@

namespace SiloHost
{
public record SiloEndpointConfiguration
{
public IPAddress Ip { get; }
public int SiloPort { get; }
public int GatewayPort { get; }

public SiloEndpointConfiguration(
IPAddress ip,
int siloPort,
int gatewayPort) => (Ip, SiloPort, GatewayPort) = (ip, siloPort, gatewayPort);
}
public record SiloEndpointConfiguration(IPAddress Ip, int SiloPort, int GatewayPort);
}
8 changes: 4 additions & 4 deletions 7/SiloHost/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public static Task Main()
var advertisedIp = Environment.GetEnvironmentVariable("ADVERTISEDIP");
var advertisedIpAddress = advertisedIp == null ? GetLocalIpAddress() : IPAddress.Parse(advertisedIp);

var extractedGatewayPort = Environment.GetEnvironmentVariable("GATEWAYPORT")?? throw new Exception("Gateway port cannot be null");
var extractedSiloPort = Environment.GetEnvironmentVariable("SILOPORT")?? throw new Exception("Silo port cannot be null");
var extractedGatewayPort = Environment.GetEnvironmentVariable("GATEWAYPORT") ?? throw new Exception("Gateway port cannot be null");
var extractedSiloPort = Environment.GetEnvironmentVariable("SILOPORT") ?? throw new Exception("Silo port cannot be null");
var extractDashboardPort = Environment.GetEnvironmentVariable("DASHBOARDPORT") ?? throw new Exception("Dashboard port cannot be null");
var extractedPrimaryPort = Environment.GetEnvironmentVariable("PRIMARYPORT") ?? throw new Exception("Primary port cannot be null");

Expand All @@ -39,7 +39,7 @@ public static Task Main()

var primarySiloEndpoint = new IPEndPoint(primaryIp, primarySiloPort);

var siloEndpointConfiguration = new SiloEndpointConfiguration(advertisedIpAddress, siloPort, gatewayPort);
var siloEndpointConfiguration = new(advertisedIpAddress, siloPort, gatewayPort);

return new HostBuilder()
.UseOrleans(siloBuilder =>
Expand Down Expand Up @@ -77,7 +77,7 @@ Using built in Percentage filter to demonstrate a feature being on/off.*/
});
})
.ConfigureLogging(logging => logging.AddConsole())

//Registering a Configuration source for Feature Management.
.ConfigureAppConfiguration(config =>
{
Expand Down
12 changes: 1 addition & 11 deletions 7/SiloHost/src/SiloEndpointConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,5 @@

namespace SiloHost
{
public record SiloEndpointConfiguration
{
public IPAddress Ip { get; }
public int SiloPort { get; }
public int GatewayPort { get; }

public SiloEndpointConfiguration(
IPAddress ip,
int siloPort,
int gatewayPort) => (Ip, SiloPort, GatewayPort) = (ip, siloPort, gatewayPort);
}
public record SiloEndpointConfiguration(IPAddress Ip, int SiloPort, int GatewayPort);
}

0 comments on commit a9b1650

Please sign in to comment.