Exemplo n.º 1
0
        /// <summary>
        /// Rebuilds the RDF graphs.
        /// </summary>
        public static void Rebuild()
        {
            _latestRebuildOutcome = "ok";

            try
            {
                var ontologyGraph = new OntologyFactory(new UmbracoDocumentTypeRepository(), new UmbracoPropertyTypeRepository()).
                    GenerateOntologyGraph();

                var resourceGraph = new ResourceFactory(new UmbracoNodeRepository(), new UmbracoPropertyTypeRepository(),
                                   new UmbracoDocumentTypeRepository()).GenerateResourceGraph();
                SaveGraphs(ontologyGraph, resourceGraph);
            }
            catch (Exception ex)
            {
                var errorEntry = string.IsNullOrEmpty(ex.Message) ? "Unspecified" : ex.Message;
                if (!string.IsNullOrEmpty(ex.StackTrace))
                {
                    errorEntry += " - " + ex.StackTrace;
                }

                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    errorEntry += " - " + ex.InnerException.Message;
                }

                _latestRebuildOutcome = errorEntry;

                Log.Error(errorEntry);
            }
        }
Exemplo n.º 2
0
        public void GenerateNode()
        {
            var focusedNode = new UmbracoNode
                                  {
                                      Name = "FocusedNode",
                                      ChildrenIds = new int[] { 2 },
                                      DocumentTypeId = 15,
                                      ParentId = 3
                                  };
            focusedNode.Properties.Add(new UmbracoProperty() { Name = "title", Value = "Focused node" });
            focusedNode.Properties.Add(new UmbracoProperty() { Name = "content4testing", Value = "Test content" });

            var childNode = new UmbracoNode
            {
                Name = "ChildNode"
            };

            var parentNode = new UmbracoNode
                                 {
                                     Name = "ParentNode"
                                 };

            var mockNodeRepo = new Mock<IUmbracoNodeRepository>();
            mockNodeRepo.Setup(x => x.GetByNodeId(1)).Returns(focusedNode);
            mockNodeRepo.Setup(x => x.GetByNodeId(2)).Returns(childNode);
            mockNodeRepo.Setup(x => x.GetByNodeId(3)).Returns(parentNode);

            var titleDt = new UmbracoPropertyType { DatabaseType = "nvarchar", Name = "title" };
            var contentDt = new UmbracoPropertyType { DatabaseType = "nvarchar", Name = "content" };
            var contentTestNameDt = new UmbracoPropertyType { DatabaseType = "nvarchar", Name = "content4testing" };

            var mockPropTypeRepo = new Mock<IUmbracoPropertyTypeRepository>();
            mockPropTypeRepo.Setup(x => x.GetForNativeDocumentTypePropertyAlias(15, "title"))
                .Returns(titleDt);
            mockPropTypeRepo.Setup(x => x.GetForNativeDocumentTypePropertyAlias(15, "content"))
                .Returns(contentDt);
            mockPropTypeRepo.Setup(x => x.GetForNativeDocumentTypePropertyAlias(15, "content4testing"))
               .Returns(contentTestNameDt);

            var dt15 = new UmbracoDocumentType()
            {
                AllowedContentTypeChildrenIds = new int[] { },
                InherritanceParentId = -1,
                Name = "TestDocumentType",
                PropertyTypes = new List<UmbracoPropertyType>()
                                                {
                                                    new UmbracoPropertyType()
                                                        {DatabaseType = "nvarchar", Name = "title"},
                                                    new UmbracoPropertyType()
                                                        {DatabaseType = "nvarchar", Name = "content"}
                                                }

            };

            var mockDocTypeRepo = new Mock<IUmbracoDocumentTypeRepository>();
            mockDocTypeRepo.Setup(x => x.GetById(15))
                .Returns(dt15);

            var resourceFactory = new ResourceFactory(mockNodeRepo.Object, mockPropTypeRepo.Object, mockDocTypeRepo.Object);

            var node = resourceFactory.GenerateNode(1);

            Assert.AreEqual("http://localhost/rdf/resource/FocusedNode", node.Iri);
            Assert.AreEqual("http://localhost/rdf/resource/ParentNode", node.ParentIri);
            Assert.AreEqual("http://localhost/rdf/resource/ChildNode", node.ChildrenIris.First());

            Assert.IsTrue(node.Properties.Any(x => x.PropertyType.Iri == "http://localhost/rdf/ontology#hasTitle" &&
                x.PropertyType.DatabaseType == "nvarchar" && x.Value == "Focused node"));

            Assert.IsTrue(node.Properties.Any(x => x.PropertyType.Iri == "http://localhost/rdf/ontology#hasTestedContent" &&
                x.PropertyType.DatabaseType == "nvarchar" && x.Value == "Test content"));
        }