Beispiel #1
0
    /// <summary>
    /// Gets and bulk updates staging servers. Called when the "Get and bulk update servers" button is pressed.
    /// Expects the CreateStagingServer method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateStagingServers()
    {
        // Prepare the parameters
        string where = "ServerName LIKE N'MyNewServer%'";

        // Get the data for the current site
        DataSet servers = ServerInfoProvider.GetSiteServers(SiteContext.CurrentSiteID, where, null, -1, null, false);

        if (!DataHelper.DataSourceIsEmpty(servers))
        {
            // Loop through the individual items
            foreach (DataRow serverDr in servers.Tables[0].Rows)
            {
                // Create object from DataRow
                ServerInfo modifyServer = new ServerInfo(serverDr);

                // Update the properties
                modifyServer.ServerDisplayName = modifyServer.ServerDisplayName.ToUpper();

                // Save the changes
                ServerInfoProvider.SetServerInfo(modifyServer);
            }

            return(true);
        }

        return(false);
    }
Beispiel #2
0
        /// <inheritdoc/>
        public IServer Update(IServer server, bool isReplace = true)
        {
            // Gets the staging server
            ServerInfo updateServer = ServerInfoProvider.GetServerInfo(server.ServerName, server.ServerSiteID);

            if (updateServer != null)
            {
                if (isReplace)
                {
                    updateServer = server.UndoActLike();
                }
                else
                {
                    // Updates the server properties
                    updateServer.ServerDisplayName    = server.ServerDisplayName ?? updateServer.ServerDisplayName;
                    updateServer.ServerURL            = server.ServerURL ?? updateServer.ServerURL;
                    updateServer.ServerEnabled        = server.ServerEnabled == null ? updateServer.ServerEnabled : (bool)server.ServerEnabled;
                    updateServer.ServerAuthentication = server.ServerAuthentication;
                    updateServer.ServerUsername       = server.ServerUsername ?? updateServer.ServerUsername;
                    updateServer.ServerPassword       = server.ServerPassword ?? updateServer.ServerPassword;
                }

                // Saves the updated server to the database
                ServerInfoProvider.SetServerInfo(updateServer);
            }

            return(updateServer.ActLike <IServer>());
        }
Beispiel #3
0
    /// <summary>
    /// Gets and updates staging server. Called when the "Get and update server" button is pressed.
    /// Expects the CreateStagingServer method to be run first.
    /// </summary>
    private bool GetAndUpdateStagingServer()
    {
        // Get the staging server
        ServerInfo updateServer = ServerInfoProvider.GetServerInfo("MyNewServer", SiteContext.CurrentSiteID);

        if (updateServer != null)
        {
            // Update the properties
            updateServer.ServerDisplayName = updateServer.ServerDisplayName.ToLowerCSafe();

            // Save the changes
            ServerInfoProvider.SetServerInfo(updateServer);

            return(true);
        }

        return(false);
    }
Beispiel #4
0
        /// <inheritdoc/>
        public IServer Create(IServer server)
        {
            var newServer = new ServerInfo
            {
                ServerDisplayName    = server.ServerDisplayName,
                ServerName           = server.ServerName,
                ServerEnabled        = (bool)server.ServerEnabled,
                ServerURL            = server.ServerURL,
                ServerAuthentication = server.ServerAuthentication,
                ServerUsername       = server.ServerUsername,
                ServerPassword       = server.ServerPassword,
                ServerSiteID         = server.ServerSiteID,
            };

            // Saves the staging server to the database
            ServerInfoProvider.SetServerInfo(newServer);

            return(newServer.ActLike <IServer>());
        }
Beispiel #5
0
    /// <summary>
    /// Creates staging server. Called when the "Create server" button is pressed.
    /// </summary>
    private bool CreateStagingServer()
    {
        // Create new staging server object
        ServerInfo newServer = new ServerInfo();

        // Set the properties
        newServer.ServerDisplayName    = "My new server";
        newServer.ServerName           = "MyNewServer";
        newServer.ServerEnabled        = true;
        newServer.ServerSiteID         = SiteContext.CurrentSiteID;
        newServer.ServerURL            = "http://localhost/KenticoCMS/";
        newServer.ServerAuthentication = ServerAuthenticationEnum.UserName;
        newServer.ServerUsername       = "******";
        newServer.ServerPassword       = "******";

        // Save the staging server
        ServerInfoProvider.SetServerInfo(newServer);

        return(true);
    }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check 'Manage servers' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.staging", "ManageServers"))
        {
            RedirectToAccessDenied("cms.staging", "ManageServers");
        }

        string errorMessage = new Validator().NotEmpty(txtServerDisplayName, GetString("General.requiresDisplayName")).NotEmpty(txtServerName, GetString("General.RequiresCodeName")).
                              IsCodeName(txtServerName.Text, GetString("general.invalidcodename"))
                              .Result;

        if (errorMessage == "")
        {
            // Server name must be unique
            serverObj = ServerInfoProvider.GetServerInfo(txtServerName.Text.Trim(), CMSContext.CurrentSite.SiteID);

            // If server name is unique
            if ((serverObj == null) || (serverObj.ServerID == serverID))
            {
                // If server name is unique -> determine whether it is update or insert
                if ((serverObj == null))
                {
                    // Get ServerInfo object by primary key
                    serverObj = ServerInfoProvider.GetServerInfo(serverID) ?? new ServerInfo();
                }

                serverObj.ServerSiteID          = CMSContext.CurrentSite.SiteID;
                serverObj.ServerX509ServerKeyID = txtServerX509ServerKeyID.Text.Trim();
                serverObj.ServerPassword        = encryptedPassword.Value.ToString();
                serverObj.ServerAuthentication  = (radX509.Checked) ? ServerAuthenticationEnum.X509 : ServerAuthenticationEnum.UserName;
                serverObj.ServerDisplayName     = txtServerDisplayName.Text.Trim();
                serverObj.ServerURL             = txtServerURL.Text.Trim();
                serverObj.ServerX509ClientKeyID = txtServerX509ClientKeyID.Text.Trim();
                serverObj.ServerName            = txtServerName.Text.Trim();
                serverObj.ServerUsername        = txtServerUsername.Text.Trim();
                serverObj.ServerEnabled         = chkServerEnabled.Checked;

                ServerInfoProvider.SetServerInfo(serverObj);

                // Refresh breadcrumbs
                InitializeBreadcrumbs(serverObj.ServerDisplayName);

                ShowChangesSaved();

                if (serverID <= 0)
                {
                    string detailUrl = "Server_Edit.aspx?serverid=" + serverObj.ServerID + "&saved=1";
                    detailUrl = URLHelper.AddParameterToUrl(detailUrl, "hash", QueryHelper.GetHash(detailUrl));

                    URLHelper.Redirect(detailUrl);
                }
            }
            else
            {
                ShowError(GetString("Server_Edit.ServerNameExists"));
            }
        }
        else
        {
            ShowError(errorMessage);
        }
    }