/// <inheritdoc/> public async Task <UnpackObjectResult> UnpackObject(ExtractArchiveEntryResult extractArchiveEntryResult) { var result = new UnpackObjectResult { LogLevel = LogLevel.Info }; try { var json = Encoding.UTF8.GetString(extractArchiveEntryResult.Data); var jObject = JObject.Parse(json); var configuration = jObject["Configuration"]; jObject.Remove("Configuration"); var content = jObject.ToObject <EplReport>(); content.Configuration = DeserializeConfiguration(content.Type, configuration); result.InstallableObject = new InstallableObject { Content = content, Target = extractArchiveEntryResult.Location, Mode = extractArchiveEntryResult.Mode }; result.Message = $"Unpacked EplReport at {extractArchiveEntryResult.Location}."; } catch (Exception ex) { result.Message = $"Failed to unpack EplReport at {extractArchiveEntryResult.Location}."; result.LogLevel = LogLevel.Error; result.Exception = ex; } return(result); }
/// <inheritdoc/> public async Task <UnpackObjectResult> UnpackObject(ExtractArchiveEntryResult extractArchiveEntryResult) { var result = new UnpackObjectResult { LogLevel = LogLevel.Info }; try { var json = Encoding.UTF8.GetString(extractArchiveEntryResult.Data); var ribbon = JsonConvert.DeserializeObject <RibbonTab>(json); result.InstallableObject = new InstallableObject { Content = ribbon, Target = extractArchiveEntryResult.Location, Mode = extractArchiveEntryResult.Mode }; result.Message = $"Unpacked RibbonTab at {extractArchiveEntryResult.Location}."; } catch (Exception ex) { result.Message = $"Failed to unpack RibbonTab at {extractArchiveEntryResult.Location}."; result.LogLevel = LogLevel.Error; result.Exception = ex; } return(result); }
/// <inheritdoc/> #pragma warning disable 1998 public async Task <UnpackObjectResult> UnpackObject(ExtractArchiveEntryResult extractArchiveEntryResult) #pragma warning restore 1998 { var result = new UnpackObjectResult { LogLevel = LogLevel.Info }; try { var json = Encoding.UTF8.GetString(extractArchiveEntryResult.Data); var jObject = JObject.Parse(json); // Separate settings and rest of json var settingsJson = jObject["Configuration"]?.ToString(); jObject.Remove("Configuration"); // Separately deserialize settings and rest of json var deserializedApplication = jObject.ToObject <Application>(); if (deserializedApplication == null) { throw new NullReferenceException("Deserialized application is null"); } deserializedApplication.Configuration = DeserializeSettings(deserializedApplication.Type, settingsJson); result.InstallableObject = new InstallableObject { Content = deserializedApplication, Target = extractArchiveEntryResult.Location, Mode = extractArchiveEntryResult.Mode }; result.Message = $"Unpacked Application at {extractArchiveEntryResult.Location}."; } catch (Exception ex) { result.Message = $"Failed to unpack Application at {extractArchiveEntryResult.Location}."; result.LogLevel = LogLevel.Error; result.Exception = ex; } return(result); }
/// <inheritdoc/> public async Task <UnpackObjectResult> UnpackObject(ExtractArchiveEntryResult extractArchiveEntryResult) { var installableObject = new InstallableObject { Content = new SqlContent { Data = Encoding.UTF8.GetString(extractArchiveEntryResult.Data) }, Target = extractArchiveEntryResult.Location, Mode = extractArchiveEntryResult.Mode }; return(new UnpackObjectResult { InstallableObject = installableObject, Message = $"Unpacked sql file at {extractArchiveEntryResult.Location}.", LogLevel = LogLevel.Info }); }
/// <inheritdoc/> public async Task <UnpackObjectResult> UnpackObject(ExtractArchiveEntryResult extractArchiveEntryResult) { var installableObject = new InstallableObject { Content = new RepositoryContent { Data = extractArchiveEntryResult.Data }, Target = extractArchiveEntryResult.Location, Mode = extractArchiveEntryResult.Mode }; return(new UnpackObjectResult { InstallableObject = installableObject, Message = $"Unpacked repository at {extractArchiveEntryResult.Location}", LogLevel = LogLevel.Info }); }
/// <inheritdoc/> public async Task <UnpackObjectResult> UnpackObject(ExtractArchiveEntryResult extractArchiveEntryResult) { var filename = Path.GetFileNameWithoutExtension(extractArchiveEntryResult.Location); var installableObject = new InstallableObject { Content = new IconContent { Guid = Guid.Parse(filename.Split('#').First()), Name = filename.Split('#').Last(), Blob = extractArchiveEntryResult.Data }, Target = extractArchiveEntryResult.Location, Mode = extractArchiveEntryResult.Mode }; return(new UnpackObjectResult { InstallableObject = installableObject, Message = $"Unpacked icon at {extractArchiveEntryResult.Location}.", LogLevel = LogLevel.Info }); }
/// <inheritdoc/> public async Task <UnpackObjectResult> UnpackObject(ExtractArchiveEntryResult extractArchiveEntryResult) { var result = new UnpackObjectResult { LogLevel = LogLevel.Info }; try { var json = Encoding.UTF8.GetString(extractArchiveEntryResult.Data); var jObject = JObject.Parse(json); // Seperate settings and rest of json var configuration = jObject["configuration"]; jObject.Remove("configuration"); // Seperately deserialize settings and rest of json var deserialiedStackContextArea = jObject.ToObject <StackContextArea>(); deserialiedStackContextArea.Configuration = DeserializedConfiguration(deserialiedStackContextArea.Type, configuration); result.InstallableObject = new InstallableObject { Content = deserialiedStackContextArea, Target = extractArchiveEntryResult.Location, Mode = extractArchiveEntryResult.Mode }; result.Message = $"Unpacked StackContextArea at {extractArchiveEntryResult.Location}."; } catch (Exception ex) { result.Message = $"Failed to unpack StackContextArea at {extractArchiveEntryResult.Location}."; result.LogLevel = LogLevel.Error; result.Exception = ex; } return(result); }
/// <summary> /// Unpacks the contents of a given package /// </summary> /// <param name="packageBytes">The package as bytes</param> /// <returns>A Packge object</returns> public async Task <Package> Unpack(byte[] packageBytes) { using (MemoryStream stream = new MemoryStream(packageBytes)) { using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Read)) { PackageConfiguration packageConfiguration = null; var configurationFile = archive.Entries.Where(x => x.Name == "package.json").FirstOrDefault(); if (configurationFile == null) { throw new InvalidPackageException("Package doesnt contain package.json file."); } var fileContent = await fileService.ReadAllTextAsync(configurationFile.Open()); try { packageConfiguration = JsonConvert.DeserializeObject <PackageConfiguration>( fileContent, new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Error }); } catch (JsonSerializationException jse) { throw new PackageConfigurationException("Couldent deserialize the package.json file.", jse); } // Validate the PackageConfiguration object var validatePackageConfigurationResult = await validatePackageConfigurationService.Validate(packageConfiguration); if (!validatePackageConfigurationResult.IsValid) { throw new PackageConfigurationException(validatePackageConfigurationResult.Message); } else { await logService.WriteAsync(validatePackageConfigurationResult.Message, validatePackageConfigurationResult.LogLevel); } // Create the package object var unpackedPackage = new Package { Name = packageConfiguration.Name, Guid = packageConfiguration.Guid, Version = packageConfiguration.Version, Dependencies = packageConfiguration.Dependencies, Extensions = packageConfiguration.Extensions }; // Load extensions. if (packageConfiguration.Extensions.Any()) { await logService.WriteAsync("Loading extensions...", LogLevel.Info); extensionService.LoadExtensionsFromZipArchive(packageConfiguration.Extensions, archive); if (packageConfiguration.Extensions.Any(x => !ExtensionHelper.LoadedExtensions.Contains(x))) { await logService.WriteAsync("Could not load all extensions", LogLevel.Error); throw new MissingExtensionException($"Could not load " + $"{packageConfiguration.Extensions.First(x => !ExtensionHelper.LoadedExtensions.Contains(x))}"); } } // Unpack all the packages content foreach (var item in packageConfiguration.Objects) { var unpackObjectService = container.Resolve <IUnpackObjectService>(item.Key); var contents = new List <InstallableObject>(); foreach (var objectListItem in item.Value) { var archiveEntry = archive.GetEntry(objectListItem.Target); if (archiveEntry == null) { throw new MissingObjectException($"There was no archive entry found " + $"at the location specified: {objectListItem.Target}."); } // Extract the main entries content var archiveEntryContent = await fileService.ReadAllBytesAsync(archiveEntry.Open()); // Extract the payloads content var payload = new Dictionary <string, byte[]>(); if (objectListItem.Payload.Any()) { foreach (var _item in objectListItem.Payload) { var payloadEntry = archive.GetEntry(_item.Target); if (payloadEntry == null) { throw new MissingObjectException($"There was no archive entry found " + $"at the location specified: {_item.Target}."); } payload[_item.Target] = await fileService.ReadAllBytesAsync(payloadEntry.Open()); } } // Set the archive entry content var extractArchiveEntryResult = new ExtractArchiveEntryResult { Data = archiveEntryContent, Location = objectListItem.Target, Mode = objectListItem.Mode, Payload = payload }; // Unpack the Object (make installable) var unpackObjectResult = await unpackObjectService.UnpackObject(extractArchiveEntryResult); if (unpackObjectResult.InstallableObject == null) { throw new InvalidObjectException(unpackObjectResult.Message, unpackObjectResult.Exception); } else { await logService.WriteAsync(unpackObjectResult.Message, unpackObjectResult.LogLevel); unpackObjectResult.InstallableObject.Guid = objectListItem.Guid; unpackObjectResult.InstallableObject.PackageGuid = unpackedPackage.Guid; unpackObjectResult.InstallableObject.PackageVersion = unpackedPackage.Version; contents.Add(unpackObjectResult.InstallableObject); } } unpackedPackage.UnpackedObjects[item.Key] = contents; } return(unpackedPackage); } } }