// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; public partial class Config : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Spludlow.WebControls.DisableOnClick(this); if (this.IsPostBack == false) { string urlTemplate = "Generic.aspx?MIME=text&A=Spludlow&T=Spludlow.ConfigMake&M=Create&P=@Host,@Offline"; DataTable table = Spludlow.Data.TextTable.ReadText(new string[] { "HostId ConfigMakeOnline ConfigMakeOffline", "String* String String", }); foreach (string host in Spludlow.Config.Hosts()) { string hostTemplate = urlTemplate.Replace("@Host", host); table.Rows.Add(new object[] { host, hostTemplate.Replace("@Offline", "False"), hostTemplate.Replace("@Offline", "True") }); } this.GridViewHosts.DataSource = table; this.GridViewHosts.DataBind(); this.DropDownListFlags.Items.Add("IgnoreSecurityKey"); this.DropDownListFlags.Items.Add("SystemUpdateMode"); this._ShowTables(); } } protected void ButtonQuery_Click(object sender, EventArgs e) { this._ShowTables(); } private void _ShowTables() { this.DataTableEditOrganizations.ShowData("@Spludlow", "Organizations", new DataTableEdit.DataLoadedHandler(FixTable)); this.DataTableEditNetworks.ShowData("@Spludlow", "Networks", new DataTableEdit.DataLoadedHandler(FixTable)); this.DataTableEditHosts.ShowData("@Spludlow", "Hosts", new DataTableEdit.DataLoadedHandler(FixTable)); Spludlow.Data.IDAL dal = Spludlow.Data.DAL.Create("@Spludlow"); DataTable table = dal.Select("SELECT NetworkId FROM Networks"); this.DropDownListNetwork.DataSource = table; this.DropDownListNetwork.DataValueField = "NetworkId"; this.DropDownListNetwork.DataValueField = "NetworkId"; this.DropDownListNetwork.DataBind(); } public static void FixTable(DataTable table) { foreach (DataRow row in table.Rows) row["Configuration"] = ((string)row["Configuration"]).Length.ToString(); } protected void ButtonToggleHosts_Click(object sender, EventArgs e) { foreach (GridViewRow row in this.GridViewHosts.Rows) { CheckBox checkBox = (CheckBox)row.FindControl("CheckBoxHost"); checkBox.Checked = ! checkBox.Checked; } } protected void ButtonSend_Click(object sender, EventArgs e) { string[] hosts = Spludlow.WebControls.CheckedKeysString(this.GridViewHosts, "CheckBoxHost", "HostId"); Spludlow.ReleaseConfig.Send(hosts); this.LabelError.Text = "Config Sent."; } protected void ButtonFlagTrue_Click(object sender, EventArgs e) { Spludlow.ConfigMake.SetFlagAllHosts(this.DropDownListFlags.SelectedValue, true); this._ShowTables(); } protected void ButtonFlagFalse_Click(object sender, EventArgs e) { Spludlow.ConfigMake.SetFlagAllHosts(this.DropDownListFlags.SelectedValue, false); this._ShowTables(); } protected void ButtonAddHost_Click(object sender, EventArgs e) { List textBoxes = new List(new TextBox[] { this.TextBoxMachineName, this.TextBoxSpludlowWebServiceAdmin, this.TextBoxSpludlowWebService, }); bool valid = Spludlow.WebControls.TrimRequired(textBoxes.ToArray()); if (valid == false) { this.LabelError.Text = "Please supply the 3 values for adding a new node host."; return; } Spludlow.Data.IDAL dal = Spludlow.Data.DAL.Create("@Spludlow"); Spludlow.Schema.HostsDataTable table = new Spludlow.Schema.HostsDataTable(); Spludlow.Schema.HostsRow row = table.NewHostsRow(); row.HostId = this.TextBoxMachineName.Text.ToUpper(); row.NetworkId = this.DropDownListNetwork.SelectedValue; row.Disabled = false; row.Notes = ""; row.Configuration = ""; row.LocalWebAddress = "https://" + this.TextBoxMachineName.Text.ToLower() + "/" + this.TextBoxSpludlowWebService.Text + "/"; row.PublicWebAddress = ""; row.AdminWebAddress = "https://localhost/" + this.TextBoxSpludlowWebServiceAdmin.Text + "/Admin.svc"; row.DevelopSource = false; row.IgnoreSecurityKey = true; row.SystemUpdateMode = true; dal.Insert(row); foreach (TextBox textBox in textBoxes) textBox.Text = ""; this.LabelError.Text = "New host added: " + row.HostId; this._ShowTables(); } }