public void Contains_is_IsSupersetOf() { var c = ContextWithPlusSeparator(); 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."); }
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); }
internal ProjectToProjectDependency(Project o, Project target, CKTrait frameworks, XElement e) { Owner = o; TargetProject = target; Frameworks = frameworks; Element = e; }
public void Contains_is_IsSupersetOf() { CKTrait m = Context.FindOrCreate("Beta+Alpha+Fridge+Combo"); Assert.That(Context.EmptyTrait.IsSupersetOf(Context.EmptyTrait), "Empty is contained by definition in itself."); Assert.That(m.IsSupersetOf(Context.EmptyTrait), "Empty is contained by definition."); Assert.That(m.IsSupersetOf(Context.FindOrCreate("Fridge+Alpha"))); Assert.That(m.IsSupersetOf(Context.FindOrCreate("Fridge"))); Assert.That(m.IsSupersetOf(Context.FindOrCreate("Fridge+Alpha+Combo"))); Assert.That(m.IsSupersetOf(Context.FindOrCreate("Fridge+Alpha+Beta+Combo"))); Assert.That(!m.IsSupersetOf(Context.FindOrCreate("Fridge+Lol"))); Assert.That(!m.IsSupersetOf(Context.FindOrCreate("Murfn"))); Assert.That(!m.IsSupersetOf(Context.FindOrCreate("Fridge+Alpha+Combo+Lol"))); Assert.That(!m.IsSupersetOf(Context.FindOrCreate("Lol+Fridge+Alpha+Beta+Combo"))); Assert.That(m.Overlaps(Context.FindOrCreate("Fridge+Alpha"))); Assert.That(m.Overlaps(Context.FindOrCreate("Nimp+Fridge+Mourfn"))); Assert.That(m.Overlaps(Context.FindOrCreate("Fridge+Alpha+Combo+Albert"))); Assert.That(m.Overlaps(Context.FindOrCreate("ZZF+AAlp+BBeBe+Combo"))); Assert.That(!m.Overlaps(Context.FindOrCreate("AFridge+ALol"))); Assert.That(!m.Overlaps(Context.FindOrCreate("Murfn"))); Assert.That(!m.Overlaps(Context.FindOrCreate("QF+QA+QC+QL"))); Assert.That(!m.Overlaps(Context.EmptyTrait), "Empty is NOT contained 'ONE' since EmptyTrait.AtomicTraits.Count == 0..."); Assert.That(!Context.EmptyTrait.Overlaps(Context.EmptyTrait), "Empty is NOT contained 'ONE' in itself."); }
static ILogEntry ReadGroupClosed(int streamVersion, CKBinaryReader r, StreamLogType t, LogLevel logLevel) { DateTimeStamp time = new DateTimeStamp(DateTime.FromBinary(r.ReadInt64()), (t & StreamLogType.HasUniquifier) != 0 ? r.ReadByte() : (Byte)0); ActivityLogGroupConclusion[] conclusions = Util.Array.Empty <ActivityLogGroupConclusion>(); if ((t & StreamLogType.HasConclusions) != 0) { int conclusionsCount = streamVersion < 6 ? r.ReadInt32() : r.ReadNonNegativeSmallInt32(); conclusions = new ActivityLogGroupConclusion[conclusionsCount]; for (int i = 0; i < conclusionsCount; i++) { CKTrait cTags = ActivityMonitor.Tags.Register(r.ReadString()); string cText = r.ReadString(); conclusions[i] = new ActivityLogGroupConclusion(cText, cTags); } } if ((t & StreamLogType.IsMultiCast) == 0) { return(new LECloseGroup(time, logLevel, conclusions)); } Guid mId; int depth; LogEntryType prevType; DateTimeStamp prevTime; ReadMulticastFooter(streamVersion, r, t, out mId, out depth, out prevType, out prevTime); return(new LEMCCloseGroup(mId, depth, prevTime, prevType, time, logLevel, conclusions)); }
public void test_Fallbacks_generation() { { CKTrait m = Context.FindOrCreate(""); IReadOnlyList <CKTrait> f = m.Fallbacks.ToArray(); Assert.That(m.FallbacksCount, Is.EqualTo(f.Count)); Assert.That(f.Count == 1); Assert.That(f[0].ToString() == ""); } { CKTrait m = Context.FindOrCreate("Alpha"); IReadOnlyList <CKTrait> f = m.Fallbacks.ToArray(); Assert.That(m.FallbacksCount, Is.EqualTo(f.Count)); Assert.That(f.Count == 1); Assert.That(f[0].ToString() == ""); } { CKTrait m = Context.FindOrCreate("Alpha+Beta"); IReadOnlyList <CKTrait> f = m.Fallbacks.ToArray(); Assert.That(m.FallbacksCount, Is.EqualTo(f.Count)); Assert.That(f.Count == 3); Assert.That(f[0].ToString() == "Alpha"); Assert.That(f[1].ToString() == "Beta"); Assert.That(f[2].ToString() == ""); } { CKTrait m = Context.FindOrCreate("Alpha+Beta+Combo"); IReadOnlyList <CKTrait> f = m.Fallbacks.ToArray(); Assert.That(m.FallbacksCount, Is.EqualTo(f.Count)); Assert.That(f.Count == 7); Assert.That(f[0].ToString() == "Alpha+Beta"); Assert.That(f[1].ToString() == "Alpha+Combo"); Assert.That(f[2].ToString() == "Beta+Combo"); Assert.That(f[3].ToString() == "Alpha"); Assert.That(f[4].ToString() == "Beta"); Assert.That(f[5].ToString() == "Combo"); Assert.That(f[6].ToString() == ""); } { CKTrait m = Context.FindOrCreate("Alpha+Beta+Combo+Fridge"); IReadOnlyList <CKTrait> f = m.Fallbacks.ToArray(); Assert.That(m.FallbacksCount, Is.EqualTo(f.Count)); Assert.That(f.Count == 15); Assert.That(f[0].ToString() == "Alpha+Beta+Combo"); Assert.That(f[1].ToString() == "Alpha+Beta+Fridge"); Assert.That(f[2].ToString() == "Alpha+Combo+Fridge"); Assert.That(f[3].ToString() == "Beta+Combo+Fridge"); Assert.That(f[4].ToString() == "Alpha+Beta"); Assert.That(f[5].ToString() == "Alpha+Combo"); Assert.That(f[6].ToString() == "Alpha+Fridge"); Assert.That(f[7].ToString() == "Beta+Combo"); Assert.That(f[8].ToString() == "Beta+Fridge"); Assert.That(f[9].ToString() == "Combo+Fridge"); Assert.That(f[10].ToString() == "Alpha"); Assert.That(f[11].ToString() == "Beta"); Assert.That(f[12].ToString() == "Combo"); Assert.That(f[13].ToString() == "Fridge"); Assert.That(f[14].ToString() == ""); } }
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(); }
/// <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); }
public void test_Combined_traits_parsing() { var c = ContextWithPlusSeparator(); CKTrait m = c.FindOrCreate("Beta+Alpha"); m.IsAtomic.Should().BeFalse(); m.AtomicTraits.Should().HaveCount(2, "Combined trait."); m.AtomicTraits[0].Should().BeSameAs(c.FindOrCreate("Alpha"), "Atomic Alpha is the first one."); m.AtomicTraits[1].Should().BeSameAs(c.FindOrCreate("Beta"), "Atomic Beta is the second one."); c.FindOrCreate("Alpha+Beta").Should().BeSameAs(m, "Canonical order is ensured."); c.FindOrCreate("+ +\t++ Alpha+++Beta++").Should().BeSameAs(m, "Extra characters and empty traits are ignored."); c.FindOrCreate("Alpha+Beta+Alpha").Should().BeSameAs(m, "Multiple identical traits are removed."); c.FindOrCreate("Alpha+ +Beta\t ++Beta+ + Alpha + Beta ++ ").Should().BeSameAs(m, "Multiple identical traits are removed."); CKTrait m2 = c.FindOrCreate("Beta+Alpha+Zeta+Tau+Pi+Omega+Epsilon"); c.FindOrCreate("++Beta+Zeta+Omega+Epsilon+Alpha+Zeta+Epsilon+Zeta+Tau+Epsilon+Pi+Tau+Beta+Zeta+Omega+Beta+Pi+Alpha").Should().BeSameAs(m2, "Unicity of Atomic trait is ensured."); c.FindOnlyExisting("Beta").ToString().Should().Be("Beta"); c.FindOnlyExisting("Beta+Gamma").ToString().Should().Be("Beta"); c.FindOnlyExisting("Beta+Gamma+Nimp+Alpha+Other").Should().BeSameAs(m); c.FindOnlyExisting("Beta+Gamma+Nimp+Alpha+Other+Tau+Pi").ToString().Should().Be("Alpha+Beta+Pi+Tau"); }
internal ActivityLogGroupConclusion( CKTrait t, string conclusion ) { Debug.Assert( t != null && t.Context == ActivityMonitor.Tags.Context ); Debug.Assert( conclusion != null ); Tag = t; Text = conclusion; }
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."); }
public void test_Union_of_traits() { CKTrait m1 = Context.FindOrCreate("Beta+Alpha+Fridge+Combo"); CKTrait m2 = Context.FindOrCreate("Xtra+Combo+Another+Fridge+Alt"); Assert.That(m1.Union(m2).ToString() == "Alpha+Alt+Another+Beta+Combo+Fridge+Xtra", "Works as expected :-)"); Assert.That(m2.Union(m1) == m1.Union(m2), "Same in both calls."); }
public LEMCLog( Guid monitorId, int depth, DateTimeStamp previousLogTime, LogEntryType previousEntryType, string text, DateTimeStamp t, string fileName, int lineNumber, LogLevel l, CKTrait tags, CKExceptionData ex ) : base( text, t, fileName, lineNumber, l, tags, ex ) { _monitorId = monitorId; _depth = depth; _previousEntryType = previousEntryType; _previousLogTime = previousLogTime; }
public Entry(ActivityMonitorLogData d) { Level = d.Level; Tags = d.Tags; Text = d.Text; Exception = d.Exception; LogTime = d.LogTime; }
public Entry(IActivityLogGroup d) { Level = d.GroupLevel; Tags = d.GroupTags; Text = d.GroupText; Exception = d.Exception; LogTime = d.LogTime; }
public Entry( ActivityMonitorLogData d ) { Level = d.Level; Tags = d.Tags; Text = d.Text; Exception = d.Exception; LogTime = d.LogTime; }
public Entry( IActivityLogGroup d ) { Level = d.GroupLevel; Tags = d.GroupTags; Text = d.GroupText; Exception = d.Exception; LogTime = d.LogTime; }
/// <summary> /// Initializes a new conclusion for a group. /// </summary> /// <param name="conclusion">Must not be null (may be empty).</param> /// <param name="tag">Must be null or be registered in <see cref="ActivityMonitor.Tags"/>.</param> public ActivityLogGroupConclusion( string conclusion, CKTrait tag = null ) { if( conclusion == null ) throw new ArgumentNullException( "conclusion" ); if( tag == null ) tag = ActivityMonitor.Tags.Empty; else if( tag.Context != ActivityMonitor.Tags.Context ) throw new ArgumentException( Impl.ActivityMonitorResources.ActivityMonitorTagMustBeRegistered, "tag" ); Tag = tag; Text = conclusion; }
public async Task TagFilters_works_Async() { CKTrait Sql = ActivityMonitor.Tags.Register("Sql"); CKTrait Machine = ActivityMonitor.Tags.Register("Machine"); DemoSinkHandler.Reset(); var config = new DynamicConfigurationSource(); config["CK-Monitoring:GrandOutput:Handlers:CK.Monitoring.Hosting.Tests.DemoSinkHandler, CK.Monitoring.Hosting.Tests"] = "true"; config["CK-Monitoring:GrandOutput:MinimalFilter"] = "Trace"; config["CK-Monitoring:TagFilters:0:0"] = "Sql"; config["CK-Monitoring:TagFilters:0:1"] = "Debug"; config["CK-Monitoring:TagFilters:1:0"] = "Machine"; config["CK-Monitoring:TagFilters:1:1"] = "Release!"; var host = new HostBuilder() .ConfigureAppConfiguration((hostingContext, c) => c.Add(config)) .UseCKMonitoring() .Build(); await host.StartAsync(); var m = new ActivityMonitor(); RunWithTagFilters(Sql, Machine, m); // Removing the TagFilters totally should keep the current filters. using (config.StartBatch()) { config.Remove("CK-Monitoring:TagFilters:0:0"); config.Remove("CK-Monitoring:TagFilters:0:1"); config.Remove("CK-Monitoring:TagFilters:1:0"); config.Remove("CK-Monitoring:TagFilters:1:1"); } await Task.Delay(200); RunWithTagFilters(Sql, Machine, m); config["CK-Monitoring:TagFilters:0"] = ""; await Task.Delay(200); m.Debug(Sql, "NOP! This is in Debug!"); m.Trace(Machine, "SHOW!"); m.Trace(Machine | Sql, "Yes again!"); m.Trace("DONE!"); await Task.Delay(200); var texts = DemoSinkHandler.LogEvents.OrderBy(e => e.LogTime).Select(e => e.Text).Concatenate(System.Environment.NewLine); texts.Should() .Contain("SHOW!") .And.Contain("Yes again!") .And.NotContain("NOP! This is in Debug!") .And.Contain("DONE!"); await host.StopAsync();
/// <summary> /// Initializes a new <see cref="ActivityMonitorTextWriterClient"/> bound to a /// function that must write a string, with a filter. /// </summary> /// <param name="writer">Function that writes the content.</param> /// <param name="filter">Filter to apply</param> public ActivityMonitorTextWriterClient( Action<string> writer, LogFilter filter ) : base( filter ) { if( writer == null ) throw new ArgumentNullException( "writer" ); _writer = writer; _buffer = new StringBuilder(); _prefixLevel = _prefix = String.Empty; _currentTags = ActivityMonitor.Tags.Empty; }
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 ); }
public void test_Union_of_traits() { var c = ContextWithPlusSeparator(); CKTrait m1 = c.FindOrCreate("Beta+Alpha+Fridge+Combo"); CKTrait m2 = c.FindOrCreate("Xtra+Combo+Another+Fridge+Alt"); m1.Union(m2).ToString().Should().Be("Alpha+Alt+Another+Beta+Combo+Fridge+Xtra", "Works as expected :-)"); m2.Union(m1).Should().BeSameAs(m1.Union(m2), "Same in both calls."); }
internal Entry( CKTrait tags, LogLevel level, string text, DateTimeStamp logTime, Exception ex ) { Debug.Assert( (level & LogLevel.IsFiltered) == 0 ); Tags = tags; MaskedLevel = level; LogTime = logTime; Text = text; Exception = ex; }
public LEOpenGroup(LEMCOpenGroup e) { _text = e.Text; _time = e.LogTime; _fileName = e.FileName; _lineNumber = e.LineNumber; _level = e.LogLevel; _tags = e.Tags; _ex = e.Exception; }
public void test_Except_of_traits() { CKTrait m1 = Context.FindOrCreate("Beta+Alpha+Fridge+Combo"); CKTrait m2 = Context.FindOrCreate("Xtra+Combo+Another+Fridge+Alt"); Assert.That(m1.Except(m2).ToString() == "Alpha+Beta", "Works as expected :-)"); Assert.That(m2.Except(m1).ToString() == "Alt+Another+Xtra", "Works as expected..."); Assert.That(m2.Except(Context.EmptyTrait) == m2 && m1.Except(Context.EmptyTrait) == m1, "Removing empty does nothing."); }
public void test_Intersect_between_traits() { CKTrait m1 = Context.FindOrCreate("Beta+Alpha+Fridge+Combo"); CKTrait m2 = Context.FindOrCreate("Xtra+Combo+Another+Fridge+Alt"); Assert.That(m1.Intersect(m2).ToString() == "Combo+Fridge", "Works as expected :-)"); Assert.That(m2.Intersect(m1) == m1.Intersect(m2), "Same object in both calls."); Assert.That(m2.Intersect(Context.EmptyTrait) == Context.EmptyTrait, "Intersecting empty gives empty."); }
public LEOpenGroup(string text, DateTimeStamp t, string?fileName, int lineNumber, LogLevel l, CKTrait tags, CKExceptionData?ex) { _text = text; _time = t; _fileName = fileName; _lineNumber = lineNumber; _level = l; _tags = tags; _ex = ex; }
public LEOpenGroup( LEMCOpenGroup e ) { _text = e.Text; _time = e.LogTime; _fileName = e.FileName; _lineNumber = e.LineNumber; _level = e.LogLevel; _tags = e.Tags; _ex = e.Exception; }
public LEOpenGroup( string text, DateTimeStamp t, string fileName, int lineNumber, LogLevel l, CKTrait tags, CKExceptionData ex ) { _text = text; _time = t; _fileName = fileName; _lineNumber = lineNumber; _level = l; _tags = tags; _ex = ex; }
public void test_FindIfAllExist() { CKTrait m = Context.FindOrCreate("Alpha+Beta+Combo+Fridge"); Assert.That(Context.FindIfAllExist(""), Is.EqualTo(Context.EmptyTrait)); Assert.That(Context.FindIfAllExist("bo"), Is.Null); Assert.That(Context.FindIfAllExist("Alpha"), Is.EqualTo(Context.FindOrCreate("Alpha"))); Assert.That(Context.FindIfAllExist("bo+pha"), Is.Null); Assert.That(Context.FindIfAllExist("Fridge+Combo+Alpha+Beta"), Is.SameAs(m)); }
public void Write(CKTrait t) { if (TraitPool.MustWrite(t)) { if (TraitContextPool.MustWrite(t.Context)) { t.Context.Write(Writer); } Writer.WriteSharedString(t.ToString()); } }
public LELog(LEMCLog e) { Debug.Assert(e.Text != null); _text = e.Text; _time = e.LogTime; _fileName = e.FileName; _lineNumber = e.LineNumber; _level = e.LogLevel; _tags = e.Tags; _ex = e.Exception; }
internal PackageReference(IProject o, ArtifactInstance t, ArtifactDependencyKind kind, CKTrait applicableSavors) { Debug.Assert(o.Savors == null && applicableSavors == null || (o.Savors.Context == applicableSavors.Context && !applicableSavors.IsEmpty && o.Savors.IsSupersetOf(applicableSavors))); Owner = o; Target = t; Kind = kind; ApplicableSavors = applicableSavors; }
public void test_Except_of_traits() { var c = ContextWithPlusSeparator(); CKTrait m1 = c.FindOrCreate("Beta+Alpha+Fridge+Combo"); CKTrait m2 = c.FindOrCreate("Xtra+Combo+Another+Fridge+Alt"); m1.Except(m2).ToString().Should().Be("Alpha+Beta", "Works as expected :-)"); m2.Except(m1).ToString().Should().Be("Alt+Another+Xtra", "Works as expected..."); m2.Except(c.EmptyTrait).Should().BeSameAs(m2, "Removing empty does nothing."); m1.Except(c.EmptyTrait).Should().BeSameAs(m1, "Removing empty does nothing."); }
public void test_FindIfAllExist() { var c = ContextWithPlusSeparator(); CKTrait m = c.FindOrCreate("Alpha+Beta+Combo+Fridge"); c.FindIfAllExist("").Should().Be(c.EmptyTrait); c.FindIfAllExist("bo").Should().BeNull(); c.FindIfAllExist("Alpha").Should().Be(c.FindOrCreate("Alpha")); c.FindIfAllExist("bo+pha").Should().BeNull(); c.FindIfAllExist("Fridge+Combo+Alpha+Beta").Should().BeSameAs(m); }
public void test_Intersect_between_traits() { var c = ContextWithPlusSeparator(); CKTrait m1 = c.FindOrCreate("Beta+Alpha+Fridge+Combo"); CKTrait m2 = c.FindOrCreate("Xtra+Combo+Another+Fridge+Alt"); m1.Intersect(m2).ToString().Should().Be("Combo+Fridge", "Works as expected :-)"); m2.Intersect(m1).Should().BeSameAs(m1.Intersect(m2), "Same object in both calls."); m2.Intersect(c.EmptyTrait).Should().BeSameAs(c.EmptyTrait, "Intersecting empty gives empty."); }
public void binary_operators_work() { var ctx = CKTraitContext.Create( "Indep", ',', shared: false ); var a = ctx.FindOrCreate( "A" ); var b = ctx.FindOrCreate( "B" ); var c = ctx.FindOrCreate( "C" ); var d = ctx.FindOrCreate( "D" ); var ab = ctx.FindOrCreate( "A,B" ); var cd = ctx.FindOrCreate( "C,D" ); var abc = ctx.FindOrCreate( "A,B,C" ); var abcd = ctx.FindOrCreate( "A,B,C,D" ); (ab + cd).Should() .BeSameAs( abcd ) .And.BeSameAs( c + d + b + a ) .And.BeSameAs( cd + ab ) .And.BeSameAs( abc | d ) .And.BeSameAs( a | b | c | d ); (ab & cd).Should().BeSameAs( ctx.EmptyTrait ); (abc & cd).Should().BeSameAs( c ); (abcd & cd).Should().BeSameAs( cd ); (ab ^ cd).Should().BeSameAs( abcd ); (abc ^ cd).Should().BeSameAs( a | b | d ); ((a|b|d) ^ cd).Should().BeSameAs( abc ); (abcd ^ cd).Should().BeSameAs( ab ); CKTrait v = a; v += b; v.Should().BeSameAs( ab ); v += d; v.Should().BeSameAs( a | b | d ); v -= c; v.Should().BeSameAs( a | b | d ); v -= abcd; v.IsEmpty.Should().BeTrue(); v |= abcd; v &= cd; v.Should().BeSameAs( cd ); v &= d; v.Should().BeSameAs( d ); v |= abcd; v.Should().BeSameAs( abcd ); v ^= b; v.Should().BeSameAs( a | cd ); v ^= ab; v.Should().BeSameAs( b | cd ); v &= ctx.EmptyTrait; v.IsEmpty.Should().BeTrue(); }
public void FindIfAllExist_tests() { var c = CKTraitContext.Create( "Indep", '+', shared: false ); CKTrait m = c.FindOrCreate( "Alpha+Beta+Combo+Fridge" ); c.FindIfAllExist( "" ).Should().Be( c.EmptyTrait ); c.FindIfAllExist( "bo" ).Should().BeNull(); var alpha = c.FindOrCreate( "Alpha" ); c.FindIfAllExist( "Alpha" ).Should().Be( alpha ); c.FindIfAllExist( "bo+pha" ).Should().BeNull(); c.FindIfAllExist( "Fridge+Combo+Alpha+Beta" ).Should().BeSameAs( m ); }
public void Toggle_is_SymmetricExcept() { var c = ContextWithPlusSeparator(); CKTrait m = c.FindOrCreate( "Beta+Alpha+Fridge+Combo" ); m.SymmetricExcept( c.FindOrCreate( "Beta" ) ).ToString().Should().Be( "Alpha+Combo+Fridge" ); m.SymmetricExcept( c.FindOrCreate( "Fridge+Combo" ) ).ToString().Should().Be( "Alpha+Beta" ); m.SymmetricExcept( c.FindOrCreate( "Beta+Fridge+Combo" ) ).ToString().Should().Be( "Alpha" ); m.SymmetricExcept( c.FindOrCreate( "Beta+Fridge+Combo+Alpha" ) ).ToString().Should().Be( "" ); m.SymmetricExcept( c.FindOrCreate( "" ) ).ToString().Should().Be( "Alpha+Beta+Combo+Fridge" ); m.SymmetricExcept( c.FindOrCreate( "Xtra" ) ).ToString().Should().Be( "Alpha+Beta+Combo+Fridge+Xtra" ); m.SymmetricExcept( c.FindOrCreate( "Alpha+Xtra" ) ).ToString().Should().Be( "Beta+Combo+Fridge+Xtra" ); m.SymmetricExcept( c.FindOrCreate( "Zenon+Alpha+Xtra+Fridge" ) ).ToString().Should().Be( "Beta+Combo+Xtra+Zenon" ); }
public void Toggle_is_SymmetricExcept() { CKTrait m = Context.FindOrCreate("Beta+Alpha+Fridge+Combo"); Assert.That(m.SymmetricExcept(Context.FindOrCreate("Beta")).ToString() == "Alpha+Combo+Fridge"); Assert.That(m.SymmetricExcept(Context.FindOrCreate("Fridge+Combo")).ToString() == "Alpha+Beta"); Assert.That(m.SymmetricExcept(Context.FindOrCreate("Beta+Fridge+Combo")).ToString() == "Alpha"); Assert.That(m.SymmetricExcept(Context.FindOrCreate("Beta+Fridge+Combo+Alpha")).ToString() == ""); Assert.That(m.SymmetricExcept(Context.FindOrCreate("")).ToString() == "Alpha+Beta+Combo+Fridge"); Assert.That(m.SymmetricExcept(Context.FindOrCreate("Xtra")).ToString() == "Alpha+Beta+Combo+Fridge+Xtra"); Assert.That(m.SymmetricExcept(Context.FindOrCreate("Alpha+Xtra")).ToString() == "Beta+Combo+Fridge+Xtra"); Assert.That(m.SymmetricExcept(Context.FindOrCreate("Zenon+Alpha+Xtra+Fridge")).ToString() == "Beta+Combo+Xtra+Zenon"); }
/// <summary> /// Writes all the information. /// </summary> /// <param name="data">Log data.</param> protected override void OnEnterLevel( ActivityMonitorLogData data ) { var w = _buffer.Clear(); _prefixLevel = _prefix + new string( ' ', data.MaskedLevel.ToString().Length + 4 ); w.Append( _prefix ) .Append( "- " ) .Append( data.MaskedLevel.ToString() ) .Append( ": " ) .AppendMultiLine( _prefixLevel, data.Text, false ); if( _currentTags != data.Tags ) { w.Append( " -[" ).Append( data.Tags ).Append( ']' ); _currentTags = data.Tags; } w.AppendLine(); if( data.Exception != null ) { DumpException( w, _prefix, !data.IsTextTheExceptionMessage, data.Exception ); } _writer( w.ToString() ); }
void IActivityMonitorClient.OnAutoTagsChanged( CKTrait newTrait ) { // Does nothing. }
internal void SetAutoTags( CKTrait tags ) { _monitor.AutoTags = tags; }
internal void TargetAutoTagsChanged( CKTrait newTags ) { foreach( var b in _callbacks ) { if( b.PullTopicAndAutoTagsFromTarget ) { b.OnTargetAutoTagsChanged( newTags ); } } }
internal void GetTargetAndAutoTags( out string targetTopic, out CKTrait targetTags ) { targetTopic = _monitor.Topic; targetTags = _monitor.AutoTags; }
/// <summary> /// Writes a group opening. /// </summary> /// <param name="g">Group information.</param> protected override void OnGroupOpen( IActivityLogGroup g ) { var w = _buffer.Clear(); string levelLabel = g.MaskedGroupLevel.ToString(); string start = string.Format( "{0}> {1}: ", _prefix, levelLabel ); _prefix += "| "; _prefixLevel = _prefix; string prefixLabel = _prefixLevel + new string( ' ', levelLabel.Length + 1 ); w.Append( start ).AppendMultiLine( prefixLabel, g.GroupText, false ); if( _currentTags != g.GroupTags ) { w.Append( " -[" ).Append( g.GroupTags ).Append( ']' ); _currentTags = g.GroupTags; } w.AppendLine(); if( g.Exception != null ) { DumpException( w, _prefix, !g.IsGroupTextTheExceptionMessage, g.Exception ); } _writer( _buffer.ToString() ); }
internal void InitializeAndSend( Exception exception, CKTrait tags, string text ) { Debug.Assert( !IsRejected ); Initialize( text, exception, tags, _monitor.NextLogTime() ); _monitor.UnfilteredLog( this ); }
void IActivityMonitorClient.OnAutoTagsChanged( CKTrait newTags ) { if( _pushTopicAndAutoTagsToTarget ) { _bridgeTarget.SetAutoTags( newTags ); } }
/// <summary> /// Writes all information. /// </summary> /// <param name="data">Log data.</param> protected override void OnContinueOnSameLevel( ActivityMonitorLogData data ) { var w = _buffer.Clear(); w.AppendMultiLine( _prefixLevel, data.Text, true ); if( _currentTags != data.Tags ) { w.Append( " -[" ).Append( data.Tags ).Append( ']' ); _currentTags = data.Tags; } w.AppendLine(); if( data.Exception != null ) { DumpException( w, _prefix, !data.IsTextTheExceptionMessage, data.Exception ); } _writer( _buffer.ToString() ); }
/// <summary> /// Initializes this group data. /// </summary> /// <param name="text">Text of the log. Can be null or empty only if <paramref name="exception"/> is not null: the <see cref="Exception.Message"/> is the text.</param> /// <param name="exception">Exception of the log. Can be null.</param> /// <param name="tags">Tags (from <see cref="ActivityMonitor.Tags"/>) to associate to the log. It will be union-ed with the current <see cref="IActivityMonitor.AutoTags"/>.</param> /// <param name="logTime"> /// Time of the log. /// You may use <see cref="DateTimeStamp.UtcNow"/> or <see cref="ActivityMonitorExtension.NextLogTime">IActivityMonitor.NextLogTime()</see> extension method. /// </param> /// <param name="getConclusionText">Optional function that provides delayed obtention of the group conclusion: will be called on group closing.</param> public void Initialize( string text, Exception exception, CKTrait tags, DateTimeStamp logTime, Func<string> getConclusionText ) { base.Initialize( text, exception, tags, logTime ); _getConclusion = getConclusionText; }
internal DateTimeStamp CombineTagsAndAdjustLogTime( CKTrait tags, DateTimeStamp lastLogTime ) { if( _tags.IsEmpty ) _tags = tags; else _tags = _tags.Union( tags ); return _logTime = new DateTimeStamp( lastLogTime, _logTime.IsKnown ? _logTime : DateTimeStamp.UtcNow ); }
/// <summary> /// Initializes this data. /// </summary> /// <param name="text"> /// Text of the log. Can be null or empty: if <paramref name="exception"/> is not null, /// the <see cref="Exception.Message"/> becomes the text otherwise <see cref="ActivityMonitor.NoLogText"/> is used. /// </param> /// <param name="exception">Exception of the log. Can be null.</param> /// <param name="tags"> /// Tags (from <see cref="ActivityMonitor.Tags"/>) to associate to the log. /// It will be union-ed with the current <see cref="IActivityMonitor.AutoTags"/>.</param> /// <param name="logTime"> /// Time of the log. /// You can use <see cref="DateTimeStamp.UtcNow"/> or <see cref="ActivityMonitorExtension.NextLogTime">IActivityMonitor.NextLogTime()</see> extension method. /// </param> public void Initialize( string text, Exception exception, CKTrait tags, DateTimeStamp logTime ) { if( string.IsNullOrEmpty( (_text = text) ) ) { _text = exception == null ? ActivityMonitor.NoLogText : exception.Message; } _exception = exception; _tags = tags ?? ActivityMonitor.Tags.Empty; _logTime = logTime; }
/// <summary> /// Initializes a new <see cref="ActivityMonitorLogData"/>. /// </summary> /// <param name="level">Log level. Can not be <see cref="LogLevel.None"/>.</param> /// <param name="exception">Exception of the log. Can be null.</param> /// <param name="tags">Tags (from <see cref="ActivityMonitor.Tags"/>) to associate to the log. It will be union-ed with the current <see cref="IActivityMonitor.AutoTags"/>.</param> /// <param name="text">Text of the log. Can be null or empty only if <paramref name="exception"/> is not null: the <see cref="T:Exception.Message"/> is the text.</param> /// <param name="logTime"> /// Time of the log. /// You can use <see cref="DateTimeStamp.UtcNow"/> or <see cref="ActivityMonitorExtension.NextLogTime">IActivityMonitor.NextLogTime()</see> extension method. /// </param> /// <param name="fileName">Name of the source file that emitted the log. Can be null.</param> /// <param name="lineNumber">Line number in the source file that emitted the log. Can be null.</param> public ActivityMonitorLogData( LogLevel level, Exception exception, CKTrait tags, string text, DateTimeStamp logTime, string fileName, int lineNumber ) : this( level, fileName, lineNumber ) { if( MaskedLevel == LogLevel.None || MaskedLevel == LogLevel.Mask ) throw new ArgumentException( Impl.ActivityMonitorResources.ActivityMonitorInvalidLogLevel, "level" ); Initialize( text, exception, tags, logTime ); }
/// <summary> /// Called when <see cref="IActivityMonitor.AutoTags"/> changed. /// Does nothing by default. /// </summary> /// <param name="newTags">The new auto tags.</param> protected virtual void OnAutoTagsChanged( CKTrait newTags ) { }
void IActivityMonitorClient.OnAutoTagsChanged( CKTrait newTags ) { OnAutoTagsChanged( newTags ); }
/// <summary> /// Initializes a new <see cref="ActivityMonitorGroupData"/>. /// </summary> /// <param name="level">Log level. Can not be <see cref="LogLevel.None"/>.</param> /// <param name="tags">Tags (from <see cref="ActivityMonitor.Tags"/>) to associate to the log. It will be union-ed with the current <see cref="IActivityMonitor.AutoTags"/>.</param> /// <param name="text">Text of the log. Can be null or empty only if <paramref name="exception"/> is not null: the <see cref="Exception.Message"/> is the text.</param> /// <param name="logTime"> /// Time of the log. /// You may use <see cref="DateTimeStamp.UtcNow"/> or <see cref="ActivityMonitorExtension.NextLogTime">IActivityMonitor.NextLogTime()</see> extension method. /// </param> /// <param name="exception">Exception of the log. Can be null.</param> /// <param name="getConclusionText">Optional function that provides delayed obtention of the group conclusion: will be called on group closing.</param> /// <param name="fileName">Name of the source file that emitted the log. Can be null.</param> /// <param name="lineNumber">Line number in the source file that emitted the log. Can be null.</param> public ActivityMonitorGroupData( LogLevel level, CKTrait tags, string text, DateTimeStamp logTime, Exception exception, Func<string> getConclusionText, string fileName, int lineNumber ) : base( level, exception, tags, text, logTime, fileName, lineNumber ) { _getConclusion = getConclusionText; }
public void OnAutoTagsChanged( CKTrait newTrait ) { }
void IActivityMonitorBridgeCallback.OnTargetAutoTagsChanged( CKTrait newTags ) { _source.AutoTags = newTags; }
/// <summary> /// Log a new line in the logger /// </summary> /// <param name="logLevel">The level of the log</param> /// <param name="tag">The tags the log should be associated with, using CKTraitTags extensions</param> /// <param name="text">The text to log</param> public void NewEntry(LogLevel logLevel, CKTrait tag, String text) { _logger.UnfilteredLog( tag, logLevel, text, DateTime.UtcNow ); if ( NewLogStringReady != null ) { NewLogStringReady( this, Output() ); } }
internal IDisposableGroup InitializeAndSend( Exception exception, CKTrait tags, string text ) { Debug.Assert( !IsRejected ); Initialize( text, exception, tags, Monitor.NextLogTime() ); return Monitor.UnfilteredOpenGroup( this ); }