-
-
Notifications
You must be signed in to change notification settings - Fork 442
Expand file tree
/
Copy pathEnvVariables.cs
More file actions
196 lines (150 loc) · 9.39 KB
/
EnvVariables.cs
File metadata and controls
196 lines (150 loc) · 9.39 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using System;
using System.IO;
using System.Collections.Generic;
using IronPython.Runtime;
using pyRevitLabs.Common;
namespace PyRevitLabs.PyRevit.Runtime {
public static class DomainStorageKeys {
public static string keyPrefix = PyRevitLabsConsts.ProductName.ToUpperInvariant();
public static string EnvVarsDictKey = keyPrefix + "EnvVarsDict";
public static string EnginesDictKey = keyPrefix + "CachedEngines";
public static string IronPythonEngineDefaultOutputStreamCfgKey = keyPrefix + "CachedEngineDefaultOutputStreamCfg";
public static string IronPythonEngineDefaultInputStreamCfgKey = keyPrefix + "CachedEngineDefaultInputStreamCfg";
public static string OutputWindowsDictKey = keyPrefix + "OutputWindowsDict";
}
public static class EnvDictionaryKeys
{
public static string keyPrefix = PyRevitLabsConsts.ProductName.ToUpperInvariant();
public static string SessionUUID = string.Format("{0}_UUID", keyPrefix);
public static string RevitVersion = string.Format("{0}_APPVERSION", keyPrefix);
public static string Version = string.Format("{0}_VERSION", keyPrefix);
public static string Clone = string.Format("{0}_CLONE", keyPrefix);
public static string IPYVersion = string.Format("{0}_IPYVERSION", keyPrefix);
public static string CPYVersion = string.Format("{0}_CPYVERSION", keyPrefix);
public static string LoggingLevel = string.Format("{0}_LOGGINGLEVEL", keyPrefix);
public static string FileLogging = string.Format("{0}_FILELOGGING", keyPrefix);
public static string LoadedAssms = string.Format("{0}_LOADEDASSMS", keyPrefix);
public static string RefedAssms = string.Format("{0}_REFEDASSMS", keyPrefix);
public static string TelemetryState = string.Format("{0}_TELEMETRYSTATE", keyPrefix);
public static string TelemetryUTCTimeStamps = string.Format("{0}_TELEMETRYUTCTIMESTAMPS", keyPrefix);
public static string TelemetryFileDir = string.Format("{0}_TELEMETRYDIR", keyPrefix);
public static string TelemetryFilePath = string.Format("{0}_TELEMETRYFILE", keyPrefix);
public static string TelemetryServerUrl = string.Format("{0}_TELEMETRYSERVER", keyPrefix);
public static string TelemetryIncludeHooks = string.Format("{0}_TELEMETRYINCLUDEHOOKS", keyPrefix);
public static string AppTelemetryState = string.Format("{0}_APPTELEMETRYSTATE", keyPrefix);
public static string AppTelemetryHandler = string.Format("{0}_APPTELEMETRYHANDLER", keyPrefix);
public static string AppTelemetryServerUrl = string.Format("{0}_APPTELEMETRYSERVER", keyPrefix);
public static string AppTelemetryEventFlags = string.Format("{0}_APPTELEMETRYEVENTFLAGS", keyPrefix);
public static string Hooks = string.Format("{0}_HOOKS", keyPrefix);
public static string HooksHandler = string.Format("{0}_HOOKSHANDLER", keyPrefix);
public static string AutoUpdating = string.Format("{0}_AUTOUPDATE", keyPrefix);
public static string OutputStyleSheet = string.Format("{0}_STYLESHEET", keyPrefix);
public static string RibbonUpdator = string.Format("{0}_RIBBONUPDATOR", keyPrefix);
public static string TabColorizer = string.Format("{0}_TABCOLORIZER", keyPrefix);
}
public class EnvDictionary
{
private PythonDictionary _envData = null;
public string SessionUUID;
public string RevitVersion;
public string PyRevitVersion;
public string PyRevitClone;
public string PyRevitIPYVersion;
public string PyRevitCPYVersion;
public int LoggingLevel;
public bool FileLogging;
public string[] LoadedAssemblies;
public string[] ReferencedAssemblies;
public bool TelemetryState;
public string TelemetryFilePath;
public string TelemetryServerUrl;
public bool TelemetryIncludeHooks;
public bool AppTelemetryState;
public string AppTelemetryServerUrl;
public string AppTelemetryEventFlags;
public Dictionary<string, Dictionary<string, string>> EventHooks =
new Dictionary<string, Dictionary<string, string>>();
public string ActiveStyleSheet;
public bool AutoUpdate;
public bool TelemetryUTCTimeStamps;
public EnvDictionary()
{
// get the dictionary from appdomain
_envData = (PythonDictionary)AppDomain.CurrentDomain.GetData(DomainStorageKeys.EnvVarsDictKey);
// base info
if (_envData.Contains(EnvDictionaryKeys.SessionUUID))
SessionUUID = (string)_envData[EnvDictionaryKeys.SessionUUID];
if (_envData.Contains(EnvDictionaryKeys.RevitVersion))
RevitVersion = (string)_envData[EnvDictionaryKeys.RevitVersion];
if (_envData.Contains(EnvDictionaryKeys.Version))
PyRevitVersion = (string)_envData[EnvDictionaryKeys.Version];
if (_envData.Contains(EnvDictionaryKeys.Clone))
PyRevitClone = (string)_envData[EnvDictionaryKeys.Clone];
if (_envData.Contains(EnvDictionaryKeys.IPYVersion))
PyRevitIPYVersion = (string)_envData[EnvDictionaryKeys.IPYVersion];
if (_envData.Contains(EnvDictionaryKeys.CPYVersion))
PyRevitCPYVersion = (string)_envData[EnvDictionaryKeys.CPYVersion];
// logging
if (_envData.Contains(EnvDictionaryKeys.LoggingLevel))
LoggingLevel = (int)_envData[EnvDictionaryKeys.LoggingLevel];
if (_envData.Contains(EnvDictionaryKeys.FileLogging))
FileLogging = (bool)_envData[EnvDictionaryKeys.FileLogging];
// assemblies
if (_envData.Contains(EnvDictionaryKeys.LoadedAssms))
LoadedAssemblies = ((string)_envData[EnvDictionaryKeys.LoadedAssms]).Split(Path.PathSeparator);
if (_envData.Contains(EnvDictionaryKeys.RefedAssms))
ReferencedAssemblies = ((string)_envData[EnvDictionaryKeys.RefedAssms]).Split(Path.PathSeparator);
// telemetry
if (_envData.Contains(EnvDictionaryKeys.TelemetryUTCTimeStamps))
TelemetryUTCTimeStamps = (bool)_envData[EnvDictionaryKeys.TelemetryUTCTimeStamps];
// script telemetry
if (_envData.Contains(EnvDictionaryKeys.TelemetryState))
TelemetryState = (bool)_envData[EnvDictionaryKeys.TelemetryState];
if (_envData.Contains(EnvDictionaryKeys.TelemetryFilePath))
TelemetryFilePath = (string)_envData[EnvDictionaryKeys.TelemetryFilePath];
if (_envData.Contains(EnvDictionaryKeys.TelemetryServerUrl))
TelemetryServerUrl = (string)_envData[EnvDictionaryKeys.TelemetryServerUrl];
if (_envData.Contains(EnvDictionaryKeys.TelemetryIncludeHooks))
TelemetryIncludeHooks = (bool)_envData[EnvDictionaryKeys.TelemetryIncludeHooks];
// app events telemetry
if (_envData.Contains(EnvDictionaryKeys.AppTelemetryState))
AppTelemetryState = (bool)_envData[EnvDictionaryKeys.AppTelemetryState];
if (_envData.Contains(EnvDictionaryKeys.AppTelemetryServerUrl))
AppTelemetryServerUrl = (string)_envData[EnvDictionaryKeys.AppTelemetryServerUrl];
if (_envData.Contains(EnvDictionaryKeys.AppTelemetryEventFlags))
AppTelemetryEventFlags = (string)_envData[EnvDictionaryKeys.AppTelemetryEventFlags];
// hooks
if (_envData.Contains(EnvDictionaryKeys.Hooks))
EventHooks = (Dictionary<string, Dictionary<string, string>>)_envData[EnvDictionaryKeys.Hooks];
else
_envData[EnvDictionaryKeys.Hooks] = EventHooks;
// misc
if (_envData.Contains(EnvDictionaryKeys.AutoUpdating))
AutoUpdate = (bool)_envData[EnvDictionaryKeys.AutoUpdating];
if (_envData.Contains(EnvDictionaryKeys.OutputStyleSheet))
ActiveStyleSheet = (string)_envData[EnvDictionaryKeys.OutputStyleSheet];
}
public void ResetEventHooks() {
((Dictionary<string, Dictionary<string, string>>)_envData[EnvDictionaryKeys.Hooks]).Clear();
}
/// <summary>
/// Seeds the AppDomain environment dictionary with session values supplied by the C# loader.
/// Called via reflection by EnvDictionarySeeder in pyRevitAssemblyBuilder (which has no
/// compile-time reference to IronPython), so the PythonDictionary is created here where
/// IronPython is already available.
/// </summary>
/// <param name="values">
/// Key/value pairs to store. Keys must match the string values of <see cref="EnvDictionaryKeys"/>.
/// Values must be plain CLR primitives (string, bool, int) — IronPython coerces them correctly.
/// </param>
public static void Seed(Dictionary<string, object> values) {
var envData = AppDomain.CurrentDomain.GetData(DomainStorageKeys.EnvVarsDictKey) as PythonDictionary
?? new PythonDictionary();
foreach (var kv in values)
envData[kv.Key] = kv.Value;
if (!envData.Contains(EnvDictionaryKeys.Hooks))
envData[EnvDictionaryKeys.Hooks] = new Dictionary<string, Dictionary<string, string>>();
AppDomain.CurrentDomain.SetData(DomainStorageKeys.EnvVarsDictKey, envData);
}
}
}