public void Init()
        {
            tree = new FamilyTree();
            tree.SetRoot(new Partnership(greg, pam), pam);
            var root = tree.Root;

            tree.AddChild(root, jeff);
            tree.AddChild(root, brent);
            tree.AddChild(root, kyle);
            tree.AddInLaw(jaclyn);
            tree.AddInLaw(aura);
            tree.AddInLaw(guy);
            tree.AddInLaw(nancy);

            var brentJaclyn = tree.AddPartnership(brent, jaclyn);

            tree.AddChild(brentJaclyn, roxi);
            tree.AddChild(brentJaclyn, della);

            var jeffAura = tree.AddPartnership(jeff, aura);

            tree.AddNonPartnershipChild(kyle, ping);

            var roxiGuy = tree.AddPartnership(roxi, guy);

            tree.AddChild(roxiGuy, timmy);

            var pingNancy = tree.AddPartnership(ping, nancy);

            tree.AddChild(pingNancy, leroy);
        }
        //Algorithm to be implemented in derived classes
        public virtual void Execute(IFamilyTree tree, IFamilyMember source = null)
        {
            if (tree == null || tree.Root == null)
            {
                throw new ArgumentNullException("Tree cannot be null.");
            }

            this.tree = tree;

            if (source != null)
            {
                if (!tree.MemberExists(source))
                {
                    throw new NotInFamilyTreeException(source);
                }
                //prevent source from being inlaw. Inlaws do not have parents, which
                //breaks traversal.
                if (source.HasFact(FactType.InLaw))
                {
                    throw new InvalidSourceException(source);
                }

                source.AddFact(FactType.XPosition, 0);
                source.AddFact(FactType.XPosition, 0);
                this.source = source;
            }

            Execute();
        }
Ejemplo n.º 3
0
        public CommandProcessor(IFamilyTree familyTree, string filename)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException($"{filename} does not exist");
            }
            var fileData = File.ReadAllText(filename);

            _commands  = fileData.Split(Environment.NewLine);
            FamilyTree = familyTree;
        }
        public override void Execute(IFamilyTree familyTree)
        {
            try
            {
                string relationsObtained = string.Join(" , ", familyTree.GetFamilyMembersForRelation(MemberName, RelationShipToGet).ToArray());

                Console.WriteLine("Found the following relations - " + relationsObtained + " for " + this.MemberName + " for relation type -" + RelationShipToGet);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
        public override void Execute(IFamilyTree familyTree)
        {
            try
            {
                familyTree.AddChild(MothersName, ChildName, IsChildMale);

                Console.WriteLine("Operation executed successfully.. Added  the child - " + ChildName + " under the mother - " + MothersName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
        }
Ejemplo n.º 6
0
 public void Process(IFamilyTree tree, IFamilyMember source)
 {
     try
     {
         foreach (var alg in algorithms)
         {
             alg.Execute(tree, source);
         }
     }
     catch (Exception)
     {
         tree.ClearMemberFacts();
         throw;
     }
 }
 public abstract void Execute(IFamilyTree familyTree);
Ejemplo n.º 8
0
 public void GatherFacts(IFamilyTree tree, IFamilyMember source)
 {
     treeProcessor.Process(tree, source);
 }