static void Main(string[] args) { var types = Assembly.GetExecutingAssembly().GetTypes().Where((t) => t.BaseType == typeof(SolutionBase)).OrderBy(t => t.Name).ToArray(); int solutionSucceedCount = 0; var sw = new System.Diagnostics.Stopwatch(); for (int i = 0; i < types.Length; i++) { Type type = types[i]; int problemNo = SolutionBase.GetProblemNo(type); if (problemNo != 126) { continue; } System.Diagnostics.Debug.Print(string.Format("\n-------- Test Problem [{0}] {1} --------", problemNo, type.Name)); SolutionBase solution = Activator.CreateInstance(type) as SolutionBase; bool isSucceed = solution.Test(sw); TimeSpan ts = sw.Elapsed; if (isSucceed) { solutionSucceedCount += 1; } System.Diagnostics.Debug.Print(string.Format(">>>>>> Test Result : {0} used time = {1} <<<<<<\n", isSucceed, ($" {sw.ElapsedMilliseconds}ms"))); } System.Diagnostics.Debug.Print(string.Format("-------->>>>>> All Test Results : {0} | Success statics : {1} / {2} <<<<<<--------", solutionSucceedCount == types.Length, solutionSucceedCount, types.Length)); }
public void GetSecondResultMultipleGood() { //Given string[] input = { "1", "2", "3", "4", "5", "2015" }; var dayOne = SolutionBase.CreateDayOneFrom(input); //When var result = dayOne.SolvePartTwo(); //Then Assert.Equal(1 * 4 * 2015, result); }
private IEnumerable <ISolution> CreateSolutions() { yield return(SolutionBase.CreateDayOneFrom(_inputFileRepository.GetInput("day1.txt"))); yield return(SolutionBase.CreateDayTwoFrom(_inputFileRepository.GetInput("day2.txt"))); yield return(SolutionBase.CreateDayThreeFrom(_inputFileRepository.GetInput("day3.txt"))); yield return(SolutionBase.CreateDayFourFrom(_inputFileRepository.GetInput("day4.txt"))); yield return(SolutionBase.CreateDayFiveFrom(_inputFileRepository.GetInput("day5.txt"))); }
private static SolutionBase Init() { string[] array = { "1-3 a: abcde", "1-3 b: cdefg", "2-9 c: ccccccccc" }; var solution = SolutionBase.CreateDayTwoFrom(array); return(solution); }
public void GetFirstResultTest() { //Given string[] input = { "672", "673", "675", "1001", "1002", "1003", "1004", "1019" }; var dayOne = SolutionBase.CreateDayOneFrom(input); //When var result = dayOne.SolvePartOne(); //Then Assert.Equal(1001 * 1019, result); }
public MSBuildProjectReference( ReferencesResolver referencesResolver, ProjectBase parent, SolutionBase solution, TempFileCollection tfc, GacCache gacCache, DirectoryInfo outputDir, string pguid, string pname, string rpath, string priv) : base(referencesResolver, parent) { _helper = new MSBuildReferenceHelper(priv, true); string projectFile = solution.GetProjectFileFromGuid(pguid); _project = LoadProject(solution, tfc, gacCache, outputDir, projectFile); }
public async Task <IHttpActionResult> DeleteSolutionBase(int id) { SolutionBase solutionBase = await db.SolutionBases.FindAsync(id); if (solutionBase == null) { return(NotFound()); } db.SolutionBases.Remove(solutionBase); await db.SaveChangesAsync(); return(Ok(solutionBase)); }
public async Task <IHttpActionResult> PostSolutionBase(DictionaryBasic ds) { SolutionBase solutionBase = new SolutionBase(); solutionBase.Name = ds.Name; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.SolutionBases.Add(solutionBase); await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.OK)); }
public void GetFirstResultTest() { //Given string[] array = { "BFFFBBFRRR", "FFFBBBFRRR", "BBFFBBFRLL" }; var solution = SolutionBase.CreateDayFiveFrom(array); //When var result = solution.SolvePartOne(); //Then Assert.Equal(820, result); }
private void OnFileDrop(object sender, RoutedEventArgs e) { var dfc = (DropFileControl)sender; var fullProjectPath = dfc.DroppedFile; var ext = Path.GetExtension(fullProjectPath); var dirName = Path.GetDirectoryName(fullProjectPath); var dirInfo = new DirectoryInfo(dirName); var name = Path.GetFileNameWithoutExtension(fullProjectPath); ProjectBase newProject = null; if (ext == SolutionFileExt) { newProject = new SolutionBase(); _projectCollection.Solution.Add((SolutionBase)newProject); } else if (ext == ProjectFileExt) { newProject = new ProjectBase(); _projectCollection.Project.Add(newProject); } if (newProject == null) { return; } newProject.CategoryId = -1; newProject.Name = name; newProject.FullPath = fullProjectPath; ScanFolder(newProject, dirInfo); var item = new CollectionItem(newProject, _projectCollection.Tags); _collectionItems.Add(item); _existProjects.Add(newProject.FullPath.ToLower()); CreateDirInTree(_folders, newProject); RefreshView(); RefreshFolders(); }
public static void RunClient(TCPClient client, Func <TCPClient, SolutionBase> newSolver) { SolutionBase solver = newSolver(client); while (true) { //if (client.TurnLeftIsNewGame().Item2) // solver.Restart(); solver.GetData(); if (solver.Act() == false) { break; } //client.Wait(); } }
public async Task <IHttpActionResult> PutSolutionBase(DictionaryBasic ds) { SolutionBase solutionBase = db.SolutionBases.Single(s => s.Id == ds.Id); if (solutionBase == null) { return(BadRequest()); } db.Entry(solutionBase).State = EntityState.Modified; if (!String.IsNullOrEmpty(ds.Name)) { solutionBase.Name = ds.Name; } await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.OK)); }
private static SolutionBase Init() { string[] array = { "..##.......", "#...#...#..", ".#....#..#.", "..#.#...#.#", ".#...##..#.", "..#.##.....", ".#.#.#....#", ".#........#", "#.##...#...", "#...##....#", ".#..#...#.#" }; var solution = SolutionBase.CreateDayThreeFrom(array); return(solution); }
public MSBuildProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) { string cfgname = solutionTask.Configuration; string platform = solutionTask.Platform; _msbuild = MSBuildEngine.CreateMSEngine(solutionTask); _msproj = new Microsoft.Build.BuildEngine.Project(_msbuild); _msproj.FullFileName = projectPath; _msproj.LoadXml(xmlDefinition.OuterXml); _msproj.GlobalProperties.SetProperty("Configuration", cfgname); SetPlatform(platform); if (outputDir != null) { _msproj.GlobalProperties.SetProperty("OutputPath", outputDir.FullName); } //evaluating _guid = _msproj.GetEvaluatedProperty("ProjectGuid"); _projectDirectory = new DirectoryInfo(_msproj.GetEvaluatedProperty("ProjectDir")); _projectPath = _msproj.GetEvaluatedProperty("ProjectPath"); ProjectEntry projectEntry = solution.ProjectEntries [_guid]; if (projectEntry != null && projectEntry.BuildConfigurations != null) { foreach (ConfigurationMapEntry ce in projectEntry.BuildConfigurations) { Configuration projectConfig = ce.Value; ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig); } } else { Configuration projectConfig = new Configuration(cfgname, platform); ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig); } //references _references = new ArrayList(); Microsoft.Build.BuildEngine.BuildItemGroup refs = _msproj.GetEvaluatedItemsByName("Reference"); foreach (Microsoft.Build.BuildEngine.BuildItem r in refs) { string rpath = r.FinalItemSpec; string priv = r.GetMetadata("Private"); string hintpath = r.GetMetadata("HintPath"); ReferenceBase reference = new MSBuildAssemblyReference( xmlDefinition, ReferencesResolver, this, gacCache, rpath, priv, hintpath); _references.Add(reference); } refs = _msproj.GetEvaluatedItemsByName("ProjectReference"); foreach (Microsoft.Build.BuildEngine.BuildItem r in refs) { string pguid = r.GetMetadata("Project"); string pname = r.GetMetadata("Name"); string rpath = r.FinalItemSpec; string priv = r.GetMetadata("Private"); ReferenceBase reference = new MSBuildProjectReference( ReferencesResolver, this, solution, tfc, gacCache, outputDir, pguid, pname, rpath, priv); _references.Add(reference); } }
public Day04Test(SolutionFixture <Day04> solutionFixture) { Solution = solutionFixture.Solution; }
public ProjectBase GetInstance(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) { return(new MSBuildProject(solution, projectPath, xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir)); }
public MSBuildProject(SolutionBase solution, string projectPath, XmlElement xmlDefinition, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver, DirectoryInfo outputDir) : base(xmlDefinition, solutionTask, tfc, gacCache, refResolver, outputDir) { string cfgname = solutionTask.Configuration; string platform = solutionTask.Platform; _msbuild = MSBuildEngine.CreateMSEngine(solutionTask); _msproj = new NAnt.MSBuild.BuildEngine.Project(_msbuild); _msproj.FullFileName = projectPath; _msproj.LoadXml(xmlDefinition.OuterXml); _msproj.GlobalProperties.SetProperty("Configuration", cfgname); if (platform.Length > 0) { _msproj.GlobalProperties.SetProperty("Platform", platform.Replace(" ", string.Empty)); } if (outputDir != null) { _msproj.GlobalProperties.SetProperty("OutputPath", outputDir.FullName); } bool generateDoc = false; //bool targwarnings = true; foreach (NAnt.Core.Tasks.PropertyTask property in solutionTask.CustomProperties) { string val; // expand properties in context of current project for non-dynamic properties if (!property.Dynamic) { val = solutionTask.Project.ExpandProperties(property.Value, solutionTask.GetLocation()); } else { val = property.Value; } switch (property.PropertyName) { //if (property.PropertyName == "TargetWarnings") targwarnings = Boolean.Parse(val); case "GenerateDocumentation": generateDoc = Boolean.Parse(val); break; default: _msproj.GlobalProperties.SetProperty(property.PropertyName, val); break; } } //set tools version to the msbuild version we got loaded _msproj.ToolsVersion = SolutionTask.Project.TargetFramework.Version.ToString(); //TODO: honoring project's TargetFrameworkVersion is not working atm. System assemblies are resolved badly _msproj.GlobalProperties.SetProperty("TargetFrameworkVersion", "v" + SolutionTask.Project.TargetFramework.Version.ToString()); //evaluating _guid = _msproj.GetEvaluatedProperty("ProjectGuid"); _projectDirectory = new DirectoryInfo(_msproj.GetEvaluatedProperty("ProjectDir")); _projectPath = _msproj.GetEvaluatedProperty("ProjectPath"); //TODO: honoring project's TargetFrameworkVersion is not working atm. System assemblies are resolved badly ////check if we targeting something else and throw a warning //if (targwarnings) //{ // string verString = _msproj.GetEvaluatedProperty("TargetFrameworkVersion"); // if (verString != null) // { // if (verString.StartsWith("v")) verString = verString.Substring(1); // Version ver = new Version(verString); // if (!ver.Equals(SolutionTask.Project.TargetFramework.Version)) // { // Log(Level.Warning, "Project '{1}' targets framework {0}.", verString, Name); // } // } //} //project configuration ProjectEntry projectEntry = solution.ProjectEntries [_guid]; if (projectEntry != null && projectEntry.BuildConfigurations != null) { foreach (ConfigurationMapEntry ce in projectEntry.BuildConfigurations) { Configuration projectConfig = ce.Value; ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig); } } else { Configuration projectConfig = new Configuration(cfgname, platform); ProjectConfigurations[projectConfig] = new MSBuildConfiguration(this, _msproj, projectConfig); } //references _references = new ArrayList(); NAnt.MSBuild.BuildEngine.BuildItemGroup refs = _msproj.GetEvaluatedItemsByName("Reference"); foreach (NAnt.MSBuild.BuildEngine.BuildItem r in refs) { string rpath = r.FinalItemSpec; string priv = r.GetMetadata("Private"); string hintpath = r.GetMetadata("HintPath"); string ext = r.GetMetadata("ExecutableExtension"); ReferenceBase reference = new MSBuildAssemblyReference( xmlDefinition, ReferencesResolver, this, gacCache, rpath, priv, hintpath, ext); _references.Add(reference); } refs = _msproj.GetEvaluatedItemsByName("ProjectReference"); foreach (NAnt.MSBuild.BuildEngine.BuildItem r in refs) { string pguid = r.GetMetadata("Project"); string pname = r.GetMetadata("Name"); string rpath = r.FinalItemSpec; string priv = r.GetMetadata("Private"); ReferenceBase reference = new MSBuildProjectReference( ReferencesResolver, this, solution, tfc, gacCache, outputDir, pguid, pname, rpath, priv); _references.Add(reference); } if (generateDoc) { string xmlDocBuildFile = FileUtils.CombinePaths(OutputPath, this.Name + ".xml"); //// make sure the output directory for the doc file exists //if (!Directory.Exists(Path.GetDirectoryName(xmlDocBuildFile))) { // Directory.CreateDirectory(Path.GetDirectoryName(xmlDocBuildFile)); //} // add built documentation file as extra output file ExtraOutputFiles[xmlDocBuildFile] = Path.GetFileName(xmlDocBuildFile); _msproj.GlobalProperties.SetProperty("DocumentationFile", xmlDocBuildFile); } }
/// <summary> /// Executes the task. /// </summary> /// <exception cref="BuildException"> /// Project build failed. /// </exception> protected override void ExecuteTask() { Log(Level.Info, "Starting solution build."); if (SolutionFile != null) { if (!SolutionFile.Exists) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, "Couldn't find solution file '{0}'.", SolutionFile.FullName), Location); } } if (Projects.FileNames.Count > 0) { Log(Level.Verbose, "Included projects:"); foreach (string projectFile in Projects.FileNames) { Log(Level.Verbose, " - {0}", projectFile); } } if (ReferenceProjects.FileNames.Count > 0) { Log(Level.Verbose, "Reference projects:"); foreach (string projectFile in ReferenceProjects.FileNames) { Log(Level.Verbose, " - {0}", projectFile); } } string basePath = null; try { using (TempFileCollection tfc = new TempFileCollection()) { // store the temp dir so we can clean it up later basePath = tfc.BasePath; // ensure temp directory exists if (!Directory.Exists(tfc.BasePath)) { Directory.CreateDirectory(tfc.BasePath); } // create temporary domain PermissionSet tempDomainPermSet = new PermissionSet(PermissionState.Unrestricted); AppDomain temporaryDomain = AppDomain.CreateDomain("temporaryDomain", AppDomain.CurrentDomain.Evidence, AppDomain.CurrentDomain.SetupInformation, tempDomainPermSet); try { ReferencesResolver referencesResolver = ((ReferencesResolver)temporaryDomain.CreateInstanceFrom(Assembly.GetExecutingAssembly().Location, typeof(ReferencesResolver).FullName).Unwrap()); using (GacCache gacCache = new GacCache(this.Project)) { SolutionBase sln = SolutionFactory.LoadSolution(this, tfc, gacCache, referencesResolver); if (!sln.Compile(_configuration)) { throw new BuildException("Project build failed.", Location); } } } finally { // unload temporary domain AppDomain.Unload(temporaryDomain); } } } finally { if (basePath != null && Directory.Exists(basePath)) { Log(Level.Debug, "Cleaning up temp folder '{0}'.", basePath); // delete temporary directory and all files in it DeleteTask deleteTask = new DeleteTask(); deleteTask.Project = Project; deleteTask.Parent = this; deleteTask.InitializeTaskConfiguration(); deleteTask.Directory = new DirectoryInfo(basePath); deleteTask.Threshold = Level.None; // no output in build log deleteTask.Execute(); } } }
private static SolutionBase Init(string[] array) { var solution = SolutionBase.CreateDayFourFrom(array); return(solution); }
public Day01Test(SolutionFixture <Day01> solutionFixture) { this.Solution = solutionFixture.Solution; }
private void TreeScan(DirectoryInfo parentDir, BackgroundWorker curWorker) { curWorker.ReportProgress(0, parentDir.FullName); // var existDir = _projectCollection.Directory.FirstOrDefault(d => d.Name == dirName); foreach (var f in parentDir.GetFiles("*" + SolutionFileExt)) { // Если проект уже найден if (_existProjects.Contains(f.FullName.ToLower())) { continue; } /*var dirName = parentDir.FullName; * dirName = NormalizePath(dirName); * * * if (dirName == _rootDirPath) * { * * } * else * { * var relativeDir = dirName.Substring(_rootDirPath.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); * // Ищем среди каталогов нужный, если он существует * if (existDir != null) * { * } * else // если родительский каталог не найдн, создаём его * { * var directories = relativeDir.Split(Path.DirectorySeparatorChar); * var createdPath = string.Empty; * ProjectCollectionDirectory lastDir = null; * foreach (var directory in directories) * { * if (string.IsNullOrEmpty(createdPath)) * createdPath = directory; * else * createdPath = Path.Combine(createdPath, directory); * var existParentDir = _projectCollection.Directory.FirstOrDefault(d => d.Path == createdPath); * if (existParentDir == null) * { * * var newDir = new ProjectCollectionDirectory * { * Id = createdPath.GetHashCode(),//(ulong) ((DateTime.Now.ToBinary() % 1000000000000)), * Name = directory, * Path = createdPath, * }; * if (lastDir != null) * newDir.ParentId = lastDir.Id; * else * newDir.ParentId = -1; * * _projectCollection.Directory.Add(newDir); * lastDir = newDir; * } * else * lastDir = existParentDir; * } * * existDir = lastDir; * } * }*/ //Debug.Assert(existDir != null); var newSolution = new SolutionBase { CategoryId = -1,//existDir?.Id ?? Name = f.Name, FullPath = f.FullName, }; ScanFolder(newSolution, parentDir); _projectCollection.Project.Add(newSolution); _existProjects.Add(newSolution.FullPath.ToLower()); //TbTest.Text += f.FullName + Environment.NewLine; } foreach (var f in parentDir.GetFiles("*" + ProjectFileExt)) { if (_existProjects.Contains(f.FullName.ToLower())) { continue; } //Debug.Assert(existDir != null); var newProject = new ProjectBase { CategoryId = -1,//existDir?.Id ?? Name = f.Name, FullPath = f.FullName, }; ScanFolder(newProject, parentDir); _projectCollection.Project.Add(newProject); _existProjects.Add(newProject.FullPath.ToLower()); } foreach (var d in parentDir.GetDirectories()) { //var relativeDir = d.FullName.Substring(_rootDirPath.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); TreeScan(d, curWorker); } }
private void Project_ItemChanged(object sender, ProjectItemEventArgs e) { IProjectItem projectItem = e.ProjectItem; if (projectItem.IsOpen) { MessageBoxResult messageBoxResult = MessageBoxResult.No; string projectItemChangedDialogFileDirtyMessage = null; if (projectItem.IsDirty) { if ((e.Options & ProjectItemEventOptions.SilentIfDirty) != ProjectItemEventOptions.SilentIfDirty) { projectItemChangedDialogFileDirtyMessage = StringTable.ProjectItemChangedDialogFileDirtyMessage; } else { messageBoxResult = MessageBoxResult.Yes; } } else if ((e.Options & ProjectItemEventOptions.SilentIfOpen) != ProjectItemEventOptions.SilentIfOpen) { projectItemChangedDialogFileDirtyMessage = StringTable.ProjectItemChangedDialogFileCleanMessage; } else { messageBoxResult = MessageBoxResult.Yes; } if (!SolutionBase.IsReloadPromptEnabled()) { messageBoxResult = MessageBoxResult.Yes; projectItemChangedDialogFileDirtyMessage = null; } if (!string.IsNullOrEmpty(projectItemChangedDialogFileDirtyMessage)) { MessageBoxArgs messageBoxArg = new MessageBoxArgs(); CultureInfo currentCulture = CultureInfo.CurrentCulture; object[] path = new object[] { projectItem.DocumentReference.Path, base.Services.ExpressionInformationService().ShortApplicationName }; messageBoxArg.Message = string.Format(currentCulture, projectItemChangedDialogFileDirtyMessage, path); messageBoxArg.Button = MessageBoxButton.YesNo; messageBoxArg.Image = MessageBoxImage.Exclamation; MessageBoxArgs messageBoxArg1 = messageBoxArg; messageBoxResult = base.Services.MessageDisplayService().ShowMessage(messageBoxArg1); } if (messageBoxResult == MessageBoxResult.Yes) { bool isReadOnly = projectItem.Document.IsReadOnly; bool document = projectItem.Document == base.Services.DocumentService().ActiveDocument; bool flag = false; foreach (IView view in base.Services.ViewService().Views) { IDocumentView documentView = view as IDocumentView; if (documentView == null || documentView.Document != projectItem.Document) { continue; } flag = true; break; } projectItem.CloseDocument(); projectItem.OpenDocument(isReadOnly); if (projectItem.IsOpen && flag) { projectItem.OpenView(document); } } } }