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; }
protected override void InnerLoad() { var contentPhysicalPath = ManifestProvider.RootPath; if (string.IsNullOrEmpty(_assembliesPath)) { throw new InvalidOperationException(Resources.AssembliesPathCannotBeNullOrEmpty); } if (string.IsNullOrEmpty(_contentVirtualPath)) { throw new InvalidOperationException(Resources.ContentPathCannotBeNullOrEmpty); } if (string.IsNullOrEmpty(contentPhysicalPath)) { throw new InvalidOperationException(Resources.ContentPathCannotBeNullOrEmpty); } if (!Directory.Exists(_assembliesPath)) { Directory.CreateDirectory(_assembliesPath); } if (!contentPhysicalPath.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { contentPhysicalPath += "\\"; } var rootUri = new Uri(contentPhysicalPath); CopyAssemblies(ManifestProvider.RootPath, _assembliesPath); foreach (var pair in ManifestProvider.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, modulePath); // Modules without assembly file don't need initialization if (string.IsNullOrEmpty(manifest.AssemblyFile)) { moduleInfo.State = ModuleState.Initialized; } else { moduleInfo.Ref = GetFileAbsoluteUri(_assembliesPath, manifest.AssemblyFile); } AddModule(moduleInfo); } }
public static ModuleDescriptor ToWebModel(this coreModel.ManifestModuleInfo moduleInfo) { var retVal = new ModuleDescriptor(); retVal.InjectFrom(moduleInfo); retVal.Version = moduleInfo.Version.ToString(); retVal.PlatformVersion = moduleInfo.PlatformVersion.ToString(); retVal.Groups = moduleInfo.Groups; if (moduleInfo.Dependencies != null) { retVal.Dependencies = moduleInfo.Dependencies.Select(x => new ModuleIdentity { Id = x.Id, Version = x.Version.ToString() }).ToList(); } retVal.ValidationErrors = moduleInfo.Errors; return(retVal); }
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 override bool Equals(object obj) { // If parameter is null return false. if (obj == null) { return(false); } // If parameter cannot be cast to ModuleIdentity return false. ManifestModuleInfo other = obj as ManifestModuleInfo; if (other == null) { return(false); } // Return true if the fields match: return((Id == other.Id) && (Version == other.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); }
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)) { using (var client = new WebClient()) using (var fileStream = File.OpenWrite(moduleZipPath)) using (var webStream = client.OpenRead(new Uri(module.Ref))) { 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); }
void WriteModuleLine(ManifestModuleInfo module) { _output.WriteLine("{0} {1} {2}", module.IsInstalled ? "INSTALLED" : "", module.Id, module.Version); }
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 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 }).ToArray(); _moduleCatalog.AddModule(module); } module.Ref = fileData.LocalFileName; retVal = module.ToWebModel(); } } } return Ok(retVal); }