示例#1
0
 /// <summary>
 /// Initializes a new <see cref="CodeCakeBuilderKeyVaultUpdatingArgs"/>.
 /// </summary>
 /// <param name="m">The monitor to use.</param>
 /// <param name="spec">Specification of the current solution.</param>
 /// <param name="solution">Current solution.</param>
 /// <param name="secrets">The secrets ready to be written.</param>
 public CodeCakeBuilderKeyVaultUpdatingArgs(IActivityMonitor m, SolutionSpec spec, ISolution solution, IDictionary <string, string> secrets)
     : base(m)
 {
     SolutionSpec = spec;
     Solution     = solution;
     Secrets      = secrets ?? throw new ArgumentNullException(nameof(secrets));
 }
示例#2
0
 public SharedPropsFile(CommonFolder f, SolutionDriver driver, SolutionSpec solutionSpec, NormalizedPath branchPath)
     : base(f.GitFolder, branchPath, f.FolderPath.AppendPart("Shared.props"), null)
 {
     _commonFolder = f;
     _driver       = driver;
     _solutionSpec = solutionSpec;
 }
 public CKSetupStoreTestHelperConfigFile(
     GitFolder f,
     SolutionDriver solutionDriver,
     SolutionSpec settings,
     IEnvLocalFeedProvider localFeedProvider,
     NormalizedPath branchPath)
     : base(f, branchPath, branchPath.AppendPart("RemoteStore.TestHelper.config"))
 {
     _solutionSpec      = settings;
     _solutionDriver    = solutionDriver;
     _localFeedProvider = localFeedProvider;
     // Always monitor branch change even if _settings.ProduceCKSetupComponents is false
     // so that we delete the test file on leaving local if it happens to exist.
     if (PluginBranch == StandardGitStatus.Local)
     {
         f.OnLocalBranchEntered += OnLocalBranchEntered;
         f.OnLocalBranchLeaving += OnLocalBranchLeaving;
     }
     // If the settings states that CKSetup is not used, there is no need to react to builds.
     if (_solutionSpec.UseCKSetup)
     {
         _solutionDriver.OnStartBuild += OnStartBuild;
         _solutionDriver.OnEndBuild   += OnEndBuild;
     }
 }
示例#4
0
        public XSolutionSpec(
            Initializer initializer,
            XBranch branch,
            SharedSolutionSpec sharedSpec)
            : base(initializer)
        {
            if (!(initializer.Parent is XBranch))
            {
                throw new Exception("A SolutionSpec must be a direct child of a Git branch.");
            }

            // The XSolutionSpec is available to siblings (ie. up to the end of the parent git branch).
            initializer.Services.Add(this);
            SolutionSpec = new SolutionSpec(sharedSpec, initializer.Reader);

            //XSharedSolutionSpec.RemoveElementWarnings( initializer );
            initializer.Reader.Handle(initializer
                                      .Element.Elements()
                                      .Where(c => c.Name.LocalName == nameof(SolutionSpec.NPMProjects) ||
                                             c.Name.LocalName == nameof(SolutionSpec.PublishedProjects) ||
                                             c.Name.LocalName == nameof(SolutionSpec.NotPublishedProjects) ||
                                             c.Name.LocalName == nameof(SolutionSpec.CKSetupComponentProjects)));

            // Registers the SolutionSpec as a branch settings: the Solution specifications becomes
            // available to any of this branch plugins.
            branch.Parent.ProtoGitFolder.PluginRegistry.RegisterSettings(SolutionSpec, branch.Name);
            foreach (var type in GitPluginRegistry.GlobalRegister.GetAllGitPlugins().Except(SolutionSpec.ExcludedPlugins))
            {
                branch.Parent.ProtoGitFolder.PluginRegistry.Register(type, branch.Name, allowGitPlugin: true);
            }
        }
示例#5
0
        public static double Post(SolutionSpec solutionSpec, int problemId, bool pack = true, bool storeSolutionWithSameResemblance = false)
        {
            if (pack)
            {
                solutionSpec = solutionSpec.Pack();
            }

            var existingSolution = repo.FindSolution(problemId);

            if (existingSolution == solutionSpec.ToString())
            {
                var resemblance = repo.GetProblemResemblance(problemId);
                Console.Out.Write($" solution is the same! current score: {resemblance} ");
                return(resemblance);
            }

            var solutionSize = solutionSpec.Size();

            if (solutionSize > 5000)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Out.Write($" solution size limit exceeded {solutionSize} ");
                Console.ResetColor();
                return(0);
            }

            return(DoPost(problemId, solutionSpec, storeSolutionWithSameResemblance));
        }
示例#6
0
 public NPMProjectsDriver(GitFolder f, NormalizedPath branchPath, SolutionDriver driver, SolutionSpec spec)
     : base(f, branchPath)
 {
     _driver = driver;
     _spec   = spec;
     _driver.OnSolutionConfiguration   += OnSolutionConfiguration;
     _driver.OnUpdatePackageDependency += OnUpdatePackageDependency;
 }
示例#7
0
 public AppveyorFile(GitFolder f, SolutionDriver driver, SolutionSpec settings, SecretKeyStore keyStore, SharedWorldState sharedState, NormalizedPath branchPath)
     : base(f, branchPath, branchPath.AppendPart("appveyor.yml"))
 {
     _driver       = driver;
     _solutionSpec = settings;
     _keyStore     = keyStore;
     _sharedState  = sharedState;
 }
示例#8
0
 public NPMRCFiles(GitFolder f, NPMProjectsDriver driver, SolutionDriver solutionDriver, SecretKeyStore secretStore, SolutionSpec solutionSpec, NormalizedPath branchPath)
     : base(f, branchPath)
 {
     _solutionDriver = solutionDriver;
     _solutionSpec   = solutionSpec;
     _driver         = driver;
     _secretStore    = secretStore;
     _solutionDriver.OnSolutionConfiguration += OnSolutionConfiguration;
 }
示例#9
0
 public CKSetupCodeCakeBuilderFolder(
     GitFolder f,
     SolutionDriver driver,
     CodeCakeBuilderKeyVaultFile keyVaultFile,
     SolutionSpec solutionSpec,
     NormalizedPath branchPath)
     : base(f, branchPath, "CodeCakeBuilder", "CKSetup/Res")
 {
     _driver       = driver;
     _solutionSpec = solutionSpec;
     _keyVaultFile = keyVaultFile;
     _driver.OnSolutionConfiguration += OnSolutionConfiguration;
     _keyVaultFile.Updating          += KeyVaultFileUpdating;
 }
示例#10
0
 public NugetConfigFile(GitFolder f, SolutionDriver driver, IEnvLocalFeedProvider localFeedProvider, SecretKeyStore secretStore, SolutionSpec s, NormalizedPath branchPath)
     : base(f, branchPath, branchPath.AppendPart("NuGet.config"), null)
 {
     _localFeedProvider = localFeedProvider;
     _solutionSpec      = s;
     _solutionDriver    = driver;
     _secretStore       = secretStore;
     if (IsOnLocalBranch)
     {
         f.OnLocalBranchEntered += OnLocalBranchEntered;
         f.OnLocalBranchLeaving += OnLocalBranchLeaving;
     }
     _solutionDriver.OnStartBuild            += OnStartBuild;
     _solutionDriver.OnZeroBuildProject      += OnZeroBuildProject;
     _solutionDriver.OnSolutionConfiguration += OnSolutionConfiguration;
 }
 public CodeCakeBuilderKeyVaultFile(
     CodeCakeBuilderFolder f,
     SolutionDriver driver,
     SolutionSpec solutionSpec,
     SecretKeyStore secretStore,
     SharedWorldState sharedState,
     NormalizedPath branchPath)
     : base(f.GitFolder, branchPath, f.FolderPath.AppendPart("CodeCakeBuilderKeyVault.txt"))
 {
     _f            = f;
     _driver       = driver;
     _secretStore  = secretStore;
     _sharedState  = sharedState;
     _solutionSpec = solutionSpec;
     _secretStore.DeclareSecretKey(SolutionDriver.CODECAKEBUILDER_SECRET_KEY, current => current?.Description
                                   ?? $"Allows update of CodeCakeBuilderKeyVault.txt used by CI/CD processes. This secret must be managed only by people that have access to the CI/CD processes and their configuration.");
 }
示例#12
0
        private static SolutionSpec TryGetInitialSolution(ProblemSpec problem, TimeSpan?timeout = null)
        {
            timeout = timeout ?? TimeSpan.FromSeconds(10);
            SolutionSpec initialSolution = null;
            var          t = new Thread(() => { initialSolution = new ImperfectSolver().SolveMovingAndRotatingInitialSquare(problem); })
            {
                IsBackground = true
            };

            t.Start();
            if (!t.Join(timeout.Value))
            {
                t.Abort();
                t.Join();
                Console.Write($"Failed to get initial solution in {timeout}! Skipping");
            }
            return(initialSolution);
        }
示例#13
0
        private static double DoPost(int problemSpecId, SolutionSpec solutionSpec, bool storeSolutionWithSameResemblance)
        {
            var client = new ApiClient();

            try
            {
                var oldResemblance = repo.GetProblemResemblance(problemSpecId);
                var response       = client.PostSolution(problemSpecId, solutionSpec);
                var resemblance    = repo.GetResemblance(response);
                if (resemblance >= oldResemblance)
                {
                    if (resemblance > oldResemblance || storeSolutionWithSameResemblance)
                    {
                        repo.PutResponse(problemSpecId, response);
                        repo.PutSolution(problemSpecId, solutionSpec);
                    }
                    if (resemblance > oldResemblance)
                    {
                        Console.ForegroundColor = resemblance >= 1.0 ? ConsoleColor.Green : ConsoleColor.White;
                        Console.Out.Write($" solution for problem {problemSpecId} improved! new score: {resemblance} ");
                        Console.ResetColor();
                    }
                    else
                    {
                        Console.Out.Write($" just solution for problem {problemSpecId} changed! old = new score: {resemblance} ");
                    }
                }
                return(resemblance);
            }
            catch (Exception e)
            {
                if (e is ThreadAbortException)
                {
                    return(0);
                }
                if (e is HttpRequestException)
                {
                    return(0);
                }
                Console.WriteLine(e);
                return(0);
            }
        }
示例#14
0
 private IEnumerable <SolutionSpec> GetAllMirrorCombinatons(SolutionSpec solution, ImmutableList <Segment> mirrors)
 {
     if (mirrors.IsEmpty)
     {
         yield return(solution);
     }
     else
     {
         var mirror      = mirrors[mirrors.Count - 1];
         var leftMirrors = mirrors.RemoveAt(mirrors.Count - 1);
         foreach (var s in GetAllMirrorCombinatons(solution.Fold(mirror), leftMirrors))
         {
             yield return(s);
         }
         foreach (var s in GetAllMirrorCombinatons(solution.Fold(new Segment(mirror.End, mirror.Start)), leftMirrors))
         {
             yield return(s);
         }
     }
 }
示例#15
0
        public static string Process(string solutionPath, string outputPath, Dictionary <string, string> nugetPackageOverrides = null)
        {
            if (string.IsNullOrWhiteSpace(solutionPath))
            {
                throw new Exception("SolutionPath cannot be empty");
            }

            if (!File.Exists(solutionPath))
            {
                throw new Exception("SolutionPath cannot be found");
            }

            //get the soltion and process it
            var sourceSolution = new SolutionSpec(solutionPath);

            sourceSolution.Build();

            //copy to a new solution and build again
            var newSolutuion = sourceSolution.CopyTo(outputPath);

            newSolutuion.Build();

            //clean the temp solution and update the samples
            newSolutuion.UpdateSampleReferencesAndClean(nugetPackageOverrides);


            var zipPath = outputPath + ".zip";

            if (File.Exists(zipPath))
            {
                File.Delete(zipPath);
            }

            ZipFile.CreateFromDirectory(outputPath, zipPath);

            Directory.Delete(outputPath, true);

            return(zipPath);
        }
 /// <summary>
 /// Initializes a new <see cref="SolutionConfigurationEventArgs"/>.
 /// </summary>
 /// <param name="m">The monitor.</param>
 /// <param name="solution">The solution to be configured.</param>
 /// <param name="isNew">Whether the solution to be configured is a brand new one or is an existing one that is reconfigured.</param>
 /// <param name="spec">The solution specification.</param>
 /// <param name="buildSecrets">See <see cref="BuildRequiredSecrets"/>.</param>
 public SolutionConfigurationEventArgs(
     IActivityMonitor m,
     Solution solution,
     bool isNew,
     SolutionSpec spec,
     IList <(string SecretKeyName, string Secret)> buildSecrets)
示例#17
0
 public CommonFolder(GitFolder f, SolutionDriver driver, SolutionSpec settings, NormalizedPath branchPath)
     : base(f, branchPath, "Common", "Basics/Res")
 {
     _driver   = driver;
     _settings = settings;
 }
示例#18
0
 public SolutionFolder(GitFolder f, SolutionDriver driver, SolutionSpec solutionSpec, NormalizedPath branchPath)
     : base(f, branchPath, subFolderPath: String.Empty, "Basics/Res")
 {
     _driver       = driver;
     _solutionSpec = solutionSpec;
 }
示例#19
0
 public GitIgnoreFile(GitFolder f, SolutionSpec solutionSpec, NormalizedPath branchPath)
     : base(f, branchPath, branchPath.AppendPart(".gitignore"))
 {
     _solutionSpec = solutionSpec;
 }
示例#20
0
 public GlobalJsonFile(GitFolder f, NormalizedPath branchPath, SolutionSpec solutionSpec)
     : base(f, branchPath, branchPath.AppendPart("global.json"))
 {
     _solutionSpec = solutionSpec;
 }