@@ -2,6 +2,7 @@ package persistence
2
2
3
3
import (
4
4
"fmt"
5
+ "sync"
5
6
6
7
"pyrevittelemetryserver/cli"
7
8
@@ -21,26 +22,37 @@ type TraceInfoV1 struct {
21
22
}
22
23
23
24
type ScriptTelemetryRecordV1 struct {
24
- Date string `json:"date" bson:"date" valid:"-"`
25
- Time string `json:"time" bson:"time" valid:"-"`
26
- UserName string `json:"username" bson:"username" valid:"-"`
27
- RevitVersion string `json:"revit" bson:"revit" valid:"numeric~Invalid revit version"`
28
- RevitBuild string `json:"revitbuild" bson:"revitbuild" valid:"matches(\\d{8}_\\d{4}\\(x\\d{2}\\))~Invalid revit build number"`
29
- SessionId string `json:"sessionid" bson:"sessionid" valid:"uuidv4~Invalid session id"`
30
- PyRevitVersion string `json:"pyrevit" bson:"pyrevit" valid:"-"`
31
- IsDebugMode bool `json:"debug" bson:"debug"`
32
- IsConfigMode bool `json:"config" bson:"config"`
33
- CommandName string `json:"commandname" bson:"commandname" valid:"-"`
34
- CommandUniqueName string `json:"commanduniquename" bson:"commanduniquename" valid:"-"`
35
- BundleName string `json:"commandbundle" bson:"commandbundle" valid:"-"`
36
- ExtensionName string `json:"commandextension" bson:"commandextension" valid:"-"`
37
- ResultCode int `json:"resultcode" bson:"resultcode" valid:"numeric~Invalid result code"`
38
- CommandResults map [ string ] string `json:"commandresults" bson:"commandresults" valid:"-"`
39
- ScriptPath string `json:"scriptpath" bson:"scriptpath" valid:"-"`
40
- TraceInfo TraceInfoV1 `json:"trace" bson:"trace"`
25
+ Date string `json:"date" bson:"date" valid:"-"`
26
+ Time string `json:"time" bson:"time" valid:"-"`
27
+ UserName string `json:"username" bson:"username" valid:"-"`
28
+ RevitVersion string `json:"revit" bson:"revit" valid:"numeric~Invalid revit version"`
29
+ RevitBuild string `json:"revitbuild" bson:"revitbuild" valid:"matches(\\d{8}_\\d{4}\\(x\\d{2}\\))~Invalid revit build number"`
30
+ SessionId string `json:"sessionid" bson:"sessionid" valid:"uuidv4~Invalid session id"`
31
+ PyRevitVersion string `json:"pyrevit" bson:"pyrevit" valid:"-"`
32
+ IsDebugMode bool `json:"debug" bson:"debug"`
33
+ IsConfigMode bool `json:"config" bson:"config"`
34
+ CommandName string `json:"commandname" bson:"commandname" valid:"-"`
35
+ CommandUniqueName string `json:"commanduniquename" bson:"commanduniquename" valid:"-"`
36
+ BundleName string `json:"commandbundle" bson:"commandbundle" valid:"-"`
37
+ ExtensionName string `json:"commandextension" bson:"commandextension" valid:"-"`
38
+ ResultCode int `json:"resultcode" bson:"resultcode" valid:"numeric~Invalid result code"`
39
+ CommandResults sync. Map `json:"commandresults" bson:"commandresults" valid:"-"`
40
+ ScriptPath string `json:"scriptpath" bson:"scriptpath" valid:"-"`
41
+ TraceInfo TraceInfoV1 `json:"trace" bson:"trace"`
41
42
}
42
43
43
44
func (logrec ScriptTelemetryRecordV1 ) PrintRecordInfo (logger * cli.Logger , message string ) {
45
+ // Convert sync.Map to regular map for printing
46
+ results := make (map [string ]string )
47
+ logrec .CommandResults .Range (func (key , value interface {}) bool {
48
+ if k , ok := key .(string ); ok {
49
+ if v , ok := value .(string ); ok {
50
+ results [k ] = v
51
+ }
52
+ }
53
+ return true
54
+ })
55
+
44
56
logger .Print (fmt .Sprintf (
45
57
"%s %s-%s %q @ %s:%s [%s.%s] code=%d info=%v" ,
46
58
message ,
@@ -52,7 +64,7 @@ func (logrec ScriptTelemetryRecordV1) PrintRecordInfo(logger *cli.Logger, messag
52
64
logrec .ExtensionName ,
53
65
logrec .CommandName ,
54
66
logrec .ResultCode ,
55
- logrec . CommandResults ,
67
+ results ,
56
68
))
57
69
}
58
70
@@ -66,10 +78,10 @@ func (logrec ScriptTelemetryRecordV1) Validate() error {
66
78
67
79
// v2.0
68
80
type EngineInfoV2 struct {
69
- Type string `json:"type" bson:"type" valid:"engine~Invalid executor engine type"`
70
- Version string `json:"version" bson:"version" valid:"-"`
71
- SysPaths []string `json:"syspath" bson:"syspath" valid:"-"`
72
- Configs map [ string ] interface {} `json:"configs" bson:"configs" valid:"-"`
81
+ Type string `json:"type" bson:"type" valid:"engine~Invalid executor engine type"`
82
+ Version string `json:"version" bson:"version" valid:"-"`
83
+ SysPaths []string `json:"syspath" bson:"syspath" valid:"-"`
84
+ Configs sync. Map `json:"configs" bson:"configs" valid:"-"`
73
85
}
74
86
75
87
type TraceInfoV2 struct {
@@ -82,33 +94,42 @@ type RecordMetaV2 struct {
82
94
}
83
95
84
96
type ScriptTelemetryRecordV2 struct {
85
- RecordMeta RecordMetaV2 `json:"meta" bson:"meta"`
86
- TimeStamp string `json:"timestamp" bson:"timestamp" valid:"rfc3339~Invalid timestamp"`
87
- UserName string `json:"username" bson:"username" valid:"-"`
88
- HostUserName string `json:"host_user" bson:"host_user" valid:"-"`
89
- RevitVersion string `json:"revit" bson:"revit" valid:"numeric~Invalid revit version"`
90
- RevitBuild string `json:"revitbuild" bson:"revitbuild" valid:"matches(\\d{8}_\\d{4}\\(x\\d{2}\\))~Invalid revit build number"`
91
- SessionId string `json:"sessionid" bson:"sessionid" valid:"uuidv4~Invalid session id"`
92
- PyRevitVersion string `json:"pyrevit" bson:"pyrevit" valid:"-"`
93
- Clone string `json:"clone" bson:"clone" valid:"-"`
94
- IsDebugMode bool `json:"debug" bson:"debug"`
95
- IsConfigMode bool `json:"config" bson:"config"`
96
- IsExecFromGUI bool `json:"from_gui" bson:"from_gui"`
97
- ExecId string `json:"exec_id" bson:"exec_id" valid:"-"`
98
- ExecTimeStamp string `json:"exec_timestamp" bson:"exec_timestamp" valid:"-"`
99
- CommandName string `json:"commandname" bson:"commandname" valid:"-"`
100
- CommandUniqueName string `json:"commanduniquename" bson:"commanduniquename" valid:"-"`
101
- BundleName string `json:"commandbundle" bson:"commandbundle" valid:"-"`
102
- ExtensionName string `json:"commandextension" bson:"commandextension" valid:"-"`
103
- DocumentName string `json:"docname" bson:"docname" valid:"-"`
104
- DocumentPath string `json:"docpath" bson:"docpath" valid:"-"`
105
- ResultCode int `json:"resultcode" bson:"resultcode" valid:"numeric~Invalid result code"`
106
- CommandResults map [ string ] interface {} `json:"commandresults" bson:"commandresults" valid:"-"`
107
- ScriptPath string `json:"scriptpath" bson:"scriptpath" valid:"-"`
108
- TraceInfo TraceInfoV2 `json:"trace" bson:"trace"`
97
+ RecordMeta RecordMetaV2 `json:"meta" bson:"meta"`
98
+ TimeStamp string `json:"timestamp" bson:"timestamp" valid:"rfc3339~Invalid timestamp"`
99
+ UserName string `json:"username" bson:"username" valid:"-"`
100
+ HostUserName string `json:"host_user" bson:"host_user" valid:"-"`
101
+ RevitVersion string `json:"revit" bson:"revit" valid:"numeric~Invalid revit version"`
102
+ RevitBuild string `json:"revitbuild" bson:"revitbuild" valid:"matches(\\d{8}_\\d{4}\\(x\\d{2}\\))~Invalid revit build number"`
103
+ SessionId string `json:"sessionid" bson:"sessionid" valid:"uuidv4~Invalid session id"`
104
+ PyRevitVersion string `json:"pyrevit" bson:"pyrevit" valid:"-"`
105
+ Clone string `json:"clone" bson:"clone" valid:"-"`
106
+ IsDebugMode bool `json:"debug" bson:"debug"`
107
+ IsConfigMode bool `json:"config" bson:"config"`
108
+ IsExecFromGUI bool `json:"from_gui" bson:"from_gui"`
109
+ ExecId string `json:"exec_id" bson:"exec_id" valid:"-"`
110
+ ExecTimeStamp string `json:"exec_timestamp" bson:"exec_timestamp" valid:"-"`
111
+ CommandName string `json:"commandname" bson:"commandname" valid:"-"`
112
+ CommandUniqueName string `json:"commanduniquename" bson:"commanduniquename" valid:"-"`
113
+ BundleName string `json:"commandbundle" bson:"commandbundle" valid:"-"`
114
+ ExtensionName string `json:"commandextension" bson:"commandextension" valid:"-"`
115
+ DocumentName string `json:"docname" bson:"docname" valid:"-"`
116
+ DocumentPath string `json:"docpath" bson:"docpath" valid:"-"`
117
+ ResultCode int `json:"resultcode" bson:"resultcode" valid:"numeric~Invalid result code"`
118
+ CommandResults sync. Map `json:"commandresults" bson:"commandresults" valid:"-"`
119
+ ScriptPath string `json:"scriptpath" bson:"scriptpath" valid:"-"`
120
+ TraceInfo TraceInfoV2 `json:"trace" bson:"trace"`
109
121
}
110
122
111
123
func (logrec ScriptTelemetryRecordV2 ) PrintRecordInfo (logger * cli.Logger , message string ) {
124
+ // Convert sync.Map to regular map for printing
125
+ results := make (map [string ]interface {})
126
+ logrec .CommandResults .Range (func (key , value interface {}) bool {
127
+ if k , ok := key .(string ); ok {
128
+ results [k ] = value
129
+ }
130
+ return true
131
+ })
132
+
112
133
logger .Print (fmt .Sprintf (
113
134
"%s %s %q %s:%s (%s) [%s.%s] code=%d info=%v" ,
114
135
message ,
@@ -120,7 +141,7 @@ func (logrec ScriptTelemetryRecordV2) PrintRecordInfo(logger *cli.Logger, messag
120
141
logrec .ExtensionName ,
121
142
logrec .CommandName ,
122
143
logrec .ResultCode ,
123
- logrec . CommandResults ,
144
+ results ,
124
145
))
125
146
}
126
147
@@ -158,15 +179,15 @@ func (logrec ScriptTelemetryRecordV2) Validate() error {
158
179
159
180
// introduced with api v2
160
181
type EventTelemetryRecordV2 struct {
161
- RecordMeta RecordMetaV2 `json:"meta" bson:"meta"`
162
- TimeStamp string `json:"timestamp" bson:"timestamp" valid:"rfc3339~Invalid timestamp"`
163
- HandlerId string `json:"handler_id" bson:"handler_id" valid:"-"`
164
- EventType string `json:"type" bson:"type" valid:"-"`
165
- EventArgs map [ string ] interface {} `json:"args" bson:"args" valid:"-"`
166
- UserName string `json:"username" bson:"username" valid:"-"`
167
- HostUserName string `json:"host_user" bson:"host_user" valid:"-"`
168
- RevitVersion string `json:"revit" bson:"revit" valid:"numeric~Invalid revit version"`
169
- RevitBuild string `json:"revitbuild" bson:"revitbuild" valid:"matches(\\d{8}_\\d{4}\\(x\\d{2}\\))~Invalid revit build number"`
182
+ RecordMeta RecordMetaV2 `json:"meta" bson:"meta"`
183
+ TimeStamp string `json:"timestamp" bson:"timestamp" valid:"rfc3339~Invalid timestamp"`
184
+ HandlerId string `json:"handler_id" bson:"handler_id" valid:"-"`
185
+ EventType string `json:"type" bson:"type" valid:"-"`
186
+ EventArgs sync. Map `json:"args" bson:"args" valid:"-"`
187
+ UserName string `json:"username" bson:"username" valid:"-"`
188
+ HostUserName string `json:"host_user" bson:"host_user" valid:"-"`
189
+ RevitVersion string `json:"revit" bson:"revit" valid:"numeric~Invalid revit version"`
190
+ RevitBuild string `json:"revitbuild" bson:"revitbuild" valid:"matches(\\d{8}_\\d{4}\\(x\\d{2}\\))~Invalid revit build number"`
170
191
171
192
// general
172
193
Cancellable bool `json:"cancellable" bson:"cancellable"`
0 commit comments