public CopySessionForm(Form parent) : base() { parentWindow = parent; InitializeComponent(); SessionController.SessionsRefreshedEventHandler scHandler = new SessionController.SessionsRefreshedEventHandler(this.SessionsRefreshed); sc.SessionsRefreshed += scHandler; csr = new CopySessionRequest(); tagCheckboxes(); tagRadioButtons(); createDictonary(); copyAllRadioButton.Checked = true; }
/// <summary> /// Copy the specified attributes from a template session /// to a list of target sessions /// </summary> /// <param name="csr">The copy session request</param> /// <returns>true if sucessful, false otherwise</returns> public bool copySessionAttributes(CopySessionRequest csr) { // Check the template session is still there RegistryKey template = Registry.CurrentUser.OpenSubKey(PUTTY_SESSIONS_REG_KEY + "\\" + csr.SessionTemplate.SessionKey, false); if (template == null) { return(false); } // Check all the target sessions still exist foreach (Session s in csr.TargetSessions) { RegistryKey targetSession = Registry.CurrentUser.OpenSubKey(PUTTY_SESSIONS_REG_KEY + "\\" + s.SessionKey, false); if (targetSession == null) { template.Close(); return(false); } else { targetSession.Close(); } } // Copy all the attributes foreach (Session s in csr.TargetSessions) { RegistryKey targetSession = Registry.CurrentUser.OpenSubKey(PUTTY_SESSIONS_REG_KEY + "\\" + s.SessionKey, true); object value; bool copy; foreach (string valueName in template.GetValueNames()) { copy = false; // Never copy the hostname onto the default session if (s.SessionKey.Equals(PUTTY_DEFAULT_SESSION) && valueName.Equals(PUTTY_HOSTNAME_ATTRIB)) { copy = false; } else if ((csr.CopyOptions == CopySessionRequest.CopySessionOptions.COPY_ALL) && !(valueName.Equals(PUTTY_HOSTNAME_ATTRIB)) && !(valueName.Equals(PUTTY_PSM_FOLDER_ATTRIB)) ) { copy = true; } else if ((csr.CopyOptions == CopySessionRequest.CopySessionOptions.COPY_EXCLUDE) && !(valueName.Equals(PUTTY_HOSTNAME_ATTRIB)) && !(valueName.Equals(PUTTY_PSM_FOLDER_ATTRIB)) && !(csr.SelectedAttributes.Contains(valueName))) { copy = true; } else if (csr.CopyOptions == CopySessionRequest.CopySessionOptions.COPY_INCLUDE) { copy = csr.SelectedAttributes.Contains(valueName); } if (copy == true) { value = template.GetValue(valueName); targetSession.SetValue(valueName, value, template.GetValueKind(valueName)); } } targetSession.Close(); } // Close the template session; template.Close(); return(true); }
/// <summary> /// Copy the specified attributes from a template session /// to a list of target sessions /// Delgates to the sessionProvider. /// </summary> /// <param name="csr">The copy session request</param> /// <returns>true if sucessful, false otherwise</returns> public bool copySessionAttributes(CopySessionRequest csr) { return(sessionProvider.copySessionAttributes(csr)); }