public ModuleDescriptor(ManifestModuleInfo moduleInfo) : this() { Id = moduleInfo.Id; Title = moduleInfo.Title; Description = moduleInfo.Description; Authors = moduleInfo.Authors; Owners = moduleInfo.Owners; LicenseUrl = moduleInfo.LicenseUrl; ProjectUrl = moduleInfo.ProjectUrl; IconUrl = moduleInfo.IconUrl; Version = moduleInfo.Version.ToString(); RequireLicenseAcceptance = moduleInfo.RequireLicenseAcceptance; ReleaseNotes = moduleInfo.ReleaseNotes; Copyright = moduleInfo.Copyright; IsRemovable = moduleInfo.IsRemovable; IsInstalled = moduleInfo.IsInstalled; PlatformVersion = moduleInfo.PlatformVersion.ToString(); Groups = moduleInfo.Groups; if (moduleInfo.Dependencies != null) { Dependencies = moduleInfo.Dependencies.Select(x => new ModuleIdentity(x.Id, x.Version)).ToList(); } ValidationErrors = moduleInfo.Errors; }
private void InnerInstall(ManifestModuleInfo module, IProgress <ProgressMessage> progress) { var dstModuleDir = Path.Combine(_options.DiscoveryPath, module.Id); var moduleZipPath = Path.Combine(dstModuleDir, GetModuleZipFileName(module.Id, module.Version.ToString())); _fileManager.CreateDirectory(dstModuleDir); //download module archive from web if (Uri.IsWellFormedUriString(module.Ref, UriKind.Absolute)) { var moduleUrl = new Uri(module.Ref); using (var fileStream = _fileSystem.File.OpenWrite(moduleZipPath)) using (var webStream = _externalClient.OpenRead(moduleUrl)) { Report(progress, ProgressMessageLevel.Info, "Downloading '{0}' ", module.Ref); webStream.CopyTo(fileStream); } } else if (_fileSystem.File.Exists(module.Ref)) { moduleZipPath = module.Ref; } _zipFileWrapper.Extract(moduleZipPath, dstModuleDir); Report(progress, ProgressMessageLevel.Info, "Successfully installed '{0}'.", module); }
protected override void InnerLoad() { var discoveryPath = _options.DiscoveryPath; if (string.IsNullOrEmpty(_options.ProbingPath)) { throw new InvalidOperationException("The ProbingPath cannot contain a null value or be empty"); } if (string.IsNullOrEmpty(_options.DiscoveryPath)) { throw new InvalidOperationException("The DiscoveryPath cannot contain a null value or be empty"); } if (!Directory.Exists(_options.ProbingPath)) { Directory.CreateDirectory(_options.ProbingPath); } if (!discoveryPath.EndsWith(Path.DirectorySeparatorChar)) { discoveryPath += Path.DirectorySeparatorChar; } var rootUri = new Uri(discoveryPath); CopyAssemblies(_options.DiscoveryPath, _options.ProbingPath); foreach (var pair in GetModuleManifests()) { var manifest = pair.Value; var manifestPath = pair.Key; var modulePath = Path.GetDirectoryName(manifestPath); CopyAssemblies(modulePath, _options.ProbingPath); var moduleVirtualPath = GetModuleVirtualPath(rootUri, modulePath); ConvertVirtualPath(manifest.Scripts, moduleVirtualPath); ConvertVirtualPath(manifest.Styles, moduleVirtualPath); var moduleInfo = new ManifestModuleInfo(manifest) { FullPhysicalPath = Path.GetDirectoryName(manifestPath) }; // Modules without assembly file don't need initialization if (string.IsNullOrEmpty(manifest.AssemblyFile)) { moduleInfo.State = ModuleState.Initialized; } else { //Set module assembly physical path for future loading by IModuleTypeLoader instance moduleInfo.Ref = GetFileAbsoluteUri(_options.ProbingPath, manifest.AssemblyFile); } moduleInfo.IsInstalled = true; AddModule(moduleInfo); } }
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); }
public async Task <IHttpActionResult> UploadModuleArchive() { EnsureModulesCatalogInitialized(); if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted")); } webModel.ModuleDescriptor retVal = null; var uploadsPath = HostingEnvironment.MapPath(_uploadsUrl); var streamProvider = new CustomMultipartFormDataStreamProvider(uploadsPath); await Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t => { if (t.IsFaulted || t.IsCanceled) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } }); var fileData = streamProvider.FileData.FirstOrDefault(); using (var packageStream = File.Open(fileData.LocalFileName, FileMode.Open)) using (var package = new ZipArchive(packageStream, ZipArchiveMode.Read)) { var entry = package.GetEntry("module.manifest"); if (entry != null) { using (var manifestStream = entry.Open()) { var manifest = ManifestReader.Read(manifestStream); var module = new ManifestModuleInfo(manifest); var alreadyExistModule = _moduleCatalog.Modules.OfType <ManifestModuleInfo>().FirstOrDefault(x => x.Equals(module)); if (alreadyExistModule != null) { module = alreadyExistModule; } else { //Force dependency validation for new module _moduleCatalog.CompleteListWithDependencies(new[] { module }).ToList().Clear(); _moduleCatalog.AddModule(module); } module.Ref = fileData.LocalFileName; retVal = module.ToWebModel(); } } } return(Ok(retVal)); }
/// <summary> /// Get the new ManifestModuleInfo for module version that has exactly the same major version as the current platform /// </summary> private ManifestModuleInfo GetLatestCompatibleWithPlatformVersion(ExternalModuleManifest manifest, bool prerelease) { ManifestModuleInfo result = null; var latestCompatibleManifest = manifest.Versions .OrderByDescending(x => x.SemanticVersion) .Where(x => x.PlatformSemanticVersion.Major == PlatformVersion.CurrentVersion.Major) .FirstOrDefault(x => string.IsNullOrEmpty(x.VersionTag) != prerelease); if (latestCompatibleManifest != null) { result = AbstractTypeFactory <ManifestModuleInfo> .TryCreateInstance(); result.LoadFromExternalManifest(manifest, latestCompatibleManifest); } return(result); }
private bool HasMissedDependencies(ManifestModuleInfo module, IEnumerable <ManifestModuleInfo> modules, IProgress <ProgressMessage> progress) { var result = true; try { result = _extModuleCatalog.CompleteListWithDependencies(new[] { module }) .OfType <ManifestModuleInfo>() .Where(x => !x.IsInstalled) .Except(modules) .Any(); } catch (MissedModuleException ex) { Report(progress, ProgressMessageLevel.Error, ex.Message); } return(result); }
private ManifestModuleInfo ReadModule(string moduleFile) { using (var packageStream = File.Open(moduleFile, FileMode.Open)) using (var package = new ZipArchive(packageStream, ZipArchiveMode.Read)) { var entry = package.GetEntry("module.manifest"); if (entry != null) { using (var manifestStream = entry.Open()) { var manifest = ManifestReader.Read(manifestStream); var module = new ManifestModuleInfo(manifest); module.Ref = packageStream.Name; return(module); } } } return(null); }
public static IApplicationBuilder UsePlatformSettings(this IApplicationBuilder appBuilder) { var moduleCatalog = appBuilder.ApplicationServices.GetRequiredService <ILocalModuleCatalog>(); var platforModuleManifest = new ManifestModuleInfo(new ModuleManifest { Id = "VirtoCommerce.Platform", Version = PlatformVersion.CurrentVersion.ToString(), PlatformVersion = PlatformVersion.CurrentVersion.ToString() }); platforModuleManifest.Settings.Add(new ModuleSettingsGroup { Name = "Platform|Security", Settings = PlatformConstants.Settings.Security.AllSettings.ToArray() }); platforModuleManifest.Settings.Add(new ModuleSettingsGroup { Name = "Platform|Cache", Settings = PlatformConstants.Settings.Cache.AllSettings.ToArray() }); platforModuleManifest.Settings.Add(new ModuleSettingsGroup { Name = "Platform|Setup", Settings = PlatformConstants.Settings.Setup.AllSettings.ToArray() }); platforModuleManifest.Settings.Add(new ModuleSettingsGroup { Name = "Platform|User Profile", Settings = PlatformConstants.Settings.UserProfile.AllSettings.ToArray() }); platforModuleManifest.Settings.Add(new ModuleSettingsGroup { Name = "Platform|User Interface", Settings = PlatformConstants.Settings.UserInterface.AllSettings.ToArray() }); moduleCatalog.AddModule(platforModuleManifest); return(appBuilder); }
protected override void InnerLoad() { var contentPhysicalPath = _modulesLocalPath; if (string.IsNullOrEmpty(_assembliesPath)) { throw new InvalidOperationException("The AssembliesPath cannot contain a null value or be empty"); } if (string.IsNullOrEmpty(_contentVirtualPath)) { throw new InvalidOperationException("The ContentVirtualPath cannot contain a null value or be empty"); } if (string.IsNullOrEmpty(contentPhysicalPath)) { throw new InvalidOperationException("The ContentPhysicalPath cannot contain a null value or be empty"); } if (!Directory.Exists(_assembliesPath)) { Directory.CreateDirectory(_assembliesPath); } if (!contentPhysicalPath.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { contentPhysicalPath += "\\"; } var rootUri = new Uri(contentPhysicalPath); CopyAssemblies(_modulesLocalPath, _assembliesPath); foreach (var pair in GetModuleManifests()) { var manifest = pair.Value; var manifestPath = pair.Key; var modulePath = Path.GetDirectoryName(manifestPath); CopyAssemblies(modulePath, _assembliesPath); var moduleVirtualPath = GetModuleVirtualPath(rootUri, modulePath); ConvertVirtualPath(manifest.Scripts, moduleVirtualPath); ConvertVirtualPath(manifest.Styles, moduleVirtualPath); var moduleInfo = new ManifestModuleInfo(manifest) { FullPhysicalPath = Path.GetDirectoryName(manifestPath) }; // Modules without assembly file don't need initialization if (string.IsNullOrEmpty(manifest.AssemblyFile)) { moduleInfo.State = ModuleState.Initialized; } else { moduleInfo.Ref = GetFileAbsoluteUri(_assembliesPath, manifest.AssemblyFile); } moduleInfo.IsInstalled = true; AddModule(moduleInfo); } }
public async Task <ActionResult> UploadModuleArchive() { ModuleDescriptor result = null; EnsureModulesCatalogInitialized(); if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) { return(BadRequest($"Expected a multipart request, but got {Request.ContentType}")); } string targetFilePath = null; var boundary = MultipartRequestHelper.GetBoundary(MediaTypeHeaderValue.Parse(Request.ContentType), _defaultFormOptions.MultipartBoundaryLengthLimit); var reader = new MultipartReader(boundary, HttpContext.Request.Body); var section = await reader.ReadNextSectionAsync(); if (section != null) { ContentDispositionHeaderValue contentDisposition; var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out contentDisposition); if (hasContentDispositionHeader) { if (MultipartRequestHelper.HasFileContentDisposition(contentDisposition)) { targetFilePath = Path.Combine(_hostingEnv.MapPath(_uploadsUrl), contentDisposition.FileName.Value); using (var targetStream = System.IO.File.Create(targetFilePath)) { await section.Body.CopyToAsync(targetStream); } } } } using (var packageStream = System.IO.File.Open(targetFilePath, FileMode.Open)) using (var package = new ZipArchive(packageStream, ZipArchiveMode.Read)) { var entry = package.GetEntry("module.manifest"); if (entry != null) { using (var manifestStream = entry.Open()) { var manifest = ManifestReader.Read(manifestStream); var module = new ManifestModuleInfo(manifest); var alreadyExistModule = _moduleCatalog.Modules.OfType <ManifestModuleInfo>().FirstOrDefault(x => x.Equals(module)); if (alreadyExistModule != null) { module = alreadyExistModule; } else { //Force dependency validation for new module _moduleCatalog.CompleteListWithDependencies(new[] { module }).ToList().Clear(); _moduleCatalog.AddModule(module); } module.Ref = targetFilePath; result = AbstractTypeFactory <ModuleDescriptor> .TryCreateInstance().FromModel(module); } } } return(Ok(result)); }
protected override void InnerLoad() { var contentPhysicalPath = _modulesLocalPath; if (string.IsNullOrEmpty(_assembliesPath)) { throw new InvalidOperationException("The AssembliesPath cannot contain a null value or be empty"); } if (string.IsNullOrEmpty(_contentVirtualPath)) { throw new InvalidOperationException("The ContentVirtualPath cannot contain a null value or be empty"); } if (string.IsNullOrEmpty(contentPhysicalPath)) { throw new InvalidOperationException("The ContentPhysicalPath cannot contain a null value or be empty"); } //Use lock file in file system to synhronize multiple platform instances initialization (to avoid collisions on initialization process) var fileLock = SimpleFileLock.Create("vc-lock", TimeSpan.FromMinutes(1)); var needCopyAssemblies = fileLock.TryAcquireLock(); if (!contentPhysicalPath.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { contentPhysicalPath += "\\"; } var rootUri = new Uri(contentPhysicalPath); if (needCopyAssemblies) { if (!Directory.Exists(_assembliesPath)) { Directory.CreateDirectory(_assembliesPath); } // Clear ~/moules directory from old assemblies // Ignore any errors, because shadow copy may not work try { foreach (var assembly in Directory.GetFiles(_assembliesPath)) { File.Delete(assembly); } } catch (Exception) { } CopyAssemblies(_modulesLocalPath, _assembliesPath); } foreach (var pair in GetModuleManifests()) { var manifest = pair.Value; var manifestPath = pair.Key; var modulePath = Path.GetDirectoryName(manifestPath); if (needCopyAssemblies) { CopyAssemblies(modulePath, _assembliesPath); } var moduleVirtualPath = GetModuleVirtualPath(rootUri, modulePath); ConvertVirtualPath(manifest.Scripts, moduleVirtualPath); ConvertVirtualPath(manifest.Styles, moduleVirtualPath); var moduleInfo = new ManifestModuleInfo(manifest) { FullPhysicalPath = Path.GetDirectoryName(manifestPath) }; // Modules without assembly file don't need initialization if (string.IsNullOrEmpty(manifest.AssemblyFile)) { moduleInfo.State = ModuleState.Initialized; } else { moduleInfo.Ref = GetFileAbsoluteUri(_assembliesPath, manifest.AssemblyFile); } moduleInfo.IsInstalled = true; AddModule(moduleInfo); } //Wait until other (first) platform instance finished initialization (copying assemblies) if (!needCopyAssemblies) { while (!fileLock.TryAcquireLock()) { Thread.Sleep(500); } } //Release file system lock fileLock.ReleaseLock(); }
void WriteModuleLine(ManifestModuleInfo module) { _output.WriteLine("{0} {1} {2}", module.IsInstalled ? "INSTALLED" : "", module.Id, module.Version); }
//private static string _tempDir; //[TestMethod] //public void ValidatePackage() //{ // var service = GetPackageService(); // // Load module descriptor from package // var module = service.LoadModule(@"source\Sample.TestModule1_1.0.0.zip"); // WriteModuleLine(module); // // Check if all dependencies are installed // var dependencyErrors = service.GetDependencyErrors(module); //} //[TestMethod] //public void InstallUpdateUninstall() //{ // var service = GetPackageService(); // var progress = new Progress<ProgressMessage>(WriteProgressMessage); // ListModules(service); // service.Install(@"source\TestModule2_v1.0.0.zip", progress); // ListModules(service); // service.Install(@"source\TestModule1_v1.0.0.zip", progress); // ListModules(service); // service.Install(@"source\TestModule2_v1.0.0.zip", progress); // ListModules(service); // service.Update("TestModule2", @"source\TestModule2_v1.1.0.zip", progress); // ListModules(service); // service.Update("TestModule1", @"source\TestModule1_v1.1.0.zip", progress); // ListModules(service); // service.Update("TestModule2", @"source\TestModule2_v1.1.0.zip", progress); // ListModules(service); // service.Uninstall("TestModule1", progress); // ListModules(service); // service.Uninstall("TestModule2", progress); // ListModules(service); // service.Uninstall("TestModule1", progress); // ListModules(service); //} //[ClassInitialize] //public static void Initialize(TestContext context) //{ // _tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); // Directory.CreateDirectory(_tempDir); //} //[ClassCleanup] //public static void Cleanup() //{ // Directory.Delete(_tempDir, true); //} //private static IModuleInstaller GetPackageService() //{ // var modulesPath = Path.Combine(_tempDir, @"modules"); // var packagesPath = Path.Combine(_tempDir, @"packages"); // var manifestProvider = new ModuleManifestProvider(modulesPath); // var service = new ZipPackageService(null, manifestProvider, packagesPath, null, null); // return service; //} //static void ListModules(IModuleInstaller service) //{ // var modules = service.GetAllModules(); // Debug.WriteLine("Modules count: {0}", modules.Length); // foreach (var module in modules) // { // WriteModuleLine(module); // } //} static void WriteModuleLine(ManifestModuleInfo module) { Debug.WriteLine("{0} {1}", module.Id, module.Version); }