private void LoadSite() { try { // Validate input Regex regex = new Regex(@"((\w+:\/\/)[-a-zA-Z0-9:@;?&=\/%\+\.\*!'\(\),\$_\{\}\^~\[\]`#|]+)"); if (!regex.IsMatch(tbSiteUrl.Text.Trim())) { MessageBox.Show("Please enter a valid URL...", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // Add new site collection AuthN authentication = cbAuthentication.SelectedIndex == 0 ? AuthN.Default : AuthN.SharePointOnline; Globals.SiteCollections.Add(new Uri(tbSiteUrl.Text), tbUsername.Text.Trim(), tbPassword.Text.Trim(), authentication); // Close dialog this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void InitSite(Uri url, string username, string password, AuthN authn) { this.Url = url.RemoveTrailingSlash(); this.Authentication = authn; this.Username = username; this.Password = password; this.Webs = new List <string>(); this.InitClientContext(); }
/// <summary> /// Adds new site to the collection or opens existing one. /// </summary> /// <param name="url"></param> /// <param name="username"></param> /// <param name="password"></param> /// <param name="authn"></param> public void Add(Uri url, string username, string password, AuthN authn) { SiteAuth site = Globals.SiteCollections.SingleOrDefault(s => s.Url.Equals(url.RemoveTrailingSlash())); // Check if site already exists if (site == null) { // Add new site to collection site = new SiteAuth(url, username, password, authn); Globals.SiteCollections.Add(site); } else { // Open existing site within collection site.Password = password; site.InitClientContext(); } }
public SiteAuth(Uri url, string username, string password, AuthN authn) { InitSite(url, username, password, authn); }