/// <summary> /// Scans the directory specified in <see cref="Platform.Directories.Packages"/> for <see cref="IPackage"/> s. /// </summary> /// <returns> /// A Result containing the result of the operation and a <see cref="List{T}"/> of found <see cref="IPackage"/> s. /// </returns> public IResult <IList <IPackage> > ScanPackages() { Guid guid = logger.EnterMethod(true); logger.Info("Scanning for Packages..."); IResult <IList <IPackage> > retVal = new Result <IList <IPackage> >(); retVal.ReturnValue = new List <IPackage>(); string searchDirectory = PlatformManager.Directories.Packages; logger.Debug($"Scanning directory '{searchDirectory}'..."); IResult <IList <string> > dirListResult = Platform.ListDirectories(searchDirectory); retVal.Incorporate(dirListResult); if (retVal.ResultCode != ResultCode.Failure) { foreach (string directory in dirListResult.ReturnValue) { if (directory == PlatformManager.Directories.PackageArchives) { continue; } IResult <IPackage> readResult = PackageFactory.GetPackage(directory); if (readResult.ResultCode != ResultCode.Failure) { retVal.ReturnValue.Add(readResult.ReturnValue); } else { retVal.AddWarning(readResult.GetLastError()); } } } retVal.LogResult(logger); logger.ExitMethod(guid); return(retVal); }
/// <summary> /// Initializes a new instance of the <see cref="PackageManager"/> class. /// </summary> /// <remarks> /// This constructor is marked private and is intended to be called from the /// <see cref="Instantiate(IApplicationManager, IPlatformManager)"/> method exclusively in order to implement the /// Singleton design pattern. /// </remarks> /// <param name="manager">The <see cref="IApplicationManager"/> instance for the application.</param> /// <param name="platformManager">The <see cref="IPlatformManager"/> instance for the application.</param> private PackageManager(IApplicationManager manager, IPlatformManager platformManager) { base.logger = logger; Guid guid = logger.EnterMethod(); ManagerName = "Package Manager"; RegisterDependency <IApplicationManager>(manager); RegisterDependency <IPlatformManager>(platformManager); PackageList = new List <IPackage>(); PackageArchiveList = new List <IPackageArchive>(); PackageFactory = new PackageFactory(PlatformManager); PackageScanner = new PackageScanner(PlatformManager, PackageFactory); ChangeState(State.Initialized); logger.ExitMethod(guid); }