private CrmServiceClient GetCrmService(CrmConnectionInfo crmConnectionInfo)
        {
            string           connStr    = _connectionHelper.BuildConnectionString(crmConnectionInfo);
            CrmServiceClient crmService = new CrmServiceClient(connStr);

            return(crmService);
        }
    private bool CreateDatabase(string collation)
    {
        try
        {
            var message = $"{ResHelper.GetFileString("Installer.LogCreatingDatabase")} {databaseDialog.NewDatabaseName}";
            AddResult(message);
            LogProgressState(LogStatusEnum.Info, message);

            var connectionString = ConnectionHelper.BuildConnectionString(AuthenticationType, userServer.ServerName, String.Empty, userServer.DBUsername, Password, SqlInstallationHelper.DB_CONNECTION_TIMEOUT);

            // Use default collation, if none specified
            if (String.IsNullOrEmpty(collation))
            {
                collation = DatabaseHelper.DatabaseCollation;
            }

            if (!DBCreated)
            {
                SqlInstallationHelper.CreateDatabase(databaseDialog.NewDatabaseName, connectionString, collation);
            }

            return(true);
        }
        catch (Exception ex)
        {
            DisplayLog = true;
            var message = $"{ResHelper.GetFileString("Intaller.LogErrorCreateDB")} {ex.Message}";
            AddResult(message);
            LogProgressState(LogStatusEnum.Error, message);
        }

        return(false);
    }
示例#3
0
 public static void Configure()
 {
     Container = new DIContainer();
     Container.RegisterSinglenton(typeof(RoadsaftDbContext),
                                  new RoadsaftPostgresqlDbContext(
                                      ConnectionHelper.BuildConnectionString(Configuration.DatabaseHostName,
                                                                             Configuration.DatabaseUserName,
                                                                             Configuration.DatabasePassword,
                                                                             Configuration.DatabaseName)));
     Container.RegisterSingleton <IDriversDataProvider, DriversDatabaseController>();
 }
示例#4
0
    /// <summary>
    /// Set connection string into web.config.
    /// </summary>
    private void SetConnectionString()
    {
        string connectionStringName = DatabaseSeparationHelper.ConnStringSeparateName;
        string encodedPassword      = HttpUtility.HtmlEncode(HttpUtility.HtmlEncode(databaseDialog.Password));

        if (!SystemContext.IsRunningOnAzure)
        {
            if (!SettingsHelper.SetConnectionString(connectionStringName, databaseDialog.ConnectionString))
            {
                string connStringDisplay   = ConnectionHelper.BuildConnectionString(databaseDialog.AuthenticationType, databaseDialog.ServerName, databaseDialog.Database, databaseDialog.Username, encodedPassword, 240);
                string resultStringDisplay = "&lt;add name=\"" + connectionStringName + "\" connectionString=\"" + connStringDisplay + "\"/&gt;";

                separationFinished.ErrorLabel.Visible = true;
                separationFinished.ErrorLabel.Text    = string.Format(ResHelper.GetFileString("Install.ConnectionStringError"), resultStringDisplay);
            }
        }
        else
        {
            string connStringValue = ConnectionHelper.BuildConnectionString(databaseDialog.AuthenticationType, databaseDialog.ServerName, databaseDialog.Database, databaseDialog.Username, encodedPassword, 240, isForAzure: true);
            string connString      = "&lt;add name=\"" + connectionStringName + "\" connectionString=\"" + connStringValue + "\"/&gt;";
            string appSetting      = "&lt;Setting name=\"" + connectionStringName + "\" value=\"" + connStringValue + "\"/&gt;";

            separationFinished.AzureErrorLabel.Visible = true;
            separationFinished.AzureErrorLabel.Text    = string.Format(ResHelper.GetFileString("Install.ConnectionStringAzure"), connString, appSetting);
        }

        // If it doesn't support OpenQuery command, show info about need to do manual data move.
        if (!SqlServerCapabilities.SupportsOpenQueryCommand)
        {
            separationFinished.AzureErrorLabel.Visible = true;
            separationFinished.AzureErrorLabel.Text   += GetManualCopyText();
        }

        if (PersistentStorageHelper.GetValue("SeparateDBSites") == null)
        {
            if (!separationFinished.ErrorLabel.Visible)
            {
                separationFinished.ErrorLabel.Text += "<br />";
            }
            else
            {
                separationFinished.ErrorLabel.Visible = true;
            }
            separationFinished.ErrorLabel.Text += ResHelper.GetFileString("separationdb.startsites");
        }
    }
    /// <summary>
    /// Sets step, that prompts user to enter connection string manually to web.config. ConnectionString is built inside the method.
    /// </summary>
    private void ManualConnectionStringInsertion()
    {
        var encodedPassword  = HttpUtility.HtmlEncode(HttpUtility.HtmlEncode(Password));
        var connectionString = ConnectionHelper.BuildConnectionString(AuthenticationType, userServer.ServerName, Database, userServer.DBUsername, encodedPassword, SqlInstallationHelper.DB_CONNECTION_TIMEOUT, isForAzure: SystemContext.IsRunningOnAzure);

        // Set error message
        var connectionStringEntry    = $"&lt;add name=\"CMSConnectionString\" connectionString=\"{connectionString}\"/&gt;";
        var applicationSettingsEntry = $"&lt;Setting name=\"CMSConnectionString\" value=\"{connectionString}\"/&gt;";

        lblErrorConnMessage.Text = SystemContext.IsRunningOnAzure
            ? String.Format(ResHelper.GetFileString("Install.ConnectionStringAzure"), connectionStringEntry, applicationSettingsEntry)
            : String.Format(ResHelper.GetFileString("Install.ConnectionStringError"), connectionStringEntry);

        // Set step that prompts user to enter connection string to web.config
        wzdInstaller.ActiveStepIndex = 2;

        if (!SystemContext.IsRunningOnAzure)
        {
            // Show troubleshoot link
            pnlError.DisplayError("Install.ErrorPermissions", HELP_TOPIC_DISK_PERMISSIONS_LINK);
        }
    }
示例#6
0
    /// <summary>
    /// Validates control.
    /// </summary>
    public bool ValidateForSeparation()
    {
        // Get database name
        if (radCreateNew.Checked && SqlServerCapabilities.SupportsDatabaseCreation)
        {
            Database = txtNewDatabaseName.Text;
        }
        else
        {
            Database = txtExistingDatabaseName.Text;
        }
        Database = TextHelper.LimitLength(Database, 100, String.Empty);

        if (String.IsNullOrEmpty(Database))
        {
            DisplaySeparationError(GetString("Install.ErrorDBNameEmpty"));
            return(false);
        }

        // Set up the connection string
        ConnectionString = ConnectionHelper.BuildConnectionString(AuthenticationType, ServerName, Database, Username, Password, 240);

        // Test existing DB
        if (radUseExisting.Checked || !SqlServerCapabilities.SupportsDatabaseCreation)
        {
            if (SqlServerCapabilities.ControlServerPermissionAvailable &&
                !DatabaseHelper.CheckDBPermission(DatabasePermission.ModifyDatabase, AuthenticationType, ServerName, Username, Password))
            {
                DisplaySeparationError(GetString("separationDB.permissionmodify"));
                return(false);
            }

            if (!String.IsNullOrEmpty(ConnectionHelper.TestConnection(AuthenticationType, ServerName, Database, Username, Password)))
            {
                DisplaySeparationError(String.Format(ResHelper.GetFileString("Install.ErrorDatabseDoesntExist"), Database));
                return(false);
            }

            if (DatabaseSeparationHelper.CheckCMDatabase(ConnectionString))
            {
                DisplaySeparationError(GetString("separationDB.errorCMexists"));
                return(false);
            }
        }
        // Test new DB
        else
        {
            if (DatabaseHelper.DatabaseExists(ConnectionString))
            {
                DisplaySeparationError(GetString("separationDB.ErrorDBExists"));
                return(false);
            }
            if (SqlServerCapabilities.ControlServerPermissionAvailable)
            {
                if (!DatabaseHelper.CheckDBPermission(DatabasePermission.ModifyDatabase, AuthenticationType, ServerName, Username, Password))
                {
                    DisplaySeparationError(GetString("separationDB.permissionmodify"));
                    return(false);
                }
                if (!DatabaseHelper.CheckDBPermission(DatabasePermission.CreateDatabase, AuthenticationType, ServerName, Username, Password))
                {
                    DisplaySeparationError(GetString("separationDB.permissioncreate"));
                    return(false);
                }
            }
        }

        // Test if tasks are stopped
        if (SchedulingHelper.EnableScheduler || SchedulingHelper.IsAnyTaskRunning())
        {
            DisplaySeparationError(GetString("separationDB.stoptaskserror"));
            return(false);
        }
        iconHelp.Visible = btnStopTasks.Visible = true;

        // Test if separation process is not already started.
        if (DatabaseSeparationHelper.SeparationInProgress)
        {
            DisplaySeparationError(GetString("separationDB.processalreadystarted"));
            return(false);
        }

        return(true);
    }
        public async Task BuildConnectionAsync()
        {
            ConnectionInProgress = true;

            string            connectionString  = "";
            CrmConnectionInfo crmConnectionInfo = null;


            ConnectionHelper connectionHelper = new ConnectionHelper();

            if (SelectedConnection != null)
            {
                crmConnectionInfo = SelectedConnection;
                connectionString  = connectionHelper.BuildConnectionString(SelectedConnection);
            }
            else
            {
                if (ConnectionItem == null || string.IsNullOrWhiteSpace(ConnectionItem.OrganizationURL) || !IsURLValid(ConnectionItem.OrganizationURL))
                {
                    SetMessageNotification(NotificationType.Error, "Please provide a  valid Organization URL");
                }

                if (string.IsNullOrWhiteSpace(ConnectionItem.AuthType))
                {
                    SetMessageNotification(NotificationType.Error, "Please provide Auth Type");
                }

                connectionString = connectionHelper.BuildConnectionString(ConnectionItem.OrganizationURL,
                                                                          ConnectionItem.AuthType,
                                                                          ConnectionItem.Domain,
                                                                          ConnectionItem.UserName,
                                                                          ConnectionItem.Password);
            }
            CrmServiceClient crmServiceClient = null;
            string           connectionError  = null;
            await Task.Factory.StartNew(() =>
            {
                try
                {
                    crmServiceClient = new CrmServiceClient(connectionString);

                    connectionError = crmServiceClient.LastCrmError;
                }
                catch (Exception ex)
                {
                    connectionError = ex.Message;
                }
            });

            if (!string.IsNullOrWhiteSpace(connectionError))
            {
                SetMessageNotification(NotificationType.Error, connectionError);
            }

            ConnectionInProgress = false;

            if (crmServiceClient != null && crmServiceClient.IsReady)
            {
                if (crmConnectionInfo == null)
                {
                    crmConnectionInfo = GetCrmConnectionInfo(crmServiceClient);

                    if (SaveConnection)
                    {
                        SaveConnectionInfo(crmConnectionInfo);
                    }
                }

                ConnectionComplete(crmConnectionInfo);
            }
        }
    protected void btnHiddenNext_onClick(object sender, EventArgs e)
    {
        StepOperation = 1;
        StepIndex++;

        switch (wzdInstaller.ActiveStepIndex)
        {
        case 0:
            // Set the authentication type
            AuthenticationType = userServer.WindowsAuthenticationChecked ? SQLServerAuthenticationModeEnum.WindowsAuthentication : SQLServerAuthenticationModeEnum.SQLServerAuthentication;

            // Check the server name
            if (String.IsNullOrEmpty(userServer.ServerName))
            {
                HandleError(ResHelper.GetFileString("Install.ErrorServerEmpty"));
                return;
            }

            // Do not allow to use empty user name or password
            bool isSQLAuthentication = AuthenticationType == SQLServerAuthenticationModeEnum.SQLServerAuthentication;
            if (isSQLAuthentication && (String.IsNullOrEmpty(userServer.DBUsername) || String.IsNullOrEmpty(userServer.DBPassword)))
            {
                HandleError(ResHelper.GetFileString("Install.ErrorUserNamePasswordEmpty"));
                return;
            }

            Password = userServer.DBPassword;

            // Check if it is possible to connect to the database
            string res = ConnectionHelper.TestConnection(AuthenticationType, userServer.ServerName, String.Empty, userServer.DBUsername, Password);
            if (!String.IsNullOrEmpty(res))
            {
                HandleError(res, "Install.ErrorSqlTroubleshoot", HELP_TOPIC_SQL_ERROR_LINK);
                return;
            }

            // Set credentials for the next step
            databaseDialog.AuthenticationType = AuthenticationType;
            databaseDialog.Password           = Password;
            databaseDialog.Username           = userServer.DBUsername;
            databaseDialog.ServerName         = userServer.ServerName;

            // Move to the next step
            wzdInstaller.ActiveStepIndex = 1;
            break;

        case 1:
        case COLLATION_DIALOG_INDEX:
            // Get database name
            Database = TextHelper.LimitLength(databaseDialog.CreateNewChecked ? databaseDialog.NewDatabaseName : databaseDialog.ExistingDatabaseName, 100);

            if (String.IsNullOrEmpty(Database))
            {
                HandleError(ResHelper.GetFileString("Install.ErrorDBNameEmpty"));
                return;
            }

            // Set up the connection string
            if (ConnectionHelper.IsConnectionStringInitialized)
            {
                ConnectionString = ConnectionHelper.ConnectionString;
            }
            else
            {
                ConnectionString = ConnectionHelper.BuildConnectionString(AuthenticationType, userServer.ServerName, Database, userServer.DBUsername, Password, SqlInstallationHelper.DB_CONNECTION_TIMEOUT);
            }

            // Check if existing DB has the same version as currently installed CMS
            if (databaseDialog.UseExistingChecked && !databaseDialog.CreateDatabaseObjects)
            {
                string dbVersion = null;
                try
                {
                    dbVersion = SqlInstallationHelper.GetDatabaseVersion(ConnectionString);
                }
                catch
                {
                }

                if (String.IsNullOrEmpty(dbVersion))
                {
                    // Unable to get DB version => DB objects missing
                    HandleError(ResHelper.GetFileString("Install.DBObjectsMissing"));
                    return;
                }

                if (dbVersion != CMSVersion.MainVersion)
                {
                    // Get wrong version number
                    HandleError(ResHelper.GetFileString("Install.WrongDBVersion"));
                    return;
                }
            }

            Info.LogContext = ctlAsyncDB.LogContext;

            // Use existing database
            if (databaseDialog.UseExistingChecked)
            {
                // Check if DB exists
                if (!DatabaseHelper.DatabaseExists(ConnectionString))
                {
                    HandleError(String.Format(ResHelper.GetFileString("Install.ErrorDatabseDoesntExist"), Database));
                    return;
                }

                // Get collation of existing DB
                string collation = DatabaseHelper.GetDatabaseCollation(ConnectionString);
                DatabaseHelper.DatabaseCollation = collation;

                if (wzdInstaller.ActiveStepIndex != COLLATION_DIALOG_INDEX)
                {
                    // Check target database collation and inform the user if it is not fully supported
                    if (!DatabaseHelper.IsSupportedDatabaseCollation(collation))
                    {
                        ucCollationDialog.IsSqlAzure = AzureHelper.IsSQLAzureServer(userServer.ServerName);
                        ucCollationDialog.Collation  = collation;
                        ucCollationDialog.InitControls();

                        // Move to "collation dialog" step
                        wzdInstaller.ActiveStepIndex = COLLATION_DIALOG_INDEX;
                        return;
                    }
                }
                else
                {
                    // Change database collation for regular database
                    if (ucCollationDialog.ChangeCollationRequested)
                    {
                        DatabaseHelper.ChangeDatabaseCollation(ConnectionString, Database, DatabaseHelper.DEFAULT_DB_COLLATION);
                    }
                }
            }
            else
            {
                // Create a new database
                if (!CreateDatabase(null))
                {
                    HandleError(String.Format(ResHelper.GetFileString("Install.ErrorCreateDB"), databaseDialog.NewDatabaseName));
                    return;
                }

                databaseDialog.ExistingDatabaseName = databaseDialog.NewDatabaseName;
                databaseDialog.CreateNewChecked     = false;
                databaseDialog.UseExistingChecked   = true;
            }

            if ((!SystemContext.IsRunningOnAzure && writePermissions) || ConnectionHelper.IsConnectionStringInitialized)
            {
                if (databaseDialog.CreateDatabaseObjects)
                {
                    if (DBInstalled && DBCreated)
                    {
                        ctlAsyncDB.RaiseFinished(this, EventArgs.Empty);
                    }
                    else
                    {
                        // Run SQL installation
                        RunSQLInstallation();
                    }
                }
                else
                {
                    CreateDBObjects = false;

                    // Set connection string
                    if (SettingsHelper.SetConnectionString(ConnectionHelper.ConnectionStringName, ConnectionString))
                    {
                        // Set the application connection string
                        SetAppConnectionString();

                        // Check if license key for current domain is present
                        LicenseKeyInfo lki = LicenseKeyInfoProvider.GetLicenseKeyInfo(hostName);
                        wzdInstaller.ActiveStepIndex = (lki == null) ? 4 : 5;
                        ucLicenseDialog.SetLicenseExpired();
                    }
                    else
                    {
                        ManualConnectionStringInsertion();
                    }
                }
            }
            else
            {
                ManualConnectionStringInsertion();
            }

            break;

        // After connection string save error
        case 2:
            // Check whether connection string is defined
            if (String.IsNullOrWhiteSpace(Service.Resolve <IConnectionStringService>()[ConnectionHelper.ConnectionStringName]))
            {
                HandleError(ResHelper.GetFileString("Install.ErrorAddConnString"));
                return;
            }

            ConnectionString = Service.Resolve <IConnectionStringService>()[ConnectionHelper.ConnectionStringName];

            if (CreateDBObjects)
            {
                if (DBInstalled)
                {
                    FinalizeDBInstallation();
                }
                else
                {
                    // Run SQL installation
                    RunSQLInstallation();
                }
            }
            else
            {
                // If this is installation to existing DB and objects are not created
                if ((hostName != "localhost") && (hostName != "127.0.0.1"))
                {
                    wzdInstaller.ActiveStepIndex = 4;
                }
                else
                {
                    wzdInstaller.ActiveStepIndex = 5;
                }
            }
            break;

        // After DB install
        case 3:
            break;

        // After license entering
        case 4:
            try
            {
                if (ucLicenseDialog.Visible)
                {
                    ucLicenseDialog.SetLicenseKey();
                    wzdInstaller.ActiveStepIndex = 5;
                }
                else if (ucWagDialog.ProcessRegistration(ConnectionString))
                {
                    wzdInstaller.ActiveStepIndex = 5;
                }
            }
            catch (Exception ex)
            {
                HandleError(ex.Message);
            }
            break;

        default:
            wzdInstaller.ActiveStepIndex++;
            break;
        }
    }