/// <nodoc /> public static GrpcFileCopierConfiguration FromDistributedContentSettings(DistributedContentSettings dcs, int grpcPort) { var grpcCopyClientCacheConfiguration = GrpcCopyClientCacheConfiguration.FromDistributedContentSettings(dcs); var grpcFileCopierConfiguration = new GrpcFileCopierConfiguration() { GrpcPort = (int)grpcPort, GrpcCopyClientCacheConfiguration = grpcCopyClientCacheConfiguration, JunctionsByDirectory = dcs.AlternateDriveMap }; ApplyIfNotNull( dcs.GrpcFileCopierGrpcCopyClientInvalidationPolicy, v => { if (!Enum.TryParse <GrpcFileCopierConfiguration.ClientInvalidationPolicy>(v, out var parsed)) { throw new ArgumentException( $"Failed to parse `{nameof(dcs.GrpcFileCopierGrpcCopyClientInvalidationPolicy)}` setting with value `{dcs.GrpcFileCopierGrpcCopyClientInvalidationPolicy}` into type `{nameof(GrpcFileCopierConfiguration.ClientInvalidationPolicy)}`"); } grpcFileCopierConfiguration.GrpcCopyClientInvalidationPolicy = parsed; }); grpcFileCopierConfiguration.UseUniversalLocations = dcs.UseUniversalLocations; grpcFileCopierConfiguration.UseDomainName = dcs.UseDomainName; return(grpcFileCopierConfiguration); }
/// <summary> /// Constructor for <see cref="GrpcFileCopier"/>. /// </summary> public GrpcFileCopier(Context context, GrpcFileCopierConfiguration configuration) { _context = context; _configuration = configuration; _clientCache = new GrpcCopyClientCache(context, _configuration.GrpcCopyClientCacheConfiguration); _junctionsByDirectory = configuration.JunctionsByDirectory?.ToDictionary(kvp => new AbsolutePath(kvp.Key), kvp => new AbsolutePath(kvp.Value)) ?? new Dictionary <AbsolutePath, AbsolutePath>(); try { _localMachineName = System.Net.Dns.GetHostName(); } catch (Exception e) { Tracer.Warning(context, $"Failed to get machine name from `Dns.GetHostName`. Falling back to `Environment.MachineName`. {e}"); _localMachineName = Environment.MachineName; } }
/// <summary> /// Constructor for <see cref="GrpcFileCopier"/>. /// </summary> public GrpcFileCopier(Context context, GrpcFileCopierConfiguration configuration) { _context = context; _configuration = configuration; _clientCache = new GrpcCopyClientCache(context, _configuration.GrpcCopyClientCacheConfiguration); _junctionsByDirectory = configuration.JunctionsByDirectory?.ToDictionary(kvp => new AbsolutePath(kvp.Key), kvp => new AbsolutePath(kvp.Value)) ?? new Dictionary <AbsolutePath, AbsolutePath>(); if (configuration.UseDomainName) { try { var ipProperties = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties(); var hostName = ipProperties.HostName; var domainName = ipProperties.DomainName; if (!string.IsNullOrEmpty(domainName) && !string.IsNullOrEmpty(hostName)) { _localMachineName = $"{hostName}.{domainName}"; } else { Tracer.Warning(context, $"Failed to get machine name and domain from `IPGlobalProperties.GetIPGlobalProperties` [Host={hostName} Domain={domainName}]. Falling back to `Dns.GetHostName`."); } } catch (Exception e) { Tracer.Warning(context, $"Failed to get machine name from `IPGlobalProperties.GetIPGlobalProperties`. Falling back to `Dns.GetHostName`. {e}"); } } if (_localMachineName == null) { try { _localMachineName = System.Net.Dns.GetHostName(); } catch (Exception e) { Tracer.Warning(context, $"Failed to get machine name from `Dns.GetHostName`. Falling back to `Environment.MachineName`. {e}"); _localMachineName = Environment.MachineName; } } }