private ErrorSuccess<IVsixPackage, string> _LoadFromFile(string file, Logger log, ErrorSuccessFactory<IVsixPackage, string> ef)
        {
            log.Info($"Reading {file}");

            ZipArchive zipFile;
            try
            {
                zipFile = ZipFile.OpenRead(file);
            }
            catch (Exception ex)
            {
                log.Error($"{file} is not a zip archive.", ex);
                return ef.Error($"{file} is not a zip archive: {ex.Message}");
            }

            using (zipFile)
            {
                var manifestEntry = zipFile.Entries.FirstOrDefault(entry => entry.FullName == Entry.Manifest);
                if (manifestEntry == null)
                {
                    return ef.Error($"{file} does not contain a {Entry.Manifest} entry.");
                }

                return _CreateFromZipManifest(file, manifestEntry, log, ef);
            }
        }
Пример #2
0
        private ErrorSuccess <IVsixPackage, string> _LoadFromFile(string file, Logger log, ErrorSuccessFactory <IVsixPackage, string> ef)
        {
            log.Info($"Reading {file}");

            ZipArchive zipFile;

            try
            {
                zipFile = ZipFile.OpenRead(file);
            }
            catch (Exception ex)
            {
                log.Error($"{file} is not a zip archive.", ex);
                return(ef.Error($"{file} is not a zip archive: {ex.Message}"));
            }

            using (zipFile)
            {
                var manifestEntry = zipFile.Entries.FirstOrDefault(entry => entry.FullName == Entry.Manifest);
                if (manifestEntry == null)
                {
                    return(ef.Error($"{file} does not contain a {Entry.Manifest} entry."));
                }

                return(_CreateFromZipManifest(file, manifestEntry, log, ef));
            }
        }
        public ErrorSuccess<IVsixPackage, string> LoadFromFile(string file, Logger log)
        {
            var ef = new ErrorSuccessFactory<IVsixPackage, string>();

            try
            {
                return _LoadFromFile(file, log, ef);
            }
            catch (Exception ex)
            {
                log.Error($"An unexpected error occurred while trying to read {file} as a vsix.", ex);
                return ef.Error($"An unexpected error occurred while trying to read {file} as a vsix: {ex.Message}");
            }
        }
Пример #4
0
        public ErrorSuccess <IVsixPackage, string> LoadFromFile(string file, Logger log)
        {
            var ef = new ErrorSuccessFactory <IVsixPackage, string>();

            try
            {
                return(_LoadFromFile(file, log, ef));
            }
            catch (Exception ex)
            {
                log.Error($"An unexpected error occurred while trying to read {file} as a vsix.", ex);
                return(ef.Error($"An unexpected error occurred while trying to read {file} as a vsix: {ex.Message}"));
            }
        }
        private ErrorSuccess<IVsixPackage, string> _CreateFromZipManifest(string file, ZipArchiveEntry manifestEntry, Logger log, ErrorSuccessFactory<IVsixPackage, string> ef)
        {
            var packageManifest = _TryGetPackageManifest(manifestEntry);
            var vsixManifest = _TryGetVsixManifest(manifestEntry);

            if (packageManifest != null)
            {
                log.Info("Loaded PackageManifest based manifest");
                return ef.Success(new VsixWithPackageManifest(file, packageManifest));
            }

            if (vsixManifest != null)
            {
                log.Info("Loaded Vsix based manifest");
                return ef.Success(new VsixWithVsixManifest(file, vsixManifest));
            }

            return ef.Error($"{file}\\{Entry.Manifest} is not a valid package manifest file.");
        }
Пример #6
0
        private ErrorSuccess <IVsixPackage, string> _CreateFromZipManifest(string file, ZipArchiveEntry manifestEntry, Logger log, ErrorSuccessFactory <IVsixPackage, string> ef)
        {
            var packageManifest = _TryGetPackageManifest(manifestEntry);
            var vsixManifest    = _TryGetVsixManifest(manifestEntry);

            if (packageManifest != null)
            {
                log.Info("Loaded PackageManifest based manifest");
                return(ef.Success(new VsixWithPackageManifest(file, packageManifest)));
            }

            if (vsixManifest != null)
            {
                log.Info("Loaded Vsix based manifest");
                return(ef.Success(new VsixWithVsixManifest(file, vsixManifest)));
            }

            return(ef.Error($"{file}\\{Entry.Manifest} is not a valid package manifest file."));
        }