コード例 #1
0
ファイル: PyRevitCLIRevitCmds.cs プロジェクト: smhrjn/pyRevit
        ListAvailableCommands()
        {
            foreach (PyRevitClone clone in PyRevitClones.GetRegisteredClones())
            {
                PyRevitCLIAppCmds.PrintHeader($"Commands in Clone \"{clone.Name}\"");
                foreach (PyRevitExtension ext in clone.GetExtensions())
                {
                    if (ext.Type == PyRevitExtensionTypes.UIExtension)
                    {
                        foreach (PyRevitRunnerCommand cmd in ext.GetCommands())
                        {
                            Console.WriteLine(cmd);
                        }
                    }
                }
            }

            foreach (PyRevitExtension ext in PyRevitExtensions.GetInstalledExtensions())
            {
                if (ext.Type == PyRevitExtensionTypes.UIExtension)
                {
                    PyRevitCLIAppCmds.PrintHeader($"Commands in Extension \"{ext.Name}\"");
                    foreach (PyRevitRunnerCommand cmd in ext.GetCommands())
                    {
                        Console.WriteLine(cmd);
                    }
                }
            }
        }
コード例 #2
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));
        }
コード例 #3
0
        UpdateClone(bool allClones, string cloneName, GitInstallerCredentials credentials)
        {
            // TODO: ask for closing running Revits

            // prepare a list of clones to be updated
            var targetClones = new List <PyRevitClone>();
            // separate the clone that this process might be running from
            // this is used to update this clone from outside since the dlls will be locked
            PyRevitClone myClone = null;

            // all clones
            if (allClones)
            {
                foreach (var clone in PyRevitClones.GetRegisteredClones())
                {
                    if (PyRevitCLIAppCmds.IsRunningInsideClone(clone))
                    {
                        myClone = clone;
                    }
                    else
                    {
                        targetClones.Add(clone);
                    }
                }
            }
            // or single clone
            else
            {
                if (cloneName != null)
                {
                    var clone = PyRevitClones.GetRegisteredClone(cloneName);
                    if (PyRevitCLIAppCmds.IsRunningInsideClone(clone))
                    {
                        myClone = clone;
                    }
                    else
                    {
                        targetClones.Add(clone);
                    }
                }
            }

            // update clones that do not include this process
            foreach (var clone in targetClones)
            {
                logger.Debug("Updating clone \"{0}\"", clone.Name);
                PyRevitClones.Update(clone, credentials);
            }

            // now update myClone if any, as last step
            if (myClone != null)
            {
                throw new PyRevitException("Can not update clone that contains this command line utility. "
                                           + "Use installer to update.");
            }
        }
コード例 #4
0
        PrintClones()
        {
            PyRevitCLIAppCmds.PrintHeader("Registered Clones (full git repos)");
            var clones = PyRevitClones.GetRegisteredClones().OrderBy(x => x.Name);

            foreach (var clone in clones.Where(c => c.IsRepoDeploy))
            {
                Console.WriteLine(clone);
            }

            PyRevitCLIAppCmds.PrintHeader("Registered Clones (deployed from archive/image)");
            foreach (var clone in clones.Where(c => !c.IsRepoDeploy))
            {
                Console.WriteLine(clone);
            }
        }