Esempio n. 1
0
        private static bool CleanKeyedNames(IEnumerable <InstallItem> lines, ILogger logger)
        {
            var groups = lines.Where(l => l.Type == InstallType.Create)
                         .GroupBy(l => $"{l.Reference.Unique}|{l.Reference.Type}");
            var result = true;

            foreach (var duplicate in groups.Where(g => g.Skip(1).Any()))
            {
                result = false;
                logger.LogError("The package has duplicate entries for creating {Type} {Name} with ID {ID} at {Paths}", duplicate.First().Reference.Type, duplicate.First().Reference.KeyedName, duplicate.First().Reference.Unique, duplicate.Select(i => i.Path));
            }

            var existing = groups
                           .ToDictionary(g => g.Key, g => g.First());
            InstallItem item;

            foreach (var line in lines.Where(l => l.Type == InstallType.Script))
            {
                if (existing.TryGetValue(line.InstalledId, out item))
                {
                    line.Reference.KeyedName = InstallItem.RenderAttributes(line.Script, item.Reference.KeyedName);
                }
            }

            return(result);
        }
Esempio n. 2
0
        public static void CleanKeyedNames(this IEnumerable <InstallItem> lines)
        {
            var groups = lines.Where(l => l.Type == InstallType.Create)
                         .GroupBy(l => l.Reference.Unique);
            var duplicates = groups.Where(g => g.Skip(1).Any()).ToArray();

            if (duplicates.Length > 0)
            {
                throw new InvalidOperationException("The package has duplicate entries for the following items: " + duplicates.GroupConcat(", ", g => g.Key));
            }
            var existing = groups
                           .ToDictionary(g => g.Key, g => g.First());
            InstallItem item;

            foreach (var line in lines.Where(l => l.Type == InstallType.Script))
            {
                if (existing.TryGetValue(line.InstalledId, out item))
                {
                    line.Reference.KeyedName = InstallItem.RenderAttributes(line.Script, item.Reference.KeyedName);
                }
            }
        }