protected override void OnLoad(EventArgs e) { Assert.ArgumentNotNull(e, "e"); base.OnLoad(e); if (!Context.ClientPage.IsEvent) { CurrenSession = WebUtil.GetQueryString("currentSessionId"); var sessions = ScriptSessionManager.GetAll(); foreach (var session in sessions) { var control = ControlFactory.GetControl("SessionIDGallery.Option") as XmlControl; Assert.IsNotNull(control, typeof(XmlControl), "Xml Control \"{0}\" not found", "Gallery.Versions.Option"); Context.ClientPage.AddControl(Sessions, control); var icon = session.ApplianceType == ApplicationNames.Console ? "powershell/16x16/console.png" : "powershell/16x16/PowerShell_Runner.png"; var builder = new ImageBuilder { Src = Images.GetThemedImageSource(icon, ImageDimension.id16x16), Class = "scRibbonToolbarSmallGalleryButtonIcon", Alt = session.ApplianceType }; var type = builder.ToString(); if (session.ID == CurrenSession) { type = "<div class=\"versionNumSelected\">" + type + "</div>"; } else { type = "<div class=\"versionNum\">" + type + "</div>"; } control["Number"] = type; control["SessionId"] = Translate.Text(Texts.SessionIDGallery_ID, session.ID); control["Location"] = Translate.Text(Texts.SessionIDGallery_Location, session.CurrentLocation); control["UserName"] = Translate.Text(Texts.SessionIDGallery_User, session.UserName); control["Click"] = string.Format("ise:setsessionid(id={0})", session.ID); } var item = Sitecore.Client.CoreDatabase.GetItem( "/sitecore/content/Applications/PowerShell/PowerShellIse/Menus/Sessions"); if ((item != null) && item.HasChildren) { var queryString = WebUtil.GetQueryString("id"); Options.AddFromDataSource(item, queryString, new CommandContext(item)); } } }
protected override void ProcessRecord() { if (ParameterSetName.Is("ID") || ParameterSetName.Is("Session")) { base.ProcessRecord(); return; } if (Current.IsPresent) { var currentSessionId = CurrentSessionId; if (!string.IsNullOrEmpty(currentSessionId)) { WriteObject(ScriptSessionManager.GetAll().Where(s => currentSessionId.Equals(s.ID, StringComparison.OrdinalIgnoreCase)), true); } } else if (Id != null && Id.Length > 0) { foreach (var id in Id) { if (ScriptSessionManager.SessionExistsForAnyUserSession(id)) { ScriptSessionManager.GetMatchingSessionsForAnyUserSession(id).ForEach(ProcessSession); } else { WriteError(typeof(ObjectNotFoundException), $"The script session with with Id '{id}' cannot be found.", ErrorIds.ScriptSessionNotFound, ErrorCategory.ResourceBusy, Id); } } } else { ScriptSessionManager.GetAll().ForEach(ProcessSession); } }