public static void ChangeDeploymentMethod(Type type) { if (_deployer.GetType().FullName != type.FullName) { Lock(); _deployer.Shutdown(); EventController.TriggerEvent(new ConfigurationDeployerChangedEvent(_deployer.GetType(), type)); Settings.Current["CoreGenerator", DEPLOYER_TYPE_SETTING_NAME] = type.FullName; _deployer = (IConfigDeployer)type.GetConstructor(Type.EmptyTypes).Invoke(new object[0]); _deployer.Init(domains, extensions, itrunks, profiles, trunks, contexts, modules, varsContent); UnLock(); } }
public static DeploymentMethod Load(string typeName) { if (!User.Current.HasRight(USER_RIGHT)) { return(null); } IConfigDeployer dep = (IConfigDeployer)Utility.LocateType(typeName).GetConstructor(Type.EmptyTypes).Invoke(new object[0]); if (dep.IsValidToUse) { return(new DeploymentMethod(dep)); } return(null); }
public static List <DeploymentMethod> LoadAll() { if (!User.Current.HasRight(USER_RIGHT)) { return(null); } List <DeploymentMethod> ret = new List <DeploymentMethod>(); foreach (Type t in Utility.LocateTypeInstances(typeof(IConfigDeployer))) { IConfigDeployer dep = (IConfigDeployer)t.GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); if (dep.IsValidToUse) { ret.Add(new DeploymentMethod(dep)); } } if (ret.Count == 0) { return(null); } return(ret); }
private DeploymentMethod(IConfigDeployer deployer) { _dep = deployer; _isCurrent = id == CoreGenerator.CurrentDeploymentMethod.FullName; }
static CoreGenerator() { StreamReader sr; if (Settings.Current[Constants.BASE_PATH_NAME] == null) { Settings.Current[Constants.BASE_PATH_NAME] = Constants.DEFAULT_BASE_BATH; } if (Settings.Current["CoreGenerator", DEPLOYER_TYPE_SETTING_NAME] == null) { Settings.Current["CoreGenerator", DEPLOYER_TYPE_SETTING_NAME] = typeof(DefaultFileConfigDeployer).FullName; } if (domains == null) { domains = new List <sDeployedDomain>(); } if (extensions == null) { extensions = new List <sDeployedExtension>(); } if (contexts == null) { contexts = new List <sDeployedContext>(); } if (extensions == null) { extensions = new List <sDeployedExtension>(); } if (trunks == null) { trunks = new List <sDeployedOutgoingSipTrunk>(); } if (itrunks == null) { itrunks = new List <sDeployedIncomingSIPTrunk>(); } if (profiles == null) { profiles = new List <sDeployedProfile>(); } if (modules == null) { DirectoryInfo di = new DirectoryInfo(Settings.Current[Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_CONF_DIR + Path.DirectorySeparatorChar + Constants.DEFAULT_AUTOLOAD_CONF_DIR); if (di.Exists) { List <sDeployedModule> mods = new List <sDeployedModule>(); foreach (FileInfo fi in di.GetFiles("*.xml")) { sr = fi.OpenText(); string cont = sr.ReadToEnd(); sr.Close(); XmlDocument doc = new XmlDocument(); while (cont.Contains("<!--")) { string pre = cont.Substring(0, cont.IndexOf("<!--")); cont = cont.Substring(cont.IndexOf("<!--") + 4); cont = pre + cont.Substring(cont.IndexOf("-->") + 3); } cont = cont.Replace('\n', ' ').Replace('\r', ' '); try { doc.LoadXml(cont); mods.Add(new sDeployedModule(fi.Name, new sFreeSwitchModuleFile(doc.ChildNodes[0].Attributes["name"].Value, (doc.ChildNodes[0].Attributes["description"] == null ? "" : doc.ChildNodes[0].Attributes["description"].Value), doc.ChildNodes[0].OuterXml))); } catch (Exception e) { throw new Exception("An error occured attempting to load the configuration file " + fi.Name, e); } } modules = mods; } } if (varsContent == null) { FileInfo fi = new FileInfo(Settings.Current[Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_CONF_DIR + Path.DirectorySeparatorChar + "vars.xml"); if (fi.Exists) { sr = fi.OpenText(); varsContent = sr.ReadToEnd(); sr.Close(); } } _deployer = (IConfigDeployer)Utility.LocateType(Settings.Current["CoreGenerator", DEPLOYER_TYPE_SETTING_NAME].ToString()).GetConstructor(Type.EmptyTypes).Invoke(new object[0]); _deployer.Init(domains, extensions, itrunks, profiles, trunks, contexts, modules, varsContent); }
static CoreGenerator() { StreamReader sr; if (Settings.Current[Constants.BASE_PATH_NAME] == null) Settings.Current[Constants.BASE_PATH_NAME] = Constants.DEFAULT_BASE_BATH; if (Settings.Current["CoreGenerator", DEPLOYER_TYPE_SETTING_NAME] == null) Settings.Current["CoreGenerator", DEPLOYER_TYPE_SETTING_NAME] = typeof(DefaultFileConfigDeployer).FullName; if (domains == null) domains = new List<sDeployedDomain>(); if (extensions == null) extensions = new List<sDeployedExtension>(); if (contexts == null) contexts = new List<sDeployedContext>(); if (extensions == null) extensions = new List<sDeployedExtension>(); if (trunks == null) trunks = new List<sDeployedOutgoingSipTrunk>(); if (itrunks == null) itrunks = new List<sDeployedIncomingSIPTrunk>(); if (profiles == null) profiles = new List<sDeployedProfile>(); if (modules == null) { DirectoryInfo di = new DirectoryInfo(Settings.Current[Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_CONF_DIR + Path.DirectorySeparatorChar + Constants.DEFAULT_AUTOLOAD_CONF_DIR); if (di.Exists) { List<sDeployedModule> mods = new List<sDeployedModule>(); foreach (FileInfo fi in di.GetFiles("*.xml")) { sr = fi.OpenText(); string cont = sr.ReadToEnd(); sr.Close(); XmlDocument doc = new XmlDocument(); while (cont.Contains("<!--")) { string pre = cont.Substring(0, cont.IndexOf("<!--")); cont = cont.Substring(cont.IndexOf("<!--") + 4); cont = pre + cont.Substring(cont.IndexOf("-->") + 3); } cont = cont.Replace('\n', ' ').Replace('\r', ' '); try { doc.LoadXml(cont); mods.Add(new sDeployedModule(fi.Name, new sFreeSwitchModuleFile(doc.ChildNodes[0].Attributes["name"].Value, (doc.ChildNodes[0].Attributes["description"] == null ? "" : doc.ChildNodes[0].Attributes["description"].Value), doc.ChildNodes[0].OuterXml))); } catch (Exception e) { throw new Exception("An error occured attempting to load the configuration file " + fi.Name, e); } } modules = mods; } } if (varsContent == null) { FileInfo fi = new FileInfo(Settings.Current[Constants.BASE_PATH_NAME].ToString() + Path.DirectorySeparatorChar + Constants.DEFAULT_CONF_DIR + Path.DirectorySeparatorChar + "vars.xml"); if (fi.Exists) { sr = fi.OpenText(); varsContent = sr.ReadToEnd(); sr.Close(); } } _deployer = (IConfigDeployer)Utility.LocateType(Settings.Current["CoreGenerator", DEPLOYER_TYPE_SETTING_NAME].ToString()).GetConstructor(Type.EmptyTypes).Invoke(new object[0]); _deployer.Init(domains, extensions, itrunks, profiles, trunks, contexts, modules, varsContent); }