private IEnumerable <ManifestModuleInfo> LoadExternalModulesManifest(string externalManifestUrl) { var result = new List <ManifestModuleInfo>(); try { _logger.Debug("Download module manifests from " + externalManifestUrl); using (var webClient = new WebClient()) { webClient.AddAuthorizationTokenForGitHub(externalManifestUrl); using (var stream = webClient.OpenRead(externalManifestUrl)) { var manifests = stream.DeserializeJson <List <ModuleManifest> >(); if (!manifests.IsNullOrEmpty()) { result.AddRange(manifests.Select(manifest => new ManifestModuleInfo(manifest))); } } } } catch (Exception ex) { _logger.Error(ex.ToString()); throw; } return(result); }
private void InnerInstall(ManifestModuleInfo module, IProgress <ProgressMessage> progress) { var dstModuleDir = Path.Combine(_modulesPath, module.Id); var moduleZipPath = Path.Combine(dstModuleDir, GetModuleZipFileName(module.Id, module.Version.ToString())); if (!Directory.Exists(dstModuleDir)) { _txFileManager.CreateDirectory(dstModuleDir); } //download module archive from web if (Uri.IsWellFormedUriString(module.Ref, UriKind.Absolute)) { var moduleUrl = new Uri(module.Ref); using (var webClient = new WebClient()) { webClient.AddAuthorizationTokenForGitHub(moduleUrl); using (var fileStream = File.OpenWrite(moduleZipPath)) using (var webStream = webClient.OpenRead(moduleUrl)) { Report(progress, ProgressMessageLevel.Info, "Downloading '{0}' ", module.Ref); webStream.CopyTo(fileStream); } } } else if (File.Exists(module.Ref)) { moduleZipPath = module.Ref; } using (var zipStream = File.Open(moduleZipPath, FileMode.Open)) using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Read)) { foreach (var entry in archive.Entries.Where(e => !string.IsNullOrEmpty(e.Name))) { //Report(progress, ProgressMessageLevel.Info, "Extracting '{0}' ", entry.FullName); var filePath = Path.Combine(dstModuleDir, entry.FullName); //Create directory if not exist var directoryPath = Path.GetDirectoryName(filePath); if (!_txFileManager.DirectoryExists(directoryPath)) { _txFileManager.CreateDirectory(directoryPath); } using (var entryStream = entry.Open()) using (var fileStream = File.Create(filePath)) { entryStream.CopyTo(fileStream); } File.SetLastWriteTime(filePath, entry.LastWriteTime.LocalDateTime); } } Report(progress, ProgressMessageLevel.Info, "Successfully installed '{0}'.", module); }