Ejemplo n.º 1
0
        public void UninstallPackage(Package package, bool checkDependencies = true)
        {
            if (checkDependencies)
            {
                OnStatusChanged(new StatusEventArgs(package, StatusType.CheckingDependencies, 0));
                Console.WriteLine("Checking for depending packages: {0}", package.Name);

                // Check depending packages before uninstall
                foreach (string xml in Cache.GetAllCachedPackageXml())
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(xml);
                    if (doc.SelectNodes("//dependencies/package[@id=\"" + package.Name + "\"]").OfType<XmlNode>().Any())
                        throw new DependencyException(string.Format("Package {0} is depending on package {1} which was marked for uninstallation.", doc.SelectSingleNode("//package/name").InnerText, package.Name));
                }
            }

            OnStatusChanged(new StatusEventArgs(package, StatusType.Uninstalling, 0));
            package.Uninstall(TargetDirectory);
            OnStatusChanged(new StatusEventArgs(package, StatusType.Finalizing, 1));
            Cache.DeleteCache(package.ID);
            OnStatusChanged(new StatusEventArgs(package, StatusType.Finished, 1));
        }
Ejemplo n.º 2
0
        private void InstallDependenciesOfPackage(Package package)
        {
            //Console.WriteLine("Checking dependencies of package: {0}", package.Name);

            // TODO: Soft dependencies? See Package.cs and Dependency.cs for suggestions.
            var packages = from pkg in package.Dependencies select GetRemotePackage(pkg);

            int i = 0;
            int j = packages.Count();

            foreach (var currentPackage in packages)
            {
                OnStatusChanged(new StatusEventArgs(package, StatusType.CheckingDependencies, (float)(i / j)));

                // This expects all packages to be hard requirements ("needed to have this package working")
                if (!Cache.IsCached(currentPackage.ID)) // not installed?
                {
                    Log.DebugFormat("Dependency needs to be installed for {1}: {0}", currentPackage.ID, package.ID);
                    OnStatusChanged(new StatusEventArgs(package, StatusType.InstallingDependencies, (float)(i / j)));
                    InstallPackage(currentPackage);
                }

                i++;
            }
        }
Ejemplo n.º 3
0
 private void InstallPackage(Package package)
 {
     InstallDependenciesOfPackage(package);
     OnStatusChanged(new StatusEventArgs(package, StatusType.Installing, 0));
     package.Install(TargetDirectory);
     OnStatusChanged(new StatusEventArgs(package, StatusType.Finalizing, 1));
     Cache.CachePackage(package.ID, package.Version, package._packageXmlNode.OwnerDocument.OuterXml);
     OnStatusChanged(new StatusEventArgs(package, StatusType.Finished, 1));
 }
 public StatusEventArgs(Package package, StatusType status, float progress)
 {
     Package = package;
     Status = status;
     Progress = progress;
 }