Exemplo n.º 1
0
        /// <summary>
        /// Replace place holders within script.
        /// </summary>
        /// <param name="tenant">Tenant authentication data.</param>
        /// <param name="script">PowerShell script with place holders.</param>
        /// <returns>Returns PowerShell script without place holders.</returns>
        private static string ReplacePlaceHolders(TenantAuthentication tenant, string script)
        {
            script = ReplacePlaceHolder(script, PLACEHOLDER_CURRENT_DIRECTORY, Environment.CurrentDirectory);
            script = ReplacePlaceHolder(script, PLACEHOLDER_TENANT_URL, tenant.AdminUrl.ToString());
            script = ReplacePlaceHolder(script, PLACEHOLDER_LOGIN_NAME, tenant.UserName);
            script = ReplacePlaceHolder(script, PLACEHOLDER_AUTHENTICATION, AUTHENTICATION_TENANT);
            script = ReplacePlaceHolder(script, PLACEHOLDER_CLIENT_SDK, HelpUtil.GetSDKDownloadTitle());
            script = ReplacePlaceHolder(script, PLACEHOLDER_CLIENT_SDK_URL, HelpUtil.GetSDKDownloadUrl());
            script = ReplacePlaceHolder(script, PLACEHOLDER_CLIENT_SDK_VERSION, HelpUtil.GetSDKMajorVersion());

            return(script);
        }
Exemplo n.º 2
0
        private void LoadSite()
        {
            try
            {
                // Validate input
                Regex regex = new Regex(@"((\w+:\/\/)[-a-zA-Z0-9:@;?&=\/%\+\.\*!'\(\),\$_\{\}\^~\[\]`#|]+)");
                if (!regex.IsMatch(tbSiteUrl.Text.Trim()) || tbSiteUrl.Text.Contains("_layouts"))
                {
                    MessageBox.Show("Please enter a valid site collection URL, like https://company.sharepoint.com or https://company.sharepoint.com/sites/teamsite.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                // Add new site collection
                AuthenticationMode authentication = (AuthenticationMode)cbAuthentication.SelectedIndex;
                SiteAuthentication site           = Globals.Sites.Add(new Uri(tbSiteUrl.Text), tbUsername.Text.Trim(), tbPassword.Text.Trim(), authentication);

                // Warning on mismatch SPCB and server build version
                Server server = null;
                if (!ProductUtil.DoesServerBuildVersionMatchThisRelease(site.BuildVersion, out server))
                {
                    if (MessageBox.Show($"The site you added is incompatible with this release of SharePoint Client Browser.\n\nThe site seems to be hosted on {server.ProductFullname} ({server.BuildVersion}) which is compatible with '{server.CompatibleRelease}', you can download this from {Constants.CODEPLEX_PROJECT_URL}.\n\nDo you want to download the '{server.CompatibleRelease}' release now?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start(Constants.CODEPLEX_PROJECT_URL);
                    }
                }

                // Close dialog
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (System.IO.FileNotFoundException ex)
            {
                // Handle the file not found exception "The specified module could not be found. (Exception from HRESULT: 0x8007007E)",
                // caused by not having installed the SharePoint Client Components
                string message = string.Format(Resources.ErrorMissingAssemblySDK, ex.Message, HelpUtil.GetSDKDownloadTitle(), Application.ProductName);

                ToggleButtons(true);
                if (MessageBox.Show(message, this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start(HelpUtil.GetSDKDownloadUrl());
                }

                LogUtil.LogException(ex);
            }
            catch (Exception ex)
            {
                ToggleButtons(true);
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                LogUtil.LogException(ex);
            }
        }
Exemplo n.º 3
0
        private void LoadTenant()
        {
            try
            {
                // Validate input
                Regex regex = new Regex(@"((\w+:\/\/)[-a-zA-Z0-9:@;?&=\/%\+\.\*!'\(\),\$_\{\}\^~\[\]`#|]+)");
                if (!regex.IsMatch(tbTenantAdminUrl.Text.Trim()) || tbTenantAdminUrl.Text.Contains("_layouts"))
                {
                    MessageBox.Show("Please enter a valid tenant admin URL, like https://company-admin.sharepoint.com.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                // Add new tenant
                Globals.Tenants.Add(new Uri(tbTenantAdminUrl.Text), tbUsername.Text.Trim(), tbPassword.Text.Trim());

                // Close dialog
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            catch (System.IO.FileNotFoundException ex)
            {
                // Handle the file not found exception "The specified module could not be found. (Exception from HRESULT: 0x8007007E)",
                // caused by not having installed the SharePoint Client Components.
                string message = string.Format(Resources.ErrorMissingAssemblySDK, ex.Message, HelpUtil.GetSDKDownloadTitle(), Application.ProductName);

                ToggleButtons(true);
                if (MessageBox.Show(message, this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start(HelpUtil.GetSDKDownloadUrl());
                }

                LogUtil.LogException(ex);
            }
            catch (Exception ex)
            {
                ToggleButtons(true);
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                LogUtil.LogException(ex);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Replace place holders within script.
        /// </summary>
        /// <param name="site">Site authentication data.</param>
        /// <param name="script">PowerShell script with place holders.</param>
        /// <returns>Returns PowerShell script without place holders.</returns>
        private static string ReplacePlaceHolders(SiteAuthentication site, string script)
        {
            script = ReplacePlaceHolder(script, PLACEHOLDER_CURRENT_DIRECTORY, Environment.CurrentDirectory);
            script = ReplacePlaceHolder(script, PLACEHOLDER_SITE_URL, site.Url.ToString());
            script = ReplacePlaceHolder(script, PLACEHOLDER_LOGIN_NAME, site.UserName);
            script = ReplacePlaceHolder(script, PLACEHOLDER_CLIENT_SDK, HelpUtil.GetSDKDownloadTitle());
            script = ReplacePlaceHolder(script, PLACEHOLDER_CLIENT_SDK_URL, HelpUtil.GetSDKDownloadUrl());
            script = ReplacePlaceHolder(script, PLACEHOLDER_CLIENT_SDK_VERSION, HelpUtil.GetSDKMajorVersion());

            switch (site.Authentication)
            {
            case AuthenticationMode.Default:
                if (string.IsNullOrEmpty(site.UserName))
                {
                    script = ReplacePlaceHolder(script, PLACEHOLDER_AUTHENTICATION, AUTHENTICATION_DEFAULT_CURRENT_USER);
                }
                else
                {
                    script = ReplacePlaceHolder(script, PLACEHOLDER_AUTHENTICATION, AUTHENTICATION_DEFAULT_CUSTOM);
                }
                break;

            case AuthenticationMode.SharePointOnline:
                script = ReplacePlaceHolder(script, PLACEHOLDER_AUTHENTICATION, AUTHENTICATION_SHAREPOINT_ONLINE);
                break;

            case AuthenticationMode.Anonymous:
                script = ReplacePlaceHolder(script, PLACEHOLDER_AUTHENTICATION, AUTHENTICATION_ANONYMOUS);
                break;

            case AuthenticationMode.Forms:
                script = ReplacePlaceHolder(script, PLACEHOLDER_AUTHENTICATION, AUTHENTICATION_FORMS_BASED);
                break;

            default:
                break;
            }

            return(script);
        }