public async Task <IActionResult> UpdatePackage(IFormFile package) { _logger.LogInformation("{Message}", "Submitting configuration"); if (!package.IsValid()) { // configuration did not meet our criteria _logger.LogError("{Message}", "empty file"); return(BadRequest("no content")); } try { using (var stream = new MemoryStream()) { await package.CopyToAsync(stream); IPackageConfiguration packageConfiguration = await _packageManager.UpdatePackageAsync(stream); return(Ok(packageConfiguration)); } } catch (Exception ex) { _logger.LogError(ex, "{Message}", "Invalid Configuration Model received"); return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
/// <summary> /// Will connect to an existing package. /// </summary> /// <param name="packageRootFilename">The package filename.</param> /// <param name="configurationFilename">The filename to use when reading the <paramref name="configurationFilename"/> from the package.</param> /// <returns>An <see cref="IConnectedPackage"/>, which represents the desired package.</returns> /// <remarks> /// See <see cref="ConnectedPackage"/> concerning proper handling of the <see cref="ConnectedPackage"/>. /// </remarks> public IConnectedPackage Connect(string packageRootFilename, string configurationFilename) { // find package if (!_AllPackagesFileStore.Contains(packageRootFilename)) { throw new ArgumentException($"Package not found. Package Filename={packageRootFilename}"); } // extract to temp location var extractedPackageFilename = _AllPackagesFileStore.Get(packageRootFilename).Extract(System.IO.Path.GetTempPath(), true); if (!System.IO.File.Exists(extractedPackageFilename)) { throw new Exception($"PackageProvider; Unable to extract Package. Filename={packageRootFilename}"); } // connect IFileStore var packageStore = PackageFileStoreProvider.Connect(extractedPackageFilename); // extract PackageConfiguration IPackageConfiguration config = RetrieveConfiguration(packageStore, configurationFilename); if (config != null) { // create IPackage return(new ConnectedPackage(_AllPackagesFileStore, packageRootFilename, extractedPackageFilename, packageStore, config)); } // return(null); }
/// <summary> /// Will create a new package. /// </summary> /// <param name="packageRootFilename">The package filename.</param> /// <param name="configurationFilename">The filename to use when writing the <paramref name="packageConfiguration"/> to the package.</param> /// <param name="packageConfiguration">The configuration for this package.</param> /// <param name="overwrite"><b>True</b> to write-over the package file if it already exists, otherwise, <b>false</b>.</param> /// <returns>An <see cref="IConnectedPackage"/>, which represents the desired package.</returns> /// <remarks> /// See <see cref="ConnectedPackage"/> concerning proper handling of the <see cref="ConnectedPackage"/>. /// </remarks> public IConnectedPackage Create(string packageRootFilename, string configurationFilename, IPackageConfiguration packageConfiguration, bool overwrite) { var tempConfigFilename = ""; try { // test for existing package if (_AllPackagesFileStore.Contains(packageRootFilename) && !overwrite) { throw new Exception($"File already exists. Filename={packageRootFilename}"); } // create package file store at temp location var backendStorageZipFilename = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "packStore_" + Guid.NewGuid().ToString()); var packageFileStore = PackageFileStoreProvider.Create(backendStorageZipFilename); // save configuration to package file store tempConfigFilename = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "configuration_" + Guid.NewGuid().ToString()); System.IO.File.WriteAllText(tempConfigFilename, _ConfigurationSerializer.Serialize(packageConfiguration.Configuration).ToString()); packageFileStore.Add(configurationFilename, tempConfigFilename, DateTime.Now, new System.IO.FileInfo(tempConfigFilename).Length); // must save now to store the configuration file before it is deleted packageFileStore.Save(false); // adds package file store to file store _AllPackagesFileStore.Add(packageRootFilename, backendStorageZipFilename, DateTime.Now, new System.IO.FileInfo(tempConfigFilename).Length); // create IPackage return(new ConnectedPackage(_AllPackagesFileStore, packageRootFilename, backendStorageZipFilename, packageFileStore, packageConfiguration)); } finally { // delete temp configuration file FileStorage.FileStorageHelper.DeleteFile(tempConfigFilename); } }
/// <summary> /// Marks package as installed. For information proposes only, rollback does not uninstall the package. /// </summary> /// <param name="packageConfiguration">Installed package</param> /// <param name="packageFiles">Installed package files</param> public void TrackInstalledPackage(IPackageConfiguration packageConfiguration, IEnumerable <PackageFileInfo> packageFiles) { var packageInfo = new ProductPackageInfo { Configuration = packageConfiguration }; packageInfo.Files.AddRange(packageFiles); _installedPackages.Add(packageInfo); }
public static string GetQualifiedAssmeblyPath(this IPackageConfiguration configuration) { if (string.IsNullOrEmpty(configuration.ExtensionProperties["AssemblyExtension"]) || configuration.ExtensionProperties["AssemblyName"].EndsWith(configuration.ExtensionProperties["AssemblyExtension"])) { return(configuration.ExtensionProperties["AssemblyName"]); } return(Path.ChangeExtension(configuration.ExtensionProperties["AssemblyName"], configuration.ExtensionProperties["AssemblyExtension"])); }
public void SetPackageConfiguration(IPackageConfiguration packageConfiguration, IEnumerable <string> files, IEnumerable <string> dependencies) { RemovePackageConfiguration(packageConfiguration.Id); Packages.Add(packageConfiguration); var info = new ProductPackageInfo(); info.Files.AddRange(files); info.Dependencies.AddRange(dependencies); ProductPackagesInfo.Add(packageConfiguration.Id.ToString(), info); }
/// <summary> /// Will write a configuration file to a package. /// </summary> /// <param name="package">The package to write the configuration file to.</param> /// <param name="configuration">The package configuration to write.</param> public void WriteConfigurationFile(IPackage package, IPackageConfiguration configuration) { // get package information var packInfo = FindPackage(package.PackageConfiguration.Name, package.PackageConfiguration.Version); if (packInfo != null) { var tempFilePath = System.IO.Path.GetTempFileName(); try { // get package using (var connectedPackage = Connect(packInfo.RootFilename)) { // get original filename var originalFilename = ""; var originalConfigFileItem = connectedPackage.FileStore.Find((x) => { return(x.RootFilename == _ConfigurationFilename); }).FirstOrDefault(); if (originalConfigFileItem != null) { originalFilename = originalConfigFileItem.OriginalFilename; } // save new configuration to tempFilePath var newConfig = _ConfigurationSerializer.Serialize(configuration.Configuration); System.IO.File.WriteAllText(tempFilePath, newConfig.ToString()); // import new configuration to package var fileInfo = new System.IO.FileInfo(tempFilePath); var addItem = connectedPackage.FileStore.Add(_ConfigurationFilename, tempFilePath, fileInfo.LastWriteTimeUtc, new System.IO.FileInfo(tempFilePath).Length); // save file store connectedPackage.FileStore.Save(false); // restore original filename var configFileItem = connectedPackage.FileStore.Find((x) => { return(x.RootFilename == _ConfigurationFilename); }).FirstOrDefault(); if ((configFileItem != null) && (!string.IsNullOrWhiteSpace(originalFilename))) { configFileItem.SetOriginalFilename(originalFilename); } if (!string.IsNullOrWhiteSpace(originalFilename)) { ((dodSON.Core.FileStorage.IFileStoreItemAdvanced)addItem).SetOriginalFilename(originalFilename); } } } finally { FileStorage.FileStorageHelper.DeleteFile(tempFilePath); } } else { throw new Exception($"Package {package.FullyQualifiedPackageName} not found."); } }
public static string DisplayName(this IPackageConfiguration packageConfiguration) { var product = packageConfiguration.Product; string displayName; if (product != null) { displayName = string.Format("{0} Config {1}", product.Name, packageConfiguration.Version.ToString()); } else { displayName = packageConfiguration.Name; } return(displayName); }
private void LoadPackageInfo(IPackageConfiguration configurationProvider, DeferredContext deferredContext, bool ignoreEntityActivationMode) { var packageStartupHandlerInfos = configurationProvider.GetPackageStartupHandlers(); if (packageStartupHandlerInfos != null) { foreach (var startupHandlerInfo in packageStartupHandlerInfos) { var startupHandler = EntityActivator.Current.GetPackageStartupHandler(startupHandlerInfo); startupHandler.Start(RuntimeContext); } } var runtimeEventsHandlerInfos = configurationProvider.GetRuntimeEventHandlers(); if (runtimeEventsHandlerInfos != null) { foreach (var eventsHandlerInfo in runtimeEventsHandlerInfos) { var eventsHandler = EntityActivator.Current.GetRuntimeEventsHandler(eventsHandlerInfo); RuntimeContext.RegisterRuntimeEventHandler(eventsHandler); } } var extensions = configurationProvider.GetExtensions(); if (extensions != null) { foreach (var extension in extensions) { RuntimeContext.RegisterExtension(extension); } } var extensibilityPoints = configurationProvider.GetExtensibilityPoints(); foreach (var extensibilityPointInfo in extensibilityPoints) { if (extensibilityPointInfo.ActivationMode == EntityActivationMode.Immediate || ignoreEntityActivationMode) { ActivateAndRegisterExtensibilityPoint(extensibilityPointInfo); } else { deferredContext.ExtensibilityPoints.Add(extensibilityPointInfo); } } }
private void HandlePackage(IPackageConfiguration config, DeferredContext deferredContext, bool ignoreEntityActivationMode) { if (!config.IsPackageEnabled) return; if (config.GetPackageActivationMode() == EntityActivationMode.Immediate) { RaiseRuntimeEvent(new BeforePackageLoadedEvent {Package = config.Id}); LoadPackageInfo(config, deferredContext, ignoreEntityActivationMode); RaiseRuntimeEvent(new AfterPackageLoadedEvent { Package = config.Id }); } else { deferredContext.PackageConfigurations.Add(config); } }
private async Task <ServiceConfigurationModel> BuildServiceConfigurationModel(string packageName, IDictionary <string, string> properties) { IPackageConfiguration configuration = await _packageManager.GetPackageConfigurationAsync(packageName); var packageContentRoot = Path.Combine(_packageManager.PackageRoot, packageName, configuration.ContentRoot); var serviceConfigurationModel = _objectMapperService.Map <ServiceConfigurationModel, IPackageConfiguration>(configuration); serviceConfigurationModel.Properties = properties.ToDictionary(x => x.Key, x => x.Value); serviceConfigurationModel.AssemblyPath = Path.Combine(packageContentRoot, configuration.GetQualifiedAssmeblyPath()); _logger.LogInformation("{Message} {@ObjectProperties}", "Component configuration loaded", serviceConfigurationModel); return(serviceConfigurationModel); }
/// <summary> /// Instantiates a new package. /// </summary> /// <param name="packageRootFilename">The filename for this package.</param> /// <param name="configurationFileName">The filename of the configuration file contained in this package.</param> /// <param name="configuration">This package's configuration.</param> public Package(string packageRootFilename, string configurationFileName, IPackageConfiguration configuration) : this() { if (string.IsNullOrWhiteSpace(packageRootFilename)) { throw new ArgumentNullException(nameof(packageRootFilename)); } RootFilename = packageRootFilename; if (string.IsNullOrWhiteSpace(configurationFileName)) { throw new ArgumentNullException(nameof(configurationFileName)); } ConfigurationFilename = configurationFileName; PackageConfiguration = configuration ?? throw new ArgumentNullException(nameof(configuration)); }
/// <summary> /// Instantiates a new connected package. /// </summary> /// <param name="packagesStore">The file store containing the package.</param> /// <param name="packageRootFilename">The package file name in the file store.</param> /// <param name="originalFilename">The file name for the package file store.</param> /// <param name="packFileStore">A file store connected to the package file store.</param> /// <param name="packConfiguration">The package configuration read from this package.</param> internal ConnectedPackage(FileStorage.IFileStore packagesStore, string packageRootFilename, string originalFilename, FileStorage.IFileStore packFileStore, IPackageConfiguration packConfiguration) : this() { _PackagesStore = packagesStore ?? throw new ArgumentNullException(nameof(packagesStore)); if (string.IsNullOrWhiteSpace(packageRootFilename)) { throw new ArgumentNullException(nameof(packageRootFilename)); } _PackageRootFilename = packageRootFilename; if (string.IsNullOrWhiteSpace(originalFilename)) { throw new ArgumentNullException(nameof(originalFilename)); } _OriginalFilename = originalFilename; _FileStore = packFileStore ?? throw new ArgumentNullException(nameof(packFileStore)); PackageConfiguration = packConfiguration ?? throw new ArgumentNullException(nameof(packConfiguration)); }
/// <summary> /// Processes all package configurations. /// </summary> public void ProcessPackageConfigurations() { // get all products that are configured IEnumerable <IProduct> products = ProductService.GetAll(); // for each product try to find new packages foreach (IProduct product in products) { IPackageConfiguration configuration = null; if (product.PackageConfigurations != null) { configuration = product.PackageConfigurations .Where(config => config.IsActive) .OrderByDescending(config => config.UpdatedAt) .FirstOrDefault(); } Version lastPackageVersion = null; if (product.Packages != null) { var packageWithHighestVersion = product.Packages.OrderBy(package => package.Version).LastOrDefault(); if (packageWithHighestVersion != null) { lastPackageVersion = packageWithHighestVersion.Version; } } if (configuration != null) { if (configuration.SearchPath != null) { string lastFileName = null; if (lastPackageVersion != null) { lastFileName = string.Format("{0}_{1}.{2}.{3}.zip", configuration.Name, lastPackageVersion.Major, lastPackageVersion.Minor, lastPackageVersion.Build); } if (Directory.Exists(configuration.SearchPath)) { foreach (string packageUrl in Directory.EnumerateFiles(configuration.SearchPath, configuration.SearchPattern)) { var fileName = new FileInfo(packageUrl).Name; if (String.Compare(fileName, lastFileName, StringComparison.InvariantCultureIgnoreCase) > 0) { //create package for this configuration IPackage package = PackageService.CreateInstance(); Match matches = FilenamePattern.Match(fileName); if (matches.Success) { package.Name = matches.Groups[1].Value; int major; if (int.TryParse(matches.Groups[2].Value, out major)) { int minor; if (int.TryParse(matches.Groups[3].Value, out minor)) { int build; if (int.TryParse(matches.Groups[4].Value, out build)) { package.Version = new Version(major, minor, build); } } } } package.Name = fileName; package.Product = product; package.Websites = configuration.Websites; package.SetupSteps = configuration.SetupSteps; package.PackageUrl = packageUrl; } } } } } } }
/// <summary> /// Will create a new package using a default package configuration name. /// </summary> /// <param name="packageRootFilename">The package filename.</param> /// <param name="packageConfiguration">The configuration for this package.</param> /// <param name="overwrite"><b>True</b> to write-over the package file if it already exists, otherwise, <b>false</b>.</param> /// <returns>An <see cref="IConnectedPackage"/>, which represents the desired package.</returns> /// <remarks> /// See <see cref="ConnectedPackage"/> concerning proper handling of the <see cref="ConnectedPackage"/>. /// </remarks> public IConnectedPackage Create(string packageRootFilename, IPackageConfiguration packageConfiguration, bool overwrite) { return(Create(packageRootFilename, _ConfigurationFilename, packageConfiguration, overwrite)); }