Ejemplo n.º 1
0
        CreateEnvJson()
        {
            // collecet search paths
            var searchPaths = new List <string>()
            {
                PyRevitConsts.DefaultExtensionsPath
            };

            searchPaths.AddRange(PyRevitExtensions.GetRegisteredExtensionSearchPaths());

            // collect list of lookup sources
            var lookupSrc = new List <string>()
            {
                PyRevitExtensions.GetDefaultExtensionLookupSource()
            };

            lookupSrc.AddRange(PyRevitExtensions.GetRegisteredExtensionLookupSources());

            // create json data object
            var jsonData = new Dictionary <string, object>()
            {
                { "meta", new Dictionary <string, object>()
                  {
                      { "version", "0.1.0" }
                  } },
                { "clones", PyRevitClones.GetRegisteredClones() },
                { "attachments", PyRevitAttachments.GetAttachments() },
                { "extensions", PyRevitExtensions.GetInstalledExtensions() },
                { "searchPaths", searchPaths },
                { "lookupSources", lookupSrc },
                { "installed", RevitProduct.ListInstalledProducts() },
                { "running", RevitController.ListRunningRevits() },
                { "pyrevitDataDir", PyRevitLabsConsts.PyRevitPath },
                { "userEnv", new Dictionary <string, object>()
                  {
                      { "osVersion", UserEnv.GetWindowsVersion() },
                      { "execUser", string.Format("{0}\\{1}", Environment.UserDomainName, Environment.UserName) },
                      { "activeUser", UserEnv.GetLoggedInUserName() },
                      { "isAdmin", UserEnv.IsRunAsAdmin() },
                      { "userAppdata", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) },
                      { "latestFramework", UserEnv.GetInstalledDotNetVersion() },
                      { "targetPacks", UserEnv.GetInstalledDotnetTargetPacks() },
                      { "targetPacksCore", UserEnv.GetInstalledDotnetCoreTargetPacks() },
                      { "cliVersion", PyRevitCLI.CLIVersion },
                  } },
            };

            var jsonExportCfg = new JsonSerializerSettings {
                Error = delegate(object sender, pyRevitLabs.Json.Serialization.ErrorEventArgs args) {
                    args.ErrorContext.Handled = true;
                },
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            jsonExportCfg.Converters.Add(new JsonVersionConverter());

            return(JsonConvert.SerializeObject(jsonData, jsonExportCfg));
        }
Ejemplo n.º 2
0
        public TelemetryRecord()
        {
            meta = new Dictionary <string, string> {
                { "schema", "2.0" },
            };

            timestamp = Telemetry.GetTelemetryTimeStamp();
            host_user = UserEnv.GetLoggedInUserName();
        }
Ejemplo n.º 3
0
        private static ScriptTelemetryRecord MakeTelemetryRecord(ref ScriptRuntime runtime)
        {
            // determine build number
            string revitbuild = "20000101_0000(x64)";

#if (REVIT2013 || REVIT2014 || REVIT2015 || REVIT2016 || REVIT2017 || REVIT2018 || REVIT2019 || REVIT2020)
            revitbuild = runtime.App.VersionBuild;
#else
            // Revit 2021 has a bug on .VersionBuild
            // it reports identical value as .VersionNumber
            // let's give a invalid, but correctly formatted value to the telemetry server
            string revitExePath = Process.GetCurrentProcess().MainModule.FileName;
            if (revitExePath != null && revitExePath != string.Empty)
            {
                HostProductInfo pinfo = RevitProductData.GetBinaryProductInfo(revitExePath);
                if (pinfo.build != null && pinfo.build != string.Empty)
                {
                    revitbuild = string.Format("{0}({1})", pinfo.build, pinfo.target);
                }
            }
#endif

            // setup a new telemetry record
            return(new ScriptTelemetryRecord {
                host_user = UserEnv.GetLoggedInUserName(),
                username = runtime.App.Username,
                revit = runtime.App.VersionNumber,
                revitbuild = revitbuild,
                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 = new JavaScriptSerializer().Deserialize <Dictionary <string, string> >(runtime.ScriptRuntimeConfigs.EngineConfigs),
                    },
                    message = runtime.TraceMessage
                }
            });
        }
Ejemplo n.º 4
0
        PrinUserEnv()
        {
            PrintHeader("User Environment");
            Console.WriteLine(UserEnv.GetWindowsVersion());
            Console.WriteLine(string.Format("Executing User: {0}\\{1}",
                                            Environment.UserDomainName, Environment.UserName));
            Console.WriteLine(string.Format("Active User: {0}", UserEnv.GetLoggedInUserName()));
            Console.WriteLine(string.Format("Admin Access: {0}", UserEnv.IsRunAsAdmin() ? "Yes" : "No"));
            Console.WriteLine(string.Format("%APPDATA%: \"{0}\"",
                                            Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)));
            Console.WriteLine(string.Format("Latest Installed .Net Framework: {0}",
                                            UserEnv.GetInstalledDotNetVersion()));
            try {
                string targetPacks = "";
                foreach (string targetPackagePath in UserEnv.GetInstalledDotnetTargetPacks())
                {
                    targetPacks += string.Format("{0} ", Path.GetFileName(targetPackagePath));
                }
                Console.WriteLine(string.Format("Installed .Net Target Packs: {0}", targetPacks));
            }
            catch {
                Console.WriteLine("No .Net Target Packs are installed.");
            }

            try {
                string targetPacks = "";
                foreach (string targetPackagePath in UserEnv.GetInstalledDotnetCoreTargetPacks())
                {
                    targetPacks += string.Format("v{0} ", Path.GetFileName(targetPackagePath));
                }
                Console.WriteLine(string.Format("Installed .Net-Core Target Packs: {0}", targetPacks));
            }
            catch {
                Console.WriteLine("No .Ne-Core Target Packs are installed.");
            }

            Console.WriteLine(string.Format("pyRevit CLI {0}", PyRevitCLI.CLIVersion.ToString()));
        }
Ejemplo n.º 5
0
 private static ScriptTelemetryRecord MakeTelemetryRecord(ref ScriptRuntime runtime)
 {
     // setup a new telemetry record
     return(new ScriptTelemetryRecord {
         host_user = UserEnv.GetLoggedInUserName(),
         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 = new JavaScriptSerializer().Deserialize <Dictionary <string, string> >(runtime.ScriptRuntimeConfigs.EngineConfigs),
             },
             message = runtime.TraceMessage
         }
     });
 }