Skip to content

Commit

Permalink
DYN-6295 : multithreaded analytics engine separated from model instan…
Browse files Browse the repository at this point in the history
…ce (#14595)

* multithreaded anaytics engine separated from model instance

* rename

* fix tests

* sync acess to track event

* increase obsolete version

* start with model

* remove duplicate internal method

* remove workspace events handling

---------

Co-authored-by: Bogdan Zavu <[email protected]>
  • Loading branch information
BogdanZavu and zavub authored Nov 22, 2023
1 parent 1a95731 commit c00af64
Show file tree
Hide file tree
Showing 24 changed files with 378 additions and 177 deletions.
4 changes: 2 additions & 2 deletions src/DynamoCLI/CommandLineRunner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -46,7 +46,7 @@ private static XmlDocument RunCommandLineArgs(DynamoModel model, StartupUtils.Co
Console.WriteLine("geometryFilePath option is only available when running DynamoWPFCLI, not DynamoCLI");
}

model.HostAnalyticsInfo = cmdLineArgs.AnalyticsInfo;
DynamoModel.HostAnalyticsInfo = cmdLineArgs.AnalyticsInfo;

cmdLineArgs.ImportedPaths.ToList().ForEach(path =>
{
Expand Down
4 changes: 2 additions & 2 deletions src/DynamoCore/Extensions/ReadyParams.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Dynamo.Graph.Workspaces;
Expand Down Expand Up @@ -78,7 +78,7 @@ public virtual ICommandExecutive CommandExecutive
/// <summary>
/// HostInfo object, Useful to determine what host context Dynamo is running in.
/// </summary>
internal HostAnalyticsInfo HostInfo => dynamoModel.HostAnalyticsInfo;
internal HostAnalyticsInfo HostInfo => DynamoModel.HostAnalyticsInfo;


/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Extensions/StartupParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ internal StartupParams(DynamoModel dynamoModel)
pathManager = dynamoModel.PathManager;
libraryLoader = new ExtensionLibraryLoader(dynamoModel);
customNodeManager = dynamoModel.CustomNodeManager;
dynamoVersion = new Version(dynamoModel.Version);
dynamoVersion = new Version(DynamoModel.Version);
preferences = dynamoModel.PreferenceSettings;
linterManager = dynamoModel.LinterManager;
IsGeometryLibraryLoaded = dynamoModel.IsASMLoaded;
Expand Down
47 changes: 15 additions & 32 deletions src/DynamoCore/Logging/AnalyticsService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Dynamo.Graph.Workspaces;
using Dynamo.Models;
using Autodesk.Analytics.ADP;
using Autodesk.Analytics.Core;
Expand All @@ -9,49 +8,29 @@ namespace Dynamo.Logging
/// <summary>
/// Utility class to support analytics tracking.
/// </summary>
class AnalyticsService
internal class AnalyticsService
{
// Use the Analytics.Core interface so that we do not have to load the ADP assembly at this time.
private static IAnalyticsUI adpAnalyticsUI;

/// <summary>
/// Starts the client when DynamoModel is created. This method initializes
/// Indicates that we don't want to shut down analytics when DynamoModel shuts down.
/// Sometimes we want to keep Analytics service running even when we don't have a DynamoModel started.
/// </summary>
internal static bool KeepAlive { get; set; }

/// <summary>
/// Starts the Analytics client. This method initializes
/// the Analytics service and application life cycle start is tracked.
/// </summary>
/// <param name="model">DynamoModel</param>
/// <param name="isHeadless">Analytics won't be started if IsHeadless, but ADP may be loaded to be disabled.</param>
/// <param name="isTestMode">Analytics won't be started if isTestMode, ADP will not be loaded.</param>
internal static void Start(DynamoModel model, bool isHeadless, bool isTestMode)
internal static void Start()
{
if (isTestMode)
{
if (Analytics.DisableAnalytics)
{
model.Logger.Log("Incompatible configuration: [IsTestMode] and [Analytics disabled] ");
}
return;
}

if (isHeadless)
{
return;
}

// Initialize the concrete class only when we initialize the Service.
// This will also load the Analytics.Net.ADP assembly
// We must initialize the ADPAnalyticsUI instance before the Analytics.Start call.
adpAnalyticsUI = new ADPAnalyticsUI();

Analytics.Start(new DynamoAnalyticsClient(model));
model.WorkspaceAdded += OnWorkspaceAdded;
}

static void OnWorkspaceAdded(WorkspaceModel obj)
{
if (obj is CustomNodeWorkspaceModel)
Analytics.TrackScreenView("CustomWorkspace");
else
Analytics.TrackScreenView("Workspace");
Analytics.Start(new DynamoAnalyticsClient(DynamoModel.HostAnalyticsInfo));
}

/// <summary>
Expand Down Expand Up @@ -99,7 +78,10 @@ internal static bool IsADPAvailable()
/// </summary>
internal static void ShutDown()
{
Analytics.ShutDown();
if (!KeepAlive)
{
Analytics.ShutDown();
}
}

/// <summary>
Expand All @@ -113,6 +95,7 @@ internal static void ShowADPConsentDialog(IntPtr? host)
adpAnalyticsUI.ShowOptInDialog(System.Threading.Thread.CurrentThread.CurrentUICulture.Name, false, host);
}
}

internal static string GetUserIDForSession()
{
if (Analytics.client is DynamoAnalyticsClient dac)
Expand Down
Loading

0 comments on commit c00af64

Please sign in to comment.