-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a warning for file logging being disabled
Closes #1119
- Loading branch information
Showing
7 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
|
||
using Couchbase.Lite.Internal.Logging; | ||
|
||
using JetBrains.Annotations; | ||
|
||
namespace Couchbase.Lite.Util | ||
{ | ||
internal sealed class RunOnce | ||
{ | ||
#region Constants | ||
|
||
private const string Tag = nameof(RunOnce); | ||
|
||
[NotNull] private static readonly ConcurrentDictionary<string, RunOnce> Instances = | ||
new ConcurrentDictionary<string, RunOnce>(); | ||
|
||
#endregion | ||
|
||
#region Variables | ||
|
||
[NotNull] | ||
private readonly string _id; | ||
|
||
[NotNull] | ||
private readonly ConcurrentDictionary<Action, bool> _seen = new ConcurrentDictionary<Action, bool>(); | ||
|
||
#endregion | ||
|
||
#region Constructors | ||
|
||
private RunOnce([NotNull]string identifier) | ||
{ | ||
_id = identifier; | ||
} | ||
|
||
#endregion | ||
|
||
#region Public Methods | ||
|
||
public static RunOnce GetInstance([NotNull]string identifier) | ||
{ | ||
return Instances.GetOrAdd(identifier, k => new RunOnce(k)); | ||
} | ||
|
||
public void Run([NotNull]Action a) | ||
{ | ||
if (_seen.TryAdd(a, false)) { | ||
WriteLog.To.Database.V(Tag, "Executing logic for {0}", _id); | ||
a(); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region Overrides | ||
|
||
public override string ToString() | ||
{ | ||
return $"RunOnce => [{_id}]"; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters