public static string GetRuntimeVersion(string xapPath) { using (var archive = XapZipArchiveFactory.Read(xapPath)) { var appManifestEntry = archive["AppManifest.xaml"]; if (appManifestEntry == null) { return(null); } var xAppManifest = XElement.Load(appManifestEntry.ToStream()); var runtimeVersion = xAppManifest.Attribute("RuntimeVersion"); return(runtimeVersion != null ? runtimeVersion.Value : null); } }
public IXapZipArchive RewriteZipHostWithFiles(byte[] hostXap, IEnumerable <ITestFile> filesToPlaceIntoHostXap, string runtimeVersion) { if (filesToPlaceIntoHostXap == null) { throw new ArgumentNullException("filesToPlaceIntoHostXap"); } //TODO: Write better tests and clean up the below // It's adding assemblies and other content, and re-writing the AppManifest.xaml var zipArchive = XapZipArchiveFactory.Create(hostXap); var xAppManifest = zipArchive.GetAppManifest(); var parts = xAppManifest.Elements().First(); _logger.Debug("re-writing host xap with the following files"); foreach (var file in filesToPlaceIntoHostXap) { if (zipArchive.ContainsFile(file.FileName)) { _logger.Debug(" - already has file {0}".FormatWith(file.FileName)); continue; } _logger.Debug(" add - {0}".FormatWith(file.FileName)); AddFile(zipArchive, file, parts); } //NOTE: the StatLightTempName is a crazy string hack because I couldn't figure out how to get the XAttribute to look like x:Name=... //xapZipArchive.RemoveEntry("AppManifest.xaml"); if (runtimeVersion != null) { xAppManifest.SetAttributeValue("RuntimeVersion", runtimeVersion); } string manifestRewritten = xAppManifest.ToString().Replace("StatLightTempName", "x:Name").Replace(" xmlns=\"\"", string.Empty); zipArchive.AddFile("AppManifest.xaml", manifestRewritten.ToByteArray()); return(zipArchive); }
public TestFileCollection LoadXapUnderTest(string archiveFileName) { var files = new List <ITestFile>(); string testAssemblyFullName = null; var fileStream = FileReader.ReadAllBytes(archiveFileName); using (IXapZipArchive archive = XapZipArchiveFactory.Create(fileStream)) { var appManifest = LoadAppManifest(archive); if (appManifest != null) { string testAssemblyName = GetTestAssemblyNameFromAppManifest(appManifest); AssemblyName assemblyName = GetAssemblyName(archive, testAssemblyName); if (assemblyName != null) { testAssemblyFullName = assemblyName.ToString(); } } files.AddRange(archive.ToList()); foreach (var item in files) { _logger.Debug("XapItems.FilesContainedWithinXap = {0}".FormatWith(item.FileName)); } } var xapItems = new TestFileCollection(_logger, testAssemblyFullName, files); return(xapItems); }