예제 #1
0
 /// <summary>
 /// Create a new instance of this class.
 /// </summary>
 /// <param name="from">The email address from which the email will be sent.</param>
 /// <param name="to">The email addresses to which the email will be sent.</param>
 /// <param name="subject">The subject of the email.</param>
 /// <param name="body">Text to add to the body of the email before the data. Default: ""</param>
 /// <param name="openers">Whether or not to use comedic openers in the email. Default: false</param>
 /// <param name="attachmentFilepath">A file to attach to this email. Default: ""</param>
 public QueryOutputEmail(string from, IEnumerable <string> to, string subject, string body = "", bool openers = false, string attachmentFilepath = "")
 {
     From           = Mail.GetEmailAddresses(new[] { from }).First();
     To             = to;
     Subject        = subject;
     Body           = body;
     Openers        = openers;
     AttachmentInfo = attachmentFilepath != null && attachmentFilepath.Length > 0 ? new QueryOutputFile(attachmentFilepath) : null;
 }
예제 #2
0
        /// <summary>
        /// Load a QueryList from a Queries.xml file.
        /// </summary>
        /// <param name="path">The path of the XML file for this list.</param>
        /// <returns>A QueryList containing all queries in the file.</returns>
        public static QueryList FromXML(string path = "Queries.xml")
        {
            QueryList queries = new QueryList(path);

            XMLFile qFile = new XMLFile(path);

            foreach (XMLSection section in qFile.GetSections()[0].GetSections())
            {
                if (!section.HasSections("output"))
                {
                    continue;
                }
                XMLSection  outputSection = section.GetSections("output")[0];
                QueryOutput output        = null;
                switch (outputSection.Get("type").ToLower())
                {
                case "file":
                    string outputLocation = outputSection.Get("location").Replace('/', '\\');
                    outputLocation = Path.GetFullPath(outputLocation);
                    if (outputSection.HasValue("dateformat"))
                    {
                        DateTime date = DateTime.Now;
                        //if (interval == "daily") date = date.AddDays(-1);

                        string[]      dateformat    = outputSection.Get("dateformat").ToLower().Split(',');
                        StringBuilder formattedDate = new StringBuilder();
                        foreach (string f in dateformat)
                        {
                            switch (f)
                            {
                            case "dayofyear":
                                formattedDate.Append(date.DayOfYear.ToString("000"));
                                break;

                            default:
                                try {
                                    formattedDate.Append(date.ToString(f));
                                } catch (FormatException) { continue; }
                                break;
                            }
                        }

                        outputLocation = outputLocation.Replace("*", formattedDate.ToString());
                    }
                    output = new QueryOutputFile(outputLocation);
                    break;

                case "email":
                    output = new QueryOutputEmail(
                        outputSection.Get("from"),
                        outputSection.Get("to").Split(','),
                        outputSection.Get("subject"),
                        outputSection.Get("body"),
                        outputSection.Get("openers", false),
                        outputSection.Get("attachmentFilepath")
                        );
                    break;

                case "ftp":
                    string filename = outputSection.Get("filename");
                    if (outputSection.HasValue("dateformat"))
                    {
                        DateTime date = DateTime.Now.AddDays(outputSection.Get("dateOffset", 0));
                        //if (interval == "daily") date = date.AddDays(-1);

                        string[]      dateformat    = outputSection.Get("dateformat").ToLower().Split(',');
                        StringBuilder formattedDate = new StringBuilder();
                        foreach (string f in dateformat)
                        {
                            switch (f)
                            {
                            case "dayofyear":
                                formattedDate.Append(date.DayOfYear.ToString("000"));
                                break;

                            default:
                                try {
                                    formattedDate.Append(date.ToString(f));
                                } catch (FormatException) { continue; }
                                break;
                            }
                        }
                        filename = filename.Replace("*", formattedDate.ToString());
                    }
                    output = new QueryOutputFTP(
                        outputSection.Get("address"),
                        filename,
                        outputSection.Get("remotepath"),
                        outputSection.Get("username"),
                        outputSection.Get("password")
                        );
                    break;
                }

                if (output == null)
                {
                    continue;
                }
                Query q = new Query(output, section.GetEnum <QueryInterval>("interval"), section.Get("name"), section.Get("database"), section.Get("dataview", ""), section.Get("transpose", false), section.Get("time", -1), section.Get("delimiter", ","), section.Get("printHeaders", false));
                if (section.HasValue("queryStatement") && section.Get("queryStatement").Length > 0)
                {
                    q.QueryStatement = section.Get("queryStatement");
                }
                if (section.HasValue("paused"))
                {
                    q.Paused = section.Get("paused", true);
                }
                queries.Add(q);
            }
            return(queries);
        }