示例#1
0
        public Node CreateNode(Node newNode)
        {
            NodeValidator nodeValidator = new NodeValidator();

            nodeValidator.Validate(newNode);

            using (IdeaStorageEntities context = new IdeaStorageEntities())
            {
                NODE newDbNode = new NODE
                {
                    Created   = newNode.Created,
                    IsDeleted = newNode.IsDeleted,
                    Modified  = newNode.Modified,
                    OwnerId   = newNode.OwnerId,
                    Text      = newNode.Text,
                    Title     = newNode.Title
                };

                TagManager tagManager = new TagManager();
                foreach (Tag tag in newNode.Tags)
                {
                    tag.TagId = tagManager.CreateTag(tag).TagId;
                    context.TAGSETS.Add(new TAGSET {
                        NodeId = newDbNode.NodeId, TagId = tag.TagId
                    });
                }

                context.NODES.Add(newDbNode);
                context.SaveChanges();

                return(newDbNode.ToModel());
            }
        }
示例#2
0
        public override SiteMapNode GetParentNode(SiteMapNode node)
        {
            var crmNode = node as CrmSiteMapNode;

            if (crmNode == null)
            {
                return(null);
            }

            var portal  = PortalContext;
            var context = portal.ServiceContext;
            var website = portal.Website;

            var entity = context.MergeClone(crmNode.Entity);

            if (crmNode.HasCrmEntityName("adx_communityforum"))
            {
                var parentPage = entity.GetRelatedEntity(context, "adx_webpage_communityforum");

                // If this association doesn't exist, this is an old schema, return the "Forums" page as the parent.
                if (parentPage == null)
                {
                    var forumsRootPage = OrganizationServiceContextExtensions.GetPageBySiteMarkerName(context, website, "Forums");

                    return(SiteMap.Provider.FindSiteMapNode(context.GetUrl(forumsRootPage)));
                }

                return(SiteMap.Provider.FindSiteMapNode(context.GetUrl(parentPage)));
            }

            if (crmNode.HasCrmEntityName("adx_communityforumthread"))
            {
                var parentForum = entity.GetRelatedEntity(context, "adx_communityforum_communityforumthread");

                if (parentForum == null)
                {
                    return(null);
                }

                var parentForumNode = GetForumNode(context, parentForum);

                return(NodeValidator.Validate(context, parentForumNode) ? parentForumNode : null);
            }

            return(null);
        }
示例#3
0
        public void UpdateNode(Node node)
        {
            NodeValidator nodeValidator = new NodeValidator();

            nodeValidator.Validate(node);

            using (IdeaStorageEntities context = new IdeaStorageEntities())
            {
                NODE dbNode = context.NODES.FirstOrDefault(n => n.NodeId == node.NodeId);

                if (dbNode == null)
                {
                    string message = string.Format("Node with ID:'{0}' doesn't exist in data base.", node.NodeId);
                    Log.Debug(message);
                    throw new EntityDoesNotExistException(message);
                }

                dbNode.Modified = node.Modified;
                dbNode.Text     = node.Text;
                dbNode.Title    = node.Title;

                List <TAGSET> dbDeleteTagsets = context.TAGSETS.Where(ts => ts.NodeId == node.NodeId).ToList();
                context.TAGSETS.RemoveRange(dbDeleteTagsets);

                TagManager tagManager = new TagManager();
                foreach (Tag tag in node.Tags)
                {
                    tag.TagId = tagManager.CreateTag(tag).TagId;
                    context.TAGSETS.Add(new TAGSET {
                        NodeId = dbNode.NodeId, TagId = tag.TagId
                    });
                }

                context.NODES.AddOrUpdate(dbNode);
                context.SaveChanges();
            }
        }
示例#4
0
 /// <summary>
 /// Creates a new NodeParser. If running in DEBUG mode, the following checks are done:
 /// - unknown attributes
 /// - missing required attributes
 /// - unknown child nodes
 /// - missing required child nodes
 /// The results are printed to the Trace.
 /// </summary>
 /// <param name="validator">The validator to use for validation.</param>
 /// <param name="node">The Node that shall be parsed and checked.</param>
 internal NodeParser(NodeValidator validator, Node node)
 {
     validator.Validate(this, node);
 }
        public override SiteMapNode GetParentNode(SiteMapNode node)
        {
            var entityNode = node as CrmSiteMapNode;

            if (entityNode == null)
            {
                return(null);
            }

            var portal         = PortalContext;
            var serviceContext = portal.ServiceContext;

            var entity = serviceContext.MergeClone(entityNode.Entity);

            if (entityNode.HasCrmEntityName("adx_blog"))
            {
                DateTime monthArchiveDate;
                var      authorArchive = entityNode[AuthorArchiveNodeAttributeKey];
                var      tagArchive    = entityNode[TagArchiveNodeAttributeKey];

                if (TryGetMonthArchiveNodeAttribute(node, out monthArchiveDate) || !string.IsNullOrEmpty(authorArchive) || !string.IsNullOrEmpty(tagArchive))
                {
                    var blogNode = GetBlogNode(serviceContext, entity);

                    return(NodeValidator.Validate(serviceContext, blogNode) ? blogNode : null);
                }

                var page = entity.GetRelatedEntity(serviceContext, "adx_webpage_blog");

                return(page == null ? null : SiteMap.Provider.FindSiteMapNode(serviceContext.GetUrl(page)));
            }

            if (entityNode.HasCrmEntityName("adx_blogpost"))
            {
                var blog = entity.GetRelatedEntity(serviceContext, "adx_blog_blogpost");

                if (blog == null)
                {
                    return(null);
                }

                var blogNode = GetBlogNode(serviceContext, blog);

                return(NodeValidator.Validate(serviceContext, blogNode) ? blogNode : null);
            }

            if (entityNode.HasCrmEntityName("adx_webfile"))
            {
                var blogPost = entity.GetRelatedEntity(serviceContext, "adx_blogpost_webfile");

                if (blogPost == null)
                {
                    return(null);
                }

                var blogPostNode = GetBlogPostNode(serviceContext, blogPost);

                return(NodeValidator.Validate(serviceContext, blogPostNode) ? blogPostNode : null);
            }

            if (entityNode.HasCrmEntityName("adx_webpage") && node["IsAggregationArchiveNode"] == "true")
            {
                return(SiteMap.Provider.FindSiteMapNode(serviceContext.GetUrl(entity)));
            }

            return(null);
        }
示例#6
0
        public async Task <IActionResult> ExtractNodes([FromBody] FeatureCollection josm)
        {
            try
            {
                // Start a timer.
                DateTime start = DateTime.Now;

                // Attempt to classify.
                if (!NodeClassifier.Classify(josm, out List <string> errors))
                {
                    return(BadRequest(new { NodeExtractorErrors = errors }));
                }

                // Validate the data.
                if (!NodeValidator.Validate(josm, out errors, out List <string> warnings))
                {
                    return(BadRequest(new { NodeExtractorErrors = errors, NodeExtractorWarnings = warnings }));
                }

                // Parse the JOSM data to nodes and edges.
                if (!NodeExtractor.ParseNodeSource(josm, out List <Node> nodes, out List <NodeEdge> edges))
                {
                    errors.Add("Parsing of JOSM failed!");
                    return(BadRequest(new { NodeExtractorErrors = errors }));
                }

                // Check for broken connections on this floor.
                List <string> brokenConnections = NodeExtractor.VerifyNodeEdgesSingleFloor(nodes, edges);

                if (brokenConnections.Count > 0)
                {
                    errors.AddRange(brokenConnections);
                    return(BadRequest(new { NodeExtractorErrors = errors }));
                }

                // Check for duplicates.
                foreach (Node node in nodes)
                {
                    int duplicateCount = nodes.Count(n => n.NodeId == node.NodeId);
                    if (duplicateCount > 1)
                    {
                        errors.Add($"Node Extractor: The node Id {node.NodeId} is duplicated {duplicateCount} times, Ids must be unique!");
                        return(BadRequest(new { NodeExtractorErrors = errors }));
                    }
                }

                // Write nodes to database.
                await WriteNodesToDatabase(nodes);

                // Calculate weights.
                edges = NodeExtractor.CalculateWeights(nodes, edges, AppSettings.EdgeCaseWeights);

                // Write edges to database.
                await WriteNodeEdgesToDatabase(edges);

                await DissDatabaseContext.SaveChangesAsync();

                // Stop the timer and return to the client a message indicating run time and warnings.
                DateTime end = DateTime.Now;
                return(Created("", new { processingTime = $"Node Extractor for {nodes.FirstOrDefault()?.BuildingCode.ToUpper()}{nodes.FirstOrDefault()?.Floor} finished in: {Math.Round((end - start).TotalMilliseconds, 2)}ms.", warnings }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }