Пример #1
0
        public static void Depend(InstallTree tree, string [] args)
        {
            Console.WriteLine("Adding " + args[0]);
            Console.WriteLine("Depending on " + String.Join(", ", args.Skip(1).ToArray()));
            var node     = new InstallNode(args[0]);
            var response = InstallMethods.AddNode(tree, args[0], args.Skip(1).ToList());

            if (response.Success)
            {
                Console.WriteLine("Dependency addition Successful");
            }
            else
            {
                Console.WriteLine("Dependency addition Failed");
            }
        }
Пример #2
0
 private static void UnInstallNode(InstallNode node)
 {
     if (!node.Installed)
     {
         Console.WriteLine("Already uninstalled, no action needed");
     }
     foreach (var d in node.Dependents)
     {
         if (d.Installed)
         {
             Console.WriteLine("Node " + d.Name + " is still installed and depends on " + node.Name + " can't uninstall");
             return;
         }
     }
     Console.WriteLine("No dependent nodes are installed, Uninstalling: " + node.Name);
     node.Installed = false;
     return;
 }
Пример #3
0
 public static bool DetectDepends(InstallNode nodeA, InstallNode nodeB)
 {
     if (nodeA.DependsOn.Count() == 0)
     {
         return(false);
     }
     foreach (var dependent in nodeA.DependsOn)
     {
         if (dependent.Name == nodeB.Name)
         {
             return(true);
         }
         if (DetectDepends(dependent, nodeB))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #4
0
        public static InstallResponse AddDepends(InstallTree tree, InstallNode addNode, List <String> DependsOn)
        {
            if (DependsOn == null)
            {
                return new InstallResponse()
                       {
                           Success = true, Tree = tree
                       }
            }
            ;
            foreach (var depends in DependsOn)
            {
                InstallNode n = null;

                if (tree.Nodes.ContainsKey(depends))
                {
                    n = tree.Nodes[depends];
                }
                else
                {
                    n = new InstallNode(depends);
                    tree.Nodes[depends] = n;
                }

                addNode.DependsOn.Add(n);
                if (DetectDepends(n, addNode))
                {
                    return(new InstallResponse()
                    {
                        Success = false, Tree = tree
                    });
                }
                ;
                n.Dependents.Add(addNode);
            }
            tree.Nodes[addNode.Name] = addNode;

            return(new InstallResponse()
            {
                Success = true, Tree = tree
            });
        }
Пример #5
0
 private static void InstallNode(InstallNode node)
 {
     Console.WriteLine("Attempting to Install " + node.Name);
     if (node.Installed)
     {
         Console.WriteLine("Already Installed, skipping " + node.Name);
         return;
     }
     if (node.DependsOn.Count() == 0)
     {
         node.Installed = true;
         Console.WriteLine("Installing " + node.Name);
         return;
     }
     foreach (var depends in node.DependsOn)
     {
         InstallNode(depends);
     }
     node.Installed = true;
     Console.WriteLine("Installing " + node.Name);
     return;
 }
Пример #6
0
        public static InstallResponse AddNode(InstallTree Tree, string Name, List <String> DependsOn)
        {
            if (Tree == null)
            {
                return(new InstallResponse()
                {
                    Tree = new InstallTree(), Success = false
                });
            }
            var response = new InstallResponse();

            InstallNode addNode = null;

            if (!Tree.Nodes.TryGetValue(Name, out addNode))
            {
                Tree.Nodes[Name] = addNode = new InstallNode(Name);
            }

            response.Tree = Tree;

            var depResp = AddDepends(Tree, addNode, DependsOn);

            return(depResp);
        }