public static void cmsStart() { try { // Set the base-path and check the CMS has been installed basePath = AppDomain.CurrentDomain.BaseDirectory; if (basePath.EndsWith("\\")) { basePath = basePath.Remove(basePath.Length - 1, 1); } if (!File.Exists(basePath + "\\CMS.config")) { state = State.NotInstalled; return; } // Load the connector settings XmlDocument doc = new XmlDocument(); doc.LoadXml(File.ReadAllText(basePath + "\\CMS.config")); connHost = doc["settings"]["db"]["host"].InnerText; connPort = int.Parse(doc["settings"]["db"]["port"].InnerText); connDatabase = doc["settings"]["db"]["database"].InnerText; connUsername = doc["settings"]["db"]["username"].InnerText; connPassword = doc["settings"]["db"]["password"].InnerText; // Set the global connector globalConnector = connectorCreate(true); // Load and start e-mail queue service if (doc["settings"]["mail"]["host"].InnerText.Length == 0 || doc["settings"]["mail"]["port"].InnerText.Length == 0 || doc["settings"]["mail"]["username"].InnerText.Length == 0 || doc["settings"]["mail"]["address"].InnerText.Length == 0) { // Create disabled e-mail queue emailQueue = new Misc.EmailQueue(); } else { emailQueue = new Misc.EmailQueue(doc["settings"]["mail"]["host"].InnerText, int.Parse(doc["settings"]["mail"]["port"].InnerText), doc["settings"]["mail"]["username"].InnerText, doc["settings"]["mail"]["password"].InnerText, doc["settings"]["mail"]["address"].InnerText); } emailQueue.start(); // Wipe the cache folder string cachePath = basePath + "\\Cache"; if (Directory.Exists(cachePath)) { // We don't just delete the directory because something could be in-use..hence we try to delete as much as possible try { foreach (string file in Directory.GetFiles(cachePath, "*", SearchOption.AllDirectories)) { File.Delete(file); } foreach (string dir in Directory.GetDirectories(cachePath, "*", SearchOption.AllDirectories)) { Directory.Delete(dir); } } catch { } } // Load settings settings = new Misc.Settings(); settings.reload(globalConnector); // Load templates templates = new Misc.HtmlTemplates(globalConnector); // Invoke plugins foreach (ResultRow plugin in globalConnector.Query_Read("SELECT pluginid, classpath FROM plugins WHERE state='" + (int)Plugins.Base.State.Enabled + "' ORDER BY invoke_order ASC")) { try { Misc.Plugins.invokeMethod(plugin["classpath"], "cmsStart", new object[] { plugin["pluginid"], globalConnector }); } catch { } } // Complete state = State.Started; // Begin cycler cyclerStart(); } catch (Exception ex) { state = State.CriticalFailure; criticalFailureError = ex; } }
public static void cmsStart() { try { // Set the base-path and check the CMS has been installed basePath = AppDomain.CurrentDomain.BaseDirectory; if (basePath.EndsWith("\\")) basePath = basePath.Remove(basePath.Length - 1, 1); if (!File.Exists(basePath + "\\CMS.config")) { state = State.NotInstalled; return; } // Load the connector settings XmlDocument doc = new XmlDocument(); doc.LoadXml(File.ReadAllText(basePath + "\\CMS.config")); connHost = doc["settings"]["db"]["host"].InnerText; connPort = int.Parse(doc["settings"]["db"]["port"].InnerText); connDatabase = doc["settings"]["db"]["database"].InnerText; connUsername = doc["settings"]["db"]["username"].InnerText; connPassword = doc["settings"]["db"]["password"].InnerText; // Set the global connector globalConnector = connectorCreate(true); // Load and start e-mail queue service if (doc["settings"]["mail"]["host"].InnerText.Length == 0 || doc["settings"]["mail"]["port"].InnerText.Length == 0 || doc["settings"]["mail"]["username"].InnerText.Length == 0 || doc["settings"]["mail"]["address"].InnerText.Length == 0) // Create disabled e-mail queue emailQueue = new Misc.EmailQueue(); else emailQueue = new Misc.EmailQueue(doc["settings"]["mail"]["host"].InnerText, int.Parse(doc["settings"]["mail"]["port"].InnerText), doc["settings"]["mail"]["username"].InnerText, doc["settings"]["mail"]["password"].InnerText, doc["settings"]["mail"]["address"].InnerText); emailQueue.start(); // Wipe the cache folder string cachePath = basePath + "\\Cache"; if (Directory.Exists(cachePath)) { // We don't just delete the directory because something could be in-use..hence we try to delete as much as possible try { foreach (string file in Directory.GetFiles(cachePath, "*", SearchOption.AllDirectories)) File.Delete(file); foreach (string dir in Directory.GetDirectories(cachePath, "*", SearchOption.AllDirectories)) Directory.Delete(dir); } catch { } } // Load settings settings = new Misc.Settings(); settings.reload(globalConnector); // Load templates templates = new Misc.HtmlTemplates(globalConnector); // Invoke plugins foreach (ResultRow plugin in globalConnector.Query_Read("SELECT pluginid, classpath FROM plugins WHERE state='" + (int)Plugins.Base.State.Enabled + "' ORDER BY invoke_order ASC")) try { Misc.Plugins.invokeMethod(plugin["classpath"], "cmsStart", new object[]{ plugin["pluginid"], globalConnector}); } catch { } // Complete state = State.Started; // Begin cycler cyclerStart(); } catch (Exception ex) { state = State.CriticalFailure; criticalFailureError = ex; } }