void bwApplyFiltersToUsers_DoWork(object sender, DoWorkEventArgs e) { var bw = (BackgroundWorker) sender; var rm = new RuleManager("savedquery", service); var templates = ((EntityReferenceCollection) ((object[]) e.Argument)[0]); var users = (List<Entity>) ((object[]) e.Argument)[1]; if (users == null) { rm.ApplyRuleToActiveUsers(templates); } else { foreach (var user in users) { bw.ReportProgress(0, string.Format("Applying filter(s) for user {0}...", user.GetAttributeValue<string>("fullname"))); rm.ApplyRulesToUser(templates, user.Id); } } }
private void ApplyTemplateToUsers(List<Guid> rulesIds, string question, RuleManager rm, BackgroundWorker worker) { worker.ReportProgress(0, "Waiting for input..."); if ( MessageBox.Show(this, question, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var usDialog = new UserSelectionDialog(service); if (usDialog.ShowDialog() == DialogResult.OK) { foreach (var user in usDialog.SelectedUsers) { worker.ReportProgress(0, string.Format("Applying rule(s) to user(s) '{0}'", user.GetAttributeValue<string>("fullname"))); var erc = new EntityReferenceCollection(); foreach (var ruleId in rulesIds) { erc.Add(new EntityReference("savedquery", ruleId)); } rm.ApplyRulesToUser(erc, user.Id); } } } }