static void Main(string[] args) { //Input Validation if (!IsValidParameters(args)) { return; } string inputFilename = args[0]; SudokuPuzzleReader reader = GetSudokuPuzzleReader(inputFilename); if (!IsValidSudokuPuzzleReader(reader)) { return; } Gameboard gameboard = reader.Read(inputFilename); string resultsToBeWritten = gameboard.ToString(true); if (gameboard.IsInitialBoardValid() && gameboard.IsValidGame) { RunSolvingAlgorithms(gameboard); resultsToBeWritten += gameboard.ToString(); resultsToBeWritten += GetTimesFromAlgs(); } string outputFilename = args.Length == 2 ? args[1] : null; SolutionWriter writer = GetSolutionWriter(outputFilename); writer.Write(outputFilename, resultsToBeWritten); }
public void WriteToDisk() { if (_isWrittenOnDisk) { return; } foreach (var project in Projects.Values) { project.Build(); } foreach (var project in Projects.Values) { _solution.AddProject(project.Build()); } _solution.NugetConfig = _nuGetConfigGenerator?.Generate(NuGetSources.ToArray()); var solutionWriter = new SolutionWriter(_outputWriter); solutionWriter.WriteToFileSystem(_solution, _testProjectFolders.PathToSolutionDirectory); _isWrittenOnDisk = true; }
public Solution Solve() { var costSolver = new CostSolver(); var solutionWriter = new SolutionWriter(); var csvWriter = new CsvWriter(); var csvFile = new FileInfo("solution.csv"); double minCost = 0; Solution bestSolution = null; while (true) { var solution = this.CreateRandomSolution(); var solutionCost = costSolver.CalculateCost(solution); if (bestSolution == null || solutionCost < minCost) { minCost = solutionCost; bestSolution = solution; Console.WriteLine("new min cost: " + minCost); Console.WriteLine(solutionWriter.WriteSolution(bestSolution)); File.WriteAllText(csvFile.FullName, csvWriter.WriteSolution(bestSolution)); } } return(null); }
public SolutionWriteToDiskDriver(SolutionDriver solutionDriver, SolutionWriter solutionWriter, TestProjectFolders testProjectFolders, NuGetRestorerFactory nugetRestorerFactory) { _solutionDriver = solutionDriver; _solutionWriter = solutionWriter; _testProjectFolders = testProjectFolders; _nugetRestorerFactory = nugetRestorerFactory; }
public void CreateEmptySolution() { string folder = Path.Combine(Path.GetTempPath(), "SpecFlow.TestProjectGenerator.Tests", Guid.NewGuid().ToString("N")); var solution = new Solution("SolutionName"); var solutionWriter = new SolutionWriter(new Mock <IOutputWriter>().Object); solutionWriter.WriteToFileSystem(solution, folder); File.Exists(Path.Combine(folder, "SolutionName.sln")).Should().BeTrue(); }
static void SolvePart1AndSubmit(int[] cups, SolutionWriter solutionWriter) { int digit = cups[0]; for (int i = 0; i < cups.Length - 1; i++) { solutionWriter.Write((char)(digit + '1')); digit = cups[digit]; } solutionWriter.Complete(); }
static void Main(string[] args) { if (args.Length < 1) { WriteUsage(); } else { string format; string solution; Hashtable parameters = new Hashtable(); Hashtable uriMap = new Hashtable(); Driver.ParseArgs(args, out format, out solution, parameters, uriMap); if (format == null) { Console.Error.WriteLine("no output format specified"); } else { if (solution == null) { solution = Driver.FindSolution(Environment.CurrentDirectory); } SolutionWriter writer = null; switch (format) { case "nant": writer = new NAntWriter(); break; case "nmake": writer = new NMakeWriter(); break; } if (writer == null) { Console.Error.WriteLine("{0} is an unsupported format.", format); } else { Driver.WriteSolution(writer, Console.Out, solution, parameters, uriMap); } } } }
public void CreateSolutionWithProject(ProgrammingLanguage programmingLanguage, string expectedEnding) { string folder = Path.Combine(Path.GetTempPath(), "SpecFlow.TestProjectGenerator.Tests", Guid.NewGuid().ToString("N")); var solution = new Solution("SolutionName"); var project = new Project("ProjectName", Guid.NewGuid(), programmingLanguage, TargetFramework.Net45, ProjectFormat.New); solution.AddProject(project); var solutionWriter = new SolutionWriter(new Mock <IOutputWriter>().Object); solutionWriter.WriteToFileSystem(solution, folder); File.Exists(Path.Combine(folder, "SolutionName.sln")).Should().BeTrue(); File.Exists(Path.Combine(folder, "ProjectName", $"ProjectName.{expectedEnding}")).Should().BeTrue(); }
/// <summary> /// Creates the <see cref="SolutionWriter" /> for the specified format. /// </summary> /// <returns> /// The <see cref="SolutionWriter" /> for the specified format, or /// <see langword="null" /> if an unknown format was specified. /// </returns> private SolutionWriter CreateSolutionWriter(string format) { SolutionWriter writer = null; switch (format) { case "nant": writer = new NAntWriter(); break; case "nmake": writer = new NMakeWriter(); break; } return(writer); }
protected override void ExecuteTask() { // display build log message Log(Level.Info, "Converting '{0}' to '{1}' using {2} format", Solution, Output, Format); // get a SLiNgshoT SolutionWriter for the specified format. SolutionWriter solutionWriter = CreateSolutionWriter(Format); // make sure the specified format is supported if (solutionWriter == null) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "'{0}' is an unsupported format.", _format), Location); } // copy parameters to hashtable. Hashtable parameters = OptionCollectionToHashtable(Parameters, "parameters"); // make sure a build.basedir parameter was specified if (!parameters.ContainsKey("build.basedir")) { throw new BuildException("The <parameters> option 'build.basedir' is required.", Location); } // copy maps to hashtable Hashtable uriMap = OptionCollectionToHashtable(Maps, "maps"); try { // NOTE: The default encoding is used. StreamWriter outputWriter = new StreamWriter(Output); // convert the solution Driver.WriteSolution(solutionWriter, outputWriter, Solution, parameters, uriMap); // close the output file outputWriter.Close(); } catch (Exception ex) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Could not convert solution '{0}'.", Solution), Location, ex); } }
static SolutionWriter GetSolutionWriter(string outputFilename) { SolutionWriter result = null; if (outputFilename == null) { result = SolutionWriters[0]; } else { string fileType = Path.GetExtension(outputFilename); foreach (SolutionWriter writer in SolutionWriters) { if (fileType == writer.Name) { result = writer; break; } } } return(result); }
public static void Execute(IReadOnlyList <SharpTreeNode> selectedNodes) { var currentLanguage = MainWindow.Instance.CurrentLanguage; var tabPage = Docking.DockWorkspace.Instance.ActiveTabPage; tabPage.ShowTextView(textView => { if (selectedNodes.Count == 1 && selectedNodes[0] is ILSpyTreeNode singleSelection) { // if there's only one treenode selected // we will invoke the custom Save logic if (singleSelection.Save(tabPage)) { return; } } else if (selectedNodes.Count > 1 && selectedNodes.All(n => n is AssemblyTreeNode)) { var selectedPath = SelectSolutionFile(); if (!string.IsNullOrEmpty(selectedPath)) { var assemblies = selectedNodes.OfType <AssemblyTreeNode>() .Select(n => n.LoadedAssembly) .Where(a => !a.HasLoadError).ToArray(); SolutionWriter.CreateSolution(textView, selectedPath, currentLanguage, assemblies); } return; } // Fallback: if nobody was able to handle the request, use default behavior. // try to save all nodes to disk. var options = new DecompilationOptions() { FullDecompilation = true }; textView.SaveToDisk(currentLanguage, selectedNodes.OfType <ILSpyTreeNode>(), options); }); }
/// <summary> /// Build Master Builder React Project /// </summary> public async Task <string> RunAsync(BuilderSettings builderSettings, Request.Project project, SolutionWriter solutionWriter, string solutionDirectory) { // Create Solution Directory var webProjectDirectory = FileHelper.CreateFolder(solutionDirectory, project.InternalName); var projectWriter = new SolutionWriter(webProjectDirectory, project.CleanDirectoryIgnoreDirectories); // dot net project files projectWriter.AddTemplate(new ProjectFiles.ProjectTemplate(project)); projectWriter.AddTemplate(new ProjectFiles.ProgramTemplate(project)); projectWriter.AddTemplate(new ProjectFiles.StartupTemplate(project)); // Not sure if this file is needed //projectWriter.AddTemplate(new ProjectFiles.WebConfigTemplate()); projectWriter.AddTemplate(new ProjectFiles.AppSettingsTemplate(project)); // Create Project Files projectWriter.AddTemplate(new ProjectFiles.TsLintTemplate(project)); //projectWriter.AddTemplate(new ProjectFiles.PackageLockJsonTemplate(project)); projectWriter.AddTemplate(new ProjectFiles.EslintrcTemplate(project)); projectWriter.AddTemplate(new ProjectFiles.EslintrcIgnoreTemplate(project)); // Server Pages projectWriter.AddTemplate(new Pages.PagesBuilder(project)); // Client App projectWriter.AddTemplate(new ClientApp.ClientAppBuilder(project)); var errors = await projectWriter.WriteAndClean(); if (!string.IsNullOrEmpty(errors)) { return(errors); } return(null); }
/// <summary> /// Build Master Builder Api Shared Project /// </summary> public async Task <string> RunAsync(BuilderSettings builderSettings, Request.Project project, SolutionWriter solutionWriter, string solutionDirectory, SourceControl.Git git, SourceControl.Models.GetRepository repository) { var apiProjectDirectory = FileHelper.CreateFolder(solutionDirectory, $"{project.InternalName}.Services"); solutionWriter.SetProjectDirectory(apiProjectDirectory); var errors = await solutionWriter.WriteAndClean(); if (!string.IsNullOrEmpty(errors)) { return(errors); } return(null); }
/// <summary> /// Build Master Builder Api Custom Project /// </summary> public async Task <string> RunAsync(BuilderSettings builderSettings, Request.Project project, SolutionWriter solutionWriter, string solutionDirectory, SourceControl.Git git, SourceControl.Models.GetRepository repository) { var apiProjectDirectory = FileHelper.CreateFolder(solutionDirectory, $"{project.InternalName}.Api.Custom"); if (!FileHelper.IsDirectoryEmpty(apiProjectDirectory)) { // If directory exists then skip this project, user can do what ever they want here return(null); } solutionWriter.SetProjectDirectory(apiProjectDirectory); // Create Project Files solutionWriter.AddTemplate(new ProjectFiles.ProjectTemplate(project)); // Extension Point solutionWriter.AddTemplate(new ProjectFiles.ExtensionPointTemplate(project)); var errors = await solutionWriter.WriteAndClean(); if (!string.IsNullOrEmpty(errors)) { return(errors); } return(null); }
public static void WriteSolution( SolutionWriter writer, TextWriter textWriter, string sln, Hashtable parameters, Hashtable uriMap) { writer.SetOutput(textWriter); writer.SetParameters(parameters); Solution solution = new Solution(); solution.Read(sln, uriMap); writer.WriteStartSolution(solution); foreach (Project project in solution.GetProjects()) { IList sourceFiles = project.GetSourceFiles(); if (sourceFiles.Count > 0) { writer.WriteStartProjectSourceFiles(project); foreach (File file in sourceFiles) { writer.WriteProjectSourceFile(file); } writer.WriteEndProjectSourceFiles(); } IList resXFiles = project.GetResXResourceFiles(); if (resXFiles.Count > 0) { writer.WriteStartProjectResXResourceFiles(project); foreach (File file in resXFiles) { writer.WriteProjectResXResourceFile(file); } writer.WriteEndProjectResXResourceFiles(); } IList resourceFiles = project.GetNonResXResourceFiles(); if (resourceFiles.Count > 0) { writer.WriteStartProjectNonResXResourceFiles(project); foreach (File file in resourceFiles) { writer.WriteProjectNonResXResourceFile(file); } writer.WriteEndProjectNonResXResourceFiles(); } } foreach (Project project in solution.GetProjects()) { if (project.CountFiles("Compile") > 0) { writer.WriteStartProject(project); writer.WriteStartProjectDependencies(); foreach (Project dependency in solution.GetDependencies(project)) { writer.WriteProjectDependency(dependency); } foreach (Reference reference in project.GetReferences()) { if (reference.Type == "Project") { writer.WriteProjectDependency(solution.GetProject(reference.Value)); } } foreach (File file in project.GetFiles()) { if (!file.RelativePath.EndsWith(".licx")) { writer.WriteProjectDependency(file); } } writer.WriteEndProjectDependencies(); IList resXFiles = project.GetResXResourceFiles(); if (resXFiles.Count > 0) { writer.WriteStartResXFiles(); foreach (File file in resXFiles) { writer.WriteResXFile(file); } writer.WriteEndResXFiles(); } writer.WriteStartAssembly(); IList sourceFiles = project.GetSourceFiles(); if (sourceFiles.Count > 0) { writer.WriteStartSourceFiles(); foreach (File file in sourceFiles) { writer.WriteSourceFile(file); } writer.WriteEndSourceFiles(); } writer.WriteStartReferences(); // Write out the standard system references. foreach (Reference reference in project.GetSystemReferences()) { if (reference != null) { // assume it's another project in sln and/or copy-local string path = reference.Value + ".dll"; bool inBuildPath = true; if (!reference.CopyLocal && (reference.Type == "AssemblyName")) { inBuildPath = false; if (reference.SourcePath != string.Empty) { path = reference.SourcePath; } if (!Path.IsPathRooted(path)) { path = Path.GetFullPath(solution.SolutionDirectory + "\\" + project.RelativePath + "\\" + path); } } writer.WriteReference(path, inBuildPath); } } // Write out the project references. foreach (Project referencedProject in project.GetReferencedProjects()) { writer.WriteReference(referencedProject); } writer.WriteEndReferences(); writer.WriteStartResources(); foreach (File file in project.GetResXResourceFiles()) { string path = project.RootNamespace + "." + Path.GetFileNameWithoutExtension(file.RelativePath) + ".resources"; writer.WriteResource(path, null, true); } foreach (File file in project.GetNonResXResourceFiles()) { writer.WriteResource( file.RelativePathFromSolutionDirectory, file.ResourceName, false); } writer.WriteEndResources(); writer.WriteEndAssembly(); // Write out the project references so that they can be copied. writer.WriteStartCopyProjectAssemblies(); foreach (Project referencedProject in project.GetReferencedProjects()) { writer.WriteCopyProjectAssembly(referencedProject); } writer.WriteEndCopyProjectAssemblies(); writer.WriteEndProject(); } } writer.WriteStartCleanTarget(); foreach (Project project in solution.GetProjects()) { writer.WriteCleanProject(project); } writer.WriteEndCleanTarget(); writer.WriteEndSolution(); }
public static void WriteSolution( SolutionWriter writer, TextWriter textWriter, string sln, Hashtable parameters, Hashtable uriMap) { writer.SetOutput(textWriter); writer.SetParameters(parameters); Solution solution = new Solution(); solution.Read(sln, uriMap); writer.WriteStartSolution(solution); foreach (Project project in solution.GetProjects()) { IList sourceFiles = project.GetSourceFiles(); if (sourceFiles.Count > 0) { writer.WriteStartProjectSourceFiles(project); foreach (File file in sourceFiles) { writer.WriteProjectSourceFile(file); } writer.WriteEndProjectSourceFiles(); } IList resXFiles = project.GetResXResourceFiles(); if (resXFiles.Count > 0) { writer.WriteStartProjectResXResourceFiles(project); foreach (File file in resXFiles) { writer.WriteProjectResXResourceFile(file); } writer.WriteEndProjectResXResourceFiles(); } IList resourceFiles = project.GetNonResXResourceFiles(); if (resourceFiles.Count > 0) { writer.WriteStartProjectNonResXResourceFiles(project); foreach (File file in resourceFiles) { writer.WriteProjectNonResXResourceFile(file); } writer.WriteEndProjectNonResXResourceFiles(); } } foreach (Project project in solution.GetProjects()) { if (project.CountFiles("Compile") > 0) { writer.WriteStartProject(project); writer.WriteStartProjectDependencies(); foreach (Project dependency in solution.GetDependencies(project)) { writer.WriteProjectDependency(dependency); } foreach (Reference reference in project.GetReferences()) { if (reference.Type == "Project") { writer.WriteProjectDependency(solution.GetProject(reference.Value)); } } foreach (File file in project.GetFiles()) { if (!file.RelativePath.EndsWith(".licx")) { writer.WriteProjectDependency(file); } } writer.WriteEndProjectDependencies(); IList resXFiles = project.GetResXResourceFiles(); if (resXFiles.Count > 0) { writer.WriteStartResXFiles(); foreach (File file in resXFiles) { writer.WriteResXFile(file); } writer.WriteEndResXFiles(); } writer.WriteStartAssembly(); IList sourceFiles = project.GetSourceFiles(); if (sourceFiles.Count > 0) { writer.WriteStartSourceFiles(); foreach (File file in sourceFiles) { writer.WriteSourceFile(file); } writer.WriteEndSourceFiles(); } writer.WriteStartReferences(); // Write out the standard system references. foreach (Reference reference in project.GetSystemReferences()) { if (reference != null) { // assume it's another project in sln and/or copy-local string path = reference.Value + ".dll"; bool inBuildPath = true; if ( !reference.CopyLocal && (reference.Type == "AssemblyName") ) { inBuildPath = false; if ( reference.SourcePath != string.Empty ) { path = reference.SourcePath; } if ( ! Path.IsPathRooted( path ) ) { path = Path.GetFullPath( solution.SolutionDirectory + "\\" + project.RelativePath + "\\" + path ); } } writer.WriteReference( path , inBuildPath ); } } // Write out the project references. foreach (Project referencedProject in project.GetReferencedProjects()) { writer.WriteReference(referencedProject); } writer.WriteEndReferences(); writer.WriteStartResources(); foreach (File file in project.GetResXResourceFiles()) { string path = project.RootNamespace + "." + Path.GetFileNameWithoutExtension(file.RelativePath) + ".resources"; writer.WriteResource(path, null, true); } foreach (File file in project.GetNonResXResourceFiles()) { writer.WriteResource( file.RelativePathFromSolutionDirectory, file.ResourceName, false); } writer.WriteEndResources(); writer.WriteEndAssembly(); // Write out the project references so that they can be copied. writer.WriteStartCopyProjectAssemblies(); foreach (Project referencedProject in project.GetReferencedProjects()) { writer.WriteCopyProjectAssembly(referencedProject); } writer.WriteEndCopyProjectAssemblies(); writer.WriteEndProject(); } } writer.WriteStartCleanTarget(); foreach (Project project in solution.GetProjects()) { writer.WriteCleanProject(project); } writer.WriteEndCleanTarget(); writer.WriteEndSolution(); }
/// <summary> /// Build Master Builder Api Project /// </summary> public async Task <string> RunAsync(BuilderSettings builderSettings, Request.Project project, SolutionWriter solutionWriter, string solutionDirectory, SourceControl.Git git, SourceControl.Models.GetRepository repository) { var apiProjectDirectory = FileHelper.CreateFolder(solutionDirectory, $"{project.InternalName}.Api"); solutionWriter.SetProjectDirectory(apiProjectDirectory); // Create Project Files solutionWriter.AddTemplate(new ProjectFiles.ProjectTemplate(project)); solutionWriter.AddTemplate(new ProjectFiles.WebConfigTemplate()); solutionWriter.AddTemplate(new ProjectFiles.NuGetconfigTemplate(project)); // Controllers solutionWriter.AddTemplate(new Controllers.ControllerTemplateBuilder(project)); // Services solutionWriter.AddTemplate(new Services.ServiceTemplateBuilder(project)); // Services/Contracts solutionWriter.AddTemplate(new Services.Contracts.ServiceContractTemplateBuilder(project)); // Create Project Files solutionWriter.AddTemplate(new ProjectFiles.ProjectTemplate(project)); // Models/Export solutionWriter.AddTemplate(new Models.Export.ModelTemplateBuilder(project)); var errors = await solutionWriter.WriteAndClean(); if (!string.IsNullOrEmpty(errors)) { return(errors); } return(null); }