コード例 #1
0
        /// <summary>
        /// 取得段落
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="uploadUrl"></param>
        /// <param name="uploadPath"></param>
        /// <returns></returns>
        public List <ParagraphItem> GetParagraphItem(long Id, string uploadUrl, string uploadPath)
        {
            List <ParagraphItem> paragraphList = new List <ParagraphItem>();

            IEnumerable <ParagraphModels> paragraphs = ParagraphDAO.GetItems(Id);

            foreach (var paragraph in paragraphs)
            {
                string matchType = (paragraph.MatchType ?? string.Empty).ToLower();
                if (matchType == "img")
                {
                    IEnumerable <ResourceImagesModels> images = paragraph.GetImages().Where(m => m.IsShow);
                    if (images == null)
                    {
                        continue;
                    }

                    if (images.Count() > 1)
                    {
                        List <ParagraphImageList> imgList = new List <ParagraphImageList>();

                        foreach (var img in images)
                        {
                            int width = 0, height = 0;
                            GetImageWidthAndHeight($"{uploadPath}\\{img.Img}", out width, out height);
                            imgList.Add(new ParagraphImageList()
                            {
                                Url    = uploadUrl + img.Img,
                                Width  = width,
                                Height = height
                            });
                        }

                        paragraphList.Add(new ParagraphItem()
                        {
                            Type        = "ImageGroup",
                            ContentList = imgList
                        });
                    }
                    else
                    {
                        foreach (var img in images)
                        {
                            int width = 0, height = 0;
                            GetImageWidthAndHeight($"{uploadPath}\\{img.Img}", out width, out height);
                            ParagraphImage imgItem = new ParagraphImage
                            {
                                Type    = "Image",
                                Content = uploadUrl + img.Img,
                                Width   = width,
                                Height  = height
                            };
                            paragraphList.Add(imgItem);
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Title))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Title", Content = paragraph.Title
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Text", Content = paragraph.Contents
                        });
                    }
                }
                else if (matchType == "video")
                {
                    ResourceVideosModels video = paragraph.GetVideo();
                    string shotUrl = string.Empty, videoUrl = string.Empty;

                    if (video.Type == "custom")
                    {
                        videoUrl = uploadUrl + video.Link;
                        if (!string.IsNullOrWhiteSpace(video.Screenshot))
                        {
                            ResourceImagesModels img = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(video.Screenshot);
                            shotUrl = uploadUrl + img.Img;
                        }
                    }
                    else
                    {
                        videoUrl = video.Link;
                        shotUrl  = video.Screenshot;
                        if (video.ScreenshotIsCustom && !string.IsNullOrWhiteSpace(shotUrl))
                        {
                            ResourceImagesModels img = Newtonsoft.Json.JsonConvert.DeserializeObject <ResourceImagesModels>(shotUrl);
                            shotUrl = uploadUrl + img.Img;
                        }
                    }
                    paragraphList.Add(new ParagraphVideo
                    {
                        Type       = "Video",
                        Content    = videoUrl,
                        VideoType  = video.Type,
                        Screenshot = shotUrl
                    });

                    if (!string.IsNullOrWhiteSpace(paragraph.Title))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Title", Content = paragraph.Title
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Text", Content = paragraph.Contents
                        });
                    }
                }
                else if (matchType == "file")
                {
                    if (!string.IsNullOrWhiteSpace(paragraph.Title))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Title", Content = paragraph.Title
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Text", Content = paragraph.Contents
                        });
                    }

                    IEnumerable <ResourceFilesModels> files = paragraph.GetFiles();
                    foreach (var file in files)
                    {
                        paragraphList.Add(new ParagraphFile
                        {
                            Type    = "File",
                            Content = uploadUrl + file.FileInfo,
                            Name    = (string.IsNullOrWhiteSpace(file.ShowName) ? System.Text.RegularExpressions.Regex.Replace(file.FileInfo, @"\.[^\.]*$", string.Empty) : file.ShowName)
                        });
                    }
                }
                else if (matchType == "link")
                {
                    if (!string.IsNullOrWhiteSpace(paragraph.Title))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Title", Content = paragraph.Title
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Text", Content = paragraph.Contents
                        });
                    }

                    IEnumerable <ResourceLinksModels> links = paragraph.GetLinks();
                    foreach (var link in links)
                    {
                        paragraphList.Add(new ParagraphFile
                        {
                            Type    = "Link",
                            Content = link.LinkInfo,
                            Name    = link.Descriptions
                        });
                    }
                }
                else if (matchType == "voice")
                {
                    if (!string.IsNullOrWhiteSpace(paragraph.Title))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Title", Content = paragraph.Title
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Text", Content = paragraph.Contents
                        });
                    }

                    IEnumerable <ResourceVoicesModels> voices = paragraph.GetVoices();
                    foreach (var voice in voices)
                    {
                        paragraphList.Add(new ParagraphItem
                        {
                            Type    = "Voice",
                            Content = uploadUrl + voice.Path
                        });
                    }
                }
                else if (string.IsNullOrWhiteSpace(matchType))
                {
                    if (!string.IsNullOrWhiteSpace(paragraph.Title))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Title", Content = paragraph.Title
                        });
                    }

                    if (!string.IsNullOrWhiteSpace(paragraph.Contents))
                    {
                        paragraphList.Add(new ParagraphItem {
                            Type = "Text", Content = paragraph.Contents
                        });
                    }
                }
            }

            return(paragraphList);
        }
コード例 #2
0
ファイル: JsonUtils.cs プロジェクト: git-thinh/Zalo
        public static JObject parseArticle2Json(Article article)
        {
            JObject result = new JObject();

            result["type"]   = article.Type;
            result["title"]  = article.Title;
            result["author"] = article.Author;

            JObject cover = new JObject();

            cover["cover_type"] = article.Cover.CoverType;
            if (article.Cover.CoverType == "photo")
            {
                CoverPhoto photoCover = (CoverPhoto)article.Cover;
                cover["photo_url"] = photoCover.PhotoUrl;
            }
            else
            {
                CoverVideo videoCover = (CoverVideo)article.Cover;
                cover["cover_view"] = videoCover.CoverView.getValue();
                cover["video_id"]   = videoCover.VideoId;
            }
            cover["status"] = article.Cover.Status.getValue();
            result["cover"] = cover;

            result["description"] = article.Description;

            JArray body = new JArray();

            foreach (Paragraph paragraph in article.Body)
            {
                JObject paragraphJson = new JObject();
                paragraphJson["type"] = paragraph.Type;
                switch (paragraph.Type)
                {
                case "text":
                    ParagraphText textParagraph = (ParagraphText)paragraph;
                    paragraphJson["content"] = textParagraph.Content;
                    break;

                case "image":
                    ParagraphImage imageParagraph = (ParagraphImage)paragraph;
                    paragraphJson["url"]     = imageParagraph.Url;
                    paragraphJson["caption"] = imageParagraph.Caption;
                    break;

                case "video":
                    ParagraphVideo videoParagraph = (ParagraphVideo)paragraph;
                    if (videoParagraph.Url != null)
                    {
                        paragraphJson["url"] = videoParagraph.Url;
                    }
                    else
                    {
                        paragraphJson["video_id"] = videoParagraph.VideoId;
                    }
                    paragraphJson["thumb"] = videoParagraph.Thumb;
                    break;

                case "product":
                    ParagraphProduct productParagraph = (ParagraphProduct)paragraph;
                    paragraphJson["id"] = productParagraph.Id;
                    break;
                }
                body.Add(paragraphJson);
            }
            result["body"] = body;

            JArray related_medias = new JArray();

            foreach (RelatedMedia relatedMedia in article.RelatedMedias)
            {
                JObject relatedMediaJson = new JObject();
                relatedMediaJson["id"] = relatedMedia.Id;
                related_medias.Add(relatedMediaJson);
            }

            result["related_medias"] = related_medias;

            if (article.TrackingLink != null)
            {
                if (article.TrackingLink.Length != 0)
                {
                    result["tracking_link"] = article.TrackingLink;
                }
            }
            result["status"]  = article.Status.getValue();
            result["comment"] = article.Comment.getValue();

            return(result);
        }
コード例 #3
0
        static public C1PrintDocument TextStyles()
        {
            C1.C1Preview.C1PrintDocument doc = new C1.C1Preview.C1PrintDocument();

            RenderText rtxt = new RenderText(doc);

            rtxt.Text                = "Text styles in C1PrintDocument";
            rtxt.Style.FontName      = "Arial";
            rtxt.Style.FontSize      = 18;
            rtxt.Style.FontBold      = true;
            rtxt.Style.TextAlignHorz = AlignHorzEnum.Center;
            rtxt.Style.Padding.All   = new Unit("5mm");
            doc.Body.Children.Add(rtxt);

            // setup some text styles
            Style s1 = doc.Style.Children.Add();

            s1.TextColor = Colors.Blue;
            s1.FontBold  = true;

            Style s2 = doc.Style.Children.Add();

            s2.BackColor = Colors.Chartreuse;

            Style s3 = doc.Style.Children.Add();

            s3.TextColor = Colors.Red;

            Style s4 = doc.Style.Children.Add();

            s4.FontName   = "Arial";
            s4.FontSize   = 14;
            s4.FontBold   = true;
            s4.FontItalic = true;

            Style s5 = doc.Style.Children.Add();

            s5.BackColor = s2.BackColor;
            s5.TextColor = s3.TextColor;
            s5.Font      = s4.Font;

            RenderParagraph rp = new RenderParagraph(doc);

            ParagraphObject po = new ParagraphText("In ");

            rp.Content.Add(po);
            po = new ParagraphText("C1PrintDocument");
            po.Style.AssignNonInheritedFrom(s1);
            rp.Content.Add(po);
            rp.Content.Add(new ParagraphText(", multi-style text is fully supported via "));
            rp.Content.Add(new ParagraphText("RenderParagraph", Colors.Blue));
            rp.Content.Add(new ParagraphText(" render objects."));

            rp.Content.Add(new ParagraphText("\rWithin a single paragraph, you can change "));

            po = new ParagraphText("background color,");
            po.Style.Parent = s2;
            rp.Content.Add(po);

            po = new ParagraphText(" text color,");
            po.Style.AssignNonInheritedFrom(s3);
            rp.Content.Add(po);

            po = new ParagraphText(" font,");
            po.Style.AssignNonInheritedFrom(s4);
            rp.Content.Add(po);

            po = new ParagraphText(" or all together.");
            po.Style.AssignNonInheritedFrom(s5);
            rp.Content.Add(po);

            rp.Content.Add(new ParagraphText("\rFont sub-properties such as "));
            rp.Content.Add(new ParagraphText("bold, "));
            rp.Content[rp.Content.Count - 1].Style.FontBold = true;
            rp.Content.Add(new ParagraphText("italic "));
            rp.Content[rp.Content.Count - 1].Style.FontItalic = true;
            rp.Content.Add(new ParagraphText("or "));
            rp.Content.Add(new ParagraphText("underline"));
            rp.Content[rp.Content.Count - 1].Style.FontUnderline = true;
            rp.Content.Add(new ParagraphText(" can be individually adjusted."));

            rp.Content.Add(new ParagraphText("\rText positions such as "));
            rp.Content.Add(new ParagraphText("superscript", TextPositionEnum.Superscript));
            rp.Content.Add(new ParagraphText(" and "));
            rp.Content.Add(new ParagraphText("subscript", TextPositionEnum.Subscript));
            rp.Content.Add(new ParagraphText(" are supported."));

            po = new ParagraphText("\rInline images ");
            rp.Content.Add(po);
            System.Drawing.Image inlineImage = System.Drawing.Image.FromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("DemoTables.check.png"));
            po = new ParagraphImage(inlineImage);
            rp.Content.Add(po);
            po = new ParagraphText(" can be embedded in the text as well.");
            rp.Content.Add(po);

            doc.Body.Children.Add(rp);

            return(doc);
        }
コード例 #4
0
        private C1.C1Preview.C1PrintDocument makeDoc_TextStyles()
        {
            C1.C1Preview.C1PrintDocument doc = new C1.C1Preview.C1PrintDocument();

            RenderText rtxt = new RenderText(doc);

            rtxt.Text                = "Text styles in the new C1PrintDocument";
            rtxt.Style.Font          = new Font("Arial", 18, FontStyle.Bold);
            rtxt.Style.TextAlignHorz = AlignHorzEnum.Center;
            rtxt.Style.Padding.All   = new Unit("5mm");
            doc.Body.Children.Add(rtxt);

            // setup some text styles
            Style s1 = doc.Style.Children.Add();

            s1.TextColor = Color.Blue;
            s1.Font      = new Font(s1.Font, FontStyle.Bold);

            Style s2 = doc.Style.Children.Add();

            s2.BackColor = Color.Chartreuse;

            Style s3 = doc.Style.Children.Add();

            s3.TextColor = Color.Red;

            Style s4 = doc.Style.Children.Add();

            s4.Font = new Font("Arial", 14, FontStyle.Bold | FontStyle.Italic);

            Style s5 = doc.Style.Children.Add();

            s5.BackColor = s2.BackColor;
            s5.TextColor = s3.TextColor;
            s5.Font      = s4.Font;


            RenderParagraph rp = new RenderParagraph(doc);

            ParagraphObject po = new ParagraphText("In the new ");

            rp.Content.Add(po);
            po = new ParagraphText("C1PrintDocument");
            po.Style.AssignNonInheritedFrom(s1);
            rp.Content.Add(po);
            po = new ParagraphText(" multi-style text is fully supported. You can change ", TextPositionEnum.Normal);
            rp.Content.Add(po);

            po = new ParagraphText("the background color,");
            // po.Style.AssignNonInheritedFrom(s2);
            po.Style.Parent = s2;
            rp.Content.Add(po);

            po = new ParagraphText(" text color,");
            po.Style.AssignNonInheritedFrom(s3);
            rp.Content.Add(po);

            po = new ParagraphText(" font,");
            po.Style.AssignNonInheritedFrom(s4);
            rp.Content.Add(po);

            po = new ParagraphText(" or all together.");
            po.Style.AssignNonInheritedFrom(s5);
            rp.Content.Add(po);

            po = new ParagraphText(" Superscript", TextPositionEnum.Superscript);
            rp.Content.Add(po);

            po = new ParagraphText(" and ");
            rp.Content.Add(po);

            po = new ParagraphText("Subscript", TextPositionEnum.Subscript);
            rp.Content.Add(po);

            po = new ParagraphText(" text can be rendered.");
            rp.Content.Add(po);

            po = new ParagraphText(" Additionally, images ");
            rp.Content.Add(po);
            po = new ParagraphImage(pictureBox2.Image);
            rp.Content.Add(po);
            po = new ParagraphText(" can be embedded in the text as well.");
            rp.Content.Add(po);

            doc.Body.Children.Add(rp);

            return(doc);
        }