Exemplo n.º 1
0
    /// <summary>
    /// Gets and bulk updates web farm servers. Called when the "Get and bulk update servers" button is pressed.
    /// Expects the CreateWebFarmServer method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateWebFarmServers()
    {
        // Get the data
        DataSet servers = WebFarmServerInfoProvider.GetAllEnabledServers();

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

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

                // Save the changes
                WebFarmServerInfoProvider.SetWebFarmServerInfo(modifyServer);
            }

            return(true);
        }

        return(false);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Initializes the web farm environment
    /// </summary>
    public static void InitWebFarm()
    {
        // Delete memory synchronization tasks
        WebSyncHelper.DeleteMemorySynchronizationTasks();

        string serverDisplayName = string.Empty;
        string serverUrl         = string.Empty;
        bool   createServer      = false;

        // Create web farm server if running on Azure
        if (AzureHelper.IsRunningOnAzure)
        {
            // Set web farm server name
            WebSyncHelperClass.ServerName = ValidationHelper.GetCodeName(AzureHelper.CurrentInstanceID);
            serverDisplayName             = AzureHelper.CurrentInstanceID;
            serverUrl = AzureHelper.CurrentInternalEndpoint;

            createServer = true;
        }
        // Get dynamic name for server name
        else if (WebSyncHelperClass.GenerateWebFarmServers)
        {
            WebSyncHelperClass.WebFarmEnabled = true;
            serverUrl    = HTTPHelper.UserHostAddress + SettingsKeyProvider.ApplicationPath.TrimEnd('/') + WebSyncHelperClass.WebFarmUpdaterPage;
            createServer = true;

            if (string.IsNullOrEmpty(WebSyncHelperClass.ServerName))
            {
                serverDisplayName             = WebFarmServerInfoProvider.GetAutomaticServerName();
                WebSyncHelperClass.ServerName = ValidationHelper.GetCodeName(serverDisplayName);
            }
            else
            {
                serverDisplayName = WebSyncHelperClass.ServerName;
            }
        }

        // Create new web farm server if is needed
        if (createServer)
        {
            string serverName = WebSyncHelperClass.ServerName;

            // Create web farm server
            WebFarmServerInfo wfsi = WebFarmServerInfoProvider.GetWebFarmServerInfo(serverName);
            if (wfsi == null)
            {
                wfsi = new WebFarmServerInfo();
            }

            wfsi.ServerName        = serverName;
            wfsi.ServerEnabled     = true;
            wfsi.ServerDisplayName = serverDisplayName;
            wfsi.ServerURL         = serverUrl;

            WebFarmServerInfoProvider.SetWebFarmServerInfo(wfsi);
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Creates web farm server. Called when the "Create server" button is pressed.
    /// </summary>
    private bool CreateWebFarmServer()
    {
        // Create new web farm server object
        WebFarmServerInfo newServer = new WebFarmServerInfo();

        // Set the properties
        newServer.ServerDisplayName = "My new server";
        newServer.ServerName        = "MyNewServer";
        newServer.ServerEnabled     = true;
        newServer.ServerURL         = "http://localhost/KenticoCMS";

        // Save the web farm server
        WebFarmServerInfoProvider.SetWebFarmServerInfo(newServer);

        return(true);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Gets and updates web farm server. Called when the "Get and update server" button is pressed.
    /// Expects the CreateWebFarmServer method to be run first.
    /// </summary>
    private bool GetAndUpdateWebFarmServer()
    {
        // Get the web farm server
        WebFarmServerInfo updateServer = WebFarmServerInfoProvider.GetWebFarmServerInfo("MyNewServer");

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

            // Save the changes
            WebFarmServerInfoProvider.SetWebFarmServerInfo(updateServer);

            return(true);
        }

        return(false);
    }
Exemplo n.º 5
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string result = new Validator().NotEmpty(rfvDisplayName, rfvDisplayName.ErrorMessage).NotEmpty(rfvCodeName, rfvCodeName.ErrorMessage).NotEmpty(rfvURL, rfvURL.ErrorMessage)
                        .IsCodeName(txtCodeName.Text, GetString("general.invalidcodename"))
                        .Result;

        // Get the object
        WebFarmServerInfo wi = WebFarmServerInfoProvider.GetWebFarmServerInfo(serverid) ?? new WebFarmServerInfo();

        // Check license web farm server limit
        if (String.IsNullOrEmpty(result))
        {
            LicenseKeyInfo lki = LicenseHelper.CurrentLicenseInfo;
            if (lki == null)
            {
                return;
            }

            // Only if server is enabled
            if (chkEnabled.Checked)
            {
                // Enabling or new server as action insert
                VersionActionEnum action = ((wi.ServerID > 0) && wi.ServerEnabled) ? VersionActionEnum.Edit : VersionActionEnum.Insert;
                if (!lki.CheckServerCount(WebSyncHelperClass.ServerCount, action))
                {
                    result = GetString("licenselimitation.infopagemessage");
                }

                // Log the message
                if (!String.IsNullOrEmpty(result))
                {
                    EventLogProvider eventLog = new EventLogProvider();
                    string           message  = GetString("licenselimitation.serversexceeded");
                    eventLog.LogEvent(EventLogProvider.EVENT_TYPE_WARNING, DateTime.Now, "WebFarms", LicenseHelper.LICENSE_LIMITATION_EVENTCODE, URLHelper.CurrentURL, message);
                }
            }
        }


        if (result == "")
        {
            wi.ServerID          = serverid;
            wi.ServerDisplayName = txtDisplayName.Text;
            wi.ServerName        = txtCodeName.Text;
            wi.ServerURL         = txtURL.Text;
            wi.ServerEnabled     = chkEnabled.Checked;
            try
            {
                WebFarmServerInfoProvider.SetWebFarmServerInfo(wi);
                // Clear server list
                URLHelper.Redirect("WebFarm_Server_Edit.aspx?serverid=" + wi.ServerID + "&saved=1");
            }
            catch (Exception ex)
            {
                lblError.Text    = ex.Message.Replace("%%name%%", wi.ServerName);
                lblError.Visible = true;
                lblInfo.Visible  = false;
            }
        }
        else
        {
            lblError.Text    = result;
            lblError.Visible = true;
            lblInfo.Visible  = false;
        }
    }