Skip to content

Commit

Permalink
sync acess to track event
Browse files Browse the repository at this point in the history
  • Loading branch information
zavub committed Nov 16, 2023
1 parent 9e3852c commit c7ae647
Showing 1 changed file with 52 additions and 27 deletions.
79 changes: 52 additions & 27 deletions src/DynamoCore/Logging/DynamoAnalyticsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static String GetUserID()
internal class DynamoAnalyticsClient : IAnalyticsClient, IDisposable
{
private readonly ManualResetEventSlim serviceInitialized = new ManualResetEventSlim(false);
private readonly object trackEventLockObj = new object();

/// <summary>
/// A dummy IDisposable class
Expand Down Expand Up @@ -188,6 +189,8 @@ public void TrackEvent(Actions action, Categories category, string description,
Task.Run(() =>
{
serviceInitialized.Wait();
lock(trackEventLockObj)
{
if (!ReportingAnalytics) return;
Expand All @@ -204,6 +207,8 @@ public void TrackPreference(string name, string stringValue, int? metricValue)
Task.Run(() =>
{
serviceInitialized.Wait();
lock (trackEventLockObj)
{
if (!ReportingAnalytics) return;
Expand All @@ -219,8 +224,11 @@ private void TrackPreferenceInternal(string name, string stringValue, int? metri
Task.Run(() =>
{
serviceInitialized.Wait();
var e = AnalyticsEvent.Create(Categories.Preferences.ToString(), name, stringValue, metricValue);
e.Track();
lock(trackEventLockObj)
{
var e = AnalyticsEvent.Create(Categories.Preferences.ToString(), name, stringValue, metricValue);
e.Track();
}
});
}

Expand All @@ -231,6 +239,8 @@ public void TrackTimedEvent(Categories category, string variable, TimeSpan time,
Task.Run(() =>
{
serviceInitialized.Wait();
lock (trackEventLockObj)
{
if (!ReportingAnalytics) return;
Expand All @@ -252,6 +262,8 @@ public void TrackScreenView(string viewName)
Task.Run(() =>
{
serviceInitialized.Wait();
lock (trackEventLockObj)
{
if (!ReportingAnalytics) return;
Expand All @@ -268,6 +280,8 @@ public void TrackException(Exception ex, bool isFatal)
Task.Run(() =>
{
serviceInitialized.Wait();
lock (trackEventLockObj)
{
if (!ReportingAnalytics) return;
Expand All @@ -281,17 +295,20 @@ public IDisposable CreateTimedEvent(Categories category, string variable, string
{
serviceInitialized.Wait();

if (!ReportingAnalytics) return Disposable;

var e = new TimedEvent()
lock (trackEventLockObj)
{
Category = category.ToString(),
VariableName = variable,
Description = description,
Value = value
};
//Timed event does not need startup tracking.
return e;
if (!ReportingAnalytics) return Disposable;

var e = new TimedEvent()
{
Category = category.ToString(),
VariableName = variable,
Description = description,
Value = value
};
//Timed event does not need startup tracking.
return e;
}
}

public Task<IDisposable> CreateTaskTimedEvent(Categories category, string variable, string description, int? value)
Expand All @@ -306,11 +323,14 @@ public IDisposable CreateCommandEvent(string name, string description, int? valu
{
serviceInitialized.Wait();

if (!ReportingAnalytics) return Disposable;
lock (trackEventLockObj)
{
if (!ReportingAnalytics) return Disposable;

var e = new CommandEvent(name) { Description = description, Value = value };
e.Track();
return e;
var e = new CommandEvent(name) { Description = description, Value = value };
e.Track();
return e;
}
}

public Task<IDisposable> CreateTaskCommandEvent(string name, string description, int? value)
Expand All @@ -326,8 +346,11 @@ public void EndEventTask(Task<IDisposable> taskToEnd)

Task.Run(() =>
{
taskToEnd.Wait();
taskToEnd.Result.Dispose();
lock(trackEventLockObj)
{
taskToEnd.Wait();
taskToEnd.Result.Dispose();
}
});
}

Expand All @@ -337,16 +360,18 @@ public IDisposable TrackFileOperationEvent(string filepath, Actions operation, i
serviceInitialized.Wait();
if (!ReportingAnalytics) return Disposable;

var e = new FileOperationEvent()
lock(trackEventLockObj)
{
FilePath = filepath,
FileSize = size,
FileAction = FileAction(operation),
Description = description
};
e.Track();

return e;
var e = new FileOperationEvent()
{
FilePath = filepath,
FileSize = size,
FileAction = FileAction(operation),
Description = description
};
e.Track();
return e;
}
}

public Task<IDisposable> TrackTaskFileOperationEvent(string filepath, Actions operation, int size, string description)
Expand Down

0 comments on commit c7ae647

Please sign in to comment.