Example #1
0
        //---------------------------------------------------------------------
        static DynamicVCConfiguration ComputeConfiguration(
            ExtendedProject project,
            SolutionContext context,
            ref string error)
        {
            var configurations = project.Configurations;
            var configuration  = configurations.FirstOrDefault(
                c => c.ConfigurationName == context.ConfigurationName && c.PlatformName == context.PlatformName);

            if (configuration == null)
            {
                var builder = new StringBuilder();

                builder.AppendLine(string.Format("Cannot find a configuration for the project {0}", project.UniqueName));
                builder.AppendLine(string.Format(" - Solution: configuration: {0} platform: {1}", context.ConfigurationName, context.PlatformName));
                foreach (var config in configurations)
                {
                    builder.AppendLine(string.Format(" - Project: configuration: {0} platform: {1}", config.ConfigurationName, config.PlatformName));
                }
                error = builder.ToString();
                return(null);
            }

            return(configuration);
        }
Example #2
0
    public Task Run(SolutionContext context)
    {
        var input = context.InputLines
                    .Select(l => l.ToCharArray())
                    .ToArray();

        var oneBits = new int[input[0].Length];

        foreach (var line in input)
        {
            for (var i = 0; i < line.Length; i++)
            {
                oneBits[i] += line[i] == '1' ? 1 : 0;
            }
        }

        var gammaBits   = new char[input[0].Length];
        var epsilonBits = new char[input[0].Length];

        for (var i = 0; i < oneBits.Length; i++)
        {
            gammaBits[i]   = oneBits[i] > input.Length - oneBits[i] ? '1' : '0';
            epsilonBits[i] = gammaBits[i] == '1' ? '0' : '1';
        }

        var gamma   = Convert.ToInt32(new string(gammaBits), 2);
        var epsilon = Convert.ToInt32(new string(epsilonBits), 2);

        Console.WriteLine(gamma * epsilon);
        return(Task.CompletedTask);
    }
        public void homonym_projects_are_automatically_named_inside_the_same_solution_when_added()
        {
            var ctx = new SolutionContext();
            var s   = ctx.AddSolution("/Solution/Path", "SolutionName");

            var pC = s.AddProject("Dir1", "c#", "Homonym");

            pC.Name.Should().Be("Homonym");
            s.Invoking(_ => _.AddProject("Dir1", "c#", "Homonym")).Should().Throw <InvalidOperationException>();
            pC.Name.Should().Be("Homonym");

            var pJ = s.AddProject("Dir1", "js", "Homonym");

            pC.Name.Should().Be("(c#)Homonym");
            pJ.Name.Should().Be("(js)Homonym");

            var pJa = s.AddProject("AltDir", "js", "Homonym");

            pC.Name.Should().Be("(c#)Homonym");
            pJ.Name.Should().Be("(js)Dir1/Homonym");
            pJa.Name.Should().Be("(js)AltDir/Homonym");

            var pCa = s.AddProject("AltDir", "c#", "Homonym");

            pC.Name.Should().Be("(c#)Dir1/Homonym");
            pCa.Name.Should().Be("(c#)AltDir/Homonym");
            pJ.Name.Should().Be("(js)Dir1/Homonym");
            pJa.Name.Should().Be("(js)AltDir/Homonym");
        }
        protected string projectCfg(SolutionContext context, IPM pm)
        {
            Debug.Assert(context != null);

            if (pm.It(LevelType.Property, "IsBuildable"))
            {
                if (pm.IsRight(LevelType.RightOperandStd))
                {
                    context.ShouldBuild = Value.toBoolean(pm.FirstLevel.Data);
                    return(Value.Empty);
                }

                if (pm.IsRight(LevelType.RightOperandEmpty))
                {
                    return(Value.from(context.ShouldBuild));
                }
            }

            if (pm.It(LevelType.Property, "IsDeployable"))
            {
                if (pm.IsRight(LevelType.RightOperandStd))
                {
                    context.ShouldDeploy = Value.toBoolean(pm.FirstLevel.Data);
                    return(Value.Empty);
                }

                if (pm.IsRight(LevelType.RightOperandEmpty))
                {
                    return(Value.from(context.ShouldDeploy));
                }
            }

            throw new IncorrectNodeException(pm);
        }
Example #5
0
    public Task Run(SolutionContext context)
    {
        var input = context.InputLines
                    .Select(l => l.Split("\t").Select(int.Parse).ToArray())
                    .ToArray();

        var sum = 0;

        foreach (var line in input)
        {
            for (var a = 0; a < input.Length; a++)
            {
                for (var b = 0; b < input.Length; b++)
                {
                    if (a == b || line[a] % line[b] > 0)
                    {
                        continue;
                    }
                    sum += line[a] / line[b];
                }
            }
        }

        Console.WriteLine(sum);
        return(Task.CompletedTask);
    }
Example #6
0
    public Task Run(SolutionContext context)
    {
        var input = context.InputLines
                    .Select(Parse)
                    .ToArray();

        var position = 0;
        var depth    = 0;
        var aim      = 0;

        foreach (var command in input)
        {
            if (command.DeltaAxis == Axis.Aim)
            {
                aim += command.Delta;
            }
            else
            {
                position += command.Delta;
                depth    += aim * command.Delta;
            }
        }

        Console.WriteLine(position * depth);
        return(Task.CompletedTask);
    }
Example #7
0
 /// <summary>
 /// Initializes an empty context for a given branch.
 /// </summary>
 /// <param name="branchName">The branch name.</param>
 internal WorldBranchContext(string branchName)
 {
     BranchName = branchName;
     _context   = new SolutionContext();
     _drivers   = new List <ISolutionDriver>();
     _pairList  = new PairList(this);
 }
Example #8
0
    public Task Run(SolutionContext context)
    {
        var input = Convert.ToInt32(context.InputString);

        int LengthOfSide(int l)
        => 2 * l + 1;
        int LengthOfLayer(int l)
        => 8 * l;
        int DistanceToClosestSide(int target, params int[] values)
        => values.Select(v => Math.Abs(v - target)).OrderBy(v => v).First();

        var layer       = 1;
        var bottomRight = 1;

        while (bottomRight < input)
        {
            bottomRight += LengthOfLayer(layer++);
        }

        layer -= 1;

        var lengthOfSide          = LengthOfSide(layer) - 1;
        var halfLengthOfSide      = lengthOfSide / 2;
        var distanceToClosestSide = DistanceToClosestSide(
            input,
            bottomRight - halfLengthOfSide,
            bottomRight - halfLengthOfSide - 1 * lengthOfSide,
            bottomRight - halfLengthOfSide - 2 * lengthOfSide,
            bottomRight - halfLengthOfSide - 3 * lengthOfSide);
        var distanceToCenter = distanceToClosestSide + layer;

        Console.WriteLine(distanceToCenter);
        return(Task.CompletedTask);
    }
Example #9
0
    public Task Run(SolutionContext context)
    {
        var(doubles, triples) = context.InputLines
                                .Select(Parse)
                                .Aggregate((a, e) => (a.Doubles + e.Doubles, a.Triples + e.Triples));

        Console.WriteLine(doubles * triples);
        return(Task.CompletedTask);
    }
Example #10
0
    public Task Run(SolutionContext context)
    {
        var result = context.InputLines
                     .Select(e => e.Trim().TrimStart('+'))
                     .Select(e => Convert.ToInt64(e, 10))
                     .Aggregate((a, e) => a + e);

        Console.WriteLine(result);
        return(Task.CompletedTask);
    }
 public VisualStudioConfiguration(SolutionContext solutionContext,
                                  EnvDTE.ConfigurationManager nativeConfigurationManager, string solutionConfiguration,
                                  string solutionPlatform)
 {
     this.solutionContext            = solutionContext;
     this.nativeConfigurationManager = nativeConfigurationManager;
     SolutionConfiguration           = solutionConfiguration;
     SolutionPlatform = solutionPlatform;
     SetAvailableConfigurationsAndPlatforms();
     SetIsBuildableAndIsDeployable();
 }
Example #12
0
        SolutionContext GetSolutionContext(int i, SolutionContexts solutionContexts)
        {
            SolutionContext solutionContext = null;

            try {
                solutionContext = solutionContexts.Item(i);
            }
            catch {
            }
            return(solutionContext);
        }
 /// <summary>
 /// Disposes all external resources.
 /// </summary>
 /// <param name="disposing">The dispose indicator.</param>
 public void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_dbContext != null)
         {
             _dbContext.Dispose();
             _dbContext = null;
         }
     }
 }
        public void AddProjectReferences(SolutionContext solutionContext)
        {
            foreach (var projectContext in solutionContext.Projects)
            {
                var project = _solution.ProjectCache[projectContext.FileName];

                foreach (var subProjectContext in projectContext.ProjectReferences)
                {
                    project.Projects.Add(_solution.ProjectCache[subProjectContext.FileName]);
                }
            }
        }
Example #15
0
    public Task Run(SolutionContext context)
    {
        var input = context.InputLines
                    .Select(int.Parse)
                    .ToArray();

        var last      = int.MaxValue;
        var increases = 0;

        for (var i = 0; i < input.Length - (Window - 1); i++)
        {
            var next = input[i..(i + Window)].Sum();
Example #16
0
        public void LoadFromFile(string path)
        {
            var solution = SolutionContext.Create(path);

            _solution.ProjectCache.Clear();

            foreach (var solutionProject in solution.Projects)
            {
                GetProject(solution, solutionProject.FileName);
            }

            _solution.SetFile(path);
        }
Example #17
0
        void GetSolutionContext(string projectFileName, Action <SolutionContext> contextAction)
        {
            SolutionContexts solutionContexts = CodeRush.Solution.Active.DTE.Solution.SolutionBuild.ActiveConfiguration.SolutionContexts;

            for (int i = 0; i < solutionContexts.Count + 1; i++)
            {
                SolutionContext solutionContext = GetSolutionContext(i, solutionContexts);
                if (solutionContext != null && Path.GetFileName(projectFileName) == Path.GetFileName(solutionContext.ProjectName))
                {
                    contextAction.Invoke(solutionContext);
                }
            }
        }
Example #18
0
        private IProject GetProject(SolutionContext context, string name)
        {
            if (!_solution.ProjectCache.TryGetValue(name, out var project))
            {
                var projectContext = context.GetProject(name);

                project         = _projectFactoryFunc(projectContext.FileName);
                project.Name    = projectContext.Name;
                project.Version = projectContext.Version;
                _solution.ProjectCache[projectContext.FileName] = project;

                foreach (var packageReferenceContext in projectContext.PackageReferences)
                {
                    if (!_packageCache.PackagesDictionary.TryGetValue(packageReferenceContext.Name, out var package))
                    {
                        package = _packageFactoryFunc(packageReferenceContext.Name);
                        _packageCache.PackagesDictionary[packageReferenceContext.Name] = package;
                    }

                    var reference = new PackageReference
                    {
                        Package          = package,
                        Version          = packageReferenceContext.Version,
                        PreReleaseSuffix = packageReferenceContext.PreRelease
                    };

                    if (project.PackageReferenceDictionary.TryGetValue(reference.Package.Name, out var existingReference))
                    {
                        _logger.Error(project,
                                      $"There is already a reference to package {existingReference.Package.Name} at version {existingReference.Version}");
                    }

                    project.PackageReferenceDictionary[reference.Package.Name] = reference;
                }

                foreach (var projectReferenceContext in projectContext.ProjectReferences)
                {
                    if (!_solution.ProjectCache.TryGetValue(projectReferenceContext.FileName, out var subProject))
                    {
                        subProject = GetProject(context, projectReferenceContext.FileName);
                    }

                    project.Projects.Add(subProject);
                    subProject.Dependencies.Add(project);
                }
            }

            return(project);
        }
Example #19
0
    public Task Run(SolutionContext context)
    {
        var input = context.InputString;

        var result = input
                     .ToUpperInvariant()
                     .Distinct()
                     .ToList()
                     .Select(unit => Replace(unit, input))
                     .Select(D05P1.React)
                     .Min(polymer => polymer.Length);

        Console.WriteLine(result);
        return(Task.CompletedTask);
    }
Example #20
0
 public void ProjectFinishedGenerating(Project project)
 {
     foreach (SolutionConfiguration solConfig in solution.SolutionBuild.SolutionConfigurations)
     {
         foreach (SolutionContext solutionContext in solConfig.SolutionContexts)
         {
             if (solutionContext.ProjectName.Contains(project.Name + "." + projectFileExtension) &&
                 solutionContext.PlatformName == buildPlatformName &&
                 solConfig.Name == buildConfigName)
             {
                 projSolutionContext = solutionContext;
                 solutionConfig      = solConfig;
             }
         }
     }
 }
Example #21
0
    public Task Run(SolutionContext context)
    {
        var input = context.InputLines
                    .Select(Parse)
                    .ToArray();

        var position = input
                       .Where(i => i.DeltaAxis == Axis.Position)
                       .Sum(i => i.Delta);
        var depth = input
                    .Where(i => i.DeltaAxis == Axis.Depth)
                    .Sum(i => i.Delta);

        Console.WriteLine(position * depth);
        return(Task.CompletedTask);
    }
 public void ProjectFinishedGenerating(Project project)
 {
     foreach (SolutionConfiguration solConfig in solution.SolutionBuild.SolutionConfigurations)
     {
         foreach (SolutionContext solutionContext in solConfig.SolutionContexts)
         {
             if (solutionContext.ProjectName.Contains(project.Name + "." + projectFileExtension) &&
                 solutionContext.PlatformName == buildPlatformName &&
                 solConfig.Name == buildConfigName)
             {
                 projSolutionContext = solutionContext;
                 solutionConfig = solConfig;
             }
         }
     }
 }
Example #23
0
        /// <summary>
        /// Rewrites the specified workspace.
        /// </summary>
        /// <param name="workspace">The workspace.</param>
        /// <param name="rewriters">The rewriters.</param>
        /// <returns></returns>
        public Result <Workspace> Rewrite(Workspace workspace, IEnumerable <IRewriter> rewriters)
        {
            var modifiedSolution = workspace.CurrentSolution;

            var solutionContext = SolutionContext.Create(workspace);

            if (solutionContext.IsFailure)
            {
                return(Result.Fail <Workspace>("Could not get SolutionContext before rewriting: " + solutionContext.Error));
            }

            var rewriteResults =
                Result.CombineAll(
                    rewriters
                    .Select(rewriter =>
            {
                var rewriteResult = Rewrite(modifiedSolution, rewriter);

                //if the rewrite was successful, use the new modified solution in the next rewrite
                if (rewriteResult.IsSuccess)
                {
                    modifiedSolution = rewriteResult.Value;
                }

                return(rewriteResult);
            })
                    );

            if (rewriteResults.IsFailure)
            {
                return(Result.Fail <Workspace>(rewriteResults.Error));
            }
            else
            {
                var appyResult = workspace.TryApplyChanges(modifiedSolution);
                if (!appyResult)
                {
                    return(Result.Fail <Workspace>("Workspace.TryApplyChanges() failed."));
                }
                else
                {
                    return(workspace);
                }
            }
        }
        public void homonym_projects_accross_solutions_are_prefixed_with_Solution_name()
        {
            var ctx = new SolutionContext();
            var s1  = ctx.AddSolution("/S1/Path", "S1");
            var s2  = ctx.AddSolution("/S2/Path", "S2");

            var p1s1 = s1.AddProject("DirP1", "c#", "P1");

            p1s1.Name.Should().Be("P1");

            var p1s2 = s2.AddProject("DirP1", "c#", "P1");

            p1s1.Name.Should().Be("S1|P1");
            p1s2.Name.Should().Be("S2|P1");

            s1.RemoveProject(p1s1);
            p1s2.Name.Should().Be("P1");
        }
Example #25
0
    public Task Run(SolutionContext context)
    {
        var input = context.InputLines
                    .Select(l => l.ToCharArray())
                    .ToArray();

        var oxygenRatings = input;
        var co2Ratings    = input;

        var index = 0;

        while (oxygenRatings.Length > 1)
        {
            oxygenRatings = oxygenRatings
                            .GroupBy(l => l[index])
                            .OrderByDescending(l => l.Count())
                            .ThenBy(l => l.Key == '1' ? 0 : 1)
                            .Take(1)
                            .SelectMany(g => g)
                            .ToArray();
            index += 1;
        }

        index = 0;
        while (co2Ratings.Length > 1)
        {
            co2Ratings = co2Ratings
                         .GroupBy(l => l[index])
                         .OrderBy(l => l.Count())
                         .ThenBy(l => l.Key == '0' ? 0 : 1)
                         .Take(1)
                         .SelectMany(g => g)
                         .ToArray();
            index += 1;
        }

        var oxygenRating = Convert.ToInt32(new string(oxygenRatings[0]), 2);
        var co2Rating    = Convert.ToInt32(new string(co2Ratings[0]), 2);

        Console.WriteLine(oxygenRating * co2Rating);
        return(Task.CompletedTask);
    }
Example #26
0
    public Task Run(SolutionContext context)
    {
        var input = context.InputLines
                    .Select(int.Parse)
                    .ToArray();

        var last      = int.MaxValue;
        var increases = 0;

        foreach (var i in input)
        {
            if (i > last)
            {
                increases += 1;
            }
            last = i;
        }

        Console.WriteLine(increases);
        return(Task.CompletedTask);
    }
Example #27
0
    public Task Run(SolutionContext context)
    {
        var input = context.InputLines
                    .Select(e => e.Trim().TrimStart('+'))
                    .Select(e => Convert.ToInt64(e, 10))
                    .ToList();

        var seen = new HashSet <long>();

        var index     = 0;
        var aggregate = 0L;

        while (seen.Add(aggregate))
        {
            aggregate += input[index];
            index      = (index + 1) % input.Count;
        }

        Console.WriteLine(aggregate);
        return(Task.CompletedTask);
    }
Example #28
0
    public Task Run(SolutionContext context)
    {
        var lines = context.InputLines;

        for (var ai = 0; ai < lines.Length; ai++)
        {
            var a = lines[ai];

            for (var bi = ai + 1; bi < lines.Length; bi++)
            {
                var b = lines[bi];

                var diffs = 0;
                for (var i = 0; i < a.Length; i++)
                {
                    diffs += a[i] == b[i] ? 0 : 1;
                    if (diffs > 1)
                    {
                        continue;
                    }
                }
                if (diffs != 1)
                {
                    continue;
                }

                for (var i = 0; i < a.Length; i++)
                {
                    if (a[i] == b[i])
                    {
                        Console.Write(a[i]);
                    }
                }
                Console.WriteLine();
            }
        }

        Console.WriteLine("No off-by-ones!");
        return(Task.CompletedTask);
    }
Example #29
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Build the entire solution.
        /// </summary>
        /// <param name="guid"></param>
        /// <param name="id"></param>
        /// <param name="customIn"></param>
        /// <param name="customOut"></param>
        /// <param name="fCancelDefault"></param>
        /// ------------------------------------------------------------------------------------
        public void OnBuildSolution(string guid, int id, object customIn, object customOut,
                                    ref bool fCancelDefault)
        {
            if (!m_fAddinEnabled)
            {
                return;
            }

            if (m_nantBuild.IsRunning)
            {
                fCancelDefault = true;
                return;
            }

            try
            {
                fCancelDefault = false;
                bool fRebuild = (id != 882);
                EnvDTE.SolutionConfiguration config =
                    DTE.Solution.SolutionBuild.ActiveConfiguration;

                int      nProjects = DTE.Solution.SolutionBuild.ActiveConfiguration.SolutionContexts.Count;
                string[] projects  = new string[nProjects];
                for (int i = 0; i < nProjects; i++)
                {
                    SolutionContext prj = DTE.Solution.SolutionBuild.ActiveConfiguration.SolutionContexts.Item(i + 1);
                    projects[i] = prj.ProjectName;
                }

                fCancelDefault = m_nantBuild.BuildSolution(Modifiers, fRebuild, DTE.Solution.FullName,
                                                           config.Name, string.Empty, projects);
                ResetFlags();
            }
            catch (Exception e)
            {
                Debug.WriteLine("OnBuildSolution: Got exception: " + e.Message);
            }
        }
Example #30
0
    public Task Run(SolutionContext context)
    {
        var input = context.InputString
                    .Select(c => Convert.ToInt32(c.ToString(), 10))
                    .ToArray();

        var a   = 0;
        var b   = 1;
        var sum = 0;

        while (a < input.Length)
        {
            if (input[a] == input[b % input.Length])
            {
                sum += input[a];
            }
            a += 1;
            b += 1;
        }

        Console.WriteLine(sum);
        return(Task.CompletedTask);
    }
        public void homonym_projects_inside_the_same_solution_are_simplified_when_removed()
        {
            var ctx = new SolutionContext();
            var s   = ctx.AddSolution("/Solution/Path", "SolutionName");

            var pC  = s.AddProject("Dir1", "c#", "Homonym");
            var pJ  = s.AddProject("Dir1", "js", "Homonym");
            var pJa = s.AddProject("AltDir", "js", "Homonym");
            var pCa = s.AddProject("AltDir", "c#", "Homonym");

            pC.Name.Should().Be("(c#)Dir1/Homonym");
            pCa.Name.Should().Be("(c#)AltDir/Homonym");
            pJ.Name.Should().Be("(js)Dir1/Homonym");
            pJa.Name.Should().Be("(js)AltDir/Homonym");

            s.RemoveProject(pC);
            pCa.Name.Should().Be("(c#)Homonym");
            pJ.Name.Should().Be("(js)Dir1/Homonym");
            pJa.Name.Should().Be("(js)AltDir/Homonym");

            s.RemoveProject(pJa);
            pCa.Name.Should().Be("(c#)Homonym");
            pJ.Name.Should().Be("(js)Homonym");
        }
        protected string stProjectConf(SolutionContext context, string data)
        {
            Debug.Assert(context != null);

            Match m = Regex.Match(data, @"\.\s*
                                          ([A-Za-z_0-9]+)            #1 - property
                                          (?:
                                            \s*=\s*(false|true|1|0)  #2 - value (optional)
                                           |
                                            \s*$
                                          )", RegexOptions.IgnorePatternWhitespace);

            if(!m.Success) {
                throw new SyntaxIncorrectException("Failed stProjectConf - '{0}'", data);
            }
            string property = m.Groups[1].Value;
            string value    = (m.Groups[2].Success)? m.Groups[2].Value : null;

            Log.Debug("stProjectConf: property - '{0}', value - '{1}'", property, value);
            switch(property) {
                case "IsBuildable":
                {
                    if(value != null) {
                        context.ShouldBuild = Value.toBoolean(value);
                        return String.Empty;
                    }
                    return Value.from(context.ShouldBuild);
                }
                case "IsDeployable":
                {
                    if(value != null) {
                        context.ShouldDeploy = Value.toBoolean(value);
                        return String.Empty;
                    }
                    return Value.from(context.ShouldDeploy);
                }
            }
            throw new OperationNotFoundException("stProjectConf: not found property - '{0}'", property);
        }
Example #33
0
        protected string projectCfg(SolutionContext context, IPM pm)
        {
            Debug.Assert(context != null);

            if(pm.It(LevelType.Property, "IsBuildable"))
            {
                if(pm.IsRight(LevelType.RightOperandStd)) {
                    context.ShouldBuild = Value.toBoolean(pm.FirstLevel.Data);
                    return Value.Empty;
                }

                if(pm.IsRight(LevelType.RightOperandEmpty)) {
                    return Value.from(context.ShouldBuild);
                }
            }

            if(pm.It(LevelType.Property, "IsDeployable"))
            {
                if(pm.IsRight(LevelType.RightOperandStd)) {
                    context.ShouldDeploy = Value.toBoolean(pm.FirstLevel.Data);
                    return Value.Empty;
                }

                if(pm.IsRight(LevelType.RightOperandEmpty)) {
                    return Value.from(context.ShouldDeploy);
                }
            }

            throw new IncorrectNodeException(pm);
        }