Exemplo n.º 1
0
        MSProjFile ReloadProjectFile(FileSystem fs, IActivityMonitor m, Dictionary <NormalizedPath, MSProjFile> cache)
        {
            _file = MSProjFile.FindOrLoadProjectFile(fs, m, Path, cache);
            if (_file != null)
            {
                XElement f = _file.Document.Root
                             .Elements("PropertyGroup")
                             .Elements()
                             .Where(x => x.Name.LocalName == "TargetFramework" || x.Name.LocalName == "TargetFrameworks")
                             .SingleOrDefault();
                if (f == null)
                {
                    m.Error($"There must be one and only one TargetFramework or TargetFrameworks element in {Path}.");
                    _file = null;
                }
                else
                {
                    TargetFrameworks = Savors.FindOrCreate(f.Value);

                    LangVersion = _file.Document.Root.Elements("PropertyGroup").Elements("LangVersion").LastOrDefault()?.Value;
                    OutputType  = _file.Document.Root.Elements("PropertyGroup").Elements("OutputType").LastOrDefault()?.Value;
                    IsPackable  = (bool?)_file.Document.Root.Elements("PropertyGroup").Elements("IsPackable").LastOrDefault();
                    DoInitializeDependencies(m);
                    if (!_dependencies.IsInitialized)
                    {
                        _file = null;
                    }
                }
            }
            if (_file == null)
            {
                TargetFrameworks = Savors.EmptyTrait;
            }
            return(_file);
        }
Exemplo n.º 2
0
        public void Traits_must_belong_to_the_same_context()
        {
            Action a = () => new CKTraitContext(null);

            a.Should().Throw <ArgumentException>();

            a = () => new CKTraitContext("  ");
            a.Should().Throw <ArgumentException>();

            CKTraitContext c1 = new CKTraitContext("C1");
            CKTraitContext c2 = new CKTraitContext("C2");

            var t1 = c1.FindOrCreate("T1");
            var t2 = c2.FindOrCreate("T2");

            t1.Should().NotBeSameAs(t2);
            t1.Invoking(sut => sut.Union(t2)).Should().Throw <InvalidOperationException>();
            t1.Invoking(sut => sut.Intersect(t2)).Should().Throw <InvalidOperationException>();
            t1.Invoking(sut => sut.Except(t2)).Should().Throw <InvalidOperationException>();
            t1.Invoking(sut => sut.SymmetricExcept(t2)).Should().Throw <InvalidOperationException>();

            t1.Invoking(sut => sut.Overlaps(t2)).Should().Throw <InvalidOperationException>();
            t1.Invoking(sut => sut.IsSupersetOf(t2)).Should().Throw <InvalidOperationException>();

            t1.Invoking(sut => sut.Union(null)).Should().Throw <ArgumentNullException>();
            t1.Invoking(sut => sut.Intersect(null)).Should().Throw <ArgumentNullException>();
            t1.Invoking(sut => sut.Except(null)).Should().Throw <ArgumentNullException>();
            t1.Invoking(sut => sut.SymmetricExcept(null)).Should().Throw <ArgumentNullException>();

            t1.Invoking(sut => sut.Overlaps(null)).Should().Throw <ArgumentNullException>();
            t1.Invoking(sut => sut.IsSupersetOf(null)).Should().Throw <ArgumentNullException>();

            t1.Invoking(sut => sut.CompareTo(null)).Should().Throw <ArgumentNullException>();
            t1.Invoking(sut => sut.CompareTo(null)).Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 3
0
        public void Traits_must_belong_to_the_same_context()
        {
            Assert.Throws <ArgumentException>(() => new CKTraitContext(null));
            Assert.Throws <ArgumentException>(() => new CKTraitContext("  "));

            CKTraitContext c1 = new CKTraitContext("C1");
            CKTraitContext c2 = new CKTraitContext("C2");

            var t1 = c1.FindOrCreate("T1");
            var t2 = c2.FindOrCreate("T2");

            Assert.That(t1 != t2);
            Assert.Throws <InvalidOperationException>(() => t1.Union(t2));
            Assert.Throws <InvalidOperationException>(() => t1.Intersect(t2));
            Assert.Throws <InvalidOperationException>(() => t1.Except(t2));
            Assert.Throws <InvalidOperationException>(() => t1.SymmetricExcept(t2));

            Assert.Throws <InvalidOperationException>(() => t1.Overlaps(t2));
            Assert.Throws <InvalidOperationException>(() => t1.IsSupersetOf(t2));

            Assert.Throws <ArgumentNullException>(() => t1.Union(null));
            Assert.Throws <ArgumentNullException>(() => t1.Intersect(null));
            Assert.Throws <ArgumentNullException>(() => t1.Except(null));
            Assert.Throws <ArgumentNullException>(() => t1.SymmetricExcept(null));

            Assert.Throws <ArgumentNullException>(() => t1.Overlaps(null));
            Assert.Throws <ArgumentNullException>(() => t1.IsSupersetOf(null));

            Assert.Throws <ArgumentNullException>(() => t1.CompareTo(null));
            Assert.Throws <ArgumentNullException>(() => c1.CompareTo(null));
        }
Exemplo n.º 4
0
        public void Traits_must_belong_to_the_same_context()
        {
            Assert.Throws<ArgumentException>( () => new CKTraitContext( null ) );
            Assert.Throws<ArgumentException>( () => new CKTraitContext( "  " ) );

            CKTraitContext c1 = new CKTraitContext( "C1" );
            CKTraitContext c2 = new CKTraitContext( "C2" );

            var t1 = c1.FindOrCreate( "T1" );
            var t2 = c2.FindOrCreate( "T2" );
            Assert.That( t1 != t2 );
            Assert.Throws<InvalidOperationException>( () => t1.Union( t2 ) );
            Assert.Throws<InvalidOperationException>( () => t1.Intersect( t2 ) );
            Assert.Throws<InvalidOperationException>( () => t1.Except( t2 ) );
            Assert.Throws<InvalidOperationException>( () => t1.SymmetricExcept( t2 ) );

            Assert.Throws<InvalidOperationException>( () => t1.Overlaps( t2 ) );
            Assert.Throws<InvalidOperationException>( () => t1.IsSupersetOf( t2 ) );

            Assert.Throws<ArgumentNullException>( () => t1.Union( null ) );
            Assert.Throws<ArgumentNullException>( () => t1.Intersect( null ) );
            Assert.Throws<ArgumentNullException>( () => t1.Except( null ) );
            Assert.Throws<ArgumentNullException>( () => t1.SymmetricExcept( null ) );

            Assert.Throws<ArgumentNullException>( () => t1.Overlaps( null ) );
            Assert.Throws<ArgumentNullException>( () => t1.IsSupersetOf( null ) );

            Assert.Throws<ArgumentNullException>( () => t1.CompareTo( null ) );
            Assert.Throws<ArgumentNullException>( () => c1.CompareTo( null ) );
        }
Exemplo n.º 5
0
        public void Comparing_tags()
        {
            CKTraitContext c1 = CKTraitContext.Create( "C1" );
            CKTraitContext c2 = CKTraitContext.Create( "C2" );

            c1.CompareTo( c1 ).Should().Be( 0 );
            c1.CompareTo( c2 ).Should().BeLessThan( 0 );

            var tAc1 = c1.FindOrCreate( "A" );
            var tBc1 = c1.FindOrCreate( "B" );
            var tABc1 = c1.FindOrCreate( "A|B" );
            var tAc2 = c2.FindOrCreate( "A" );

            tAc1.CompareTo( tAc1 ).Should().Be( 0 );
            tAc1.CompareTo( tBc1 ).Should().BeGreaterThan( 0, "In the same context, A is stronger than B." );
            tABc1.CompareTo( tBc1 ).Should().BeGreaterThan( 0, "In the same context, A|B is stronger than B." );
            tAc1.CompareTo( tAc2 ).Should().BeLessThan( 0, "Between different contexts, the context ordering drives the ordering." );
            tABc1.CompareTo( tAc2 ).Should().BeLessThan( 0, "Between different contexts, the context ordering drives the ordering." );
        }
Exemplo n.º 6
0
        public void Comparing_traits()
        {
            CKTraitContext c1    = new CKTraitContext("C1");
            CKTraitContext c1Bis = new CKTraitContext("C1");
            CKTraitContext c2    = new CKTraitContext("C2");

            Assert.That(c1.CompareTo(c1), Is.EqualTo(0));
            Assert.That(c1.CompareTo(c2), Is.LessThan(0));
            Assert.That(c1Bis.CompareTo(c1), Is.GreaterThan(0));

            var tAc1  = c1.FindOrCreate("A");
            var tBc1  = c1.FindOrCreate("B");
            var tABc1 = c1.FindOrCreate("A|B");
            var tAc2  = c2.FindOrCreate("A");

            Assert.That(tAc1.CompareTo(tAc1), Is.EqualTo(0));
            Assert.That(tAc1.CompareTo(tBc1), Is.GreaterThan(0), "In the same context, A is stronger than B.");
            Assert.That(tABc1.CompareTo(tBc1), Is.GreaterThan(0), "In the same context, A|B is stronger than B.");
            Assert.That(tAc1.CompareTo(tAc2), Is.LessThan(0), "Between different contexts, the context ordering drives the ordering.");
            Assert.That(tABc1.CompareTo(tAc2), Is.LessThan(0), "Between different contexts, the context ordering drives the ordering.");
        }
Exemplo n.º 7
0
        public void Comparing_traits()
        {
            CKTraitContext c1 = new CKTraitContext( "C1" );
            CKTraitContext c1Bis = new CKTraitContext( "C1" );
            CKTraitContext c2 = new CKTraitContext( "C2" );

            Assert.That( c1.CompareTo( c1 ), Is.EqualTo( 0 ) );
            Assert.That( c1.CompareTo( c2 ), Is.LessThan( 0 ) );
            Assert.That( c1Bis.CompareTo( c1 ), Is.GreaterThan( 0 ) );

            var tAc1 = c1.FindOrCreate( "A" );
            var tBc1 = c1.FindOrCreate( "B" );
            var tABc1 = c1.FindOrCreate( "A|B" );
            var tAc2 = c2.FindOrCreate( "A" );

            Assert.That( tAc1.CompareTo( tAc1 ), Is.EqualTo( 0 ) );
            Assert.That( tAc1.CompareTo( tBc1 ), Is.GreaterThan( 0 ), "In the same context, A is stronger than B." );
            Assert.That( tABc1.CompareTo( tBc1 ), Is.GreaterThan( 0 ), "In the same context, A|B is stronger than B." );
            Assert.That( tAc1.CompareTo( tAc2 ), Is.LessThan( 0 ), "Between different contexts, the context ordering drives the ordering." );
            Assert.That( tABc1.CompareTo( tAc2 ), Is.LessThan( 0 ), "Between different contexts, the context ordering drives the ordering." );
        }
Exemplo n.º 8
0
        public void trait_separator_can_be_changed_from_the_default_pipe()
        {
            var     c = new CKTraitContext("SemiColonContext", ';');
            CKTrait m = c.FindOrCreate("Beta;Alpha;Fridge;Combo");

            c.EmptyTrait.IsSupersetOf(c.EmptyTrait).Should().BeTrue("Empty is contained by definition in itself.");
            m.IsSupersetOf(c.EmptyTrait).Should().BeTrue("Empty is contained by definition.");
            m.IsSupersetOf(c.FindOrCreate("Fridge;Alpha")).Should().BeTrue();
            m.IsSupersetOf(c.FindOrCreate("Fridge")).Should().BeTrue();
            m.IsSupersetOf(c.FindOrCreate("Fridge;Alpha;Combo")).Should().BeTrue();
            m.IsSupersetOf(c.FindOrCreate("Fridge;Alpha;Beta;Combo")).Should().BeTrue();
            m.IsSupersetOf(c.FindOrCreate("Fridge;Lol")).Should().BeFalse();
            m.IsSupersetOf(c.FindOrCreate("Murfn")).Should().BeFalse();
            m.IsSupersetOf(c.FindOrCreate("Fridge;Alpha;Combo+Lol")).Should().BeFalse();
            m.IsSupersetOf(c.FindOrCreate("Lol;Fridge;Alpha;Beta;Combo")).Should().BeFalse();

            m.Overlaps(c.FindOrCreate("Fridge;Alpha")).Should().BeTrue();
            m.Overlaps(c.FindOrCreate("Nimp;Fridge;Mourfn")).Should().BeTrue();
            m.Overlaps(c.FindOrCreate("Fridge;Alpha;Combo;Albert")).Should().BeTrue();
            m.Overlaps(c.FindOrCreate("ZZF;AAlp;BBeBe;Combo")).Should().BeTrue();
            m.Overlaps(c.FindOrCreate("AFridge;ALol")).Should().BeFalse();
            m.Overlaps(c.FindOrCreate("Murfn")).Should().BeFalse();
            m.Overlaps(c.FindOrCreate("QF;QA;QC;QL")).Should().BeFalse();
            m.Overlaps(c.EmptyTrait).Should().BeFalse("Empty is NOT contained 'ONE' since EmptyTrait.AtomicTraits.Count == 0...");
            c.EmptyTrait.Overlaps(c.EmptyTrait).Should().BeFalse("Empty is NOT contained 'ONE' in itself.");
        }
Exemplo n.º 9
0
        public void EmptyTrait_is_everywhere()
        {
            CKTrait m = Context.EmptyTrait;

            Assert.That(m.ToString() == String.Empty, "Empty trait is the empty string.");
            Assert.That(m.IsAtomic, "Empty trait is considered as atomic.");
            Assert.That(m.AtomicTraits.Count == 0, "Empty trait has no atomic traits inside.");

            Assert.That(Context.FindOrCreate((string)null) == m, "Null gives the empty trait.");
            Assert.That(Context.FindOrCreate("") == m, "Obtaining empty string gives the empty trait.");
            Assert.That(Context.FindOrCreate("+") == m, "Obtaining '+' gives the empty trait.");
            Assert.Throws <ArgumentException>(() => Context.FindOrCreate(" \t \n  "), "No \n inside.");
            Assert.Throws <ArgumentException>(() => Context.FindOrCreate(" \r "), "No \r inside.");
            Assert.That(Context.FindOrCreate("+ \t +") == m, "Leading and trailing '+' are ignored.");
            Assert.That(Context.FindOrCreate("++++") == m, "Multiple + are ignored");
            Assert.That(Context.FindOrCreate("++  +++  + \t +") == m, "Multiple empty strings leads to empty trait.");

            Assert.That(Context.FindOnlyExisting(null), Is.Null);
            Assert.That(Context.FindOnlyExisting(""), Is.Null);
            Assert.That(Context.FindOnlyExisting(" "), Is.Null);
            Assert.That(Context.FindOnlyExisting(" ++  + "), Is.Null);
            Assert.That(Context.FindOnlyExisting("NONE"), Is.Null);
            Assert.That(Context.FindOnlyExisting("NO+NE"), Is.Null);
            Assert.That(Context.FindOnlyExisting("N+O+N+E"), Is.Null);
        }
Exemplo n.º 10
0
        MSProjFile ReloadProjectFile(FileSystem fs, IActivityMonitor m, Dictionary <NormalizedPath, MSProjFile> cache)
        {
            _primaryFile = MSProjFile.FindOrLoadProjectFile(fs, m, Path, cache);
            if (_primaryFile != null)
            {
                XElement f = _primaryFile.Document.Root
                             .Elements("PropertyGroup")
                             .Elements()
                             .Where(x => x.Name.LocalName == "TargetFramework" || x.Name.LocalName == "TargetFrameworks")
                             .SingleOrDefault();
                if (f == null)
                {
                    m.Error($"There must be one and only one TargetFramework or TargetFrameworks element in {Path}.");
                    _primaryFile = null;
                }
                else
                {
                    TargetFrameworks = Savors.FindOrCreate(f.Value);

                    LangVersion = _primaryFile.Document.Root.Elements("PropertyGroup").Elements("LangVersion").LastOrDefault()?.Value;
                    OutputType  = _primaryFile.Document.Root.Elements("PropertyGroup").Elements("OutputType").LastOrDefault()?.Value;
                    IsPackable  = (bool?)_primaryFile.Document.Root.Elements("PropertyGroup").Elements("IsPackable").LastOrDefault();

                    bool useMicrosoftBuildCentralPackageVersions = _primaryFile.Document.Root.Elements("Sdk")
                                                                   .Attributes("Name")
                                                                   .Any(a => a.Value == "Microsoft.Build.CentralPackageVersions");
                    if (useMicrosoftBuildCentralPackageVersions)
                    {
                        NormalizedPath packageFile;
                        var            definer = _primaryFile.AllFiles.Select(file => file.Document.Root)
                                                 .SelectMany(root => root.Elements("PropertyGroup"))
                                                 .Elements()
                                                 .FirstOrDefault(e => e.Name.LocalName == "CentralPackagesFile");
                        if (definer != null)
                        {
                            m.Info($"Found Property '{definer}' that defines CentralPackagesFile.");
                            var fileDefiner = _primaryFile.AllFiles.Single(file => file.Document == definer.Document);
                            packageFile = definer.Value.Replace("$(MSBuildThisFileDirectory)", fileDefiner.Path.RemoveLastPart() + '/');
                        }
                        else
                        {
                            packageFile = Solution.SolutionFolderPath.AppendPart("Packages.props");
                        }
                        _centralPackagesFile = MSProjFile.FindOrLoadProjectFile(fs, m, packageFile, cache);
                        if (_centralPackagesFile == null)
                        {
                            // Emits an error: reading the missing Version attribute will fail.
                            m.Error($"Failed to read '{packageFile}' central package file.");
                        }
                    }
                    DoInitializeDependencies(m);
                    if (!_dependencies.IsInitialized)
                    {
                        _primaryFile = null;
                    }
                }
            }
            if (_primaryFile == null)
            {
                TargetFrameworks = Savors.EmptyTrait;
            }
            return(_primaryFile);
        }
Exemplo n.º 11
0
 public CKTrait ReadExistingTrait(CKTraitContext ctx) => ctx.FindOrCreate(Reader.ReadSharedString());
Exemplo n.º 12
0
        public void trait_separator_can_be_changed_from_the_default_pipe()
        {
            var c = new CKTraitContext( "SemiColonContext", ';' );
            CKTrait m = c.FindOrCreate( "Beta;Alpha;Fridge;Combo" );

            Assert.That( c.EmptyTrait.IsSupersetOf( c.EmptyTrait ), "Empty is contained by definition in itself." );
            Assert.That( m.IsSupersetOf( c.EmptyTrait ), "Empty is contained by definition." );
            Assert.That( m.IsSupersetOf( c.FindOrCreate( "Fridge;Alpha" ) ) );
            Assert.That( m.IsSupersetOf( c.FindOrCreate( "Fridge" ) ) );
            Assert.That( m.IsSupersetOf( c.FindOrCreate( "Fridge;Alpha;Combo" ) ) );
            Assert.That( m.IsSupersetOf( c.FindOrCreate( "Fridge;Alpha;Beta;Combo" ) ) );
            Assert.That( !m.IsSupersetOf( c.FindOrCreate( "Fridge;Lol" ) ) );
            Assert.That( !m.IsSupersetOf( c.FindOrCreate( "Murfn" ) ) );
            Assert.That( !m.IsSupersetOf( c.FindOrCreate( "Fridge;Alpha;Combo+Lol" ) ) );
            Assert.That( !m.IsSupersetOf( c.FindOrCreate( "Lol;Fridge;Alpha;Beta;Combo" ) ) );

            Assert.That( m.Overlaps( c.FindOrCreate( "Fridge;Alpha" ) ) );
            Assert.That( m.Overlaps( c.FindOrCreate( "Nimp;Fridge;Mourfn" ) ) );
            Assert.That( m.Overlaps( c.FindOrCreate( "Fridge;Alpha;Combo;Albert" ) ) );
            Assert.That( m.Overlaps( c.FindOrCreate( "ZZF;AAlp;BBeBe;Combo" ) ) );
            Assert.That( !m.Overlaps( c.FindOrCreate( "AFridge;ALol" ) ) );
            Assert.That( !m.Overlaps( c.FindOrCreate( "Murfn" ) ) );
            Assert.That( !m.Overlaps( c.FindOrCreate( "QF;QA;QC;QL" ) ) );
            Assert.That( !m.Overlaps( c.EmptyTrait ), "Empty is NOT contained 'ONE' since EmptyTrait.AtomicTraits.Count == 0..." );
            Assert.That( !c.EmptyTrait.Overlaps( c.EmptyTrait ), "Empty is NOT contained 'ONE' in itself." );
        }
Exemplo n.º 13
0
        /// <summary>
        /// Build a <see cref="Func{TResult}"/> from a given <see cref="IExpressionModel"/> array.
        /// </summary>
        /// <param name="this"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException">Will be thrown if an enum cannot be parsed.</exception>
        /// <exception cref="InvalidOperationException">Will be thrown if an invalid field is encountered.</exception>
        public static Func <AlertEntry, bool> Build(this IExpressionModel[] @this)
        {
            Expression expression = null;

            foreach (var alertExpression in @this)
            {
                var member = alertExpression.Field.IndexOf('.') == -1
                    ? Expression.Property(Parameter, alertExpression.Field)
                    : BuildMember(alertExpression.Field);

                ConstantExpression constant;
                EField             field;

                switch (alertExpression.Field)
                {
                case "LogType":
                    if (!Enum.TryParse(alertExpression.Body, out LogEntryType logEntryType) || logEntryType == 0)
                    {
                        throw new ArgumentException($"{nameof( logEntryType )} {alertExpression.Body} is invalid.");
                    }
                    constant = Expression.Constant(logEntryType);
                    field    = EField.Enum;
                    break;

                case "LogLevel":
                    if (!Enum.TryParse(alertExpression.Body, out LogLevel logLevel) || logLevel == 0)
                    {
                        throw new ArgumentException($"{nameof( logLevel )} {alertExpression.Body} is invalid.");
                    }
                    constant = Expression.Constant(logLevel);
                    field    = EField.Enum;
                    break;

                case "GroupDepth":
                case "LineNumber":
                    constant = Expression.Constant(int.Parse(alertExpression.Body));
                    field    = EField.Int;
                    break;

                case "FileName":
                case "AppName":
                case "Text":
                case "Exception.Message":
                case "Exception.StackTrace":
                    constant = Expression.Constant(alertExpression.Body);
                    field    = EField.String;
                    break;

                case "Tags":
                    constant = Expression.Constant(TraitContext.FindOrCreate(alertExpression.Body));
                    field    = EField.Trait;
                    break;

                default:
                    throw new InvalidOperationException
                              ($"{nameof( alertExpression.Field )} {alertExpression.Field} is invalid.");
                }

                var operation = ParseOperation(alertExpression.Operation);
                if (!AllowedOperations[(int)field].HasFlag(operation))
                {
                    throw new InvalidOperationException
                              ($"{nameof( alertExpression.Operation )} {alertExpression.Operation} is invalid for field {alertExpression.Field}.");
                }

                var innerExpression = field != EField.String
                    ? Expressions[operation].Invoke(member, constant)
                    : Expressions[operation].Invoke(Expression.Coalesce(member, Expression.Constant(string.Empty)), constant);

                expression = expression == null
                   ? innerExpression
                   : Expression.And(expression, innerExpression);
            }

            return(Expression.Lambda <Func <AlertEntry, bool> >(expression, Parameter).Compile());
        }