/// <summary> /// Handles after validation event of UIForm. /// </summary> protected void OnAfterValidate(object sender, EventArgs e) { // Perform additional validation if web farm server is enabled if (ValidationHelper.GetBoolean(Control.GetFieldValue("ServerEnabled"), false)) { // Get the web farm server object var serverId = QueryHelper.GetInteger("objectid", 0); var webFarm = WebFarmServerInfoProvider.GetWebFarmServerInfo(serverId) ?? new WebFarmServerInfo(); // Get current license var currentLicense = LicenseContext.CurrentLicenseInfo; if (currentLicense == null) { return; } // Enabling or new server as action insert var action = ((webFarm.ServerID > 0) && webFarm.ServerEnabled) ? ObjectActionEnum.Edit : ObjectActionEnum.Insert; if (!currentLicense.CheckServerCount(WebSyncHelper.ServerCount, action)) { // Set validation message Control.ValidationErrorMessage = ResHelper.GetStringFormat("licenselimitation.infopagemessage", FeatureEnum.Webfarm.ToStringRepresentation()); Control.StopProcessing = true; // Log "servers exceeded" event var message = ResHelper.GetString("licenselimitation.serversexceeded"); EventLogProvider.LogEvent(EventType.WARNING, "WebFarms", LicenseHelper.LICENSE_LIMITATION_EVENTCODE, message, RequestContext.CurrentURL); } } }
/// <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); } }
/// <summary> /// Deletes web farm server. Called when the "Delete server" button is pressed. /// Expects the CreateWebFarmServer method to be run first. /// </summary> private bool DeleteWebFarmServer() { // Get the web farm server WebFarmServerInfo deleteServer = WebFarmServerInfoProvider.GetWebFarmServerInfo("MyNewServer"); // Delete the web farm server WebFarmServerInfoProvider.DeleteWebFarmServerInfo(deleteServer); return(deleteServer != null); }
protected void Page_Load(object sender, EventArgs e) { this.CurrentMaster.Title.HelpTopicName = "webfarm_server_list"; // Initialize breadcrumbs string[,] pageTitleTabs = new string[2, 3]; pageTitleTabs[0, 0] = GetString("WebFarmServers_Edit.WebFarmServers"); pageTitleTabs[0, 1] = "~/CMSModules/WebFarm/Pages/WebFarm_Server_List.aspx"; pageTitleTabs[0, 2] = ""; pageTitleTabs[1, 1] = ""; pageTitleTabs[1, 2] = ""; pageTitleTabs[1, 0] = GetString("WebFarmServers_Edit.New"); btnOk.Text = GetString("general.ok"); rfvCodeName.ErrorMessage = GetString("general.requirescodename"); rfvURL.ErrorMessage = GetString("WebFarmServers_Edit.UrlEmpty"); rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname"); // Get server ID serverid = QueryHelper.GetInteger("serverid", 0); if (serverid > 0) { WebFarmServerInfo wi = WebFarmServerInfoProvider.GetWebFarmServerInfo(serverid); if (wi == null) { lblError.Visible = true; lblError.Text = GetString("WebFarmServers_Edit.InvalidServerID"); plcEditForm.Visible = false; } else { pageTitleTabs[1, 0] = HTMLHelper.HTMLEncode(wi.ServerDisplayName); if (!RequestHelper.IsPostBack()) { txtCodeName.Text = wi.ServerName; txtDisplayName.Text = wi.ServerDisplayName; txtURL.Text = wi.ServerURL; chkEnabled.Checked = wi.ServerEnabled; } } } this.CurrentMaster.Title.Breadcrumbs = pageTitleTabs; // Associate server checker control serverChecker.TextBoxControlID = txtURL.ID; if (ValidationHelper.GetString(Request.QueryString["saved"], "") != "") { lblInfo.Text = GetString("General.ChangesSaved"); lblInfo.Visible = true; } }
/// <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); }
/// <summary> /// Handles external databound event of unigrid. /// </summary> protected object OnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLowerCSafe()) { case "serveredit": if (WebFarmContext.WebFarmMode == WebFarmModeEnum.Automatic) { CMSGridActionButton button = (CMSGridActionButton)sender; button.Enabled = false; button.ToolTip = LocalizationHelper.GetString("webfarmservers_list.disablededit"); } break; case "serverenabled": return(UniGridFunctions.ColoredSpanYesNo(parameter)); case "serverstatus": var server = WebFarmServerInfoProvider.GetWebFarmServerInfo(ValidationHelper.GetInteger(parameter, 0)); switch (server.Status) { case WebFarmServerStatusEnum.Healthy: return(new Tag { Text = ResHelper.GetString("webfarmservers_list.status.healthy"), Color = "#497d04" }); case WebFarmServerStatusEnum.Transitioning: return(new Tag { Text = ResHelper.GetString("webfarmservers_list.status.transitioning"), Color = "#c98209" }); default: return(new Tag { Text = ResHelper.GetString("webfarmservers_list.status.notresponding"), Color = "#b12628" }); } } return(parameter); }
/// <summary> /// Handles after validation event of UIForm. /// </summary> protected void OnAfterValidate(object sender, EventArgs e) { // Perform additional validation if web farm server is enabled if (ValidationHelper.GetBoolean(Control.GetFieldValue("ServerEnabled"), false)) { // Get the web farm server object var serverId = QueryHelper.GetInteger("objectid", 0); var webFarmServer = WebFarmServerInfoProvider.GetWebFarmServerInfo(serverId) ?? new WebFarmServerInfo(); if (!webFarmServer.ServerEnabled && !WebFarmLicenseHelper.CanAddServer) { // Set validation message Control.ValidationErrorMessage = ResHelper.GetStringFormat("licenselimitation.infopagemessage", FeatureEnum.Webfarm.ToStringRepresentation()); Control.StopProcessing = true; // Log "servers exceeded" event var message = ResHelper.GetString("licenselimitation.serversexceeded"); EventLogProvider.LogEvent(EventType.WARNING, "WebFarms", LicenseHelper.LICENSE_LIMITATION_EVENTCODE, message, RequestContext.CurrentURL); } } }
/// <summary> /// Run task list. /// </summary> protected void btnRunTasks_Click(object sender, EventArgs e) { switch (selectedServer) { case allServers: WebSyncHelper.SynchronizeWebFarm(true); // Call synchronization method WebSyncHelper.ProcessMyTasks(); break; default: // Get the server info object WebFarmServerInfo wfsi = WebFarmServerInfoProvider.GetWebFarmServerInfo(SqlHelperClass.GetSafeQueryString(selectedServer, false)); // If server is enabled if (wfsi.ServerEnabled) { if (wfsi.ServerName.ToLower() == WebSyncHelperClass.ServerName.ToLower()) { // Call synchronization method WebSyncHelper.ProcessMyTasks(); } else { if (WebSyncHelperClass.Servers.Contains(wfsi.ServerID)) { WebFarmUpdaterAsync wfu = new WebFarmUpdaterAsync(); // Add server for sync wfu.Urls.Add(wfsi.ServerURL.TrimEnd('/') + WebSyncHelperClass.WebFarmUpdaterPage); } } } break; } UniGrid.ReloadData(); // Show info label lblInfo.Text = GetString("webfarmtasks.taskexecuted"); lblInfo.Visible = true; }
/// <summary> /// Handles the UniGrid's OnAction event. /// </summary> /// <param name="actionName">Name of item (button) that throws event</param> /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param> protected void uniGrid_OnAction(string actionName, object actionArgument) { if (actionName == "delete") { // Delete object from database if (selectedServer == allServers) { // Delete task object WebFarmTaskInfoProvider.DeleteWebFarmTaskInfo(Convert.ToInt32(actionArgument)); } else { // Get infos for task and server WebFarmTaskInfo wfti = WebFarmTaskInfoProvider.GetWebFarmTaskInfo(Convert.ToInt32(actionArgument)); WebFarmServerInfo wfsi = WebFarmServerInfoProvider.GetWebFarmServerInfo(selectedServer); // Delete task binding to server WebFarmTaskInfoProvider.DeleteServerTask(wfsi.ServerID, wfti.TaskID); } UniGrid.ReloadData(); } }
/// <summary> /// Run task list. /// </summary> private void RunTasks() { switch (selectedServer) { case allServers: { WebSyncHelper.NotifyServers(true); WebSyncHelper.ProcessMyTasks(); } break; default: // Get the server info object WebFarmServerInfo wfsi = WebFarmServerInfoProvider.GetWebFarmServerInfo(SqlHelper.GetSafeQueryString(selectedServer, false)); // If server is enabled if (wfsi.ServerEnabled) { if (wfsi.ServerName.ToLowerCSafe() == WebSyncHelper.ServerName.ToLowerCSafe()) { // Call synchronization method WebSyncHelper.ProcessMyTasks(); } else if (WebSyncHelper.EnabledServers.Any(s => s.ServerID == wfsi.ServerID)) { WebFarmUpdaterAsync wfu = new WebFarmUpdaterAsync(); // Add server for sync wfu.Urls.Add(wfsi.ServerURL); wfu.Run(); } } break; } UniGrid.ReloadData(); // Show info label ShowInformation(GetString("webfarmtasks.taskexecuted")); }
protected void Page_Load(object sender, EventArgs e) { this.timRefresh.Interval = 1000 * ValidationHelper.GetInteger(this.drpRefresh.SelectedValue, 0); // Check permissions RaiseOnCheckPermissions("READ", this); if (StopProcessing) { return; } // Get values from counters long totalSystemRequests = RequestHelper.TotalSystemPageRequests.GetValue(null); long totalPageRequests = RequestHelper.TotalPageRequests.GetValue(null); long totalPageNotFoundRequests = RequestHelper.TotalPageNotFoundRequests.GetValue(null); long totalNonPageRequests = RequestHelper.TotalNonPageRequests.GetValue(null); long totalGetFileRequests = RequestHelper.TotalGetFileRequests.GetValue(null); // Reevaluate RPS if (mLastRPS != DateTime.MinValue) { double seconds = DateTime.Now.Subtract(mLastRPS).TotalSeconds; if ((seconds < 3) && (seconds > 0)) { mRPSSystemPageRequests = (totalSystemRequests - mLastSystemPageRequests) / seconds; mRPSPageRequests = (totalPageRequests - mLastPageRequests) / seconds; mRPSPageNotFoundRequests = (totalPageNotFoundRequests - mLastPageNotFoundRequests) / seconds; mRPSNonPageRequests = (totalNonPageRequests - mLastNonPageRequests) / seconds; mRPSGetFileRequests = (totalGetFileRequests - mLastGetFileRequests) / seconds; } else { mRPSGetFileRequests = -1; mRPSNonPageRequests = -1; mRPSPageNotFoundRequests = -1; mRPSPageRequests = -1; mRPSSystemPageRequests = -1; } } mLastRPS = DateTime.Now; // Update last values mLastGetFileRequests = totalGetFileRequests; mLastNonPageRequests = totalNonPageRequests; mLastPageNotFoundRequests = totalPageNotFoundRequests; mLastPageRequests = totalPageRequests; mLastSystemPageRequests = totalSystemRequests; // Do not count this page with async postback if (RequestHelper.IsAsyncPostback()) { RequestHelper.TotalSystemPageRequests.Decrement(null); } pnlSystemInfo.GroupingText = GetString("Administration-System.SystemInfo"); pnlSystemTime.GroupingText = GetString("Administration-System.SystemTimeInfo"); pnlDatabaseInfo.GroupingText = GetString("Administration-System.DatabaseInfo"); lblServerName.Text = GetString("Administration-System.ServerName"); lblServerVersion.Text = GetString("Administration-System.ServerVersion"); lblDBName.Text = GetString("Administration-System.DatabaseName"); lblDBSize.Text = GetString("Administration-System.DatabaseSize"); lblMachineName.Text = GetString("Administration-System.MachineName"); lblMachineNameValue.Text = HTTPHelper.MachineName; lblAspAccount.Text = GetString("Administration-System.Account"); lblValueAspAccount.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name; // Get application pool name lblPool.Text = GetString("Administration-System.Pool"); lblValuePool.Text = GetString("General.NA"); try { lblValuePool.Text = SystemHelper.GetApplicationPoolName(); } catch { } // Get application trust level lblTrustLevel.Text = GetString("Administration-System.TrustLevel"); lblValueTrustLevel.Text = GetString("General.NA"); try { lblValueTrustLevel.Text = SystemHelper.CurrentTrustLevel.ToString(); } catch { } lblAspVersion.Text = GetString("Administration-System.Version"); lblValueAspVersion.Text = System.Environment.Version.ToString(); pnlMemory.GroupingText = GetString("Administration-System.MemoryStatistics"); lblAlocatedMemory.Text = GetString("Administration-System.Memory"); lblPeakMemory.Text = GetString("Administration-System.PeakMemory"); lblVirtualMemory.Text = GetString("Administration-System.VirtualMemory"); lblPhysicalMemory.Text = GetString("Administration-System.PhysicalMemory"); lblIP.Text = GetString("Administration-System.IP"); pnlPageViews.GroupingText = GetString("Administration-System.PageViews"); lblPageViewsValues.Text = GetString("Administration-System.PageViewsValues"); lblPages.Text = GetString("Administration-System.Pages"); lblSystemPages.Text = GetString("Administration-System.SystemPages"); lblNonPages.Text = GetString("Administration-System.NonPages"); lblGetFilePages.Text = GetString("Administration-System.GetFilePages"); lblPagesNotFound.Text = GetString("Administration-System.PagesNotFound"); lblPending.Text = GetString("Administration-System.Pending"); pnlCache.GroupingText = GetString("Administration-System.CacheStatistics"); lblCacheExpired.Text = GetString("Administration-System.CacheExpired"); lblCacheRemoved.Text = GetString("Administration-System.CacheRemoved"); lblCacheUnderused.Text = GetString("Administration-System.CacheUnderused"); lblCacheItems.Text = GetString("Administration-System.CacheItems"); lblCacheDependency.Text = GetString("Administration-System.CacheDependency"); pnlGC.GroupingText = GetString("Administration-System.GC"); btnClear.Text = GetString("Administration-System.btnClear"); btnClearCache.Text = GetString("Administration-System.btnClearCache"); btnRestart.Text = GetString("Administration-System.btnRestart"); btnRestartWebfarm.Text = GetString("Administration-System.btnRestartWebfarm"); btnClearCounters.Text = GetString("Administration-System.btnClearCounters"); btnRestartServices.Text = GetString("Administration-System.btnRestartServices"); // Hide button if wefarms are not enabled or disallow restarting webfarms for Windows Azure if (!WebSyncHelperClass.WebFarmEnabled || AzureHelper.IsRunningOnAzure) { this.btnRestartWebfarm.Visible = false; } // Hide the web farm restart button if this web farm server is not enabled if (!RequestHelper.IsPostBack()) { WebFarmServerInfo webFarmServerObj = WebFarmServerInfoProvider.GetWebFarmServerInfo(WebSyncHelperClass.ServerName); if ((webFarmServerObj != null) && (!webFarmServerObj.ServerEnabled)) { this.btnRestartWebfarm.Visible = false; } } // Hide restart service button if services folder doesn't exist this.btnRestartServices.Visible = SystemHelper.IsFullTrustLevel && WinServiceHelper.ServicesAvailable(); // Hide the performance counters clear button if the health monitoring is not enabled or feature is not available this.btnClearCounters.Visible = SystemHelper.IsFullTrustLevel && LicenseHelper.CheckFeature(URLHelper.GetCurrentDomain(), FeatureEnum.HealthMonitoring); LoadData(); if (!RequestHelper.IsPostBack()) { switch (QueryHelper.GetString("lastaction", String.Empty).ToLower()) { case "restarted": lblInfo.Text = GetString("Administration-System.RestartSuccess"); break; case "webfarmrestarted": if (ValidationHelper.ValidateHash("WebfarmRestarted", QueryHelper.GetString("restartedhash", String.Empty))) { lblInfo.Text = GetString("Administration-System.WebframRestarted"); // Restart other servers - create webfarm task for application restart WebSyncHelperClass.CreateTask(WebFarmTaskTypeEnum.RestartApplication, "RestartApplication", "", null); } else { lblInfo.Text = GetString("general.actiondenied"); } break; case "countercleared": lblInfo.Text = GetString("Administration-System.CountersCleared"); break; case "winservicesrestarted": lblInfo.Text = GetString("Administration-System.WinServicesRestarted"); break; } } lblRunTime.Text = GetString("Administration.System.RunTime"); lblServerTime.Text = GetString("Administration.System.ServerTime"); // Remove miliseconds from the end of the time string string timeSpan = (DateTime.Now - CMSAppBase.ApplicationStart).ToString(); int index = timeSpan.LastIndexOf('.'); if (index >= 0) { timeSpan = timeSpan.Remove(index); } // Display application run time lblRunTimeValue.Text = timeSpan; lblServerTimeValue.Text = Convert.ToString(DateTime.Now) + " " + TimeZoneHelper.GetGMTStringOffset(TimeZoneHelper.ServerTimeZone); lblIPValue.Text = Request.UserHostAddress; }
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; } }