public static void RegisterShellMenuCommands([NotNull] SitecorePackage package) { Assert.ArgumentNotNull(package, nameof(package)); menuCommands.Clear(); var menuCommandService = package.MenuService; var context = new ShellContext(); context.Initialize(); var boundCommands = new List <BoundCommand>(); var unboundCommands = new Dictionary <ShellMenuCommandPlacement, List <UnboundCommand> >(); unboundCommands[ShellMenuCommandPlacement.MainMenu] = new List <UnboundCommand>(); unboundCommands[ShellMenuCommandPlacement.SolutionExplorerItem] = new List <UnboundCommand>(); unboundCommands[ShellMenuCommandPlacement.SolutionExplorerFolder] = new List <UnboundCommand>(); unboundCommands[ShellMenuCommandPlacement.SolutionExplorerProject] = new List <UnboundCommand>(); GetCommands(boundCommands, unboundCommands); CreateShellMenuCommands(context, menuCommandService, boundCommands); CreateShellMenuCommands(context, menuCommandService, unboundCommands, ShellMenuCommandPlacement.MainMenu, CommandIds.ExtensibilityMenu); CreateShellMenuCommands(context, menuCommandService, unboundCommands, ShellMenuCommandPlacement.SolutionExplorerItem, CommandIds.SolutionExplorerItemExtensibilityMenu); CreateShellMenuCommands(context, menuCommandService, unboundCommands, ShellMenuCommandPlacement.SolutionExplorerFolder, CommandIds.SolutionExplorerFolderExtensibilityMenu); CreateShellMenuCommands(context, menuCommandService, unboundCommands, ShellMenuCommandPlacement.SolutionExplorerProject, CommandIds.ProjectExtensibilityMenu); }
public static void UnregisterShellMenuCommands([NotNull] SitecorePackage package) { Assert.ArgumentNotNull(package, nameof(package)); var menuCommandService = package.MenuService; foreach (var command in menuCommands) { command.Visible = true; menuCommandService.RemoveCommand(command); } menuCommands.Clear(); }
/// <summary> /// Installs the packages found in the package source folder. /// </summary> private List <SitecorePackage> InstallPackages() { var packages = new List <SitecorePackage>(); //Check to see if there is a post-step pending, and skip package install if there is if (File.Exists(Path.Combine(_packageSource, STARTUP_POST_STEP_PACKAGE_FILENAME))) { Log.Info("Install packages skipped because there is a post step pending", this); return(packages); } InstallLogger installLogger = new InstallLogger(new RootLogger(Level.ALL)); //Return if another installation is happening if (GetInstallerState() != InstallerState.Ready) { Log.Info(string.Format("Install packages skipped because install state is {0}. ", GetInstallerState()), this); return(packages); } //Prevent shutdown using (new ShutdownGuard()) { //If Sitecore is shutting down, don't start the installer if (ShutdownDetected) { Log.Info("Skipping Install because shutdown is pending", this); return(packages); } //Block further package installs SetInstallerState(InstallerState.InstallingPackage); using (new SecurityDisabler()) { //Find pending packages. This loop may not complete if there were binary/config changes foreach (string updatePackageFilename in Directory.GetFiles(_packageSource, "*.update", SearchOption.TopDirectoryOnly).OrderBy(f => f)) { string updatePackageFilenameStripped = updatePackageFilename.Split('\\').Last(); var package = new SitecorePackage { Name = updatePackageFilenameStripped, Status = SitecorePackageStatus.Ready }; if (ShutdownDetected) { Log.Info("Install packages aborting due to shutdown", this); if (GetInstallerState() != InstallerState.WaitingForPostSteps) { SetInstallerState(InstallerState.Ready); } package.Status = SitecorePackageStatus.Aborted; packages.Add(package); break; } Log.Info(String.Format("Begin Installation: {0}", updatePackageFilenameStripped), this); string installationHistoryRoot = null; List <ContingencyEntry> logMessages = new List <ContingencyEntry>(); PostStepDetails postStepDetails = new PostStepDetails { PostStepPackageFilename = updatePackageFilename, ResultFileName = Path.Combine(Path.GetDirectoryName(updatePackageFilename), Path.GetFileNameWithoutExtension(updatePackageFilename) + ".json") }; string installStatus = null; try { //Run the installer if (sitecoreUpdateVersionInfo.ProductMajorPart == 1) { logMessages = UpdateHelper.Install(BuildPackageInfo(updatePackageFilename), installLogger, out installationHistoryRoot); } else { object[] installationParamaters = new object[] { BuildReflectedPackageInfo(updatePackageFilename), installLogger, null }; logMessages = (List <ContingencyEntry>)updateHelperType.InvokeMember("Install", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, null, null, installationParamaters, null); installationHistoryRoot = installationParamaters[2].ToString(); } postStepDetails.HistoryPath = installationHistoryRoot; if (_updateConfigurationFiles) { FindAndUpdateChangedConfigs(Path.GetFileNameWithoutExtension(updatePackageFilename)); } //Sleep for 4 seconds to see if there was a file change that could cause a problem Thread.Sleep(4000); //Abort if Sitecore is shutting down. The install post steps will have to be completed later if (ShutdownDetected) { SetInstallerState(InstallerState.WaitingForPostSteps); RunPostStepsAtStartup(updatePackageFilename, installationHistoryRoot, postStepDetails); RestartSitecoreServer(); package.Status = SitecorePackageStatus.Shutdown; packages.Add(package); break; } else { ExecutePostSteps(installLogger, postStepDetails, false); installStatus = SUCCESS; Log.Info(String.Format("Installation Complete: {0}", updatePackageFilenameStripped), this); SetInstallerState(InstallerState.InstallingPackage); } package.Status = SitecorePackageStatus.Installed; packages.Add(package); } catch (PostStepInstallerException ex) { installStatus = FAIL; logMessages = ex.Entries; installationHistoryRoot = ex.HistoryPath; installLogger.Fatal("Package install failed", ex); package.Status = SitecorePackageStatus.Failed; packages.Add(package); throw ex; } catch (Exception ex) { installStatus = FAIL; Log.Error(String.Format("Installation Failed: {0}", updatePackageFilenameStripped), ex, this); installLogger.Fatal("Package install failed", ex); ThreadPool.QueueUserWorkItem(new WaitCallback((ctx) => { try { //The update package may be locked because the file object hasn't been disposed. Wait for it. Thread.Sleep(100); //I really hate this, but I couldn't find another reliable way to ensure the locked file is closed before I move it. GC.Collect(2); GC.WaitForPendingFinalizers(); File.Move(updatePackageFilename, updatePackageFilename + ".error_" + DateTime.Now.ToString("yyyyMMdd.hhmmss")); } catch (Exception ex1) { Log.Error("Error moving broken package", ex1, this); } })); package.Status = SitecorePackageStatus.Failed; packages.Add(package); break; } finally { if (installationHistoryRoot != null) { //Write logs installLogger.WriteMessages(Path.Combine(installationHistoryRoot, "Install.log")); SaveInstallationMessages(installationHistoryRoot, logMessages); } //Send the status if there is one if (installStatus != null) { NotifiyPackageComplete(installStatus, postStepDetails); } } } if (!ShutdownDetected) { //Allow additional installs SetInstallerState(InstallerState.Ready); } } } return(packages); }