Esempio n. 1
0
        private void LogMessages_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            using (InvokeHelper ih = new InvokeHelper(listLog))
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Reset:
                    ih.InvokeMethod(() => listLog.Items.Clear());
                    break;

                case NotifyCollectionChangedAction.Add:
                    if (e.NewItems != null)
                    {
                        IEnumerable <LogItem> items = e.NewItems.Cast <LogItem>();
                        foreach (string message in items.Select(m => m.Message))
                        {
                            ih.InvokeMethod(() => listLog.Items.Insert(0, message));
                        }
                    }
                    break;

                case NotifyCollectionChangedAction.Replace:
                    foreach (string message in CurrentLog.LogMessages.Select(m => m.Message))
                    {
                        ih.InvokeMethod(() => listLog.Items.Insert(0, message));
                    }
                    break;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Disables current user account option.
        /// </summary>
        private void DisableCurrentUserAccount()
        {
            using (InvokeHelper ih = new InvokeHelper(radUseCurrentUserAccount))
            {
                ih.InvokeMethod(() => radUseCurrentUserAccount.Checked = false);

                using (InvokeHelper ih1 = new InvokeHelper(radSpecifyCredentials))
                {
                    ih1.InvokeMethod(() => radSpecifyCredentials.Checked = true);
                }

                ih.InvokeMethod(() => radUseCurrentUserAccount.Enabled = false);
            }
            ImportProfile.ADUseCurrentUserAccount = false;
        }
Esempio n. 3
0
        private void SetWait(bool wait, string message)
        {
            Wizard.SetWaitState(wait, message);

            // Enable/disable mass actions buttons
            using (InvokeHelper ih = new InvokeHelper(pnlButtons))
            {
                ih.InvokeMethod(() => pnlButtons.Enabled = !wait);
            }

            // Enable/disable tree with groups
            using (InvokeHelper ih = new InvokeHelper(treeGroups))
            {
                ih.InvokeMethod(() =>
                {
                    treeGroups.Enabled = !wait;

                    if (!wait)
                    {
                        // Return focus to previously selected node
                        treeGroups.Focus();
                    }
                });
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Displays waiting animation.
 /// </summary>
 /// <param name="wait">Indicates whether to wait</param>
 /// <param name="message">Message to display</param>
 public void SetWaitState(bool?wait, string message)
 {
     using (InvokeHelper ih = new InvokeHelper(this))
     {
         ih.InvokeMethod(() => SetWaitStateInternal(wait, message));
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Sets 'Enabled' property of control.
 /// </summary>
 /// <param name="control">Control to set property</param>
 /// <param name="enabled">Indicates whether control should be enabled</param>
 public void SetControlEnabled(Control control, bool enabled)
 {
     using (InvokeHelper ih = new InvokeHelper(control))
     {
         ih.InvokeMethod(() => control.Enabled = enabled);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Sets information message.
 /// </summary>
 /// <param name="label">Label to use</param>
 /// <param name="message">Information message</param>
 public void SetMessage(Label label, string message)
 {
     using (InvokeHelper ih = new InvokeHelper(label))
     {
         ih.InvokeMethod(() => SetMessageInternal(label, message, false));
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Verifies connection credentials and performs proper action.
        /// </summary>
        private Task <bool> VerifyADConnection()
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();

            try
            {
                ADProvider.InitializeDomainContext();
                SetMessage("Step3_ConnectionSuccessful");
                tcs.SetResult(true);
            }
            catch (LocalUserAccountException)
            {
                DisableCurrentUserAccount();
                SetError(ResHelper.GetString("Error_ConnectingAD") + AbstractResHelper.LINE_BREAK + ResHelper.GetString("Error_LocalUserAccountException"));
            }
            catch (DCConnectionException)
            {
                SetError(ResHelper.GetString("Error_ConnectingAD") + AbstractResHelper.LINE_BREAK + ResHelper.GetString("Error_LocalUserAccountException"));
            }
            catch (Exception ex)
            {
                SetError(ResHelper.GetString("Error_ConnectingAD") + AbstractResHelper.LINE_BREAK + ex.Message);
            }
            finally
            {
                Wizard.SetWaitState(false, string.Empty);
                Wizard.SetControlEnabled(Wizard.ButtonNext, true);
                using (InvokeHelper ih = new InvokeHelper(this))
                {
                    ih.InvokeMethod(() => Enabled = true);
                }
            }
            return(tcs.Task);
        }
Esempio n. 8
0
        /// <summary>
        /// Verifies connection credentials, database version, license.
        /// </summary>
        private Task <bool> ValidateDatabase()
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();
            bool validationResult           = false;

            try
            {
                // Change message
                Wizard.SetWaitState(null, ResHelper.GetString("Step2_CheckingLicense"));

                using (InvokeHelper ih = new InvokeHelper(cmbDBName))
                {
                    ih.InvokeMethod(() => ImportProfile.SQLServerDatabase = cmbDBName.Text);
                }

                if (!string.IsNullOrEmpty(ImportProfile.SQLServerDatabase))
                {
                    var projectVersion = GetDatabaseVersion(CMSImport.ConnectionString);

                    if (String.IsNullOrEmpty(projectVersion))
                    {
                        SetError("Step2_OtherDB");
                    }
                    else
                    {
                        Wizard.SetWaitState(null, ResHelper.GetString("Step2_CheckingVersion"));

                        // Version has to correspond with DLL version
                        if (projectVersion.EqualsCSafe(ADWizard.SupportedVersion))
                        {
                            // Set new connection string
                            CMSImport.ConfigureApplicationSettings();

                            // Initialize application to enable usage of providers
                            CMSImport.CMSInit();

                            validationResult = true;
                            SetMessage("Step2_ConnectionToDBSuccessfull");
                        }
                        else
                        {
                            SetError(ResHelper.GetString("Step2_WrongVersion", ADWizard.SupportedVersion, projectVersion));
                        }
                    }
                }
                else
                {
                    SetError("Step2_SelectDatabase");
                }
            }
            catch (SqlException)
            {
                validationResult = false;
                SetError("Step2_OtherDB");
            }
            tcs.SetResult(validationResult);
            return(tcs.Task);
        }
Esempio n. 9
0
        private void SetWait(bool wait, string message)
        {
            Wizard.SetWaitState(wait, message);

            using (InvokeHelper ih = new InvokeHelper(pnlFilter))
            {
                ih.InvokeMethod(() => pnlFilter.Enabled = !wait);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Connects to selected SQL instance.
        /// </summary>
        private void ConnectToInstance()
        {
            try
            {
                string[] databases = SqlServerHelper.GetDatabaseNames(CMSImport.BaseConnectionString).ToArray();
                using (InvokeHelper ih = new InvokeHelper(cmbDBName))
                {
                    ih.InvokeMethod(InvalidateDBs);
                    ih.InvokeMethod(() => cmbDBName.Items.AddRange(databases));
                    ih.InvokeMethod(() => cmbDBName.Enabled = true);
                    if (!string.IsNullOrEmpty(ImportProfile.SQLServerDatabase))
                    {
                        ih.InvokeMethod(delegate
                        {
                            if (cmbDBName.Items.Contains(ImportProfile.SQLServerDatabase))
                            {
                                cmbDBName.SelectedItem = ImportProfile.SQLServerDatabase;
                            }
                        });
                    }
                }

                SetMessage("Step2_ConnectionSuccessful");
                connectionResult = true;
            }
            catch (Exception ex)
            {
                connectionResult = false;
                SetError(ResHelper.GetString("Step2_ErrorConnectingDB") + AbstractResHelper.LINE_BREAK + ex.Message);
            }
            finally
            {
                Wizard.SetWaitState(false, string.Empty);
                Wizard.SetControlEnabled(Wizard.ButtonNext, true);
                using (InvokeHelper ih = new InvokeHelper(this))
                {
                    ih.InvokeMethod(() => Enabled = true);
                }
            }
        }
Esempio n. 11
0
 private void SetupSelectionControls()
 {
     using (InvokeHelper ih = new InvokeHelper(treeGroups))
     {
         ih.InvokeMethod(delegate
         {
             // Enable or disable context menus and buttons
             ADProvider.SetContextMenuEnabledState(importGroups);
             btnSelectAllGroups.Enabled   = importGroups;
             btnDeselectAllGroups.Enabled = importGroups;
         });
     }
 }
Esempio n. 12
0
        private void InitializeAutoComplete()
        {
            // Change message
            Wizard.SetWaitState(true, ResHelper.GetString("Step2_LoadingInstances"));
            string[] instances = SQLInstanceNames.ToArray();
            AutoCompleteStringCollection autoCompleteStringCollection = new AutoCompleteStringCollection();

            autoCompleteStringCollection.AddRange(instances);

            using (InvokeHelper ih = new InvokeHelper(cmbSQLServerAddress))
            {
                ih.InvokeMethod(() => cmbSQLServerAddress.AutoCompleteCustomSource = autoCompleteStringCollection);
                ih.InvokeMethod(() => cmbSQLServerAddress.Items.Clear());
                ih.InvokeMethod(() => cmbSQLServerAddress.Items.AddRange(instances));
                ih.InvokeMethod(() => cmbSQLServerAddress.Text = ImportProfile.SQLServerAddress);
            }

            if (!string.IsNullOrEmpty(ImportProfile.SQLServerDatabase))
            {
                using (InvokeHelper ih = new InvokeHelper(cmbDBName))
                {
                    ih.InvokeMethod(delegate
                    {
                        if (cmbDBName.Items.Contains(ImportProfile.SQLServerDatabase))
                        {
                            cmbDBName.SelectedItem = ImportProfile.SQLServerDatabase;
                        }
                        else
                        {
                            cmbDBName.Text = ImportProfile.SQLServerDatabase;
                        }
                    });
                }
            }
            Wizard.SetWaitState(false, string.Empty);
        }
Esempio n. 13
0
        public Response Invoke(string assemblyName, string className, string methodName, params byte[] inputParam)
        {
            Response response = new Response();

            try
            {
                object[] args = Serializer.DeserializeBinary(inputParam);

                object result = InvokeHelper.InvokeMethod(assemblyName, className, methodName, args);

                result = Serializer.SerializeBinary(new object[] { result });

                response.Result = result;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = ResponseStatus.Error;
                response.Result  = null;
            }

            return(response);
        }
Esempio n. 14
0
        /// <summary>
        /// Refresh checked status of all nodes that belong to this principal.
        /// Refresh import profile.
        /// </summary>
        private void RefreshTreeNodes()
        {
            if (enableCheck)
            {
                foreach (TreeNode node in TreeNodes)
                {
                    enableCheck = false;
                    if (node.TreeView != null)
                    {
                        // Check node thread safely
                        using (InvokeHelper ih = new InvokeHelper(node.TreeView))
                        {
                            ih.InvokeMethod(() => node.Checked = IsSelected);
                        }
                    }
                    else
                    {
                        node.Checked = IsSelected;
                    }
                    enableCheck = true;
                }

                // Update import profile
                Guid?identifier = ValidationHelper.GetGuid(Identifier, Guid.Empty);
                if (identifier != Guid.Empty)
                {
                    if (InnerPrincipal.StructuralObjectClass == PrincipalProvider.GroupIdentifier)
                    {
                        if (ImportProfile.Groups.Contains(identifier) && !IsSelected)
                        {
                            ImportProfile.Groups.Remove(identifier);
                        }
                        else if (!ImportProfile.Groups.Contains(identifier) && IsSelected)
                        {
                            ImportProfile.Groups.Add(identifier);
                        }
                    }
                    else if (InnerPrincipal.StructuralObjectClass == PrincipalProvider.UserIdentifier)
                    {
                        if (ImportProfile.Users.Contains(identifier) && !IsSelected)
                        {
                            ImportProfile.Users.Remove(identifier);
                        }
                        else if (!ImportProfile.Users.Contains(identifier) && IsSelected)
                        {
                            ImportProfile.Users.Add(identifier);
                        }
                    }
                }

                if (IsSelected)
                {
                    // Load collection with memberships
                    if (InnerPrincipal.StructuralObjectClass == ADProvider.USER)
                    {
                        WaitCallback touchCallback = TouchGroups;
                        ThreadPool.QueueUserWorkItem(touchCallback);
                    }
                }
            }
        }
Esempio n. 15
0
        private void BindUsers()
        {
            // Set waiting state
            SetWait(true, ResHelper.GetString("Step7_LoadingUsers"));

            DataTable usersTable = null;

            if (DataHelper.DataSourceIsEmpty(grdUsers.DataSource))
            {
                // Create new datatable
                usersTable = new DataTable();

                // Create columns
                DataColumn selectedCol    = new DataColumn(COLUMN_SELECTED, typeof(Boolean));
                DataColumn displayNameCol = new DataColumn(COLUMN_DISPLAYNAME, typeof(String));
                DataColumn userNameCol    = new DataColumn(COLUMN_USERNAME, typeof(String));
                DataColumn userGuidCol    = new DataColumn(COLUMN_USERGUID, typeof(Guid));

                // Add columns to datatable
                usersTable.Columns.Add(selectedCol);
                usersTable.Columns.Add(displayNameCol);
                usersTable.Columns.Add(userNameCol);
                usersTable.Columns.Add(userGuidCol);

                // Fill table with data
                foreach (IPrincipalObject user in ADProvider.GetAllUsers())
                {
                    // Create new row with the table schema
                    DataRow dr = usersTable.NewRow();

                    // Get user's identifier
                    object userIdentifier = user.Identifier;

                    // Get the display name of user
                    string displayName = !string.IsNullOrEmpty(user.DisplayName) ? user.DisplayName : user.Name;

                    // Add data to row
                    object[] dataRow = { user.IsSelected, displayName, user.GetCMSCodeName(true), userIdentifier };
                    dr.ItemArray = dataRow;

                    // Add row to table
                    usersTable.Rows.Add(dr);
                }

                // Apply sorting
                usersTable.DefaultView.Sort = COLUMN_DISPLAYNAME;
            }
            else
            {
                usersTable = (DataTable)grdUsers.DataSource;
                foreach (DataRow dr in usersTable.Rows)
                {
                    string userIdentifier = ValidationHelper.GetString(dr[COLUMN_USERGUID], string.Empty);
                    // Preselect users
                    bool selected = ImportProfile.Users.Contains(ADProvider.ConvertToObjectIdentifier(userIdentifier));
                    dr[COLUMN_SELECTED] = selected;
                    dr[COLUMN_USERNAME] = ADProvider.GetPrincipalObject(userIdentifier).GetCMSCodeName(true);
                }
            }

            using (InvokeHelper ih = new InvokeHelper(grdUsers))
            {
                ih.InvokeMethod(() => SetupGrid(usersTable));
            }

            using (InvokeHelper ih = new InvokeHelper(grdUsers))
            {
                ih.InvokeMethod(() => grdUsers.Enabled = true);
            }
            // Turn off wait state
            SetWait(false, string.Empty);
        }
Esempio n. 16
0
        private void BindGroups()
        {
            // Set waiting state
            SetWait(true, ResHelper.GetString("Step8_LoadingGroups"));

            DataTable groupsTable = null;

            if (DataHelper.DataSourceIsEmpty(grdGroups.DataSource))
            {
                // Create new datatable
                groupsTable = new DataTable();

                // Create columns
                DataColumn selectedCol     = new DataColumn(COLUMN_SELECTED, typeof(Boolean));
                DataColumn groupNameCol    = new DataColumn(COLUMN_GROUPNAME, typeof(String));
                DataColumn groupCMSNameCol = new DataColumn(COLUMN_CMSGROUPNAME, typeof(String));
                DataColumn groupGuidCol    = new DataColumn(COLUMN_GROUPGUID, typeof(Guid));

                // Add columns to datatable
                groupsTable.Columns.Add(selectedCol);
                groupsTable.Columns.Add(groupNameCol);
                groupsTable.Columns.Add(groupCMSNameCol);
                groupsTable.Columns.Add(groupGuidCol);

                var  possibleConflicts = new HashSet <string>();
                bool askForGuid        = true;

                // Fill table with data
                foreach (IPrincipalObject group in ADProvider.GetAllGroups())
                {
                    // Look for possible code name conflicts and ask user if he wants to replace them with GUID
                    string codeName = group.GetCMSCodeName(true);

                    if (ImportProfile.RoleCodeNameFormat != CodenameFormat.Guid)
                    {
                        if (askForGuid && !possibleConflicts.Add(codeName))
                        {
                            if (MessageBox.Show(ResHelper.GetString("Step8_ConflictsText"), ResHelper.GetString("Step8_ConflictsCaption"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                            {
                                ImportProfile.RoleCodeNameFormat = CodenameFormat.Guid;
                            }

                            // Ask user only once
                            askForGuid = false;
                        }
                    }

                    // Create new row with the table schema
                    DataRow dr = groupsTable.NewRow();

                    // Add data to row
                    object[] dataRow = { group.IsSelected, group.Name, codeName, group.Identifier };
                    dr.ItemArray = dataRow;

                    // Add row to table
                    groupsTable.Rows.Add(dr);
                }

                // Apply sorting
                groupsTable.DefaultView.Sort = COLUMN_GROUPNAME;
            }
            else
            {
                groupsTable = (DataTable)grdGroups.DataSource;
                foreach (DataRow dr in groupsTable.Rows)
                {
                    string groupIdentifier = ValidationHelper.GetString(dr[COLUMN_GROUPGUID], string.Empty);
                    // Preselect users
                    bool selected = ImportProfile.Groups.Contains(ADProvider.ConvertToObjectIdentifier(groupIdentifier));
                    dr[COLUMN_SELECTED]     = selected;
                    dr[COLUMN_CMSGROUPNAME] = ADProvider.GetPrincipalObject(groupIdentifier).GetCMSCodeName(true);
                }
            }

            using (InvokeHelper ih = new InvokeHelper(grdGroups))
            {
                ih.InvokeMethod(() => SetupGrid(groupsTable));
            }

            using (InvokeHelper ih = new InvokeHelper(grdGroups))
            {
                ih.InvokeMethod(() => grdGroups.Enabled = true);
            }

            // Turn off wait state
            SetWait(false, string.Empty);
        }
Esempio n. 17
0
        /// <summary>
        /// Loads users of given group.
        /// </summary>
        /// <param name="principalKey">Identifier (GUID) of group to load users from.</param>
        private void LoadGroupUsers(object principalKey)
        {
            DataTable usersTable = new DataTable();

            usersTable.Columns.Add(new DataColumn(COLUMN_SELECTED, typeof(Boolean)));
            usersTable.Columns.Add(new DataColumn(COLUMN_DISPLAYNAME, typeof(String)));
            usersTable.Columns.Add(new DataColumn(COLUMN_USERNAME, typeof(String)));
            usersTable.Columns.Add(new DataColumn(COLUMN_USERGUID, typeof(Guid)));

            // Get group based on node selected in tree
            IPrincipalObject group = ADProvider.GetPrincipalObject(principalKey);

            if (group != null)
            {
                // Get members of group
                List <IPrincipalObject> users = ADProvider.GetUsersOf(group);
                foreach (IPrincipalObject user in users)
                {
                    // Get user's identifier
                    object userIdentifier = user.Identifier;

                    // Get the display name of user
                    string displayName = !string.IsNullOrEmpty(user.DisplayName) ? user.DisplayName : user.Name;

                    // Create new row with the table schema
                    DataRow dr = usersTable.NewRow();

                    // Add row to table
                    usersTable.Rows.Add(dr);

                    // Add data to row
                    object[] dataRow = { user.IsSelected, displayName, user.GetCMSCodeName(true), userIdentifier };
                    dr.ItemArray = dataRow;
                }

                // Apply sorting
                usersTable.DefaultView.Sort = COLUMN_DISPLAYNAME;

                // Bind table as a grid's data source
                using (InvokeHelper ih = new InvokeHelper(grdUsers))
                {
                    ih.InvokeMethod(delegate
                    {
                        grdUsers.DataSource = usersTable;

                        // Adjust columns
                        DataGridViewColumn columnSelected = grdUsers.Columns[COLUMN_SELECTED];
                        if (columnSelected != null)
                        {
                            columnSelected.HeaderText   = ResHelper.GetString("General_Import");
                            columnSelected.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
                        }
                        DataGridViewColumn columnDisplayName = grdUsers.Columns[COLUMN_DISPLAYNAME];
                        if (columnDisplayName != null)
                        {
                            columnDisplayName.HeaderText   = ResHelper.GetString("General_DisplayName");
                            columnDisplayName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                            columnDisplayName.ReadOnly     = true;
                        }
                        DataGridViewColumn columnUserName = grdUsers.Columns[COLUMN_USERNAME];
                        if (columnUserName != null)
                        {
                            columnUserName.HeaderText   = ResHelper.GetString("General_CMSUsername");
                            columnUserName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                            columnUserName.ReadOnly     = true;
                        }
                        DataGridViewColumn columnUserGuid = grdUsers.Columns[COLUMN_USERGUID];
                        if (columnUserGuid != null)
                        {
                            columnUserGuid.Visible = false;
                        }

                        // Set enabled state
                        btnSelectAllUsers.Enabled   = (grdUsers.Rows.Count > 0);
                        btnDeselectAllUsers.Enabled = (grdUsers.Rows.Count > 0);
                    });
                }
            }

            // Do not interrupt mass actions
            if ((treeMassActions == null) || (!treeMassActions.IsAlive))
            {
                SetWait(false, string.Empty);
            }
        }