private IPackage GetPackage(Func <string, IPackage> openPackage, string path)
        {
            PackageCacheEntry cacheEntry;
            DateTimeOffset    lastModified = FileSystem.GetLastModified(path);

            // If we never cached this file or we did and it's current last modified time is newer
            // create a new entry
            if (!_packageCache.TryGetValue(path, out cacheEntry) ||
                (cacheEntry != null && lastModified > cacheEntry.LastModifiedTime))
            {
                // We need to do this so we capture the correct loop variable
                string packagePath = path;

                // Create the package
                IPackage package = openPackage(packagePath);

                // create a cache entry with the last modified time
                cacheEntry = new PackageCacheEntry(package, lastModified);

                if (_enableCaching)
                {
                    // Store the entry
                    _packageCache[packagePath] = cacheEntry;
                    _packagePathLookup[new PackageName(package.Id, package.Version)] = path;
                }
            }

            return(cacheEntry.Package);
        }
Example #2
0
 public LoadedAssembly LoadAssembly(string path, Extension requestingExtension, PackageDefinition packagingDefinition)
 {
     if (ValidatePackagePath(path, requestingExtension))
     {
         UnpackPackageTask unpackPackageTask = new UnpackPackageTask(path, true);
         ProcessTaskDialog dialog            = new ProcessTaskDialog(unpackPackageTask);
         dialog.ShowDialog();
         if (dialog.TaskToExecute.IsCanceled)
         {
             return(null);
         }
         PackageCacheEntry unpackedPackage  = unpackPackageTask.UnpackedPackage;
         string            assemblyPath     = Path.Combine(unpackedPackage.Folder, unpackedPackage.Manifest.DllPath);
         LoadAssemblyTask  loadAssemblyTask = new LoadAssemblyTask(assemblyPath, requestingExtension);
         dialog = new ProcessTaskDialog(loadAssemblyTask);
         dialog.ShowDialog();
         if (dialog.TaskToExecute.IsCanceled)
         {
             return(null);
         }
         loadAssemblyTask.LoadedAssembly.PackagePath = path;
         loadAssemblyTask.LoadedAssembly.InPackage   = true;
         return(loadAssemblyTask.LoadedAssembly);
     }
     else
     {
         return(null);
     }
 }
Example #3
0
        private IPackage GetPackage(Func <string, IPackage> openPackage, string path)
        {
            PackageCacheEntry entry;
            DateTimeOffset    lastModified = this.FileSystem.GetLastModified(path);

            if (!this._packageCache.TryGetValue(path, out entry) || ((entry != null) && (lastModified > entry.LastModifiedTime)))
            {
                string   arg     = path;
                IPackage package = openPackage(arg);
                entry = new PackageCacheEntry(package, lastModified);
                if (this._enableCaching)
                {
                    this._packageCache[arg] = entry;
                    this._packagePathLookup.GetOrAdd(new PackageName(package.Id, package.Version), path);
                }
            }
            return(entry.Package);
        }
Example #4
0
        public static PackageCacheEntry Unpack(string path, bool addToCache)
        {
            if (Studio.packageCache != null)
            {
                if (Studio.packageCache.Entries.Any((p) => { return(p.PackageFile == path); }))
                {
                    return(Studio.packageCache.Entries.Find((p) => { return p.PackageFile == path; }));
                }
            }

            string targetDirectory = Path.Combine(App.EXECUTABLE_DIRECTORY, "packages", Guid.NewGuid().ToString());

            try
            {
                Directory.CreateDirectory(targetDirectory);
                ZipFile.ExtractToDirectory(path, targetDirectory);
                PackageCacheEntry entry = new PackageCacheEntry();
                entry.Folder      = targetDirectory;
                entry.PackageFile = path;
                if (File.Exists(Path.Combine(targetDirectory, "manifest.json")) == false)
                {
                    throw new InvalidOperationException("No manifest.json file in package.");
                }
                entry.Manifest = JsonConvert.DeserializeObject <PackageManifest>(Path.Combine(targetDirectory, "manifest.json"));

                if (addToCache)
                {
                    App.PackageCache.CacheDate = DateTime.Now;
                    App.PackageCache.Entries.Add(entry);
                    Studio.Instance.ScheduleBackgroundTask(new SavePackageCacheTask(App.PackageCache));
                }

                return(entry);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"Could not unpack package:\n{ex.Message}");
            }
        }
        private IPackage GetPackage(Func<string, IPackage> openPackage, string path)
        {
            PackageCacheEntry cacheEntry;
            DateTimeOffset lastModified = FileSystem.GetLastModified(path);
            // If we never cached this file or we did and it's current last modified time is newer
            // create a new entry
            if (!_packageCache.TryGetValue(path, out cacheEntry) ||
                (cacheEntry != null && lastModified > cacheEntry.LastModifiedTime))
            {
                // We need to do this so we capture the correct loop variable
                string packagePath = path;

                // Create the package
                IPackage package = openPackage(packagePath);

                // create a cache entry with the last modified time
                cacheEntry = new PackageCacheEntry(package, lastModified);

                if (_enableCaching)
                {
                    // Store the entry
                    _packageCache[packagePath] = cacheEntry;
                    _packagePathLookup.GetOrAdd(new PackageName(package.Id, package.Version), path);
                }
            }

            return cacheEntry.Package;
        }