public static List <AgentPresetConfig> GetAllPresets() { List <AgentPresetConfig> presets = new List <AgentPresetConfig>(); return(ReadPresetsFromFile(MonitorPack.GetQuickMonUserDataTemplatesFile())); //string progDataPath = MonitorPack.GetQuickMonUserDataDirectory();// System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Hen IT\\QuickMon 3"); //foreach (AgentPresetConfig apc in ReadPresetsFromDirectory(progDataPath)) //{ // if ((from p in presets // where p.Description == apc.Description && p.AgentClassName == apc.AgentClassName // select p).FirstOrDefault() == null) // presets.Add(apc); //} ////search current directory as well //string presetPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); //foreach (AgentPresetConfig apc in ReadPresetsFromDirectory(presetPath)) //{ // if ((from p in presets // where p.Description == apc.Description && p.AgentClassName == apc.AgentClassName // select p).FirstOrDefault() == null) // presets.Add(apc); //} //return presets; }
public static List <QuickMonTemplate> GetAllTemplates() { List <QuickMonTemplate> list = new List <QuickMonTemplate>(); string fileContents = System.IO.File.ReadAllText(MonitorPack.GetQuickMonUserDataTemplatesFile()); if (fileContents.Contains("<quickMonTemplate>") && fileContents.Contains("</quickMonTemplate>")) { try { XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(fileContents); XmlElement root = xdoc.DocumentElement; foreach (XmlNode templateNode in root.SelectNodes("template")) { try { QuickMonTemplate newTemplate = new QuickMonTemplate(); newTemplate.Name = templateNode.ReadXmlElementAttr("name", ""); newTemplate.TemplateType = TemplateTypeConverter.FromText(templateNode.ReadXmlElementAttr("type", "MonitorPack")); newTemplate.ForClass = templateNode.ReadXmlElementAttr("class", ""); newTemplate.Description = templateNode.ReadXmlElementAttr("description", ""); newTemplate.Config = templateNode.InnerXml; list.Add(newTemplate); } catch { } } } catch (Exception ex) { LastError = ex.Message; } } return(list); }
public static void SaveTemplates(List <QuickMonTemplate> list) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.AppendLine("<quickMonTemplate>"); //MonitorPacks foreach (QuickMonTemplate template in (from t in list where t.TemplateType == TemplateType.MonitorPack orderby t.Name select t)) { sb.AppendLine(GetTemplateXmlString(template.Name, "MonitorPack", "MonitorPack", template.Description, template.Config)); } //CollectorHosts foreach (QuickMonTemplate template in (from t in list where t.TemplateType == TemplateType.CollectorHost orderby t.Name select t)) { sb.AppendLine(GetTemplateXmlString(template.Name, "CollectorHost", "CollectorHost", template.Description, template.Config)); } //CollectorAgent foreach (QuickMonTemplate template in (from t in list where t.TemplateType == TemplateType.CollectorAgent orderby t.Name select t)) { sb.AppendLine(GetTemplateXmlString(template.Name, "CollectorAgent", template.ForClass, template.Description, template.Config)); } //NotifierHosts foreach (QuickMonTemplate template in (from t in list where t.TemplateType == TemplateType.NotifierHost orderby t.Name select t)) { sb.AppendLine(GetTemplateXmlString(template.Name, "NotifierHost", "NotifierHost", template.Description, template.Config)); } //NotifierAgents foreach (QuickMonTemplate template in (from t in list where t.TemplateType == TemplateType.NotifierAgent orderby t.Name select t)) { sb.AppendLine(GetTemplateXmlString(template.Name, "NotifierAgent", template.ForClass, template.Description, template.Config)); } sb.AppendLine("</quickMonTemplate>"); if (System.IO.File.Exists(MonitorPack.GetQuickMonUserDataTemplatesFile() + ".bak")) { System.IO.File.SetAttributes(MonitorPack.GetQuickMonUserDataTemplatesFile() + ".bak", System.IO.FileAttributes.Normal); System.IO.File.Delete(MonitorPack.GetQuickMonUserDataTemplatesFile() + ".bak"); } if (System.IO.File.Exists(MonitorPack.GetQuickMonUserDataTemplatesFile())) { System.IO.File.Move(MonitorPack.GetQuickMonUserDataTemplatesFile(), MonitorPack.GetQuickMonUserDataTemplatesFile() + ".bak"); } System.IO.File.WriteAllText(MonitorPack.GetQuickMonUserDataTemplatesFile(), sb.ToString().BeautifyXML()); }
public static void ResetTemplates() { string path = MonitorPack.GetQuickMonUserDataTemplatesFile(); if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(path))) { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path)); } System.IO.File.WriteAllText(path, Properties.Resources.QuickMon5DefaultTemplate); }
public static void SaveAllPresetsToFile(List <AgentPresetConfig> list) { SavePresetsToFile(MonitorPack.GetQuickMonUserDataTemplatesFile(), list); //string progDataPath = MonitorPack.GetQuickMonUserDataDirectory(); // System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Hen IT\\QuickMon 3"); //foreach(string agentClass in (from ps in list // group ps by ps.AgentClassName.ToLower() into g // select g.Key)) //{ // string presetFilePath = System.IO.Path.Combine(progDataPath, agentClass + ".qps"); // SavePresetsToFile(presetFilePath, (from presetsByAgentType in list // where presetsByAgentType.AgentClassName.ToLower() == agentClass.ToLower() // select presetsByAgentType).ToList()); //} }
static void Main(string[] args) { if (Properties.Settings.Default.NewVersion) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.NewVersion = false; Properties.Settings.Default.Save(); } if (Properties.Settings.Default.RecentQMConfigFiles == null) { Properties.Settings.Default.RecentQMConfigFiles = new System.Collections.Specialized.StringCollection(); } if (Properties.Settings.Default.KnownRemoteHosts == null) { Properties.Settings.Default.KnownRemoteHosts = new System.Collections.Specialized.StringCollection(); } Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Copy installed presets to user's application data directory try { if (!System.IO.File.Exists(MonitorPack.GetQuickMonUserDataTemplatesFile())) { string commonAppData = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Hen IT\\QuickMon 3"); List <AgentPresetConfig> presets = AgentPresetConfig.ReadPresetsFromDirectory(commonAppData); AgentPresetConfig.SaveAllPresetsToFile(presets); } } catch { } //if application is launched with qmconfig file set it as last Monitor pack if (args.Length > 0 && System.IO.File.Exists(args[0]) && (args[0].ToLower().EndsWith(".qmconfig") || args[0].ToLower().EndsWith(".qmp"))) { Properties.Settings.Default.LastMonitorPack = args[0]; } Application.Run(new MainForm()); }
static void Main(string[] args) { Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; if (Properties.Settings.Default.NewVersion) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.NewVersion = false; Properties.Settings.Default.Save(); } if (Properties.Settings.Default.ApplicationMasterKey == null || Properties.Settings.Default.ApplicationMasterKey == "") { Properties.Settings.Default.ApplicationMasterKey = "QuickMon-" + System.Net.Dns.GetHostName(); } if (Properties.Settings.Default.ApplicationUserNameCacheFilePath == null || Properties.Settings.Default.ApplicationUserNameCacheFilePath == "") { Properties.Settings.Default.ApplicationUserNameCacheFilePath = System.IO.Path.Combine(MonitorPack.GetQuickMonUserDataDirectory(), "QM5MasterKeys.qmmxml"); } if (Properties.Settings.Default.ApplicationUserNameCache == null) { Properties.Settings.Default.ApplicationUserNameCache = new System.Collections.Specialized.StringCollection(); } if (Properties.Settings.Default.RecentQMConfigFiles == null) { Properties.Settings.Default.RecentQMConfigFiles = new System.Collections.Specialized.StringCollection(); } if (Properties.Settings.Default.KnownRemoteHosts == null) { Properties.Settings.Default.KnownRemoteHosts = new System.Collections.Specialized.StringCollection(); } try { if (HenIT.Security.AdminModeTools.IsInAdminMode()) { if (Properties.Settings.Default.DisableAutoAdminMode) { HenIT.Security.AdminModeTools.DeleteAdminLaunchTask(AppGlobals.AppTaskId); } else { HenIT.Security.AdminModeTools.CreateAdminLaunchTask(AppGlobals.AppTaskId); } } } catch { } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (args.Length > 0 && args[0].ToLower().Contains(".qmp")) { string qmpFile = args[0]; if (System.IO.File.Exists(qmpFile)) { Properties.Settings.Default.LastMonitorPack = qmpFile; } } try { if (!System.IO.File.Exists(MonitorPack.GetQuickMonUserDataTemplatesFile())) { try { QuickMonTemplate.ResetTemplates(); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); } } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Templates", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!System.IO.Directory.Exists(Properties.Settings.Default.ScriptRepositoryDirectory)) { try { System.IO.Directory.CreateDirectory(Properties.Settings.Default.ScriptRepositoryDirectory); } catch { } } MainForm mainForm = new MainForm(); Application.Run(mainForm); }