NServiceBus.InstanceMappingFileMonitor.LogChanges C# (CSharp) Method

LogChanges() public method

public LogChanges ( List instances, string filepath ) : void
instances List
filepath string
return void
        void LogChanges(List<EndpointInstance> instances, string filepath)
        {
            var output = new StringBuilder();
            var hasChanges = false;

            var instancesPerEndpoint = instances.GroupBy(i => i.Endpoint).ToDictionary(g => g.Key, g => g.ToArray());

            output.AppendLine($"Updating instance mapping table from '{filepath}':");

            foreach (var endpoint in instancesPerEndpoint)
            {
                EndpointInstance[] existingInstances;
                if (previousInstances.TryGetValue(endpoint.Key, out existingInstances))
                {
                    var newInstances = endpoint.Value.Except(existingInstances).Count();
                    var removedInstances = existingInstances.Except(endpoint.Value).Count();

                    if (newInstances > 0 || removedInstances > 0)
                    {
                        output.AppendLine($"Updated endpoint '{endpoint.Key}': +{Instances(newInstances)}, -{Instances(removedInstances)}");
                        hasChanges = true;
                    }
                }
                else
                {
                    output.AppendLine($"Added endpoint '{endpoint.Key}' with {Instances(endpoint.Value.Length)}");
                    hasChanges = true;
                }
            }

            foreach (var removedEndpoint in previousInstances.Keys.Except(instancesPerEndpoint.Keys))
            {
                output.AppendLine($"Removed all instances of endpoint '{removedEndpoint}'");
                hasChanges = true;
            }

            if (hasChanges)
            {
                log.Info(output.ToString());
            }

            previousInstances = instancesPerEndpoint;
        }