/// <summary> /// Adds the ScriptManifest to the zip package. /// Only includes the supplied ScriptVersion in the package manifest versions list. /// </summary> /// <param name="manifest">The ScriptManifest instance to add.</param> /// <param name="version">The ScriptVersion to filter out from the manifest. All other versions will not be included.</param> public virtual void AddManifest(ScriptManifest manifest, ScriptVersion version) { ScriptManifest manifestCopy = manifest.Copy(); ScriptVersion versionCopy = version.Copy(); versionCopy.ScriptPath = ScriptManifestTokens.Replace(versionCopy.ScriptPath, manifest, version); manifestCopy.Versions = new List<ScriptVersion>() { versionCopy }; using (StringWriter stringWriter = new StringWriter()) { JsonFileHandler<ScriptManifest> handler = new JsonFileHandler<ScriptManifest>(); handler.Write(stringWriter, manifestCopy); //TODO: change this to work with multiple manifests? _currentZipFile.AddEntry(PackageBuilder.InstallerArchivePath + "script" + ScriptManifest.DefaultExtension, stringWriter.ToString()); } }
/// <summary> /// Writes a ScriptManifest to a file. /// </summary> /// <param name="manifest">The ScriptManifest to write.</param> /// <param name="filePath">The IPath instance of the file to write to.</param> /// <returns>True upon success.</returns> /// <remarks>Consider removing from this class.</remarks> public Boolean WriteManifest(ScriptManifest manifest, IPath filePath) { //Copy manifest and replace manifest tokens before writing. ScriptManifest manifestCopy = manifest.Copy(); foreach (ScriptVersion v in manifestCopy.Versions) { v.ScriptPath = ScriptManifestTokens.Replace(v.ScriptPath, manifestCopy, v); } //Write manifest. filePath.AbsolutePath = ScriptManifestTokens.Replace(filePath.AbsolutePath, manifest, manifest.LatestVersion); try { JsonFileHandler<ScriptManifest> handler = new JsonFileHandler<ScriptManifest>(); handler.Write(filePath, manifestCopy); } catch { return false; } return true; }