private string[,,] AboutParagraphs = new string[3, 10, 2];            //temporary solution

        private dynamic GetParagraphs(ParagraphModel model)
        {
            GetCollection(model, "paragraphs", "cat", "History", 0);
            GetCollection(model, "paragraphs", "cat", "Staff", 1);
            GetCollection(model, "paragraphs", "cat", "Organization", 2);

            return(AboutParagraphs);
        }
Esempio n. 2
0
 public ParagraphModel EndParagraph()
 {
     _buffer.EndOfLine();
     var retval = new ParagraphModel(_buffer.ToArray(), _heading);
     _buffer.Clear();
     _buffer = null;
     _heading = null;
     return retval;
 }
Esempio n. 3
0
        private ParagraphModel MergePhagraph(List <ParagraphModel> paragraphs, ParagraphModel paragraph)
        {
            if (paragraph.Runs.Count == 0)
            {
                return(paragraph);
            }

            paragraphs.Add(paragraph);

            paragraph = new ParagraphModel();

            return(paragraph);
        }
Esempio n. 4
0
 // POST: api/Paragraph
 public IHttpActionResult Post([FromBody] ParagraphModel paragraphModel)
 {
     try
     {
         Utils.IsAValidToken(Request, AuthorizationBusinessLogic);
         ParagraphBusinessLogic.AddParagraph(paragraphModel.ToEntity());
         return(Ok(paragraphModel));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Esempio n. 5
0
 public IHttpActionResult Get([FromUri] Guid paragraphId)
 {
     try
     {
         Utils.IsAValidToken(Request, AuthorizationBusinessLogic);
         var paragraph = ParagraphBusinessLogic.GetParagraph(paragraphId);
         return(Ok(ParagraphModel.ToModel(paragraph)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Esempio n. 6
0
 public void TestInitialize()
 {
     paragraph      = Utils.CreateParagraphForTest();
     paragraphModel = ParagraphModel.ToModel(paragraph);
     text           = Utils.CreateTextForTest();
     textModel      = TextModel.ToModel(text);
     user           = Utils.CreateUserForTest();
     userModel      = UserModel.ToModel(user);
     mockParagraphAuthorizationLogic = new Mock <IAuthorizationBusinessLogic>();
     mockParagraphBusinessLogic      = new Mock <IParagraphBusinessLogic>();
     mockAuditLogBusinessLogic       = new Mock <IAuditLogBussinesLogic>();
     paragraphController             = new ParagraphController(mockParagraphBusinessLogic.Object, mockParagraphAuthorizationLogic.Object, mockAuditLogBusinessLogic.Object);
     InitializeToken();
 }
        public ActionResult Organization(ParagraphModel model)
        {
            ViewBag.para = "Not Working !!";

            if (ModelState.IsValid)
            {
                ViewBag.para = GetParagraphs(model);
                return(View());
            }
            else
            {
                return(View());
            }
        }
Esempio n. 8
0
 // GET: api/Paragraph
 public IHttpActionResult Get()
 {
     try
     {
         Utils.IsAValidToken(Request, AuthorizationBusinessLogic);
         var paragraphs = ParagraphBusinessLogic.GetParagraphs();
         IList <ParagraphModel> paragraphsModel = ParagraphModel.ToModel(paragraphs).ToList();
         return(Ok(paragraphsModel));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public IHttpActionResult Post([FromUri] Guid documentId, [FromBody] ParagraphModel documentPart)
        {
            try
            {
                Utils.IsAValidToken(Request, AuthorizationBusinessLogic);

                var paragraph = documentPart.ToEntity();
                DocumentBusinessLogic.AddDocumentParagraphAtLast(documentId, paragraph);

                AuditLogBussinesLogic.CreateLog("Document", documentId, Utils.GetUsername(Request), ActionPerformed.MODIFY);
                return(Ok(documentPart));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Esempio n. 10
0
        public void TestInitialize()
        {
            document       = Utils.CreateDocumentForTest();
            documentModel  = DocumentModel.ToModel(document);
            paragraph      = Utils.CreateParagraphForTest();
            paragraphModel = ParagraphModel.ToModel(paragraph);
            margin         = Utils.CreateMarginForTest();
            marginModel    = MarginModel.ToModel(margin);
            user           = Utils.CreateUserForTest();
            userModel      = UserModel.ToModel(user);
            mockDocumentAuthorizationLogic = new Mock <IAuthorizationBusinessLogic>();
            mockDocumentBusinessLogic      = new Mock <IDocumentBusinessLogic>();
            mockAuditLogBusinessLogic      = new Mock <IAuditLogBussinesLogic>();
            mockUserBusinessLogic          = new Mock <IUserBusinessLogic>();

            documentController = new DocumentController(mockDocumentBusinessLogic.Object, mockDocumentAuthorizationLogic.Object, mockAuditLogBusinessLogic.Object, mockUserBusinessLogic.Object);
            InitializeToken();
        }
Esempio n. 11
0
        public IHttpActionResult Put([FromUri] Guid paragraphId, [FromBody] ParagraphModel paragraphModel)
        {
            try
            {
                Utils.IsAValidToken(Request, AuthorizationBusinessLogic);

                paragraphModel.Id = paragraphId;

                ParagraphBusinessLogic.ModifyParagraph(paragraphModel.ToEntity());

                AuditLogBussinesLogic.CreateLog("Document", paragraphModel.DocumentId, Utils.GetUsername(Request), ActionPerformed.MODIFY);
                return(Ok("Paragraph Modified"));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        //All parameters required
        //Fiunction fills up a global 3D array with found collections
        private string[,,] GetCollection(ParagraphModel model, string collectionName, string column, string value, int tableNumber)
        {
            //Variables Declaration
            int count      = 0;                  // var used as counter
            var client     = new MongoClient("mongodb://*****:*****@ds235401.mlab.com:35401/icm_website");
            var db         = client.GetDatabase("icm_website");
            var collection = db.GetCollection <ParagraphModel>(collectionName);
            var filter     = Builders <ParagraphModel> .Filter.Eq(column, value);

            var paragraph = collection.Find(filter).ToList();

            foreach (ParagraphModel item in paragraph)
            {
                AboutParagraphs[tableNumber, count, 0] = item.title;
                AboutParagraphs[tableNumber, count, 1] = item.Pbody;
                count++;
            }
            return(AboutParagraphs);
        }
Esempio n. 13
0
        private ParagraphModel ParseParagraph(HtmlNode node)
        {
            if (string.IsNullOrWhiteSpace(node.InnerHtml))
            {
                return(null);
            }

            var model = new ParagraphModel();

            if (_primaryTitles.Any(predicate => predicate == node.Name))
            {
                model.ParagraphType = ParagraphType.Title;
            }
            else if (_secondaryTitles.Any(predicate => predicate == node.Name))
            {
                model.ParagraphType = ParagraphType.SecondaryTitle;
            }
            else if (_texts.Any(predicate => predicate == node.Name))
            {
                model.ParagraphType = ParagraphType.Text;
            }
            else if (_quotes.Any(predicate => predicate == node.Name))
            {
                model.ParagraphType = ParagraphType.Quote;
            }
            else
            {
                return(null);
            }

            foreach (var childNode in node.ChildNodes)
            {
                var text = ParseText(childNode);
                if (text != null)
                {
                    CollapseModelsIfNecessary(text, new List <TextType>());
                    model.Children.Add(text);
                }
            }

            return(model);
        }
Esempio n. 14
0
        public void UpdateRichTextBox(ParagraphModel paragraphModel, RichTextBlock richTextBlock)
        {
            try
            {
                if (paragraphModel == null ||
                    (paragraphModel.Runs.Count == 1 && paragraphModel.Runs.FirstOrDefault() is LineBreakRun))
                {
                    return;
                }

                richTextBlock.Blocks.Clear();

                var paragraph = new Paragraph();
                foreach (var run in paragraphModel.Runs)
                {
                    #region Paragraph Build

                    if (run is LineBreakRun)
                    {
                        #region LineBreak

                        var span = new Span();
                        span.Inlines.Add(new LineBreak());

                        paragraph.Inlines.Add(span);

                        #endregion
                    }
                    else if (run is TextRun)
                    {
                        #region TextRun

                        var textRun = run as TextRun;
                        var span    = new Span();

                        switch (textRun.Type)
                        {
                        case TextType.Plain:
                            span.Inlines.Add(new Run()
                            {
                                Text = Decode(textRun.Text)
                            });
                            break;

                        case TextType.H1:
                        case TextType.H2:
                        case TextType.H3:
                        case TextType.Bold:
                            var bold = new Bold();

                            bold.Inlines.Add(new Run()
                            {
                                Text = Decode(textRun.Text)
                            });

                            span.Inlines.Add(bold);
                            break;

                        case TextType.Italic:
                            var italic = new Italic();

                            italic.Inlines.Add(new Run()
                            {
                                Text = Decode(textRun.Text)
                            });

                            span.Inlines.Add(italic);
                            break;
                        }

                        paragraph.Inlines.Add(span);

                        #endregion
                    }
                    else if (run is ImageRun)
                    {
                        #region ImageRun

                        var imageRun = run as ImageRun;

                        if (imageRun.Image.Contains("equation"))
                        {
                            #region 公式

                            var img = new Image()
                            {
                                Margin              = new Thickness(6, 6, 6, 6),
                                Source              = new BitmapImage(new Uri(imageRun.Image)),
                                Stretch             = Stretch.None,
                                HorizontalAlignment = HorizontalAlignment.Left,
                                VerticalAlignment   = VerticalAlignment.Center,
                                Tag = imageRun,
                            };

                            paragraph.Inlines.Add(new InlineUIContainer()
                            {
                                Child = img,
                            });

                            #endregion
                        }
                        else
                        {
                            #region 普通图片

                            paragraph.Inlines.Add(new LineBreak());

                            paragraph.Inlines.Add(new InlineUIContainer()
                            {
                                Child = new PlaceholderImage()
                                {
                                    ImageContent = imageRun,
                                },
                            });

                            #endregion
                        }

                        #endregion
                    }
                    else if (run is ImageHrefRun)
                    {
                        #region ImageHrefRun

                        var imgHrefRun = run as ImageHrefRun;

                        var hyperLink = new HyperlinkButton()
                        {
                            Tag     = new Uri(imgHrefRun.Href),
                            Content = new Image()
                            {
                                HorizontalAlignment = HorizontalAlignment.Left,
                                VerticalAlignment   = VerticalAlignment.Center,
                                Source  = new BitmapImage(new Uri(imgHrefRun.Image)),
                                Stretch = imgHrefRun.Width > 400 ? Stretch.Fill : Stretch.UniformToFill,
                            }
                        };

                        hyperLink.Click -= HyperLink_Click;
                        hyperLink.Click += HyperLink_Click;

                        paragraph.Inlines.Add(new InlineUIContainer()
                        {
                            Child = hyperLink,
                        });

                        #endregion
                    }
                    else if (run is TextHrefRun)
                    {
                        #region TextHrefRun

                        var textHrefRun = run as TextHrefRun;

                        if (textHrefRun.IsRelative)
                        {
                            var bold = new Bold();

                            bold.Inlines.Add(new Run()
                            {
                                Text = Decode(textHrefRun.Text)
                            });

                            paragraph.Inlines.Add(bold);

                            continue;
                        }

                        var hyperLink = new HyperlinkButton()
                        {
                            Foreground = new SolidColorBrush(Theme.Instance.LinkForeColor),
                            Content    = new TextBlock()
                            {
                                Text         = Decode(textHrefRun.Text),
                                TextWrapping = TextWrapping.Wrap,
                                Margin       = new Thickness(0, 0, 0, -12),
                                Padding      = new Thickness(0, 0, 0, 0),
                                FontSize     = Theme.Instance.FeedSummary,
                            },
                            Tag = textHrefRun.Href,
                        };

                        hyperLink.Click -= HyperLink_Click;
                        hyperLink.Click += HyperLink_Click;

                        paragraph.Inlines.Add(new InlineUIContainer()
                        {
                            Child = hyperLink
                        });

                        #endregion
                    }
                    else if (run is VideoRun)
                    {
                        #region VideoRun

                        var videoRun   = run as VideoRun;
                        var videoThumb = new Grid();

                        videoThumb.Children.Add(new Image()
                        {
                            Source              = new BitmapImage(new Uri(videoRun.Thumb)),
                            Stretch             = Stretch.UniformToFill,
                            HorizontalAlignment = HorizontalAlignment.Left,
                            Margin              = new Thickness(0, 12, 0, 12),
                        });
                        videoThumb.Children.Add(new Image()
                        {
                            Source = new BitmapImage(new Uri("ms-appx:///Resource/Images/Public/play-icon.png")),
                            Width  = 88,
                            HorizontalAlignment = HorizontalAlignment.Center,
                            VerticalAlignment   = VerticalAlignment.Center
                        });

                        var hyperLink = new HyperlinkButton()
                        {
                            Tag     = new Uri(videoRun.HostPage),
                            Content = videoThumb
                        };

                        hyperLink.Click -= HyperLink_Click;
                        hyperLink.Click += HyperLink_Click;

                        var uiContainer = new InlineUIContainer()
                        {
                            Child = hyperLink
                        };

                        paragraph.Inlines.Add(uiContainer);

                        #endregion
                    }

                    #endregion
                }

                richTextBlock.Blocks.Add(paragraph);
            }
            catch (Exception ex)
            {
                UmengAnalytics.TrackException(ex, ex.Message);
            }
        }
Esempio n. 15
0
        public IList <ParagraphModel> GetParagraphs(HtmlNodeCollection nodeCollection, Boolean topEndHolder = false)
        {
            var paragraphs = new List <ParagraphModel>();

            //var header = new ParagraphModel();
            //header.Runs.Add(new LineBreakRun());
            //paragraphs.Add(header);

            try
            {
                var paragraph = new ParagraphModel();

                foreach (var node in nodeCollection)
                {
                    if (node.Name == "#text")
                    {
                        #region #text

                        var run = new TextRun()
                        {
                            Text = node.InnerText, Type = TextType.Plain
                        };

                        paragraph.Runs.Add(run);

                        #endregion
                    }
                    else if (node.Name == "div" &&
                             node.Attributes.Hashitems.ContainsKey("class") &&
                             node.Attributes["class"].Value == "video-box")
                    {
                        #region video-box-inner

                        var videoRun = GetVideobox(node);

                        if (videoRun != null)
                        {
                            paragraph = MergePhagraph(paragraphs, paragraph);

                            var para = new ParagraphModel();

                            para.Runs.Add(videoRun);

                            paragraphs.Add(para);
                        }

                        #endregion
                    }
                    else if (node.Name == "br")
                    {
                        #region br

                        paragraph.Runs.Add(new LineBreakRun());

                        #endregion
                    }
                    else if (node.Name == "b")
                    {
                        #region b

                        foreach (var child in node.ChildNodes)
                        {
                            foreach (var inline in GetInlines(child))
                            {
                                paragraph.Runs.Add(inline);
                            }
                        }

                        #endregion
                    }
                    else if (node.Name == "a")
                    {
                        #region a

                        foreach (var child in node.ChildNodes)
                        {
                            foreach (var inline in GetInlines(child))
                            {
                                paragraph.Runs.Add(inline);
                            }
                        }

                        #endregion
                    }
                    else if (node.Name == "h2" || node.Name == "p" || node.Name == "ol")
                    {
                        #region h2 p ol

                        paragraph = MergePhagraph(paragraphs, paragraph);

                        var para = new ParagraphModel();

                        foreach (var child in node.ChildNodes)
                        {
                            foreach (var inline in GetInlines(child))
                            {
                                para.Runs.Add(inline);
                            }
                        }

                        paragraphs.Add(para);

                        #endregion
                    }
                    else if (node.Name == "img")
                    {
                        #region img

                        var imageRun = new ImageRun()
                        {
                            Image = node.Attributes["src"].Value
                        };

                        if (true == node.Attributes.Hashitems.ContainsKey("data-rawwidth"))
                        {
                            imageRun.Width = Double.Parse(node.Attributes["data-rawwidth"].Value);
                        }

                        if (true == node.Attributes.Hashitems.ContainsKey("data-rawheight"))
                        {
                            imageRun.Height = Double.Parse(node.Attributes["data-rawheight"].Value);
                        }

                        if (imageRun.Width > 0)
                        {
                            paragraph = MergePhagraph(paragraphs, paragraph);

                            var para = new ParagraphModel();

                            para.Runs.Add(imageRun);

                            para.Runs.Add(new LineBreakRun());
                            paragraphs.Add(para);
                        }
                        else
                        {
                            paragraph.Runs.Add(imageRun);
                        }

                        #endregion
                    }
                    else if (node.ChildNodes.Count > 0)
                    {
                        #region Inner

                        paragraph = MergePhagraph(paragraphs, paragraph);

                        var para = new ParagraphModel();

                        foreach (var grandChildNode in node.ChildNodes)
                        {
                            var inlines = GetInlines(grandChildNode);

                            foreach (var inlineItem in inlines)
                            {
                                paragraph.Runs.Add(inlineItem);
                            }
                        }

                        paragraphs.Add(para);

                        #endregion
                    }
                }

                paragraphs.Add(paragraph);
            }
            catch (Exception ex)
            {
                UmengAnalytics.TrackException(ex, ex.Message);
            }

            return(paragraphs);
        }
 public static void SetContent(DependencyObject element, ParagraphModel value)
 {
     element.SetValue(ContentProperty, value);
 }
Esempio n. 17
0
 internal void ShowPlaceholder(ParagraphModel para)
 {
     _paragraph = para;
 }