/// <summary>
 /// Fire the SyncSessionsRequested event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnSyncSessionsRequested(Object sender, SyncSessionsRequestedEventArgs e)
 {
     if (SyncSessionsRequested != null)
     {
         SyncSessionsRequested(sender, e);
     }
 }
        private void tableControl1_SyncSessionsRequested(object sender, SyncSessionsRequestedEventArgs e)
        {
            // Double check that the template session still exists
            // or else that will cause issues later
            if (sc.findSession(e.SessionTemplate) == null)
            {
                MessageBox.Show("Template session:\n" + e.SessionTemplate.SessionDisplayText
                                + "\nhas been removed.\n"
                                + "Please clear your selection and try again."
                                , "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Attempt to backup the existing sessions
            DialogResult dr = backupSessions(sc.getSessionList());

            if ((dr == DialogResult.Yes) ||
                (dr == DialogResult.No))
            {
                sessionsCount = e.SessionActionList.Count;
                progressDialog.reset(sessionsCount);

                backgroundWorker.RunWorkerAsync(e);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public int syncSessions(BackgroundWorker worker, SyncSessionsRequestedEventArgs e)
        {
            int            modifiedCount = 0;
            List <Session> delList       = new List <Session>();

            // Disable session refreshes
            BeginUpdate();

            foreach (SessionAction sa in e.SessionActionList)
            {
                if (sa.Action == SessionAction.ACTION.ADD)
                {
                    NewSessionRequest nsr = new NewSessionRequest(e.SessionTemplate
                                                                  , sa.NewSession.FolderName
                                                                  , sa.NewSession.Hostname
                                                                  , sa.NewSession.SessionDisplayText
                                                                  , sa.NewSession.Protocol
                                                                  , sa.NewSession.Portnumber
                                                                  , true, false);
                    createNewSession(nsr, worker);
                }
                else if (sa.Action == SessionAction.ACTION.DELETE)
                {
                    delList.Add(sa.ExistingSession);
                }
                else if (sa.Action == SessionAction.ACTION.UPDATE)
                {
                    Session existingSession = findSession(sa.NewSession);
                    if (existingSession != null)
                    {
                        sessionProvider.updateHostname(sa.NewSession);
                        sessionProvider.updateFolder(sa.NewSession);
                        sessionProvider.updateProtocol(sa.NewSession);
                        sessionProvider.updatePortnumber(sa.NewSession);
                    }
                }
                else if (sa.Action == SessionAction.ACTION.RENAME)
                {
                    Session existingSession = findSession(sa.ExistingSession);
                    sessionProvider.renameSession(existingSession, sa.NewSession.SessionDisplayText);
                    existingSession.FolderName = sa.NewSession.FolderName;
                    sessionProvider.updateFolder(existingSession);
                }
                modifiedCount++;
                worker.ReportProgress(modifiedCount);
            }

            if (delList.Count > 0)
            {
                deleteSessions(delList, worker);
            }

            worker.ReportProgress(e.SessionActionList.Count);

            // Re-enable session refreshes
            EndUpdate();

            return(modifiedCount);
        }
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // Get the BackgroundWorker that raised this event.
            BackgroundWorker worker             = sender as BackgroundWorker;
            SyncSessionsRequestedEventArgs srea = (SyncSessionsRequestedEventArgs)e.Argument;

            e.Result = sc.syncSessions(worker, srea);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void syncButton_Click(object sender, EventArgs e)
        {
            SyncSessionsRequestedEventArgs ssre = new SyncSessionsRequestedEventArgs(getSessionsToUpdate(), templateSession, ignoreExistingSessions);

            if (ssre.SessionActionList.Count > 0)
            {
                OnSyncSessionsRequested(this, ssre);
            }
            else
            {
                MessageBox.Show("No sessions selected for modification"
                                , "Warning"
                                , MessageBoxButtons.OK
                                , MessageBoxIcon.Warning);
            }
        }