Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-6295 : multithreaded analytics engine separated from model instance #14595

Merged
merged 8 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
QilongTang marked this conversation as resolved.
Show resolved Hide resolved

/// <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
Loading