public static async Task <IntegrationMap> Create(string name, string assemblyName, Version maximumVersion)
        {
            var instance = new IntegrationMap();

            if (!NugetPackages.ContainsKey(name))
            {
                throw new Exception($"Missing key: {name} - Every integration must be represented in the packages map.");
            }

            instance.Name                   = name;
            instance.AssemblyName           = assemblyName;
            instance.MaximumAssemblyVersion = maximumVersion;

            await instance.PopulatePackages();

            return(instance);
        }
Ejemplo n.º 2
0
        public static async Task UpdateIntegrations(AbsolutePath honeypotProject, List <InstrumentedAssembly> targets)
        {
            var fakeRefs = string.Empty;

            var distinctIntegrations = new List <IntegrationMap>();

            foreach (var tg in targets.GroupBy(t => t.TargetAssembly))
            {
                var maxVersionTarget =
                    tg
                    .OrderByDescending(a => a.TargetMaximumMajor)
                    .ThenByDescending(a => a.TargetMaximumMinor)
                    .ThenByDescending(a => a.TargetMaximumPatch)
                    .First();
                var maxVersion =
                    new Version(
                        maxVersionTarget.TargetMaximumMajor,
                        maxVersionTarget.TargetMaximumMinor,
                        maxVersionTarget.TargetMaximumPatch);
                distinctIntegrations.Add(
                    await IntegrationMap.Create(
                        name: tg.Key,
                        assemblyName: maxVersionTarget.TargetAssembly,
                        maxVersion));
            }

            foreach (var integration in distinctIntegrations)
            {
                foreach (var package in integration.Packages)
                {
                    fakeRefs += $@"{Environment.NewLine}    <!-- Integration: {integration.Name} -->";
                    fakeRefs += $@"{Environment.NewLine}    <!-- Assembly: {integration.AssemblyName} -->";
                    fakeRefs += $@"{Environment.NewLine}    <!-- Latest package https://www.nuget.org/packages/{package.NugetName}/{package.LatestNuget} -->";
                    fakeRefs += $@"{Environment.NewLine}    <PackageReference Include=""{package.NugetName}"" Version=""{package.LatestSupportedNuget}"" />{Environment.NewLine}";
                }
            }

            var honeypotProjTemplate = GetHoneyPotProjTemplate();

            honeypotProjTemplate = honeypotProjTemplate.Replace("##PACKAGE_REFS##", fakeRefs);

            File.WriteAllText(honeypotProject, honeypotProjTemplate);
        }