/// <summary> /// Method analyze collection html elements /// </summary> /// <param name="elements">Сollection html elements</param> /// <returns>Сollection QSTask</returns> public Dictionary <string, QSTask> Parse(HtmlElementCollection elements) { this.m_logger.WriteLog("Start parsing html elements"); Dictionary <string, QSTask> result = new Dictionary <string, QSTask>(); foreach (HtmlElement row in elements) { var id = row.GetAttribute("id"); QSTask task = new QSTask(id) { Name = row.Children[0].GetAttribute("title"), AssociatedResource = row.Children[1].InnerText, Type = row.Children[2].InnerText, Enable = row.Children[3].InnerText, Status = row.Children[4].Children[1].Children[0].InnerText, LastExecution = row.Children[5].GetAttribute("title"), NextExecution = row.Children[6].InnerText }; result.Add(task.Id, task); } this.m_logger.WriteLog("End parsing html elements"); this.m_logger.WriteLog(string.Format("Found {0} QTasks", result.Count)); return(result); }
private void Execute() { System.Threading.Thread.Sleep(7000); this.BeginInvoke((MethodInvoker) delegate() { this.m_logger.WriteLog("Parse current statuses tasks"); var table = this.webBrowser1.FindElementByClass("qmc-table-rows"); if (table == null) { this.m_logger.WriteLog("Actual statuses not found"); return; } var rows = table.Children[1].Children; this.m_currentTasks = this.m_parser.Parse(rows); var toSendAlerst = this.m_parser.Compare( historyTasks: this.m_historyTasks.Values.ToList(), currentTasks: this.m_currentTasks.Values.ToList()); if (this.m_sendSNTPMail != null) { this.m_sendSNTPMail.SendAlerts(toSendAlerst, this.m_instance, this.emailTextBox.Text, this.toTextBox.Text); } else { this.m_logger.WriteLog("Failed tasks not found"); } QSTask.WriteToFile(this.m_currentTasks, pathHistory); this.Close(); }); }
/// <summary> /// Method of serializing the collection QSTask to disk /// </summary> /// <param name="tasks">Collection QSTask</param> /// <param name="filename">File name to save</param> public static void WriteToFile(Dictionary <string, QSTask> tasks, string filename) { StringBuilder sb = new StringBuilder(); foreach (QSTask task in tasks.Values) { sb.AppendLine(QSTask.ConvertoToJSON(task)); } File.WriteAllText(filename, sb.ToString()); }
/// <summary> /// Method for serializing object to JSON /// </summary> /// <param name="task">QSTask</param> /// <returns>JSON string</returns> private static string ConvertoToJSON(QSTask task) { using (MemoryStream stream = new MemoryStream()) { DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(QSTask)); jsonFormatter.WriteObject(stream, task); stream.Seek(0, SeekOrigin.Begin); using (StreamReader reader = new StreamReader(stream)) { return(reader.ReadToEnd()); } } }
/// <summary> /// Clone QTask object /// </summary> /// <param name="task">source QTask</param> /// <returns>New QTask</returns> public static QSTask Clone(QSTask task) { return(new QSTask(task.Id, task.AlreadySent) { AssociatedResource = task.AssociatedResource, Enable = task.Enable, LastExecution = task.LastExecution, Name = task.Name, NextExecution = task.NextExecution, Status = task.Status, Type = task.Type }); }
/// <summary> /// Method of deserializing the collection QSTask from disk /// </summary> /// <param name="filename">File name to read data</param> /// <returns>Collection QSTask</returns> public static Dictionary <string, QSTask> ReadFromFile(string filename) { Dictionary <string, QSTask> tasks = new Dictionary <string, QSTask>(); var jsons = File.ReadAllLines(filename); foreach (var json in jsons) { var task = QSTask.ConvertoFromJSON(json); tasks.Add(task.Id, task); } return(tasks); }
private void Form1_Load(object sender, EventArgs e) { this.m_logger.WriteLog("Start read configuration"); this.urlTextBox.Text = this.m_conf.ReadSetting("url"); this.usernameTextBox.Text = this.m_conf.ReadSetting("username"); bool savePwd = Convert.ToBoolean(this.m_conf.ReadSetting("savePwd")); if (this.checkBox1.Checked = savePwd) { this.pwdTextBox.Text = this.m_conf.ReadSetting("pwd", true); } this.smtpTextBox.Text = this.m_conf.ReadSetting("smtp_server_address"); this.portTextBox.Text = this.m_conf.ReadSetting("smtp_server_port"); bool useSsl = Convert.ToBoolean(this.m_conf.ReadSetting("smtp_server_ssl")); this.checkBox2.Checked = useSsl; this.smtpuserTextBox.Text = this.m_conf.ReadSetting("smtp_username"); this.smtppwdTextBox.Text = this.m_conf.ReadSetting("smtp_pwd", true); this.emailTextBox.Text = this.m_conf.ReadSetting("smtp_email"); this.toTextBox.Text = this.m_conf.ReadSetting("smtp_to"); this.m_instance = this.m_conf.ReadSetting("instance"); this.m_autostart = Convert.ToBoolean(this.m_conf.ReadSetting("auto_start")); if (this.checkBox3.Checked = this.m_autostart) { this.m_logger.WriteLog("Auto start execute parse"); this.Shown += Form1_Shown; } this.button1.Visible = !this.m_autostart; this.button4.Visible = !this.m_autostart; if (System.IO.File.Exists(pathHistory)) { this.m_logger.WriteLog("Load previous statuses tasks"); this.m_historyTasks = QSTask.ReadFromFile(pathHistory); } }
/// <summary> /// Clone current object QTask /// </summary> /// <returns></returns> public object Clone() { return(QSTask.Clone(this)); }