using System;
using System.Security.Principal;
using CMS.DataEngine;
using CMS.DatabaseHelper;
using CMS.GlobalHelper;
using CMS.UIControls;
using CMS.SettingsProvider;
public partial class CMSInstall_Controls_WizardSteps_UserServer : CMSUserControl
{
#region "Properties"
///
/// Server name.
///
public string ServerName
{
get
{
return txtServerName.Text.Trim();
}
set
{
txtServerName.Text = value;
}
}
///
/// Database password.
///
public string DBPassword
{
get
{
return txtDBPassword.Text.Trim();
}
}
///
/// User name.
///
public string DBUsername
{
get
{
return txtDBUsername.Text.Trim();
}
}
///
/// Windows authentication checked
///
public bool WindowsAuthenticationChecked
{
get
{
return radWindowsAuthentication.Checked;
}
}
///
/// Indicates if is DB separation.
///
public bool IsDBSeparation
{
get;
set;
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
lblDBPassword.Text = ResHelper.GetFileString("Install.lblPassword");
lblDBUsername.Text = ResHelper.GetFileString("Install.lblUsername");
lblServerName.Text = ResHelper.GetFileString("Install.lblServername");
lblSQLServer.Text = IsDBSeparation ? GetString("separationDB.server") : ResHelper.GetFileString("Install.lblSQLServer");
txtDBPassword.Enabled = radSQLAuthentication.Checked;
txtDBUsername.Enabled = radSQLAuthentication.Checked;
radSQLAuthentication.Text = ResHelper.GetFileString("Install.radSQlAuthentication");
if (ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSWWAGInstallation"], false))
{
radWindowsAuthentication.Text = "Windows authentication is disabled (it is not supported by SQL Azure)";
radWindowsAuthentication.Enabled = false;
}
else
{
radWindowsAuthentication.Text = ResHelper.GetFileString("Install.radWindowsAuthentication") + "
" + String.Format(ResHelper.GetFileString("Install.Account"), WindowsIdentity.GetCurrent().Name) + "";
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
txtDBPassword.Enabled = radSQLAuthentication.Checked;
txtDBUsername.Enabled = radSQLAuthentication.Checked;
if (IsDBSeparation)
{
plcRadSQL.Visible = false;
plcWinAuth.Visible = false;
if (!String.IsNullOrEmpty(DBSeparationHelper.ConnStringSeparate))
{
DisplaySeparationError(GetString("separationDB.separationerror"));
}
}
}
///
/// Validates control, returns error if failed.
///
public bool ValidateForSeparation()
{
// Check if separation is not already completed
if (!String.IsNullOrEmpty(DBSeparationHelper.ConnStringSeparate))
{
DisplaySeparationError(GetString("separationDB.separationerror"));
return false;
}
// Check the server name
if (String.IsNullOrEmpty(txtServerName.Text))
{
DisplaySeparationError(ResHelper.GetFileString("Install.ErrorServerEmpty"));
return false;
}
// Check if it is possible to connect to the database
string res = TestNewConnection();
if (!string.IsNullOrEmpty(res))
{
DisplaySeparationError(res);
return false;
}
return true;
}
///
/// Displays separation error.
///
private void DisplaySeparationError(string error)
{
plcSeparationError.Visible = true;
lblError.Text = error;
}
///
/// Test new connection.
///
private string TestNewConnection()
{
SQLServerAuthenticationModeEnum authenticationType = radSQLAuthentication.Checked
? SQLServerAuthenticationModeEnum.
SQLServerAuthentication
: SQLServerAuthenticationModeEnum.
WindowsAuthentication;
string res = ConnectionHelper.TestConnection(authenticationType, txtServerName.Text.Trim(), "",
txtDBUsername.Text.Trim(), txtDBPassword.Text.Trim());
return res;
}
}