Beispiel #1
0
        public IPackage GetLoadPackage(PackageName name)
        {
            if (Packages.ContainsKey(name))
                return Packages[name];

            var package = packageLoader.LoadPackage(name);
            Packages.Add(name, package);

            return package;
        }
Beispiel #2
0
        public IPackage LoadPackage(PackageName packageName)
        {
            PackageName availablePackageName;
            if(!TryGetPackageName(packageName, out availablePackageName))
                throw new Exception("Package "+ packageName +" unavailable.");

            var packageFile = availablePackageName + PackageExtension;
            var packagePath = Path.Combine(PackageFolder, packageFile);

            using (var zip = ZipFile.Read(packagePath))
            {
                var packageDllEntry = zip[packageName.Id+".dll"];

                var packageAssembly = ExtractAssembly(packageDllEntry);
                return LoadPackageAssembly(packageAssembly);
            }
        }
Beispiel #3
0
        //Gets the most recent compatible PackageName available.
        private bool TryGetPackageName(PackageName packageName, out PackageName packageNameFound)
        {
            var wasNameFound = false;
            var bestVersion = packageName.Version;
            packageNameFound = default (PackageName);

            foreach (var name in availablePackages)
            {
                if (name.Id != packageName.Id)
                    continue;

                if (name.Version.Major != bestVersion.Major)
                    continue;

                if (name.Version.Minor < bestVersion.Minor)
                    continue;

                if (name.Version.Patch < bestVersion.Patch)
                    continue;

                wasNameFound = true;
                bestVersion = name.Version;
                packageNameFound = name;
            }

            return wasNameFound;
        }
Beispiel #4
0
        private void Init()
        {
            var filePaths = Directory.EnumerateFiles(PackageFolder);
            foreach (var filePath in filePaths)
            {
                if (!filePath.EndsWith(PackageExtension))
                    return;

                var fileName = Path.GetFileNameWithoutExtension(filePath);
                var packageName = new PackageName(fileName);
                availablePackages.Add(packageName);
            }
        }