internal TaxonomyNode AddChildTo(TaxonomyNode taxon, string name, string description)
        {
            if (taxon.IsDetached)
            {
                throw new Exception(String.Format("Taxon '{0}' is detached", taxon.Name));
            }
            if (taxon.Children.Any(x => x.Name == name))
            {
                throw new DataLayerException("Duplicate taxon name in node");
            }
            var entity = new TaxonEntity()
            {
                Name        = name,
                Description = description
            };

            repo.Save(entity);
            relationSrv.AddRelation(taxon.entity, entity, RelationDirection.Forward, rootNode);
            var newNode = new TaxonomyNode(this, entity)
            {
                parent = taxon
            };

            taxon.children.Add(newNode);
            return(newNode);
        }
        public TaxonomyTree(ILog log, TaxonRepository repo, RelationService relationSrv, int rootId)
        {
            this.log         = log;
            this.rootId      = rootId;
            this.repo        = repo;
            this.relationSrv = relationSrv;
            rootEntity       = repo.Get(rootId);

            if (rootEntity == null)
            {
                if (rootId == 1)
                {
                    rootEntity = new TaxonEntity()
                    {
                        Name        = "Root",
                        Description = "Root node - parent of all taxon entries"
                    };
                    repo.Save(rootEntity);
                }
                else
                {
                    throw new Exception("Root node is not found");
                }
            }
            rootNode = new TaxonomyNode(this, rootEntity);
        }
        internal void RemoveNode(TaxonomyNode taxonomyNode, bool includeChildren)
        {
            if (taxonomyNode.IsDetached)
            {
                throw new Exception(String.Format("Taxon '{0}' is detached", taxonomyNode.Name));
            }
            if (taxonomyNode == rootNode)
            {
                throw new Exception("Can't remove root");
            }
            if (!includeChildren && taxonomyNode.Children.Count > 0)
            {
                throw new DataLayerException("Taxon have children");
            }

            var nodesToRemove = new List <TaxonomyNode>(taxonomyNode.GetAllChildren());

            nodesToRemove.Add(taxonomyNode);
            foreach (var node in nodesToRemove)
            {
                node.IsDetached = true;
                repo.Delete(node.entity);
            }
            taxonomyNode.Parent.children.Remove(taxonomyNode);
        }
 internal void UpdateEntity(TaxonomyNode taxon)
 {
     if (taxon.IsDetached)
     {
         throw new Exception(String.Format("Taxon '{0}' is detached", taxon.Name));
     }
     repo.Update(taxon.entity);
 }
 public StateEntity Put <T>(string key, object obj, TaxonomyNode trigger = null, long durationSeconds = 0, string description = null)
     where T : class
 {
     lock (stateLocker)
     {
         Remove <T>(key);
         return(repo.CreateAndPersist(String.Format("{0}", key), (T)obj, trigger, durationSeconds, description));
     }
 }
Example #6
0
        public int RemoveRelations(IClassifiable relatable, TaxonomyNode type = null)
        {
            var rels = relationRepo.GetAllRelationsFor(relatable).AsEnumerable();

            if (type != null)
            {
                rels = rels.Where(r => r.Type != null && r.Type.Id == type.entity.Id);
            }
            relationRepo.DeleteAll(rels);
            return(rels.Count());
        }
 dynamic ToJson(TaxonomyNode node)
 {
     return new 
                {
                    id = node.Path,
                    text = node.Name,
                    description = node.Description,
                    expanded = false,
                    hasChildren = node.Children.Count
                };
 }
 IEnumerable<dynamic> GetMenuItems(TaxonomyNode node)
 {
     return node.Children.Select(
         n => new
         {
             name = n.Name,
             action = n.Description,
             menuitems = GetMenuItems(n),
             weight = 0
         });
 }
        internal TaxonomyNode LoadParent(TaxonomyNode taxon)
        {
            if (taxon.IsDetached)
            {
                throw new Exception(String.Format("Taxon '{0}' is detached", taxon.Name));
            }
            var entity = relationSrv.GetByRelated <TaxonEntity>(taxon.entity, RelationDirection.Forward, rootNode).FirstOrDefault();

            if (entity == null)
            {
                return(null);
            }
            return(new TaxonomyNode(this, entity));
        }
Example #10
0
        public MetricsService(
            MetricsRepository metricsRepo,
            MetricsEntryRepository metricsEntryRepo,
            RelationService relationService,
            TaxonomyTree taxonomyTree,
            ILog log)
        {
            this.metricsRepo      = metricsRepo;
            this.metricsEntryRepo = metricsEntryRepo;
            this.relationService  = relationService;
            this.log = log;

            relationNode = taxonomyTree.GetOrCreatePath(RELATIONS_PATH, "MetricsRepository relations");
        }
        public MetricsService(
            MetricsRepository metricsRepo,
            MetricsEntryRepository metricsEntryRepo,
            RelationService relationService,
            TaxonomyTree taxonomyTree,
            ILog log)
        {
            this.metricsRepo = metricsRepo;
            this.metricsEntryRepo = metricsEntryRepo;
            this.relationService = relationService;
            this.log = log;

            relationNode = taxonomyTree.GetOrCreatePath(RELATIONS_PATH, "MetricsRepository relations");
        }
        public HttpProxyDecoratorBase(
            HttpProxyRepository repo, 
            TaxonomyTree tree,
            StateService stateService, 
            ILog log)
        {
            _repo = repo;
            _tree = tree;
            _stateService = stateService;
            _log = log;

            StoringDuration = TimeSpan.FromHours(3); //default storing duration 3 hours //one day
            RootDescriminatorStateTriggers =
                tree.GetOrCreatePath(STATE_TRIGGER_PATH, "Trigger to flush all Browsing cache");
        }
        internal List <TaxonomyNode> LoadChildren(TaxonomyNode taxon)
        {
            if (taxon.IsDetached)
            {
                throw new Exception(String.Format("Taxon '{0}' is detached", taxon.Name));
            }
            var children = new List <TaxonomyNode>();
            var entities = relationSrv.GetRelated <TaxonEntity>(taxon.entity, RelationDirection.Forward, rootNode).ToList();

            foreach (var entity in entities)
            {
                var newNode = new TaxonomyNode(this, entity)
                {
                    parent = taxon
                };
                children.Add(newNode);
            }
            return(children);
        }
 public bool IsClassified(IClassifiable classifiable, TaxonomyNode node)
 {
     return(relationSrv.IsRelated(classifiable, node));
 }
Example #15
0
 public IList <T> GetByRelated <T>(IClassifiable classifiable, RelationDirection direction = RelationDirection.Undefined, TaxonomyNode type = null) where T : Entity, IClassifiable
 {
     return(relationRepo.GetByRelated <T>(classifiable, direction, type == null?null:type.entity));
 }
 public void Trigger(TaxonomyNode trigger, bool withChildren = false)
 {
     repo.Trigger(trigger, withChildren);
 }
Example #17
0
 public IList <RelatedIdsResult> GetByRelatedIds(IClassifiable classifiable, RelationDirection direction = RelationDirection.Undefined, TaxonomyNode type = null)
 {
     return(relationRepo.GetByRelatedIds(classifiable, direction, type == null ? null : type.entity));
 }
Example #18
0
 public void SetRelation(IClassifiable relatable, IClassifiable related, RelationDirection direction = RelationDirection.Undefined, TaxonomyNode type = null)
 {
     foreach (var relEntity in relationRepo.GetRelated(relatable, direction, type == null ? null : type.entity))
     {
         relationRepo.Delete(relEntity);
     }
     RelateInternal(relatable, related, direction, type);
 }
Example #19
0
 public void AddRelation(IClassifiable relatable, IClassifiable related, RelationDirection direction = RelationDirection.Undefined, TaxonomyNode type = null)
 {
     RelateInternal(relatable, related, direction, type);
     RelateInternal(related, relatable, BackDirection(direction), type);
 }
Example #20
0
 public void RemoveRelation(IClassifiable relatable, IClassifiable related, TaxonomyNode type = null)
 {
     AddRelation(related, relatable, type: type);
 }
Example #21
0
        protected void RelateInternal(IClassifiable relatable, IClassifiable related, RelationDirection direction, TaxonomyNode type)
        {
            var currentRelation = GetRelation(relatable, related, type);

            if (direction == RelationDirection.Undefined)
            {
                if (currentRelation != null)
                {
                    relationRepo.Delete(currentRelation);
                }
                //do nothing if direction is undefined
            }
            else
            {
                if (currentRelation == null)
                {
                    currentRelation = RelationEntity.Create(relatable, related, type == null?null:type.entity, direction);
                    relationRepo.Save(currentRelation);
                }
                else
                {
                    currentRelation.Direction = direction;
                    relationRepo.Update(currentRelation);
                }
            }
        }
Example #22
0
 public RelationEntity GetRelation(IClassifiable relatable, IClassifiable related, TaxonomyNode type = null)
 {
     return(relationRepo.GetRelation(relatable, related, type == null?null:type.entity));
 }
 public IList <T> GetClassifiables <T>(TaxonomyNode node) where T : Entity, IClassifiable
 {
     return(relationSrv.GetRelated <T>(node, RelationDirection.Both));
 }
 public void Declassify(IClassifiable classifiable, TaxonomyNode node)
 {
     relationSrv.RemoveRelation(classifiable, node);
 }
Example #25
0
 public bool IsRelated(IClassifiable relatable, IClassifiable related, TaxonomyNode type = null)
 {
     return(GetRelation(relatable, related, type) != null);
 }
 public void Classify(IClassifiable classifiable, TaxonomyNode node)
 {
     relationSrv.AddRelation(classifiable, node, RelationDirection.Both);
 }