-
-
Notifications
You must be signed in to change notification settings - Fork 325
/
ScriptTelemetry.cs
103 lines (93 loc) · 4.42 KB
/
ScriptTelemetry.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System.Collections.Generic;
using System.Threading.Tasks;
using pyRevitLabs.Json;
namespace PyRevitLabs.PyRevit.Runtime {
public class ScriptTelemetryRecordEngineInfo {
public string type { get; set; }
public string version { get; set; }
public List<string> syspath { get; set; }
public Dictionary<string, string> configs { get; set; }
}
public class ScriptTelemetryRecordTraceInfo {
public ScriptTelemetryRecordEngineInfo engine { get; set; }
public string message { get; set; }
}
public class ScriptTelemetryRecord: TelemetryRecord {
// by who?
public string username { get; set; }
// on what?
public string revit { get; set; }
public string revitbuild { get; set; }
public string sessionid { get; set; }
public string pyrevit { get; set; }
public string clone { get; set; }
// on which document
public string docname { get; set; }
public string docpath { get; set; }
// which mode?
public bool debug { get; set; }
public bool config { get; set; }
public bool from_gui { get; set; }
public string exec_id { get; set; }
public string exec_timestamp { get; set; }
// which script?
public string commandname { get; set; }
public string commandbundle { get; set; }
public string commandextension { get; set; }
public string commanduniquename { get; set; }
public string scriptpath { get; set; }
public string arguments { get; set; }
// returned what?
public int resultcode { get; set; }
public Dictionary<string, string> commandresults { get; set; }
// any errors?
public ScriptTelemetryRecordTraceInfo trace { get; set; }
public ScriptTelemetryRecord(): base() {}
}
public static class ScriptTelemetry {
private static ScriptTelemetryRecord MakeTelemetryRecord(ref ScriptRuntime runtime) {
// setup a new telemetry record
return new ScriptTelemetryRecord {
username = Telemetry.GetRevitUser(runtime.App),
revit = Telemetry.GetRevitVersion(runtime.App),
revitbuild = Telemetry.GetRevitBuild(runtime.App),
sessionid = runtime.SessionUUID,
pyrevit = runtime.PyRevitVersion,
clone = runtime.CloneName,
debug = runtime.ScriptRuntimeConfigs.DebugMode,
config = runtime.ScriptRuntimeConfigs.ConfigMode,
from_gui = runtime.ScriptRuntimeConfigs.ExecutedFromUI,
exec_id = runtime.ExecId,
exec_timestamp = runtime.ExecTimestamp,
commandname = runtime.ScriptData.CommandName,
commandbundle = runtime.ScriptData.CommandBundle,
commandextension = runtime.ScriptData.CommandExtension,
commanduniquename = runtime.ScriptData.CommandUniqueId,
scriptpath = runtime.ScriptSourceFile,
docname = runtime.DocumentName,
docpath = runtime.DocumentPath,
resultcode = runtime.ExecutionResult,
commandresults = runtime.GetResultsDictionary(),
trace = new ScriptTelemetryRecordTraceInfo {
engine = new ScriptTelemetryRecordEngineInfo {
type = runtime.EngineType.ToString().ToLower(),
version = runtime.EngineVersion,
syspath = runtime.ScriptRuntimeConfigs.SearchPaths,
configs = JsonConvert.DeserializeObject<Dictionary<string, string>>(runtime.ScriptRuntimeConfigs.EngineConfigs),
},
message = runtime.TraceMessage
}
};
}
public static void LogScriptTelemetryRecord(ref ScriptRuntime runtime) {
var env = new EnvDictionary();
var record = MakeTelemetryRecord(ref runtime);
if (env.TelemetryServerUrl != null && !string.IsNullOrEmpty(env.TelemetryServerUrl))
new Task(() =>
Telemetry.PostTelemetryRecord(env.TelemetryServerUrl, record)).Start();
if (env.TelemetryFilePath != null && !string.IsNullOrEmpty(env.TelemetryFilePath))
new Task(() =>
Telemetry.WriteTelemetryRecord(env.TelemetryFilePath, record)).Start();
}
}
}