internal Image Snapshot(VM vm, string elevatedUsername, string elevatedPassword) { Program.AssertOffEventThread(); VNCView view = null; bool useElevatedCredentials = false; if (!vncViews.ContainsKey(vm)) { Program.Invoke(this, delegate { // use elevated credentials, if provided, to create a vncView (CA-91132) useElevatedCredentials = !String.IsNullOrEmpty(elevatedUsername) && !String.IsNullOrEmpty(elevatedPassword); if (useElevatedCredentials) { view = new VNCView(vm, elevatedUsername, elevatedPassword) { Dock = DockStyle.Fill } } ; else { setCurrentSource(vm); if (vncViews.ContainsKey(vm)) { view = vncViews[vm]; } } });
public bool isVNCPausedForSource(VM source) { Program.AssertOnEventThread(); VNCView vncView = null; if (vncViews.ContainsKey(source)) { vncView = vncViews[source]; return(vncView.isPaused); } return(false); }
internal void setCurrentSource(VM source) { Program.AssertOnEventThread(); // activeVNCView is going to change, so the current activeVNCView will become inactive // Start a timer for closing the inactive VNC connection after an interval (20 seconds) StartCloseVNCTimer(activeVNCView); this.Controls.Clear(); if (source == null) { activeVNCView = null; return; } List <Role> allowedRoles = null; if (RbacDenied(source, out allowedRoles)) { lableRbacWarning.Text = String.Format(allowedRoles.Count == 1 ? Messages.RBAC_CONSOLE_WARNING_ONE : Messages.RBAC_CONSOLE_WARNING_MANY, Role.FriendlyCSVRoleList(source.Connection.Session.Roles), Role.FriendlyCSVRoleList(allowedRoles)); this.Controls.Add(RbacWarningPanel); if (activeVNCView != null) { this.Controls.Remove(activeVNCView); } return; } activeVMConsoles.Remove(source); activeVMConsoles.Add(source); StopCloseVncTimer(source); while (activeVMConsoles.Count > MAX_ACTIVE_VM_CONSOLES) { closeVNCForSource(activeVMConsoles[0]); } if (vncViews.ContainsKey(source)) { activeVNCView = vncViews[source]; } else { activeVNCView = new VNCView(source, null, null); vncViews[source] = activeVNCView; } activeVNCView.refreshIsoList(); this.Controls.Add(activeVNCView); this.ClearErrorMessage(); }
internal Image Snapshot(VM vm, string elevatedUsername, string elevatedPassword) { Program.AssertOffEventThread(); VNCView view = null; bool useElevatedCredentials = false; if (!vncViews.ContainsKey(vm)) { Program.Invoke(this, delegate { // use elevated credentials, if provided, to create a vncView (CA-91132) useElevatedCredentials = !String.IsNullOrEmpty(elevatedUsername) && !String.IsNullOrEmpty(elevatedPassword); if (useElevatedCredentials) { view = new VNCView(vm, elevatedUsername, elevatedPassword); } else { setCurrentSource(vm); if (vncViews.ContainsKey(vm)) { view = vncViews[vm]; } } }); } else { view = vncViews[vm]; } if (view == null) { return(null); } Image snapshot = view.Snapshot(); // TODO: only pause the view if we're not currently using it. // view.Pause(); if (useElevatedCredentials) { //used the elevated credentials for snapshot, need to close vnc when finished Program.Invoke(this, () => view.Dispose()); } return(snapshot); }
public void StartCloseVNCTimer(VNCView vncView) { if (vncView == null) { return; } // find the <VM, VNCView> pair in vncViews and start timer on the vm foreach (var kvp in vncViews.Where(kvp => kvp.Value == vncView)) { StartCloseVNCTimer(kvp.Key); break; } }
internal void setCurrentSource(VM source) { Program.AssertOnEventThread(); this.Controls.Clear(); if (source == null) { activeVNCView = null; return; } List <Role> allowedRoles = null; if (RbacDenied(source, out allowedRoles)) { lableRbacWarning.Text = String.Format(allowedRoles.Count == 1 ? Messages.RBAC_CONSOLE_WARNING_ONE : Messages.RBAC_CONSOLE_WARNING_MANY, Role.FriendlyCSVRoleList(source.Connection.Session.Roles), Role.FriendlyCSVRoleList(allowedRoles)); this.Controls.Add(RbacWarningPanel); if (activeVNCView != null) { this.Controls.Remove(activeVNCView); } return; } activeVMConsoles.Remove(source); activeVMConsoles.Add(source); while (activeVMConsoles.Count > MAX_ACTIVE_VM_CONSOLES) { closeVNCForSource(activeVMConsoles[0]); activeVMConsoles.RemoveAt(0); } if (vncViews.ContainsKey(source)) { activeVNCView = vncViews[source]; } else { activeVNCView = new VNCView(source, null, null); vncViews[source] = activeVNCView; } activeVNCView.refreshIsoList(); this.Controls.Add(activeVNCView); this.ClearErrorMessage(); }
public void closeVNCForSource(VM source) { Program.AssertOnEventThread(); if (!vncViews.ContainsKey(source)) { return; } VNCView vncView = vncViews[source]; if (!vncView.isDocked) { return; } vncViews.Remove(source); vncView.Dispose(); }
internal void setCurrentSource(VM source) { Program.AssertOnEventThread(); // activeVNCView is going to change, so the current activeVNCView will become inactive // Start a timer for closing the inactive VNC connection after an interval (20 seconds) StartCloseVNCTimer(activeVNCView); tableLayoutPanelRbac.Visible = false; if (activeVNCView != null) { Controls.Remove(activeVNCView); activeVNCView = null; } if (source == null) { return; } List <Role> allowedRoles; if (RbacDenied(source, out allowedRoles)) { string msg = allowedRoles.Count == 1 ? Messages.RBAC_CONSOLE_WARNING_ONE : Messages.RBAC_CONSOLE_WARNING_MANY; lableRbacWarning.Text = string.Format(msg, Role.FriendlyCSVRoleList(source.Connection.Session.Roles), Role.FriendlyCSVRoleList(allowedRoles)); tableLayoutPanelRbac.Visible = true; return; } StopCloseVncTimer(source); //remove one more as we're adding the selected further down //Take(arg) returns empty list if the arg <= 0 var viewsToRemove = vncViews.Where(v => v.Key.opaque_ref != source.opaque_ref).Take(vncViews.Count - 1 - MAX_ACTIVE_VM_CONSOLES); foreach (var view in viewsToRemove) { closeVNCForSource(view.Key); } if (vncViews.ContainsKey(source)) { activeVNCView = vncViews[source]; } else { activeVNCView = new VNCView(source, null, null) { Dock = DockStyle.Fill }; vncViews[source] = activeVNCView; } activeVNCView.refreshIsoList(); Controls.Add(activeVNCView); ClearErrorMessage(); }