SwitchAttachment(string cloneName, string revitYear)
        {
            var clone = PyRevit.GetRegisteredClone(cloneName);

            if (revitYear != null)
            {
                int revitYearNumber = 0;
                if (int.TryParse(revitYear, out revitYearNumber))
                {
                    var attachment = PyRevit.GetAttached(revitYearNumber);
                    if (attachment != null)
                    {
                        if (attachment.Engine != null)
                        {
                            PyRevit.Attach(attachment.Product.ProductYear,
                                           clone,
                                           engineVer: attachment.Engine.Version,
                                           allUsers: attachment.AllUsers);
                        }
                        else
                        {
                            throw new pyRevitException(
                                      string.Format("Can not determine attachment engine for Revit \"{0}\"",
                                                    revitYear)
                                      );
                        }
                    }
                    else
                    {
                        throw new pyRevitException(
                                  string.Format("Can not determine existing attachment for Revit \"{0}\"",
                                                revitYear)
                                  );
                    }
                }
                else
                {
                    throw new pyRevitException(string.Format("Invalid Revit year \"{0}\"", revitYear));
                }
            }
            else
            {
                // read current attachments and reattach using the same config with the new clone
                foreach (var attachment in PyRevit.GetAttachments())
                {
                    if (attachment.Engine != null)
                    {
                        PyRevit.Attach(
                            attachment.Product.ProductYear,
                            clone,
                            engineVer: attachment.Engine.Version,
                            allUsers: attachment.AllUsers);
                    }
                    else
                    {
                        throw new pyRevitException("Can not determine attachment engine.");
                    }
                }
            }
        }
        Extend(string extName, string destPath, string branchName)
        {
            var ext = PyRevit.FindRegisteredExtension(extName);

            if (ext != null)
            {
                logger.Debug("Matching extension found \"{0}\"", ext.Name);
                PyRevit.InstallExtension(ext, destPath, branchName);
            }
            else
            {
                if (Errors.LatestError == ErrorCodes.MoreThanOneItemMatched)
                {
                    throw new pyRevitException(
                              string.Format("More than one extension matches the name \"{0}\"",
                                            extName));
                }
                else
                {
                    throw new pyRevitException(
                              string.Format("Not valid extension name or repo url \"{0}\"",
                                            extName));
                }
            }
        }
 ProcessExtensionInfoCommands(string extName, bool info, bool help, bool open)
 {
     if (extName != null)
     {
         var ext = PyRevit.FindRegisteredExtension(extName);
         if (Errors.LatestError == ErrorCodes.MoreThanOneItemMatched)
         {
             logger.Warn("More than one extension matches the search pattern \"{0}\"", extName);
         }
         else
         {
             if (info)
             {
                 Console.WriteLine(ext.ToString());
             }
             else if (help)
             {
                 Process.Start(ext.Website);
             }
             else if (open)
             {
                 var instExt = PyRevit.GetInstalledExtension(extName);
                 CommonUtils.OpenInExplorer(instExt.InstallPath);
             }
         }
     }
 }
 GetSetCloneTag(string cloneName, string tagName)
 {
     if (cloneName != null)
     {
         var clone = PyRevit.GetRegisteredClone(cloneName);
         // get version for git clones
         if (clone.IsRepoDeploy)
         {
             if (tagName != null)
             {
                 clone.SetTag(tagName);
             }
             else
             {
                 logger.Error("Version finder not yet implemented for git clones.");
                 // TODO: grab version from repo (last tag?)
             }
         }
         // get version for other clones
         else
         {
             if (tagName != null)
             {
                 logger.Error("Version setter not yet implemented for clones.");
                 // TODO: set version for archive clones?
             }
             else
             {
                 Console.WriteLine(clone.ModuleVersion);
             }
         }
     }
 }
 GetSetCloneOrigin(string cloneName, string originUrl, bool reset)
 {
     if (cloneName != null)
     {
         var clone = PyRevit.GetRegisteredClone(cloneName);
         if (clone.IsRepoDeploy)
         {
             if (originUrl != null || reset)
             {
                 string newUrl =
                     reset ? PyRevitConsts.OriginalRepoPath : originUrl;
                 clone.SetOrigin(newUrl);
             }
             else
             {
                 Console.WriteLine(string.Format("Clone \"{0}\" origin is at \"{1}\"",
                                                 clone.Name, clone.Origin));
             }
         }
         else
         {
             PyRevitCLIAppCmds.ReportCloneAsNoGit(clone);
         }
     }
 }
 GetSetExtensionOrigin(string extName, string originUrl, bool reset)
 {
     if (extName != null)
     {
         var extension = PyRevit.GetInstalledExtension(extName);
         if (extension != null)
         {
             if (reset)
             {
                 var ext = PyRevit.FindRegisteredExtension(extension.Name);
                 if (ext != null)
                 {
                     extension.SetOrigin(ext.Url);
                 }
                 else
                 {
                     throw new pyRevitException(
                               string.Format("Can not find the original url in the extension " +
                                             "database for extension \"{0}\"",
                                             extension.Name));
                 }
             }
             else if (originUrl != null)
             {
                 extension.SetOrigin(originUrl);
             }
             else
             {
                 Console.WriteLine(string.Format("Extension \"{0}\" origin is at \"{1}\"",
                                                 extension.Name, extension.Origin));
             }
         }
     }
 }
 GetSetCloneBranch(string cloneName, string branchName)
 {
     if (cloneName != null)
     {
         var clone = PyRevit.GetRegisteredClone(cloneName);
         if (clone != null)
         {
             if (clone.IsRepoDeploy)
             {
                 if (branchName != null)
                 {
                     clone.SetBranch(branchName);
                 }
                 else
                 {
                     Console.WriteLine(string.Format("Clone \"{0}\" is on branch \"{1}\"",
                                                     clone.Name, clone.Branch));
                 }
             }
             else
             {
                 PyRevitCLIAppCmds.ReportCloneAsNoGit(clone);
             }
         }
     }
 }
 AddExtensionPath(string searchPath)
 {
     if (searchPath != null)
     {
         PyRevit.RegisterExtensionSearchPath(searchPath);
     }
 }
 RenameClone(string cloneName, string cloneNewName)
 {
     if (cloneNewName != null)
     {
         PyRevit.RenameClone(cloneName, cloneNewName);
     }
 }
Пример #10
0
 RegisterClone(string cloneName, string clonePath, bool force)
 {
     if (clonePath != null)
     {
         PyRevit.RegisterClone(cloneName, clonePath, forceUpdate: force);
     }
 }
 AddExtensionLookupSource(string lookupPath)
 {
     if (lookupPath != null)
     {
         PyRevit.RegisterExtensionLookupSource(lookupPath);
     }
 }
Пример #12
0
        public static void RunUpdate(string clonePath)
        {
            try {
                // find target clone
                var clone = PyRevit.GetRegisteredClone(clonePath);

                // run update
                PyRevit.Update(clone);

                // write success message to system logs
                using (EventLog eventLog = new EventLog("Application")) {
                    eventLog.Source = "Application";
                    eventLog.WriteEntry(
                        string.Format("Successfully Updated Clone \"{0}\"", clone.Name),
                        EventLogEntryType.Information
                        );
                }
            }
            catch (Exception ex) {
                // write error message to system logs
                using (EventLog eventLog = new EventLog("Application")) {
                    eventLog.Source = "pyRevit Updater";
                    eventLog.WriteEntry(
                        string.Format("Update Error: {0}", ex.Message),
                        EventLogEntryType.Error
                        );
                }
            }
        }
Пример #13
0
 CreateClone(string cloneName, string deployName, string branchName, string repoUrl, string imagePath, string destPath)
 {
     // FIXME: implement image
     if (cloneName != null)
     {
         // if deployment requested or image path is provided
         if (imagePath != null || deployName != null)
         {
             PyRevit.DeployFromImage(
                 cloneName,
                 deploymentName: deployName,
                 branchName: branchName,
                 imagePath: imagePath,
                 destPath: destPath
                 );
         }
         // otherwise clone the full repo
         else
         {
             PyRevit.DeployFromRepo(
                 cloneName,
                 deploymentName: deployName,
                 branchName: branchName,
                 repoUrl: repoUrl,
                 destPath: destPath
                 );
         }
     }
 }
 PrintExtensionDefinitions(string searchPattern, string headerPrefix = "Registered")
 {
     PyRevitCLIAppCmds.PrintHeader(string.Format("{0} Extensions", headerPrefix));
     foreach (PyRevitExtensionDefinition ext in PyRevit.LookupRegisteredExtensions(searchPattern))
     {
         Console.WriteLine(ext);
     }
 }
Пример #15
0
        CreateEnvJson()
        {
            // collecet search paths
            var searchPaths = new List <string>()
            {
                PyRevit.pyRevitDefaultExtensionsPath
            };

            searchPaths.AddRange(PyRevit.GetRegisteredExtensionSearchPaths());

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

            lookupSrc.AddRange(PyRevit.GetRegisteredExtensionLookupSources());

            // create json data object
            var jsonData = new Dictionary <string, object>()
            {
                { "meta", new Dictionary <string, object>()
                  {
                      { "version", "0.1.0" }
                  } },
                { "clones", PyRevit.GetRegisteredClones() },
                { "attachments", PyRevit.GetAttachments() },
                { "extensions", PyRevit.GetInstalledExtensions() },
                { "searchPaths", searchPaths },
                { "lookupSources", lookupSrc },
                { "installed", RevitProduct.ListInstalledProducts() },
                { "running", RevitController.ListRunningRevits() },
                { "pyrevitDataDir", PyRevit.pyRevitAppDataPath },
                { "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));
        }
 PrintExtensionLookupSources()
 {
     PyRevitCLIAppCmds.PrintHeader("Extension Sources - Default");
     Console.WriteLine(PyRevit.GetDefaultExtensionLookupSource());
     PyRevitCLIAppCmds.PrintHeader("Extension Sources - Additional");
     foreach (var extLookupSrc in PyRevit.GetRegisteredExtensionLookupSources())
     {
         Console.WriteLine(extLookupSrc);
     }
 }
Пример #17
0
 public static void RunUpdate(string clonePath)
 {
     try {
         var clone = PyRevit.GetRegisteredClone(clonePath);
         PyRevit.Update(clone);
     }
     catch (Exception ex) {
         MessageBox.Show(ex.Message, PyRevitConsts.AddinFileName);
     }
 }
 PrintExtensionSearchPaths()
 {
     PyRevitCLIAppCmds.PrintHeader("Default Extension Search Path");
     Console.WriteLine(PyRevit.pyRevitDefaultExtensionsPath);
     PyRevitCLIAppCmds.PrintHeader("Extension Search Paths");
     foreach (var searchPath in PyRevit.GetRegisteredExtensionSearchPaths())
     {
         Console.WriteLine(searchPath);
     }
 }
Пример #19
0
        AttachClone(string cloneName,
                    bool latest, bool dynamoSafe, string engineVersion,
                    string revitYear, bool installed, bool attached,
                    bool allUsers)
        {
            var clone = PyRevit.GetRegisteredClone(cloneName);

            // grab engine version
            int engineVer = 0;

            int.TryParse(engineVersion, out engineVer);

            if (latest)
            {
                logger.Debug("Attaching on latest engine...");
                var latestCloneEngine =
                    clone.GetEngines().Where(x => x.Runtime).OrderByDescending(x => x.Version).First();
                logger.Debug(string.Format("Latest engine: {0}", latestCloneEngine));
                if (latestCloneEngine != null)
                {
                    engineVer = latestCloneEngine.Version;
                }
                else
                {
                    throw new pyRevitException("Can not determine latest runtime engine for this clone.");
                }
            }
            else if (dynamoSafe)
            {
                logger.Debug("Attaching on dynamo-safe engine");
                engineVer = PyRevitConsts.ConfigsDynamoCompatibleEnginerVer;
            }

            // decide targets revits to attach to
            int revitYearNumber = 0;

            if (installed)
            {
                foreach (var revit in RevitProduct.ListInstalledProducts())
                {
                    PyRevit.Attach(revit.ProductYear, clone, engineVer: engineVer, allUsers: allUsers);
                }
            }
            else if (attached)
            {
                foreach (var attachment in PyRevit.GetAttachments())
                {
                    PyRevit.Attach(attachment.Product.ProductYear, clone, engineVer: engineVer, allUsers: allUsers);
                }
            }
            else if (int.TryParse(revitYear, out revitYearNumber))
            {
                PyRevit.Attach(revitYearNumber, clone, engineVer: engineVer, allUsers: allUsers);
            }
        }
Пример #20
0
        UpdateClone(bool allClones, string cloneName)
        {
            // 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 PyRevit.GetRegisteredClones())
                {
                    if (PyRevitCLIAppCmds.IsRunningInsideClone(clone))
                    {
                        myClone = clone;
                    }
                    else
                    {
                        targetClones.Add(clone);
                    }
                }
            }
            // or single clone
            else
            {
                if (cloneName != null)
                {
                    var clone = PyRevit.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);
                PyRevit.Update(clone);
            }

            // now update myClone if any, as last step
            if (myClone != null)
            {
                PyRevitCLIAppCmds.UpdateFromOutsideAndClose(myClone);
            }
        }
Пример #21
0
 public static PyRevitClone GetCloneFromManifest(RevitAddonManifest manifest)
 {
     foreach (var clone in PyRevit.GetRegisteredClones())
     {
         if (manifest.Assembly.Contains(clone.ClonePath))
         {
             return(clone);
         }
     }
     return(null);
 }
 UpdateExtension(bool all, string extName)
 {
     if (all)
     {
         PyRevit.UpdateAllInstalledExtensions();
     }
     else if (extName != null)
     {
         PyRevit.UpdateExtension(extName);
     }
 }
Пример #23
0
        public void DeployFromImage_Full_Test()
        {
            var testCloneBranch = "master";

            RunCommand(string.Format("clone \"{0}\" core --dest=\"{1}\"", testCloneName, TempPath));

            var clone = PyRevit.GetRegisteredClone(testCloneName);

            PyRevit.UnregisterClone(clone);
            Assert.AreEqual(testCloneBranch, clone.Branch, string.Format("{0} != {1}", testCloneBranch, clone.Branch));
        }
 ForgetExtensionLookupSources(bool all, string lookupPath)
 {
     if (all)
     {
         PyRevit.UnregisterAllExtensionLookupSources();
     }
     else if (lookupPath != null)
     {
         PyRevit.UnregisterExtensionLookupSource(lookupPath);
     }
 }
Пример #25
0
 PrintCloneEngines(string cloneName)
 {
     if (cloneName != null)
     {
         var clone = PyRevit.GetRegisteredClone(cloneName);
         PyRevitCLIAppCmds.PrintHeader(string.Format("Deployments for \"{0}\"", clone.Name));
         foreach (var engine in clone.GetConfiguredEngines())
         {
             Console.WriteLine(engine);
         }
     }
 }
        PrintExtensions(IEnumerable <PyRevitExtension> extList = null, string headerPrefix = "Installed")
        {
            if (extList == null)
            {
                extList = PyRevit.GetInstalledExtensions();
            }

            PyRevitCLIAppCmds.PrintHeader(string.Format("{0} Extensions", headerPrefix));
            foreach (PyRevitExtension ext in extList.OrderBy(x => x.Name))
            {
                Console.WriteLine(ext);
            }
        }
Пример #27
0
 ForgetClone(bool allClones, string cloneName)
 {
     if (allClones)
     {
         PyRevit.UnregisterAllClones();
     }
     else
     {
         PyRevit.UnregisterClone(
             PyRevit.GetRegisteredClone(cloneName)
             );
     }
 }
 ToggleExtension(bool enable, string extName)
 {
     if (extName != null)
     {
         if (enable)
         {
             PyRevit.EnableExtension(extName);
         }
         else
         {
             PyRevit.DisableExtension(extName);
         }
     }
 }
 ForgetAllExtensionPaths(bool all, string searchPath)
 {
     if (all)
     {
         foreach (string regSearchPath in PyRevit.GetRegisteredExtensionSearchPaths())
         {
             PyRevit.UnregisterExtensionSearchPath(regSearchPath);
         }
     }
     else
     {
         PyRevit.UnregisterExtensionSearchPath(searchPath);
     }
 }
Пример #30
0
 DeleteClone(bool allClones, string cloneName, bool clearConfigs)
 {
     if (allClones)
     {
         PyRevit.DeleteAllClones(clearConfigs: clearConfigs);
     }
     else
     {
         if (cloneName != null)
         {
             PyRevit.Delete(PyRevit.GetRegisteredClone(cloneName), clearConfigs: clearConfigs);
         }
     }
 }