Esempio n. 1
0
        public BaseSendMessage Reply(ReceiveMessage message)
        {
            TkDbContext context;

            if (string.IsNullOrEmpty(ContextName))
            {
                context = DbContextUtil.CreateDefault();
            }
            else
            {
                context = DbContextUtil.CreateDbContext(ContextName);
            }
            using (EmptyDbDataSource source = new EmptyDbDataSource())
            {
                source.Context = context;
                string sql = Expression.Execute(Sql, source);
                SqlSelector.Select(source.Context, source.DataSet, TABLE_NAME, sql);
                DataTable table = source.DataSet.Tables[TABLE_NAME];
                if (table.Rows.Count == 0)
                {
                    TextSendMessage result = new TextSendMessage(message, EmptyMessage);
                    return(result);
                }
                else
                {
                    NewsSendMessage result = new NewsSendMessage(message);
                    int             count  = 0;
                    if (fFirstArticles.Count > 0)
                    {
                        foreach (var article in fFirstArticles)
                        {
                            result.Add(article);
                            ++count;
                        }
                    }

                    int maxCount = MAX_COUNT;
                    if (FootArticle != null)
                    {
                        maxCount--;
                    }
                    foreach (DataRow row in table.Rows)
                    {
                        if (++count > maxCount)
                        {
                            break;
                        }
                        Article article = DataRowArticle.CreateArticle(source, row, message);
                        result.Add(article);
                    }

                    if (FootArticle != null)
                    {
                        result.Add(FootArticle);
                    }

                    return(result);
                }
            }
        }
Esempio n. 2
0
        public DataRowNewsMessage(MarcoConfigItem sql, DataRowArticle dataRowArticle, string emptyMessage)
        {
            TkDebug.AssertArgumentNull(sql, "sql", null);
            TkDebug.AssertArgumentNull(dataRowArticle, "dataRowArticle", null);
            TkDebug.AssertArgumentNullOrEmpty(emptyMessage, "emptyMessage", null);

            Sql            = sql;
            DataRowArticle = dataRowArticle;
            fFirstArticles = new List <Article>();
            EmptyMessage   = emptyMessage;
        }
        public DataRowNewsMessage(MarcoConfigItem sql, DataRowArticle dataRowArticle, string emptyMessage)
        {
            TkDebug.AssertArgumentNull(sql, "sql", null);
            TkDebug.AssertArgumentNull(dataRowArticle, "dataRowArticle", null);
            TkDebug.AssertArgumentNullOrEmpty(emptyMessage, "emptyMessage", null);

            Sql = sql;
            DataRowArticle = dataRowArticle;
            fFirstArticles = new List<Article>();
            EmptyMessage = emptyMessage;
        }