// 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.Text; using System.Threading.Tasks; using System.IO; using System.Data; namespace Spludlow { public class ReleaseConfig { public static void Send() { Send(Spludlow.Config.Hosts()); } public static void Send(string[] hosts) { Task[] tasks = new Task[hosts.Length]; for (int index = 0; index < hosts.Length; ++index) { string host = hosts[index]; tasks[index] = new Task(() => SendWorker(host)); } foreach (Task task in tasks) task.Start(); Task.WaitAll(tasks); } public static void SendWorker(string host) { string config = Spludlow.ConfigMake.Create(host); Spludlow.Call.Queue(host + ":Sys", "Spludlow", "Spludlow.ReleaseConfig", "Receive", new object[] { Spludlow.Text.GetBytes(config) }); Spludlow.Log.Info("Config Send to:\t" + host); } public static void Receive(byte[] config) { string filename = Spludlow.Config.ProgramData + @"\Config\Spludlow.config"; if (File.Exists(filename) == true) Spludlow.Io.Files.DeletePersistently(filename); File.WriteAllBytes(filename, config); Spludlow.Log.Report("Config Receive at:\t" + Environment.MachineName); Spludlow.Status.ReStartAll(); } public static void RestartApplications() { DataTable table = Spludlow.Config.Applications().Tables[0]; List webAppPools = new List(); List services = new List(); foreach (DataRow row in table.Rows) { if (row.IsNull("Hosted") == true) continue; string appType = (string)row["ApplicationType"]; string hosted = (string)row["Hosted"]; if (appType == "Web") { if (webAppPools.Contains(hosted) == false) webAppPools.Add(hosted); } if (appType == "Service") { if (services.Contains(hosted) == false) services.Add(hosted); } } string adminWebKey = "Spludlow-WebService-Admin"; if (webAppPools.Contains(adminWebKey) == true) { Spludlow.Admin.WebRecycle(adminWebKey); webAppPools.Remove(adminWebKey); } if (webAppPools.Count > 0) Spludlow.Admin.WebRecycles(webAppPools.ToArray()); if (services.Count > 0) { foreach (string service in services) { try { Spludlow.Admin.ServiceStop(service); System.Threading.Thread.Sleep(0); Spludlow.Admin.ServiceStart(service); Spludlow.Log.Report("Restarted Service:\t" + service); } catch (Exception ee) { Spludlow.Log.Error("Restarting Service:\t" + service, ee); } } } } } }