private void autoSelectSecurityGroups(XElement SecurityGroupsDNs) { SGList.ClearSelected(); if (SecurityGroupsDNs == null) { return; } foreach (XElement SGDNs in SecurityGroupsDNs.Elements("SecurityGroupDN")) { XElement SGs = Config.Current.Element("SecurityGroups"); if (SGs == null) { continue; } foreach (XElement SG in SGs.Elements("SecurityGroup")) { XElement Name = SG.Element("Name"); XElement DN = SG.Element("DistinguishedName"); if (Name == null || DN == null) { continue; } if (DN.Value == SGDNs.Value) { SGList.SelectedItems.Add(Name.Value); } } } }
private async void createComputer() { if (nameTextBox.Text == "") { showMsg("Computer Name is empty.", warnImg); return; } if (OUList.SelectedItem == null) { showMsg("No Organizational Unit is selected.", warnImg); return; } if (adDomainName == "" || adUserName == "" || adPassword == "") { showPassPrompt(); return; } XElement BaseDN = Config.Current.Element("BaseDN"); XElement SecurityGroups = Config.Current.Element("SecurityGroups"); if (BaseDN == null || SecurityGroups == null) { showMsg("BaseDN or SecurityGroups elements is missing from SuperADD.xml", warnImg); return; } showMsg("Adding computer to Active Directory...", loadImg, dismissable: false); Dictionary <string, string> postData = new Dictionary <string, string>() { { "basedn", BaseDN.Value }, { "function", "update" }, { "cn", nameTextBox.Text }, { "description", descTextBox.Text }, { "destinationdn", currentCreateSelectedOU } }; int index = 0; foreach (XElement SG in SecurityGroups.Elements("SecurityGroup")) { XElement SGName = SG.Element("Name"); XElement SGDN = SG.Element("DistinguishedName"); if (SGName == null || SGDN == null) { continue; } if (SGList.SelectedItems.Contains(SGName.Value)) { postData.Add("addgroups[" + (index++) + "]", SGDN.Value); } else { postData.Add("removegroups[" + (index++) + "]", SGDN.Value); } } if (computerOverwriteConfirmed) { postData.Add("confirm", ""); } try { string error = await HTTP.Post(postData); if (error != "") { if (error == "confirm") { if (desktopMode) { showMsg("This computer object already exists!\nPress \"Save\" again to confirm.", warnImg, disableForm: false); } else { showMsg("This computer object already exists!\nPress \"Join Domain\" again to confirm.", warnImg, disableForm: false); } computerOverwriteConfirmed = true; } else { showMsg("Daemon: " + error, warnImg); } } else { if (desktopMode) { hideMsg(); } else { setTSVariables(); } } } catch (HttpRequestException e) { showMsg(e.Message + ": " + e.InnerException.Message, warnImg); } catch (Exception e) { showMsg(e.Message, warnImg); } }