Example #1
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);
        }
Example #2
0
        public void EmptyTrait_is_everywhere()
        {
            var     c = ContextWithPlusSeparator();
            CKTrait m = c.EmptyTrait;

            m.ToString().Should().BeSameAs(string.Empty, "Empty trait is the empty string.");
            m.IsAtomic.Should().BeTrue("Empty trait is considered as atomic.");
            m.AtomicTraits.Should().BeEmpty("Empty trait has no atomic traits inside.");

            c.FindOrCreate(null).Should().BeSameAs(m, "Null gives the empty trait.");
            c.FindOrCreate("").Should().BeSameAs(m, "Obtaining empty string gives the empty trait.");
            c.FindOrCreate("+").Should().BeSameAs(m, "Obtaining '+' gives the empty trait.");
            c.Invoking(sut => sut.FindOrCreate(" \t \n  ")).Should().Throw <ArgumentException>("No \n inside.");
            c.Invoking(sut => sut.FindOrCreate(" \r ")).Should().Throw <ArgumentException>("No \r inside.");
            c.FindOrCreate("+ \t +").Should().BeSameAs(m, "Leading and trailing '+' are ignored.");
            c.FindOrCreate("++++").Should().BeSameAs(m, "Multiple + are ignored");
            c.FindOrCreate("++  +++  + \t +").Should().BeSameAs(m, "Multiple empty strings leads to empty trait.");

            c.FindOnlyExisting(null).Should().BeNull();
            c.FindOnlyExisting("").Should().BeNull();
            c.FindOnlyExisting(" ").Should().BeNull();
            c.FindOnlyExisting(" ++  + ").Should().BeNull();
            c.FindOnlyExisting("NONE").Should().BeNull();
            c.FindOnlyExisting("NO+NE").Should().BeNull();
            c.FindOnlyExisting("N+O+N+E").Should().BeNull();
        }
Example #3
0
 public void OnEnterLevel( CKTrait trait, LogLevel level, string text, DateTime time )
 {
     time = time.ToLocalTime();
     if ( LoggerContent.Count >= 200 )
     {
         LoggerContent.RemoveAt( LoggerContent.IndexOf( LoggerContent.First() ) );
     }
     LoggerContent.Add( time.ToString( "H:mm:ss" ) + " [" + level.ToString() + " : "+ trait.ToString() +"] " + text );
 }
Example #4
0
 public void Write(CKTrait t)
 {
     if (TraitPool.MustWrite(t))
     {
         if (TraitContextPool.MustWrite(t.Context))
         {
             t.Context.Write(Writer);
         }
         Writer.WriteSharedString(t.ToString());
     }
 }
Example #5
0
        static void DoWriteLog(CKBinaryWriter w, StreamLogType t, LogLevel level, DateTimeStamp logTime, string text, CKTrait tags, CKExceptionData ex, string fileName, int lineNumber)
        {
            if (tags != null && !tags.IsEmpty)
            {
                t |= StreamLogType.HasTags;
            }
            if (ex != null)
            {
                t |= StreamLogType.HasException;
                if (text == ex.Message)
                {
                    t |= StreamLogType.IsTextTheExceptionMessage;
                }
            }
            if (fileName != null)
            {
                t |= StreamLogType.HasFileName;
            }
            if (logTime.Uniquifier != 0)
            {
                t |= StreamLogType.HasUniquifier;
            }

            WriteLogTypeAndLevel(w, t, level);
            w.Write(logTime.TimeUtc.ToBinary());
            if (logTime.Uniquifier != 0)
            {
                w.Write(logTime.Uniquifier);
            }
            if ((t & StreamLogType.HasTags) != 0)
            {
                w.Write(tags.ToString());
            }
            if ((t & StreamLogType.HasFileName) != 0)
            {
                w.Write(fileName);
                w.WriteNonNegativeSmallInt32(lineNumber);
            }
            if ((t & StreamLogType.HasException) != 0)
            {
                ex.Write(w);
            }
            if ((t & StreamLogType.IsTextTheExceptionMessage) == 0)
            {
                w.Write(text);
            }
        }
Example #6
0
 public void WriteExistingTrait(CKTrait t) => Writer.WriteSharedString(t.ToString());
Example #7
0
        /// <summary>
        /// Sets the TargetFramework(s) element in the project file.
        /// The dependencies are analysed and new <see cref="Dependencies.UselessDependencies"/> may appear.
        /// </summary>
        /// <param name="m">The activity monitor to use.</param>
        /// <param name="frameworks">The framework(s) to set.</param>
        /// <returns>True if the change has been made. False if the frameworks are the same as the current one.</returns>
        public bool SetTargetFrameworks(IActivityMonitor m, CKTrait frameworks)
        {
            if (frameworks?.IsEmpty ?? true)
            {
                throw new ArgumentException("Must not be null or empty.", nameof(frameworks));
            }
            if (frameworks.Context != Savors)
            {
                throw new ArgumentException("Must be from MSProject.Traits context.", nameof(frameworks));
            }
            if (_file == null)
            {
                throw new InvalidOperationException("Invalid project file.");
            }
            if (TargetFrameworks == frameworks)
            {
                return(false);
            }
            XElement f = _file.Document.Root
                         .Elements("PropertyGroup")
                         .Elements()
                         .Where(x => x.Name.LocalName == "TargetFramework" || x.Name.LocalName == "TargetFrameworks")
                         .SingleOrDefault();

            f.ReplaceWith(new XElement(frameworks.IsAtomic ? "TargetFramework" : "TargetFrameworks", frameworks.ToString()));
            m.Trace($"Replacing TargetFrameworks='{TargetFrameworks}' with '{frameworks}' in {ToString()}.");
            TargetFrameworks = frameworks;
            OnChange(m);
            return(true);
        }
 static StringBuilder CreateHeader( DateTimeStamp logTime, string text, LogLevel level, CKTrait tags )
 {
     StringBuilder buffer = new StringBuilder();
     buffer.Append( '<' ).Append( level.ToString() ).Append( '>' ).Append( '@' ).Append( logTime.ToString() );
     if( tags != null && !tags.IsEmpty ) buffer.Append( " - " ).Append( tags.ToString() );
     buffer.AppendLine();
     if( text != null && text.Length > 0 ) buffer.Append( text ).AppendLine();
     return buffer;
 }
Example #9
0
        static void DoWriteLog( CKBinaryWriter w, StreamLogType t, LogLevel level, DateTimeStamp logTime, string text, CKTrait tags, CKExceptionData ex, string fileName, int lineNumber )
        {
            if( tags != null && !tags.IsEmpty ) t |= StreamLogType.HasTags;
            if( ex != null )
            {
                t |= StreamLogType.HasException;
                if( text == ex.Message ) t |= StreamLogType.IsTextTheExceptionMessage;
            }
            if( fileName != null ) t |= StreamLogType.HasFileName;
            if( logTime.Uniquifier != 0 ) t |= StreamLogType.HasUniquifier;

            WriteLogTypeAndLevel( w, t, level );
            w.Write( logTime.TimeUtc.ToBinary() );
            if( logTime.Uniquifier != 0 ) w.Write( logTime.Uniquifier );
            if( (t & StreamLogType.HasTags) != 0 ) w.Write( tags.ToString() );
            if( (t & StreamLogType.HasFileName) != 0 )
            {
                w.Write( fileName );
                w.WriteNonNegativeSmallInt32( lineNumber );
            }
            if( (t & StreamLogType.HasException) != 0 ) ex.Write( w );
            if( (t & StreamLogType.IsTextTheExceptionMessage) == 0 ) w.Write( text );
        }