public static StandardResult <SimpleTable> Execute(string data, string newRow, char delimiter = '=', IList <string> columns = null)
        {
            var lines = data.Split(new string[] { "\r\n" }, StringSplitOptions.None);
            var table = new SimpleTable();

            if (columns != null)
            {
                for (int i = 0; i < columns.Count; i++)
                {
                    table.SetColumnName(i, columns[i]);
                }
            }

            SimpleTableRow row = null;

            foreach (var line in lines)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                if (line.StartsWith("#"))
                {
                    continue;
                }

                if (line == newRow)
                {
                    row = table.CreateRow();

                    continue;
                }

                int pos = line.IndexOf(delimiter);

                if (pos < 0)
                {
                    continue;
                }

                string name  = line.Substring(0, pos);
                string value = line.Substring(pos + 1);

                if (columns == null && !table.ContainColumn(name))
                {
                    table.SetColumnName(table.ColumnNames.Count, name);
                }

                if (table.ContainColumn(name))
                {
                    row.SetField(name, value);
                }
            }

            return(StandardResult <SimpleTable> .ReturnResult(table));
        }
Ejemplo n.º 2
0
        public static StandardResult <bool> Execute(SimpleTable sourceTable)
        {
            foreach (var row in sourceTable)
            {
                var message = new MailMessage(row["Mail-From"], row["Mail-To"])
                {
                    Subject = row["Mail-Subject"],
                    Body    = row["Mail-Body"]
                };

                if (sourceTable.ContainColumn("Mail-CC"))
                {
                    var cc = row["Mail-CC"];

                    if (!string.IsNullOrWhiteSpace(cc))
                    {
                        message.CC.Add(cc);
                    }
                }

                message.IsBodyHtml = true;

                var result = SendEMail.Execute(message);

                if (result.HasError)
                {
                    return(result);
                }
            }

            return(StandardResult <bool> .ReturnResult(true));
        }