public override void Init(string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(); } InstalledPath = path; var dirs = Directory.GetDirectories(path); var packages = new PackageCollection <ThemePackage, Theme>(); var factory = new ThemePackageFactory(); foreach (var dir in dirs) { try { var dirInfo = new DirectoryInfo(dir); if (dirInfo.Name.Equals("base", StringComparison.OrdinalIgnoreCase)) { continue; } packages.Add(factory.Create(dir)); } catch { continue; } } Packages = packages; }
/// <summary> /// Loads the packages. /// </summary> private void LoadPackages( ) { PackageCollection.Clear( ); PackageCache.Clear( ); foreach (Package package in Package.GetPackages(Application.ApplicationId)) { PackageCollection.Add(package); PackageCache.Add(package); } IEnumerable <TenantActivatedPackage> activatedPackages = TenantActivatedPackage.GetTenantActivatedPackages( ); foreach (TenantActivatedPackage activation in activatedPackages) { Package p = PackageCollection.FirstOrDefault(pkg => pkg.AppVerId == activation.AppVerId); Tenant tenant = p?.TenantCollection.FirstOrDefault(t => t.EntityId == activation.TenantId); if (tenant != null) { p.TenantCollection.Remove(tenant); } } if (PackageCollection.Count == 1) { SelectedPackage = PackageCollection[0]; } }
bool CheckAddins(bool updating) { entries.Clear(); bool addinsNotFound = false; foreach (string id in addin_ids) { string name = Addin.GetIdName(id); string version = Addin.GetIdVersion(id); AddinRepositoryEntry[] ares = setup.Repositories.GetAvailableAddin(name, version); if (ares.Length == 0) { addinsNotFound = true; } else { entries.Add(Package.FromRepository(ares[0])); } } DependencyCollection unresolved; PackageCollection toUninstall; if (!setup.ResolveDependencies(this, entries, out toUninstall, out unresolved)) { /* Change this to some way of notifying that there are missing deps * foreach (Dependency dep in unresolved) { * txt += "<span foreground='red'><b>" + dep.Name + "</b> (not found)</span>\n"; * } */ addinsNotFound = true; } return(!addinsNotFound); }
/// <summary> /// 获取可用更新包集合 /// </summary> /// <param name="current">当前版本</param> /// <returns>更新包集合</returns> public PackageCollection GetAvailables(Version current) { PackageCollection packages = new PackageCollection(); FullPackage maxFullPackage = this.FullPackages.Max(); if (maxFullPackage != null && maxFullPackage.To > current) { packages.Add(maxFullPackage); current = maxFullPackage.To; } DiffPackage diffPackage; while (this.DiffPackages.TryGetValue(current, out diffPackage)) { packages.Add(diffPackage); current = diffPackage.To; } return(packages); }
/// <summary> /// Loads the packages. /// </summary> private void LoadPackages( ) { foreach (Package package in Package.GetPackages(Application.ApplicationId)) { PackageCollection.Add(package); PackageCache.Add(package); } if (PackageCollection.Count == 1) { SelectedPackage = PackageCollection[0]; } }
/// <summary> /// Initializes a new instance of the <see cref="PackageSession"/> class. /// </summary> public PackageSession(Package package) { constraintProvider.AddConstraint(PackageStore.Instance.DefaultPackageName, new VersionSpec(PackageStore.Instance.DefaultPackageVersion.ToSemanticVersion())); Packages = new PackageCollection(); packagesCopy = new PackageCollection(); AssemblyContainer = new AssemblyContainer(); Packages.CollectionChanged += PackagesCollectionChanged; if (package != null) { Packages.Add(package); } }
/// <summary> /// Finds the package dependencies for the specified <see cref="Package" />. See remarks. /// </summary> /// <param name="rootPackage">The root package.</param> /// <param name="includeRootPackage">if set to <c>true</c> [include root package].</param> /// <param name="isRecursive">if set to <c>true</c> [is recursive].</param> /// <param name="storeOnly">if set to <c>true</c> [ignores local packages and keeps only store packages].</param> /// <returns>List<Package>.</returns> /// <exception cref="System.ArgumentNullException">rootPackage</exception> /// <exception cref="System.ArgumentException">Root package must be part of a session;rootPackage</exception> public static PackageCollection FindDependencies(this Package rootPackage, bool includeRootPackage = false, bool isRecursive = true, bool storeOnly = false) { if (rootPackage == null) throw new ArgumentNullException("rootPackage"); var packages = new PackageCollection(); if (includeRootPackage) { packages.Add(rootPackage); } FillPackageDependencies(rootPackage, isRecursive, packages, storeOnly); return packages; }
/// <summary> /// Installs the plugin. /// </summary> /// <returns> /// The plugin. /// </returns> /// <param name='args'> /// Arguments. /// </param> public bool InstallPlugin(int ndx, out Dictionary <string, object> result) { Dictionary <string, object> res = new Dictionary <string, object>(); PackageCollection pack = new PackageCollection(); PackageCollection toUninstall; DependencyCollection unresolved; IProgressStatus ps = new ConsoleProgressStatus(false); AddinRepositoryEntry[] available = GetSortedAvailbleAddins(); if (ndx > (available.Length - 1)) { MainConsole.Instance.Output("Selection out of range"); result = res; return(false); } AddinRepositoryEntry aentry = available[ndx]; Package p = Package.FromRepository(aentry); pack.Add(p); ResolveDependencies(ps, pack, out toUninstall, out unresolved); // Attempt to install the plugin disabled if (Install(ps, pack) == true) { MainConsole.Instance.Output("Ignore the following error..."); PluginRegistry.Update(ps); Addin addin = PluginRegistry.GetAddin(aentry.Addin.Id); PluginRegistry.DisableAddin(addin.Id); addin.Enabled = false; MainConsole.Instance.Output("Installation Success"); ListInstalledAddins(out res); result = res; return(true); } else { MainConsole.Instance.Output("Installation Failed"); result = res; return(false); } }
public static PackageCollection GetPackagesByWaiveID(Int64 WaiveID) { PackageCollection c = new PackageCollection(); DataTable dt = Execute.FillDataTable(StoredProcedures.GetPackagesByWaiveID, new System.Data.SqlClient.SqlParameter("WaiveID", WaiveID)); if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { Package o = new Package(); LoadPackageByReader(row, o); c.Add(o); } } return(c); }
bool CheckAddins(bool updating) { string txt = ""; entries.Clear(); bool addinsNotFound = false; foreach (string id in addinIds) { string name = Addin.GetIdName(id); string version = Addin.GetIdVersion(id); AddinRepositoryEntry[] ares = setup.Repositories.GetAvailableAddin(name, version); if (ares.Length == 0) { addinsNotFound = true; if (updating) { txt += "<span foreground='grey'><b>" + name + " " + version + "</b> (searching add-in)</span>\n"; } else { txt += "<span foreground='red'><b>" + name + " " + version + "</b> (not found)</span>\n"; } } else { entries.Add(Package.FromRepository(ares[0])); txt += "<b>" + ares[0].Addin.Name + " " + ares[0].Addin.Version + "</b>\n"; } } PackageCollection toUninstall; DependencyCollection unresolved; if (!setup.ResolveDependencies(this, entries, out toUninstall, out unresolved)) { foreach (Dependency dep in unresolved) { txt += "<span foreground='red'><b>" + dep.Name + "</b> (not found)</span>\n"; } addinsNotFound = true; } addinList.Markup = txt; return(!addinsNotFound); }
/// <summary> /// Searches this instance. /// </summary> /// <param name="searchText">The search text.</param> private void Search(string searchText) { PackageCollection.Clear( ); bool cleared = string.IsNullOrEmpty(searchText); foreach (Package package in PackageCache) { if (cleared) { PackageCollection.Add(package); } else { if (package.Version.Contains(searchText)) { PackageCollection.Add(package); } } } }
private static Package PreLoadPackage(PackageSession session, ILogger log, string filePath, bool isSystemPackage, PackageCollection loadedPackages, PackageLoadParameters loadParameters) { if (session == null) throw new ArgumentNullException("session"); if (log == null) throw new ArgumentNullException("log"); if (filePath == null) throw new ArgumentNullException("filePath"); if (loadedPackages == null) throw new ArgumentNullException("loadedPackages"); if (loadParameters == null) throw new ArgumentNullException("loadParameters"); try { var packageId = Package.GetPackageIdFromFile(filePath); // Check that the package was not already loaded, otherwise return the same instance if (session.Packages.ContainsById(packageId)) { return session.Packages.Find(packageId); } // Package is already loaded, use the instance if (loadedPackages.ContainsById(packageId)) { return loadedPackages.Find(packageId); } // Load the package without loading any assets var package = Package.LoadRaw(log, filePath); package.IsSystem = isSystemPackage; // Convert UPath to absolute (Package only) // Removed for now because it is called again in PackageSession.LoadAssembliesAndAssets (and running it twice result in dirty package) // If we remove it from here (and call it only in the other method), templates are not loaded (Because they are loaded via the package store that do not use PreLoadPackage) //if (loadParameters.ConvertUPathToAbsolute) //{ // var analysis = new PackageAnalysis(package, new PackageAnalysisParameters() // { // ConvertUPathTo = UPathType.Absolute, // SetDirtyFlagOnAssetWhenFixingAbsoluteUFile = true, // IsProcessingUPaths = true, // }); // analysis.Run(log); //} // If the package doesn't have a meta name, fix it here (This is supposed to be done in the above disabled analysis - but we still need to do it!) if (string.IsNullOrWhiteSpace(package.Meta.Name) && package.FullPath != null) { package.Meta.Name = package.FullPath.GetFileName(); package.IsDirty = true; } // Add the package has loaded before loading dependencies loadedPackages.Add(package); // Package has been loaded, register it in constraints so that we force each subsequent loads to use this one (or fails if version doesn't match) session.constraintProvider.AddConstraint(package.Meta.Name, new VersionSpec(package.Meta.Version.ToSemanticVersion())); // Load package dependencies // This will perform necessary asset upgrades // TODO: We should probably split package loading in two recursive top-level passes (right now those two passes are mixed, making it more difficult to make proper checks) // - First, load raw packages with their dependencies recursively, then resolve dependencies and constraints (and print errors/warnings) // - Then, if everything is OK, load the actual references and assets for each packages PreLoadPackageDependencies(session, log, package, loadedPackages, loadParameters); // Add the package to the session but don't freeze it yet session.Packages.Add(package); return package; } catch (Exception ex) { log.Error("Error while pre-loading package [{0}]", ex, filePath); } return null; }
void FillSummaryPage() { btnPrev.Sensitive = true; AddinHeader[] infos = tree.GetSelectedAddins(); PackageCollection packs = new PackageCollection(); foreach (AddinHeader info in infos) { AddinRepositoryEntry arep = (AddinRepositoryEntry)tree.GetAddinData(info); packs.Add(Package.FromRepository(arep)); } packagesToInstall = new PackageCollection(packs); PackageCollection toUninstall; DependencyCollection unresolved; bool res; InstallMonitor m = new InstallMonitor(); res = service.ResolveDependencies(m, packs, out toUninstall, out unresolved); StringBuilder sb = new StringBuilder(); if (!res) { sb.Append("<b><span foreground=\"red\">").Append(Catalog.GetString("The selected extensions can't be installed because there are dependency conflicts.")).Append("</span></b>\n"); foreach (string s in m.Errors) { sb.Append("<b><span foreground=\"red\">" + s + "</span></b>\n"); } sb.Append("\n"); } if (m.Warnings.Count != 0) { foreach (string w in m.Warnings) { sb.Append("<b><span foreground=\"red\">" + w + "</span></b>\n"); } sb.Append("\n"); } sb.Append("<b>").Append(Catalog.GetString("The following packages will be installed:")).Append("</b>\n\n"); foreach (Package p in packs) { sb.Append(p.Name); if (!p.SharedInstall) { sb.Append(Catalog.GetString(" (in user directory)")); } sb.Append("\n"); } sb.Append("\n"); if (toUninstall.Count > 0) { sb.Append("<b>").Append(Catalog.GetString("The following packages need to be uninstalled:")).Append("</b>\n\n"); foreach (Package p in toUninstall) { sb.Append(p.Name + "\n"); } sb.Append("\n"); } if (unresolved.Count > 0) { sb.Append("<b>").Append(Catalog.GetString("The following dependencies could not be resolved:")).Append("</b>\n\n"); foreach (Dependency p in unresolved) { sb.Append(p.Name + "\n"); } sb.Append("\n"); } btnNext.Sensitive = res; labelSummary.Markup = sb.ToString(); }
private static Package PreLoadPackage(PackageSession session, ILogger log, string filePath, bool isSystemPackage, PackageCollection loadedPackages, PackageLoadParameters loadParameters) { if (session == null) throw new ArgumentNullException("session"); if (log == null) throw new ArgumentNullException("log"); if (filePath == null) throw new ArgumentNullException("filePath"); if (loadedPackages == null) throw new ArgumentNullException("loadedPackages"); if (loadParameters == null) throw new ArgumentNullException("loadParameters"); try { var packageId = Package.GetPackageIdFromFile(filePath); // Check that the package was not already loaded, otherwise return the same instance if (session.Packages.ContainsById(packageId)) { return session.Packages.Find(packageId); } // Package is already loaded, use the instance if (loadedPackages.ContainsById(packageId)) { return loadedPackages.Find(packageId); } // Load the package without loading assets var newLoadParameters = loadParameters.Clone(); newLoadParameters.AssemblyContainer = session.assemblyContainer; // Load the package var package = Package.Load(log, filePath, newLoadParameters); package.IsSystem = isSystemPackage; // Add the package has loaded before loading dependencies loadedPackages.Add(package); // Package has been loaded, register it in constraints so that we force each subsequent loads to use this one (or fails if version doesn't match) session.constraintProvider.AddConstraint(package.Meta.Name, new VersionSpec(package.Meta.Version.ToSemanticVersion())); // Load package dependencies PreLoadPackageDependencies(session, log, package, loadedPackages, loadParameters); // Add the package to the session but don't freeze it yet session.Packages.Add(package); // Validate assets from package package.ValidateAssets(loadParameters.GenerateNewAssetIds); // Freeze the package after loading the assets session.FreezePackage(package); return package; } catch (Exception ex) { log.Error("Error while pre-loading package [{0}]", ex, filePath); } return null; }
private void AddPackage(Package package) { Application.Current.Dispatcher.VerifyAccess( ); PackageCollection.Add(package); PackageCache.Add(package); }
void FillSummaryPage() { PackageCollection packs = new PackageCollection(); if (filesToInstall != null) { foreach (string file in filesToInstall) { packs.Add(Package.FromFile(file)); } } else { foreach (AddinRepositoryEntry arep in addinsToInstall) { packs.Add(Package.FromRepository(arep)); } } packagesToInstall = new PackageCollection(packs); PackageCollection toUninstall; DependencyCollection unresolved; bool res; InstallMonitor m = new InstallMonitor(); res = service.ResolveDependencies(m, packs, out toUninstall, out unresolved); StringBuilder sb = new StringBuilder(); if (!res) { sb.Append("<b><span foreground=\"red\">").Append(Catalog.GetString("The selected add-ins can't be installed because there are dependency conflicts.")).Append("</span></b>\n"); foreach (string s in m.Errors) { sb.Append("<b><span foreground=\"red\">" + s + "</span></b>\n"); } sb.Append("\n"); } if (m.Warnings.Count != 0) { foreach (string w in m.Warnings) { sb.Append("<b><span foreground=\"red\">" + w + "</span></b>\n"); } sb.Append("\n"); } sb.Append("<b>").Append(Catalog.GetString("The following packages will be installed:")).Append("</b>\n\n"); foreach (Package p in packs) { sb.Append(p.Name); if (!p.SharedInstall) { sb.Append(Catalog.GetString(" (in user directory)")); } sb.Append("\n"); } sb.Append("\n"); if (toUninstall.Count > 0) { sb.Append("<b>").Append(Catalog.GetString("The following packages need to be uninstalled:")).Append("</b>\n\n"); foreach (Package p in toUninstall) { sb.Append(p.Name + "\n"); } sb.Append("\n"); } if (unresolved.Count > 0) { sb.Append("<b>").Append(Catalog.GetString("The following dependencies could not be resolved:")).Append("</b>\n\n"); foreach (Dependency p in unresolved) { sb.Append(p.Name + "\n"); } sb.Append("\n"); } buttonOk.Sensitive = res; ShowMessage(sb.ToString()); }
public static void RegisterPackage(Package package) { ExtraPackages.Add(package); }