コード例 #1
0
 private void GetBlocks(XElement curNode)
 {
     if (curNode.Name.Equals(Xns + "img"))
     {
         int        id     = ImageBlocks.Count;
         ImageBlock iBlock = new ImageBlock(id, curNode, this);
         ImageBlocks.Add(iBlock);
         curNode.SetAttributeValue("id", iBlock.B_ID);
         Blocks.Add(iBlock);
     }
     foreach (XNode childNode in curNode.Nodes())
     {
         if (childNode is XText)
         {
             XText        textNode = childNode as XText;
             int          id       = ContentBlocks.Count;
             String       text     = textNode.Value;
             ContentBlock cBlock   = new ContentBlock(id, text, this);
             ContentBlocks.Add(cBlock);
             textNode.Value = cBlock.B_ID;
             Blocks.Add(cBlock);
         }
         else if (childNode is XElement)
         {
             GetBlocks(childNode as XElement);
         }
     }
 }
コード例 #2
0
        public void SetUp()
        {
            _contentBlocks = new ContentBlocks
            {
                contentBlocks = new List <ContentBlock>
                {
                    new ContentBlock
                    {
                        Title = "error1",
                        Id    = 1
                    },
                    new ContentBlock
                    {
                        Title = "error2",
                        Id    = 2
                    },
                    new ContentBlock
                    {
                        Title = "error3",
                        Id    = 3
                    }
                }
            };
            var restResponse = new Mock <IRestResponse <ContentBlocks> >();

            restResponse.Setup(mocked => mocked.Data).Returns(_contentBlocks);

            _cmsRestClient = new Mock <IRestClient>();
            _cmsRestClient.Setup(mocked => mocked.Execute <ContentBlocks>(It.IsAny <IRestRequest>())).Returns(restResponse.Object);

            _fixture = new ContentBlockService(_cmsRestClient.Object);
        }
コード例 #3
0
        public void CleanUp()
        {
            var           operations   = new ContentOperations <ContentBlocks>();
            ContentBlocks contentBlock = new ContentBlocks();

            contentBlock.ID = contentBlockId;
            if (operations.GetItem(contentBlock).StatusCode == HttpStatusCode.OK)
            {
                operations.Delete(contentBlock);
            }
        }
コード例 #4
0
        public void DeleteContentBlock()
        {
            this.CreateContentBlock();
            ContentBlocks contentBlock = new ContentBlocks();

            contentBlock.ID = contentBlockId;

            var operations = new ContentOperations <ContentBlocks>();

            var response = operations.Delete(contentBlock);

            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
        }
コード例 #5
0
        /// <summary>
        /// Add a new content block to this gadget
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public ContentBlock AddContentBlock(ContentBlock content)
        {
            content.MyRootMaster = this;
            ContentBlocks.Add(content);
            content.IncludeWrappingDivs = RenderingOptions.DivWrapContentBlocks;
            //check for reserved profile.left / profile.right and handle side effects
            string pmount;

            if (content.IsReservedProfileView(out pmount))
            {
                this.MySpaceViewSettings.ProfileLocation = pmount;
            }

            return(content);
        }
コード例 #6
0
        public void ModifyContentBlock()
        {
            this.CreateContentBlock();
            var operations = new ContentOperations <ContentBlocks>();

            ContentBlocks contentBlockItem = new ContentBlocks();

            contentBlockItem.ID     = contentBlockId;
            contentBlockItem.Title += "Updated";

            var response = operations.Modify(contentBlockItem);

            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);

            response = operations.GetItem(contentBlockItem);
            var results = JsonConvert.DeserializeObject <dynamic>(response.Content);

            Assert.AreEqual(contentBlockItem.Title, results.Title.ToString());
        }
コード例 #7
0
        public void CreateContentBlock()
        {
            var operations = new ContentOperations <ContentBlocks>();

            var contentBlock = new ContentBlocks();

            ContentBlockTitle    = TestContentPrefix + Guid.NewGuid().ToString();
            contentBlock.Title   = ContentBlockTitle;
            contentBlock.Content = ContentBlockContent;

            var response = operations.CreateDraft(contentBlock);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);

            var results = JsonConvert.DeserializeObject <dynamic>(response.Content);

            Assert.AreEqual(contentBlock.Title, results.Title.ToString());
            Assert.AreEqual(contentBlock.Content, results.Content.ToString());

            contentBlockId = results.Id;
            Assert.IsNotNull(contentBlockId);
        }
コード例 #8
0
        public ContentBlockService(IRestClient cmsRestClient)
        {
            try
            {
                // NOTE: In order to connect to the CMS server over SSL, you must enable
                // SecurityProtocolType.Tls12.  This is handled already in TlsHelper.cs
                // called from Application_Start(), but if this code is reused elsewhere
                // beware of this dependency.
                RestRequest   request  = new RestRequest("/api/ContentBlock", Method.GET);
                IRestResponse response = cmsRestClient.Execute(request);

                ContentBlocks blocks = JsonConvert.DeserializeObject <ContentBlocks>(response.Content);
                foreach (ContentBlock b in blocks.contentBlocks)
                {
                    Add(b.Title, b);
                }
            }
            catch (Exception e)
            {
                _logger.Error("ContentBlockService: Unable to get the content blocks from the CMS!", e);
            }
        }
コード例 #9
0
        public void SetUp()
        {
            _contentBlocks = new ContentBlocks
            {
                contentBlocks = new List <ContentBlock>
                {
                    new ContentBlock
                    {
                        Title   = "error1",
                        Id      = 1,
                        Type    = ContentBlockType.Error,
                        Content = "Error Message Text"
                    },
                    new ContentBlock
                    {
                        Title   = "info2",
                        Id      = 2,
                        Type    = ContentBlockType.Info,
                        Content = "Info Message Text"
                    },
                    new ContentBlock
                    {
                        Title   = "success3",
                        Id      = 3,
                        Type    = ContentBlockType.Success,
                        Content = "Success Message Text"
                    }
                }
            };
            var restResponse = new Mock <IRestResponse <string> >();

            restResponse.Setup(mocked => mocked.Content).Returns(JsonConvert.SerializeObject(_contentBlocks));

            _cmsRestClient = new Mock <IRestClient>();
            _cmsRestClient.Setup(mocked => mocked.Execute(It.IsAny <IRestRequest>())).Returns(restResponse.Object);

            _fixture = new ContentBlockService(_cmsRestClient.Object);
        }
コード例 #10
0
        protected PDFContentBlock ProcessTreeNode(IPDFDictionary node, PDFName type)
        {
            PDFContentBlock cb = new PDFContentBlock
            {
                StartMarker = new PDFContentOperator
                {
                    Name      = "BDC",
                    Arguments = new List <IPDFToken>
                    {
                        type,
                        node
                    }
                },
                Content = new List <PDFContentOperator>()
            };

            if (node.Dict.ContainsKey("K"))
            {
                IPDFElement K = node.Dict["K"];
                if (K is IPDFList && ((IPDFList)K).List != null)
                {
                    foreach (IPDFElement elem in ((IPDFList)K).List)
                    {
                        if (elem is IPDFDictionary)
                        {
                            IPDFDictionary v = (IPDFDictionary)elem;
                            PDFName        vtype;
                            if (v.Dict.TryGet("S", out vtype))
                            {
                                PDFContentBlock blk = ProcessTreeNode(v, vtype);
                                blk.Parent = cb;
                                cb.Content.Add(blk);
                            }
                        }
                        else if (elem is PDFInteger)
                        {
                            long       mcid = ((PDFInteger)elem).Value;
                            IPDFObjRef objref;

                            if (node.Dict.TryGet("Pg", out objref))
                            {
                                if (ContentBlocks.ContainsKey(objref.ObjRef))
                                {
                                    Dictionary <long, PDFContentBlock> blocksByMcid = ContentBlocks[objref.ObjRef];
                                    if (blocksByMcid.ContainsKey(mcid))
                                    {
                                        PDFContentBlock blk = blocksByMcid[mcid];
                                        blk.Parent = cb;
                                        cb.Content.Add(blk);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (K is IPDFDictionary && ((IPDFDictionary)K).Dict != null)
                {
                    PDFName vtype;
                    if (((IPDFDictionary)K).Dict.TryGet("S", out vtype))
                    {
                        PDFContentBlock blk = ProcessTreeNode((IPDFDictionary)K, vtype);
                        blk.Parent = cb;
                        cb.Content.Add(blk);
                    }
                    else
                    {
                        System.Diagnostics.Debugger.Break();
                    }
                }
                else if (K is PDFInteger && node.Dict.ContainsKey("Pg"))
                {
                    long       mcid = ((PDFInteger)K).Value;
                    IPDFObjRef objref;

                    if (node.Dict.TryGet("Pg", out objref))
                    {
                        if (ContentBlocks.ContainsKey(objref.ObjRef))
                        {
                            Dictionary <long, PDFContentBlock> blocksByMcid = ContentBlocks[objref.ObjRef];
                            if (blocksByMcid.ContainsKey(mcid))
                            {
                                PDFContentBlock blk = blocksByMcid[mcid];
                                blk.Parent = cb;
                                cb.Content.Add(blk);
                            }
                        }
                    }
                }
            }

            return(cb);
        }