Пример #1
0
        private void ButtonChangeRoles_Click(object sender, EventArgs e)
        {
            Program.AssertOnEventThread();
            if (Helpers.FeatureForbidden(_connection, Host.RestrictRBAC))
            {
                // Show upsell dialog
                using (var dlg = new UpsellDialog(HiddenFeatures.LinkLabelHidden ? Messages.UPSELL_BLURB_RBAC : Messages.UPSELL_BLURB_RBAC + Messages.UPSELL_BLURB_TRIAL,
                                                  InvisibleMessages.UPSELL_LEARNMOREURL_TRIAL))
                    dlg.ShowDialog(this);
                return;
            }


            // Double check, this method is called from a context menu as well and the state could have changed under it
            if (!ButtonChangeRoles.Enabled)
            {
                return;
            }

            List <Subject> selectedSubjects = new List <Subject>();

            foreach (DataGridViewRow r in GridViewSubjectList.SelectedRows)
            {
                AdSubjectRow selectedRow = (AdSubjectRow)r;
                // Should not be here, you can't change the root man!
                if (selectedRow.IsLocalRootRow)
                {
                    continue;
                }
                selectedSubjects.Add(selectedRow.subject);
            }

            using (var dialog = new RoleSelectionDialog(_connection, selectedSubjects.ToArray()))
                dialog.ShowDialog(this);
        }
Пример #2
0
 private int LoggedInCompare(AdSubjectRow s1, AdSubjectRow s2)
 {
     if (s1.LoggedIn)
     {
         if (s2.LoggedIn)
         {
             return(0);
         }
         return(1);
     }
     else
     {
         if (s2.LoggedIn)
         {
             return(-1);
         }
         return(0);
     }
 }
Пример #3
0
        private void GridViewSubjectList_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
        {
            // First of all, the admin row is always displayed at the top.
            AdSubjectRow row1 = (AdSubjectRow)GridViewSubjectList.Rows[e.RowIndex1];
            AdSubjectRow row2 = (AdSubjectRow)GridViewSubjectList.Rows[e.RowIndex2];

            if (row1.IsLocalRootRow)
            {
                e.SortResult = GridViewSubjectList.SortOrder == SortOrder.Ascending ? -1 : 1;
            }
            else if (row2.IsLocalRootRow)
            {
                e.SortResult = GridViewSubjectList.SortOrder == SortOrder.Ascending ? 1 : -1;
            }
            else
            {
                // Next we look to see which column we are sorting on
                switch (GridViewSubjectList.SortedColumn.Index)
                {
                case 0:     // shouldn't happen (expander column)
                case 1:     // Group/individual picture column
                    e.SortResult = GroupCompare(row1.subject, row2.subject);
                    break;

                case 2:     // Name and detail column
                    e.SortResult = NameCompare(row1.subject, row2.subject);
                    break;

                case 3:     // Role Column
                    e.SortResult = RoleCompare(row1.subject, row2.subject);
                    break;

                case 4:     // Logged in column
                    e.SortResult = LoggedInCompare(row1, row2);
                    break;
                }
            }
            e.Handled = true;
        }
Пример #4
0
 private int LoggedInCompare(AdSubjectRow s1, AdSubjectRow s2)
 {
     if (s1.LoggedIn)
     {
         if (s2.LoggedIn)
             return 0;
         return 1;
     }
     else
     {
         if (s2.LoggedIn)
             return -1;
         return 0;
     }
 }
Пример #5
0
        private void RepopulateListBox()
        {
            Program.AssertOnEventThread();

            Dictionary<string, bool> selectedSubjectUuids = new Dictionary<string, bool>();
            Dictionary<string, bool> expandedSubjectUuids = new Dictionary<string, bool>();
            bool rootExpanded = false;
            string topSubject = "";
            if (GridViewSubjectList.FirstDisplayedScrollingRowIndex > 0)
            {
                AdSubjectRow topRow = GridViewSubjectList.Rows[GridViewSubjectList.FirstDisplayedScrollingRowIndex] as AdSubjectRow;
                if (topRow.subject != null)
                    topSubject = topRow.subject.uuid;
            }

            if (GridViewSubjectList.SelectedRows.Count > 0)
            {
                foreach (AdSubjectRow r in GridViewSubjectList.SelectedRows)
                {
                    if (r.subject != null)
                        selectedSubjectUuids.Add(r.subject.uuid, true);
                }
            }
            foreach (AdSubjectRow row in GridViewSubjectList.Rows)
            {
                if (row.Expanded)
                    if (row.subject == null)
                        rootExpanded = true;
                    else
                        expandedSubjectUuids.Add(row.subject.uuid, true);
            }

            try
            {
                GridViewSubjectList.SuspendLayout();
                // Populate list of authenticated users
                GridViewSubjectList.Rows.Clear();

                // Add local root account, a null value for the subject shows this
                AdSubjectRow adminRow = new AdSubjectRow(null);
                GridViewSubjectList.Rows.Add(adminRow);

                List<DataGridViewRow> rows = new List<DataGridViewRow>();
                Session session = pool.Connection.Session;
                // Add all other Subjects in the server list
                foreach (Subject subject in pool.Connection.Cache.Subjects)
                {
                    subject.PropertyChanged += new PropertyChangedEventHandler(subject_PropertyChanged);
                    AdSubjectRow r = new AdSubjectRow(subject);
                    // we show them as unknown logged in status until the background thread updates them
                    r.showStatusLost();
                    rows.Add(r);
                }
                GridViewSubjectList.Rows.AddRange(rows.ToArray());
                GridViewSubjectList.Sort(GridViewSubjectList.SortedColumn ?? GridViewSubjectList.Columns[2],
                                         GridViewSubjectList.SortOrder == SortOrder.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending);

                // restore old selection, old expansion state and top row
                foreach (AdSubjectRow r in GridViewSubjectList.Rows)
                {
                    r.Selected = r.subject != null && selectedSubjectUuids.ContainsKey(r.subject.uuid);
                    r.Expanded = r.subject != null && expandedSubjectUuids.ContainsKey(r.subject.uuid);
                    if (r.subject == null && rootExpanded)
                        r.Expanded = true;
                    if (r.subject != null && topSubject == r.subject.uuid)
                        GridViewSubjectList.FirstDisplayedScrollingRowIndex = r.Index;
                }
                if (GridViewSubjectList.SelectedRows.Count == 0)
                    GridViewSubjectList.Rows[0].Selected = true;

                HelpersGUI.ResizeLastGridViewColumn(ColumnSubject);
                HelpersGUI.ResizeLastGridViewColumn(ColumnRoles);
                HelpersGUI.ResizeLastGridViewColumn(ColumnStatus);
            }
            finally
            {
                GridViewSubjectList.ResumeLayout();
            }
        }
Пример #6
0
        private void RepopulateListBox()
        {
            Program.AssertOnEventThread();

            if (!GridViewSubjectList.Enabled)
            {
                return;
            }

            Dictionary <string, bool> selectedSubjectUuids = new Dictionary <string, bool>();
            Dictionary <string, bool> expandedSubjectUuids = new Dictionary <string, bool>();
            bool   rootExpanded = false;
            string topSubject   = "";

            if (GridViewSubjectList.FirstDisplayedScrollingRowIndex > 0)
            {
                AdSubjectRow topRow = GridViewSubjectList.Rows[GridViewSubjectList.FirstDisplayedScrollingRowIndex] as AdSubjectRow;
                if (topRow != null && topRow.subject != null)
                {
                    topSubject = topRow.subject.uuid;
                }
            }

            if (GridViewSubjectList.SelectedRows.Count > 0)
            {
                foreach (AdSubjectRow r in GridViewSubjectList.SelectedRows)
                {
                    if (r.subject != null)
                    {
                        selectedSubjectUuids.Add(r.subject.uuid, true);
                    }
                }
            }
            foreach (AdSubjectRow row in GridViewSubjectList.Rows)
            {
                if (row.Expanded)
                {
                    if (row.subject == null)
                    {
                        rootExpanded = true;
                    }
                    else
                    {
                        expandedSubjectUuids.Add(row.subject.uuid, true);
                    }
                }
            }

            try
            {
                _updateInProgress = true;
                GridViewSubjectList.SuspendLayout();

                foreach (AdSubjectRow row in GridViewSubjectList.Rows)
                {
                    if (row.IsLocalRootRow)
                    {
                        continue;
                    }
                    row.subject.PropertyChanged -= subject_PropertyChanged;
                }

                GridViewSubjectList.Rows.Clear();

                var rows = new List <DataGridViewRow> {
                    new AdSubjectRow(null)
                };                                                      //local root account

                foreach (Subject subject in _connection.Cache.Subjects) //all other subjects in the pool
                {
                    subject.PropertyChanged += subject_PropertyChanged;
                    rows.Add(new AdSubjectRow(subject));
                }
                GridViewSubjectList.Rows.AddRange(rows.ToArray());

                GridViewSubjectList.Sort(GridViewSubjectList.SortedColumn ?? ColumnSubject,
                                         GridViewSubjectList.SortOrder == SortOrder.Ascending ? ListSortDirection.Ascending : ListSortDirection.Descending);

                // restore old selection, old expansion state and top row
                foreach (AdSubjectRow r in GridViewSubjectList.Rows)
                {
                    r.Selected = !r.IsLocalRootRow && selectedSubjectUuids.ContainsKey(r.subject.uuid);
                    r.Expanded = r.IsLocalRootRow ? rootExpanded : expandedSubjectUuids.ContainsKey(r.subject.uuid);

                    if (!r.IsLocalRootRow && topSubject == r.subject.uuid)
                    {
                        GridViewSubjectList.FirstDisplayedScrollingRowIndex = r.Index;
                    }
                }
                if (GridViewSubjectList.SelectedRows.Count == 0)
                {
                    GridViewSubjectList.Rows[0].Selected = true;
                }

                HelpersGUI.ResizeGridViewColumnToAllCells(ColumnSubject);
                HelpersGUI.ResizeGridViewColumnToAllCells(ColumnRoles);
                HelpersGUI.ResizeGridViewColumnToAllCells(ColumnStatus);
            }
            finally
            {
                GridViewSubjectList.ResumeLayout();
                _updateInProgress = false;
                EnableButtons();
            }
        }