示例#1
0
        void BindAttachmentList()
        {
            List <Attachment> atms = AttachmentHelper.GetAttachments(ArticleID);

            DataGridView.DataSource = atms;
            DataGridView.DataBind();
        }
示例#2
0
        /// <summary>
        /// 取得当前的文章
        /// </summary>
        /// <returns>文章实体</returns>
        protected virtual Article GetThisArticle()
        {
            Article article = null;

            Attachments = new List <Attachment>();
            if (DesignHelper.IsDesigning)
            {
                DesignHelper.FillItems <Article>(out article, PageSize);
                Attachments.Add(new Attachment()
                {
                    ArticleID = article.ID, FilePath = DesignHelper.GetAttachment()
                });
                Attachments.Add(new Attachment()
                {
                    ArticleID = article.ID, FilePath = DesignHelper.GetAttachment()
                });
                Attachments.Add(new Attachment()
                {
                    ArticleID = article.ID, FilePath = DesignHelper.GetAttachment()
                });
                Attachments.Add(new Attachment()
                {
                    ArticleID = article.ID, FilePath = DesignHelper.GetAttachment()
                });
            }
            else
            {
                if (We7Helper.IsEmptyID(BindColumnID) && !We7Helper.IsEmptyID(ArticleID))
                {
                    article = ArticleHelper.GetArticle(ArticleID, null);
                }
                else
                {
                    List <Article> articles = GetArticleListFromDB();
                    if (articles.Count > 0)
                    {
                        article = articles[0];
                    }
                }
            }

            if (article != null)
            {
                List <Article> list = new List <Article>();
                list.Add(article);
                FormatArticlesData(list);
                article = list[0];
                if (AttachmentNum > 0)
                {
                    Attachments = AttachmentHelper.GetAttachments(article.ID);
                }
            }
            else
            {
                article = new Article();
            }

            return(article);
        }
示例#3
0
        void LoadArticle()
        {
            Attachments = new List <Attachment>();

            if (!We7Helper.IsEmptyID(ArticleID))
            {
                Article a = ArticleHelper.GetArticle(ArticleID);
                if (a != null)
                {
                    TitleLabel.Text   = a.Title;
                    ContentLabel.Text = a.Content;
                    Attachments       = AttachmentHelper.GetAttachments(a.ID);
                }
            }
        }
示例#4
0
        public async Task <bool> SendAsync(EmailMessage email, bool deleteAttachmentes, params string[] attachments)
        {
            var config = this.Config as Config;

            if (config == null)
            {
                email.Status = Status.Cancelled;
                return(false);
            }

            try
            {
                Api.ApiKey = config.ApiKey;

                email.Status = Status.Executing;

                var emailAttachements = AttachmentHelper.GetAttachments(attachments);

                var result = await Api.Email.SendAsync(email.Subject, email.FromIdentifier, email.FromName,
                                                       to : email.SendTo.Split(','), bodyText : email.IsBodyHtml? "" : email.Message,
                                                       bodyHtml : email.IsBodyHtml?email.Message : "", attachmentFiles : emailAttachements,
                                                       replyTo : email.ReplyToEmail, replyToName : email.ReplyToName)
                             .ConfigureAwait(false);


                email.Status = !string.IsNullOrWhiteSpace(result.TransactionID) ? Status.Completed : Status.Failed;

                return(true);
            }
            // ReSharper disable once CatchAllClause
            catch (Exception ex)
            {
                email.Status = Status.Failed;
                Log.Warning(@"Could not send email to {To} using ElasticEmail API. {Ex}. ", email.SendTo, ex);
            }
            finally
            {
                if (deleteAttachmentes && email.Status == Status.Completed)
                {
                    FileHelper.DeleteFiles(attachments);
                }
            }

            return(false);
        }
示例#5
0
        /// <summary>
        /// 取得附件名称
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <param name="type">附件类型</param>
        /// <returns>附件名称</returns>
        public string GetAttachmentName(string id, string type)
        {
            string attachmentName = "";
            string attachmentType = "";
            int    index          = 0;

            if (type == "0" && AttachmentOneName != null)
            {
                attachmentType = AttachmentOneType;
            }
            if (type == "1" && AttachmentTwoName != null)
            {
                attachmentType = AttachmentTwoType;
                index          = 1;
            }

            List <Attachment> list = AttachmentHelper.GetAttachments(id);

            {
                if (list.Count > 0)
                {
                    if (attachmentType == "" || attachmentType == ".*" || attachmentType == "*.*")
                    {
                        if (list.Count > index)
                        {
                            attachmentName = Context.Server.UrlEncode(list[index].FileName);
                        }
                    }
                    else
                    {
                        foreach (Attachment attachment in list)
                        {
                            if (attachment.FileType == attachmentType)
                            {
                                attachmentName = Context.Server.UrlEncode(attachment.FileName);
                            }
                            break;
                        }
                    }
                }
            }
            return(attachmentName);
        }
示例#6
0
        /// <summary>
        /// 取得图片
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <returns>图片地址</returns>
        public string GetImage(string id)
        {
            Attachment attach = AttachmentHelper.GetAttachments(id).Find(a => !a.FileName.StartsWith("thumb_", true, null));

            return(attach != null?Path.Combine(attach.FilePath, attach.FileName).Replace("\\", "/") : "");
        }
示例#7
0
        /// <summary>
        /// 格式化列表中的数据
        /// </summary>
        /// <param name="list">文章列表</param>
        protected List <Article> FormatArticlesData(List <Article> list)
        {
            DateTime now = DateTime.Now;

            foreach (Article a in list)
            {
                if (ShowField("Thumbnail"))
                {
                    a.TagThumbnail = GetTagThumbnail(a, ThumbnailTag); //a.GetTagThumbnail(ThumbnailTag);
                }
                //Channel ch = ChannelHelper.GetChannel(a.OwnerID, null);
                if (!String.IsNullOrEmpty(ShowChannel))
                {
                    string channelName = a.ChannelName;
                    if (ChannelHasLink)
                    {
                        channelName = string.Format("<a href='{1}' target='{2}'>{0}</a>", a.ChannelName, a.ChannelFullUrl, LinkTarget);
                    }

                    a.FullChannelPath = string.Format(ShowChannel, channelName);
                }

                a.Icon = GetIcon(a.State);

                if (NoLink)
                {
                    a.LinkUrl = "";
                }
                else
                {
                    if (a.ContentType == (int)TypeOfArticle.LinkArticle)
                    {
                        a.LinkUrl = a.ContentUrl;
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(a.ChannelFullUrl) && !String.IsNullOrEmpty(a.ModelName))
                        {
                            //这儿只能做一个容错处理
                            List <Channel> chs = ChannelHelper.GetChannelByModelName(a.ModelName);
                            if (chs.Count > 0)
                            {
                                a.ChannelFullUrl = chs[0].FullUrl;
                            }
                        }
                        a.LinkUrl = String.Format("{0}{1}", a.ChannelFullUrl, a.FullUrl);
                    }
                }

                if (DateFormat == null || DateFormat == "")
                {
                    TimeSpan ts = now - a.Updated;
                    a.TimeNote = GetTimeNote(ts);
                }
                else
                {
                    a.TimeNote = a.Updated.ToString(DateFormat);
                }

                if (ShowField("ToolTip"))
                {
                    a.FullTitle  = a.Title;
                    a.FullTitle += "," + a.TimeNote;
                    if (a.Clicks > 0)
                    {
                        a.FullTitle += ",阅读量:" + a.Clicks;
                    }
                }
                else
                {
                    a.FullTitle = a.Title;
                }

                if (TitleMaxLength > 0 && a.Title.Length > TitleMaxLength)
                {
                    a.Title = a.Title.Substring(0, TitleMaxLength) + "...";
                }

                if (!string.IsNullOrEmpty(KeyWord))
                {
                    a.Title = a.Title.Replace(KeyWord, "<em>" + KeyWord + "</em>");
                }

                if (Show("Description"))
                {
                    if (SummaryMaxLength > 0 && a.Description != null &&
                        a.Description.Length > SummaryMaxLength)
                    {
                        a.Description = a.Description.Substring(0, SummaryMaxLength) + "...";
                    }

                    if (string.IsNullOrEmpty(a.Description) && !string.IsNullOrEmpty(a.Content))
                    {
                        string content = We7Helper.RemoveHtml(a.Content);
                        if (content.Length > summaryMaxLength)
                        {
                            a.Description = content.Substring(0, SummaryMaxLength) + "...";
                        }
                        else
                        {
                            a.Description = content;
                        }
                    }

                    if (!string.IsNullOrEmpty(KeyWord) && !string.IsNullOrEmpty(a.Description))
                    {
                        a.Description = a.Description.Replace(KeyWord, "<em>" + KeyWord + "</em>");
                    }
                }

                if (AttachmentNum > 0)
                {
                    a.Attachments = AttachmentHelper.GetAttachments(a.ID);
                }
            }
            return(list);
        }