Esempio n. 1
0
    protected override void OnTargetStart(string target)
    {
        if (VersionSuffix.IsNullOrEmpty() && !CustomVersionSuffix.IsNullOrEmpty())
        {
            //module.manifest
            if (IsModule)
            {
                var manifest = ModuleManifest.Clone();
                manifest.VersionTag = CustomVersionSuffix;
                using (var writer = new Utf8StringWriter())
                {
                    XmlSerializer xml = new XmlSerializer(typeof(ModuleManifest));
                    xml.Serialize(writer, manifest);
                    File.WriteAllText(ModuleManifestFile, writer.ToString(), Encoding.UTF8);
                }
            }

            //directory.Build.Props
            var xmlDoc = new XmlDocument()
            {
                PreserveWhitespace = true
            };
            xmlDoc.LoadXml(File.ReadAllText(DirectoryBuildPropsPath));
            var suffix = xmlDoc.GetElementsByTagName("VersionSuffix");
            suffix[0].InnerText = CustomVersionSuffix;
            using (var writer = new Utf8StringWriter())
            {
                xmlDoc.Save(writer);
                File.WriteAllText(DirectoryBuildPropsPath, writer.ToString());
            }
        }
        base.OnTargetStart(target);
    }
Esempio n. 2
0
        public void finds_manifest_in_multi_level_tree()
        {
            // module name 
            const string moduleName = "moduleName";
            

            // create sub folder
            const string folderName = "folderName";
            string folderPathCreated = Path.Combine(_testDirectory, folderName);
            Directory.CreateDirectory(folderPathCreated);

            // create name for manifest
            string pathToManifest = Path.Combine(folderPathCreated, "SOME_ITCHY_NAME" + ModuleManifest.ManifestFileNameSuffix);

            // put manifest there
            var manifest = new ModuleManifest()
                                 {
                                     ModuleName = moduleName
                                 };
            var data = XmlSerializerHelper.Serialize(manifest);
            File.WriteAllBytes(pathToManifest, data);

            // create package with manifest of the same name
            var package = GetPackageWithName(moduleName);

            // run test
            var folderPathResolved = _moduleFinder.FindDirectoryForPackage(_testDirectory, package);

            // assert that path to sub folder has been returned
            Assert.AreEqual(folderPathResolved, folderPathCreated, "The path to folder was not found properly");
        }
Esempio n. 3
0
        private void UpdateDependencyIndex(ModuleManifest module)
        {
            var dependedModules = Modules.Where(m => m.Manifest.Dependencies.Any(k => k.ModuleName == module.Name));

            if (DependencyIndex.Any(m => m.ModuleName == module.Name))
            {
                DependencyIndex.Single(m => m.ModuleName == module.Name).Dep = module.Dependencies.Select(dp => dp.ModuleName).ToList();
                //Modules.Single(m => m.Value.Manifest.ModuleName == module.Manifest.ModuleName).Value.Manifest.Dependencies = module.Manifest.Dependencies;
                try
                {
                    var oldModule       = Modules.Single(m => m.Manifest.Name == module.Name);
                    var dependOnModules = Modules.Where(m => oldModule.Manifest.Dependencies.Select(d => d.ModuleName).Contains(m.Manifest.Name));
                    var targets         = DependencyIndex.Where(dp => dependOnModules.Any(m => m.Manifest.Name == dp.ModuleName)).ToList();
                    foreach (var target in targets)
                    {
                        DependencyIndex.Single(d => d.ModuleName == target.ModuleName).Cnt--;
                    }
                }
                catch { }
            }
            else
            {
                var temp = new ModuleIndexData {
                    Dep = module.Dependencies.Select(m => m.ModuleName).ToList(), Cnt = 0, ModuleName = module.Name
                };
                DependencyIndex.Add(temp);
            }
            foreach (var dependency in module.Dependencies)
            {
                DependencyIndex.Single(m => m.ModuleName == dependency.ModuleName).Cnt++;
            }
            File.WriteAllText(GetDiFilePath(), JsonConvert.SerializeObject(DependencyIndex));
        }
Esempio n. 4
0
        private async Task <string> UploadArtifactAsync(ModuleManifest manifest, string relativeFilePath, string description)
        {
            var filePath = Path.Combine(Settings.OutputDirectory, relativeFilePath);

            // only upload files that don't exist
            var destinationKey = manifest.ModuleInfo.GetArtifactPath(Path.GetFileName(filePath));

            if (_forcePublish || !await DoesS3ObjectExistsAsync(destinationKey))
            {
                Console.WriteLine($"=> Uploading {description}: {Path.GetFileName(destinationKey)}");
                var request = new TransferUtilityUploadRequest {
                    FilePath   = filePath,
                    BucketName = Settings.DeploymentBucketName,
                    Key        = destinationKey
                };
                request.Metadata[AMAZON_METADATA_ORIGIN] = Settings.DeploymentBucketName;
                try {
                    await _transferUtility.UploadAsync(request);

                    _changesDetected = true;
                } catch (AmazonS3Exception e) when(e.Message == "The XML you provided was not well-formed or did not validate against our published schema")
                {
                    // NOTE (2019-09-14, bjorg): this exception can occur on slow/unreliable networks
                    LogError($"unable to upload {description} due to a network error");
                }
            }
            return(destinationKey);
        }
Esempio n. 5
0
        private async Task <bool> ImportDependencies(ModuleManifest manifest, bool allowImport = true)
        {
            // discover module dependencies
            var dependencies = await _loader.DiscoverAllDependenciesAsync(manifest, checkExisting : false, allowImport, allowDependencyUpgrades : false);

            if (HasErrors)
            {
                return(false);
            }

            // copy all dependencies to deployment bucket that are missing or have a pre-release version
            foreach (var dependency in dependencies.Where(dependency => dependency.ModuleLocation.SourceBucketName != Settings.DeploymentBucketName))
            {
                var imported = false;

                // copy check-summed module artifacts (guaranteed immutable)
                foreach (var artifact in dependency.Manifest.Artifacts)
                {
                    imported = imported | await ImportS3Object(dependency.ModuleLocation.ModuleInfo.Origin, artifact);
                }

                // copy version manifest
                imported = imported | await ImportS3Object(dependency.ModuleLocation.ModuleInfo.Origin, dependency.ModuleLocation.ModuleInfo.VersionPath, replace : dependency.ModuleLocation.ModuleInfo.Version.IsPreRelease());

                // show message if any artifacts were imported
                if (imported)
                {
                    Console.WriteLine($"=> Imported {dependency.ModuleLocation.ModuleInfo}");
                }
            }
            return(true);
        }
Esempio n. 6
0
        //--- Methods ---
        public bool TryLoadManifestFromCloudFormationFile(string filepath, out ModuleManifest manifest)
        {
            JObject cloudformation;

            try {
                // load cloudformation template
                var template = File.ReadAllText(filepath);
                cloudformation = JObject.Parse(template);
            } catch (Exception) {
                manifest       = null;
                cloudformation = null;
                return(false);
            }

            // extract manifest from cloudformation template
            if (
                cloudformation.TryGetValue("Metadata", out var metadataToken) &&
                (metadataToken is JObject metadata) &&
                metadata.TryGetValue(ModuleManifest.MetadataName, out var manifestToken)
                )
            {
                manifest = manifestToken.ToObject <ModuleManifest>();
                if (manifest.Version == ModuleManifest.CurrentVersion)
                {
                    return(true);
                }
                LogError($"Incompatible LambdaSharp manifest version (found: {manifest.Version ?? "<null>"}, expected: {ModuleManifest.CurrentVersion})");
            }
            else
            {
                LogError("CloudFormation file does not contain a LambdaSharp manifest");
            }
            manifest = null;
            return(false);
        }
Esempio n. 7
0
        /// <summary>
        ///     Unzips the data from <paramref name="packageData"/> and access <see cref="ModuleManifest"/>.
        /// </summary>
        /// <param name="packageData">The raw data of the package.</param>
        /// <returns><see cref="ModuleInfo"/> object that has ModuleManifest found.</returns>
        public IModuleInfo UnPack(byte[] packageData)
        {
            if (packageData == null)
            {
                throw new ArgumentNullException("packageData");
            }

            ZipFile        zipFile  = null;
            ModuleManifest manifest = null;

            try
            {
                zipFile = ZipFile.Read(packageData);

                // find manifest inside the zip data
                foreach (ZipEntry zipEntry in zipFile)
                {
                    if (zipEntry.FileName.EndsWith(ModuleManifest.ManifestFileNameSuffix))
                    {
                        // use this file as manifest
                        var ms = new MemoryStream();
                        zipEntry.Extract(ms);
                        manifest = XmlSerializerHelper.Deserialize <ModuleManifest>(ms.ToArray());

                        // now search for the assembly described by this manifest, simply by iterating through zip entries
                        if (
                            !zipFile.Any(
                                entry =>
                                entry.FileName.EndsWith(".dll") | entry.FileName.EndsWith("exe")))
                        {
                            throw new ArgumentException("No assembly in the package");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw new InvalidDataException("The file is corrupted", e);
            }
            finally
            {
                if (zipFile != null)
                {
                    zipFile.Dispose();
                }
            }

            // have not found manifest
            if (manifest == null)
            {
                throw new InvalidDataException("No manifest file in package");
            }

            return(new ModuleInfo
            {
                ModuleData = packageData,
                Manifest = manifest
            });
        }
Esempio n. 8
0
 public static ModuleDescriptor ToModel(this ModuleManifest module)
 {
     return(new ModuleDescriptor
     {
         Id = module.Id,
         Title = module.Title,
     });
 }
Esempio n. 9
0
 //--- Constructors ---
 public ModuleManifestTypeSystem(string source, ModuleManifest manifest)
 {
     Source         = source ?? throw new ArgumentNullException(nameof(source));
     _manifest      = manifest;
     _resourceTypes = new Dictionary <string, IResourceType>();
     foreach (var resourceType in manifest.ResourceTypes)
     {
         _resourceTypes[resourceType.Type ?? throw new ArgumentException("missing resource type name")] = new ModuleManifestResourceType(resourceType);
Esempio n. 10
0
        private ModuleDescriptor ConvertToModuleDescriptor(ModuleManifest manifest, List <string> installedPackages = null)
        {
            ModuleDescriptor result = null;

            if (manifest != null)
            {
                result = new ModuleDescriptor
                {
                    Id                       = manifest.Id,
                    Version                  = manifest.Version,
                    PlatformVersion          = manifest.PlatformVersion,
                    Title                    = manifest.Title,
                    Description              = manifest.Description,
                    Authors                  = manifest.Authors,
                    Owners                   = manifest.Owners,
                    RequireLicenseAcceptance = manifest.RequireLicenseAcceptance,
                    ReleaseNotes             = manifest.ReleaseNotes,
                    Copyright                = manifest.Copyright,
                    Tags                     = manifest.Tags,
                };

                if (manifest.Dependencies != null)
                {
                    result.Dependencies = manifest.Dependencies.Select(d => new ModuleIdentity {
                        Id = d.Id, Version = d.Version
                    });
                }

                if (manifest.LicenseUrl != null)
                {
                    result.LicenseUrl = new Uri(manifest.LicenseUrl);
                }

                if (manifest.ProjectUrl != null)
                {
                    result.ProjectUrl = new Uri(manifest.ProjectUrl);
                }

                if (manifest.IconUrl != null)
                {
                    result.IconUrl = new Uri(manifest.IconUrl);
                }

                if (installedPackages != null && installedPackages.Any())
                {
                    var packageFileName = GetPackageFileName(manifest.Id, manifest.Version);
                    result.IsRemovable = installedPackages.Contains(packageFileName, StringComparer.OrdinalIgnoreCase);
                }

                if (_moduleCatalog != null && _moduleCatalog.Modules != null)
                {
                    result.ModuleInfo = _moduleCatalog.Modules.FirstOrDefault(x => x.ModuleName == result.Id);
                }
            }

            return(result);
        }
Esempio n. 11
0
    public void ChangeProjectVersion(string prefix = null, string suffix = null)
    {
        //theme
        if (IsTheme)
        {
            //var json = JsonDocument.Parse(File.ReadAllText(PackageJsonPath));
            //json.RootElement.GetProperty("version")
            var json = SerializationTasks.JsonDeserializeFromFile <JObject>(PackageJsonPath);
            json["version"] = prefix;
            SerializationTasks.JsonSerializeToFile(json, Path.GetFullPath(PackageJsonPath));
        }
        else
        {
            //module.manifest
            if (IsModule)
            {
                var manifest = ModuleManifest.Clone();
                if (!String.IsNullOrEmpty(prefix))
                {
                    manifest.Version = prefix;
                }
                if (!String.IsNullOrEmpty(suffix))
                {
                    manifest.VersionTag = suffix;
                }
                using (var writer = new Utf8StringWriter())
                {
                    XmlSerializer xml = new XmlSerializer(typeof(ModuleManifest));
                    xml.Serialize(writer, manifest);
                    File.WriteAllText(ModuleManifestFile, writer.ToString(), Encoding.UTF8);
                }
            }

            //Directory.Build.props
            var xmlDoc = new XmlDocument()
            {
                PreserveWhitespace = true
            };
            xmlDoc.LoadXml(File.ReadAllText(DirectoryBuildPropsPath));
            if (!String.IsNullOrEmpty(prefix))
            {
                var prefixNodex = xmlDoc.GetElementsByTagName("VersionPrefix");
                prefixNodex[0].InnerText = prefix;
            }
            if (String.IsNullOrEmpty(VersionSuffix) && !String.IsNullOrEmpty(suffix))
            {
                var suffixNodes = xmlDoc.GetElementsByTagName("VersionSuffix");
                suffixNodes[0].InnerText = suffix;
            }
            using (var writer = new Utf8StringWriter())
            {
                xmlDoc.Save(writer);
                File.WriteAllText(DirectoryBuildPropsPath, writer.ToString());
            }
        }
    }
Esempio n. 12
0
        public void publishes_avaliable_modules_message_when_everything_is_ok()
        {
            const string assembly   = "test_assembly.dll";
            var          moduleInfo = new ModuleInfo(assembly);

            var moduleManifest = new ModuleManifest
            {
                ModuleName    = assembly,
                ModuleVersion = new Version("0.0.0.0")
            };

            var updateManifest = new ModuleManifest
            {
                ModuleName    = assembly,
                ModuleVersion = new Version("0.0.0.1")
            };

            ModuleDiscovery.Setup(x => x.GetModules()).Returns(new List <ModuleInfo>
            {
                moduleInfo
            });

            // FIXME: this should use internal manifest factory
            ModuleManifestFactory.Setup(x => x.GetManifest(It.Is <ModuleInfo>(y => y == moduleInfo)))
            .Returns(moduleManifest);


            EventAggregator.Setup(x => x.Publish(It.IsAny <NomadAvailableUpdatesMessage>()))
            .Callback <NomadAvailableUpdatesMessage>(msg =>
            {
                Assert.AreEqual(1,
                                msg.AvailableUpdates.
                                Count);
                Assert.AreEqual(updateManifest,
                                msg.AvailableUpdates.
                                First());
            })
            .Returns(null)
            .Verifiable("Message was not published");

            ModulesRepository
            .Setup(x => x.GetAvailableModules())
            .Returns(new AvailableModules
            {
                Manifests = new List <ModuleManifest> {
                    updateManifest
                }
            })
            .Verifiable("Get Avaliable modules has not been called");

            NomadUpdater.CheckUpdates();

            ModulesRepository.Verify();
            EventAggregator.Verify();
        }
Esempio n. 13
0
        private static string AddManifestFile()
        {
            // generate manifest for SimplestModulePossible file
            var builder = new ManifestBuilder(IssuerName, IssuerXmlPath,
                                              @"SimplestModulePossible1.dll",
                                              @"Modules\Simple");

            _manifest = builder.CreateAndPublish();
            return(@"Modules\Simple\SimplestModulePossible1.dll" +
                   ModuleManifest.ManifestFileNameSuffix);
        }
Esempio n. 14
0
        public async Task <(ModuleManifest Manifest, string Reason)> LoadManifestFromLocationAsync(ModuleLocation moduleLocation)
        {
            StartLogPerformance($"LoadManifestFromLocationAsync() for {moduleLocation.ModuleInfo}");
            var cached = false;

            try {
                // attempt to load manifest from cache
                var cachedManifestFilePath = GetCachedManifestFilePath(moduleLocation);
                if (!Settings.ForceRefresh && (cachedManifestFilePath is not null) && File.Exists(cachedManifestFilePath))
                {
                    ModuleManifest result = null;
                    try {
                        result = JsonSerializer.Deserialize <ModuleManifest>(await File.ReadAllTextAsync(cachedManifestFilePath), Settings.JsonSerializerOptions);
                        cached = true;
                        return(Manifest : result, Reason : null);
                    } catch {
                        // cached manifest file is either corrupted or inaccessible; attempt to delete it
                        try {
                            File.Delete(cachedManifestFilePath);
                        } catch {
                            // nothing to do
                        }
                    }
                }

                // download manifest from S3
                var manifestText = await GetS3ObjectContentsAsync(moduleLocation.SourceBucketName, moduleLocation.ModuleInfo.VersionPath);

                if (manifestText == null)
                {
                    return(Manifest : null, Reason : $"could not load module manifest for {moduleLocation.ModuleInfo}");
                }
                var manifest = JsonSerializer.Deserialize <ModuleManifest>(manifestText, Settings.JsonSerializerOptions);

                // validate manifest
                if (manifest.Version != ModuleManifest.CurrentVersion)
                {
                    return(Manifest : null, Reason : $"incompatible LambdaSharp manifest version (found: {manifest.Version ?? "<null>"}, expected: {ModuleManifest.CurrentVersion})");
                }

                // keep manifest if we have a valid file path for it
                if (cachedManifestFilePath is not null)
                {
                    try {
                        await File.WriteAllTextAsync(cachedManifestFilePath, manifestText);
                    } catch {
                        // cached manifest file could not be written; nothing to do
                    }
                }
                return(Manifest : manifest, Reason : null);
            } finally {
                StopLogPerformance(cached);
            }
        }
Esempio n. 15
0
 public ModuleMeta(Assembly asm, ModuleManifest manifest)
 {
     Assembly    = asm;
     ServiceMeta = new ServiceMeta
     {
         Name         = Assembly.GetName().Name,
         ModuleName   = manifest.Name,
         VersionMajor = manifest.Version.Major
     };
     TypeChanger = new TypeConverter.TypeConverter(Assembly);
     ResolveServiceFunctions();
     ResolveServiceModels();
 }
Esempio n. 16
0
        protected void ResolveRoutes(Assembly assembly, ModuleManifest moduleManifest)
        {
            var Types = assembly.GetTypes().Where(m => m.IsSubclassOf(typeof(Controller)));

            foreach (var type in Types)
            {
                var          ctrlRouteAttr = type.GetCustomAttribute <RouteAttribute>();
                MethodInfo[] methods       = GetMethods(type);
                foreach (var method in methods)
                {
                    AddMethodToRoute(type, method, moduleManifest.Name, ctrlRouteAttr);
                }
            }
        }
Esempio n. 17
0
 public ModuleInfo LoadModuler(ModuleManifest moduleManifest)
 {
     var(_, alc) = HostLoader.LoadPlugin(new PluginInfo
     {
         PluginName = moduleManifest.ModuleName,
         PluginDll  = moduleManifest.ModuleEntrypoint
     });
     return(new ModuleInfo
     {
         Alc = alc,
         ModuleAssembly = alc.EntryAssemlby,
         Manifest = moduleManifest
     });
 }
Esempio n. 18
0
        private async Task <string> UploadTemplateFileAsync(ModuleManifest manifest, string description)
        {
            var moduleInfo = manifest.ModuleInfo;

            // rewrite artifacts in manifest to have an absolute path
            manifest.Artifacts = manifest.Artifacts
                                 .OrderBy(artifact => artifact)
                                 .Select(artifact => moduleInfo.GetArtifactPath(artifact)).ToList();

            // add template to list of artifacts
            var destinationKey = manifest.GetModuleTemplatePath();

            manifest.Artifacts.Insert(0, destinationKey);

            // update cloudformation template with manifest and minify it
            var template = File.ReadAllText(SourceFilename)
                           .Replace(ModuleInfo.MODULE_ORIGIN_PLACEHOLDER, moduleInfo.Origin ?? throw new ApplicationException("missing Origin information"));
            var cloudformation = JObject.Parse(template);

            ((JObject)cloudformation["Metadata"])["LambdaSharp::Manifest"] = JObject.FromObject(manifest, new JsonSerializer {
                NullValueHandling = NullValueHandling.Ignore
            });
            var minified = JsonConvert.SerializeObject(cloudformation, new JsonSerializerSettings {
                Formatting        = Formatting.None,
                NullValueHandling = NullValueHandling.Ignore
            });

            // upload minified json
            if (_forcePublish || !await DoesS3ObjectExistsAsync(destinationKey))
            {
                Console.WriteLine($"=> Uploading {description}: {Path.GetFileName(destinationKey)}");
                var request = new TransferUtilityUploadRequest {
                    InputStream = new MemoryStream(Encoding.UTF8.GetBytes(minified)),
                    BucketName  = Settings.DeploymentBucketName,
                    ContentType = "application/json",
                    Key         = destinationKey
                };
                request.Metadata[AMAZON_METADATA_ORIGIN] = Settings.DeploymentBucketName;
                try {
                    await _transferUtility.UploadAsync(request);

                    _changesDetected = true;
                } catch (AmazonS3Exception e) when(e.Message == "The XML you provided was not well-formed or did not validate against our published schema")
                {
                    // NOTE (2019-09-14, bjorg): this exception can occur on slow/unreliable networks
                    LogError("unable to upload template due to a network error");
                }
            }
            return(destinationKey);
        }
Esempio n. 19
0
        public void set_up()
        {
            _simpleManifest     = new ModuleManifest();
            _moduleManifestMock = new Mock <IModuleManifestFactory>(MockBehavior.Loose);
            _moduleManifestMock.Setup(x => x.GetManifest(It.IsAny <ModuleInfo>())).Returns(
                _simpleManifest);

            _dependencyMock = new Mock <IDependencyChecker>(MockBehavior.Loose);
            _dependencyMock.Setup(x => x.SortModules(It.IsAny <IEnumerable <ModuleInfo> >()))
            .Returns <IEnumerable <ModuleInfo> >(e => e);

            _moduleFilterMock = new Mock <IModuleFilter>(MockBehavior.Loose);
            _moduleFilterMock.Setup(x => x.Matches(It.IsAny <ModuleInfo>())).Returns(true);
        }
        private void CreateFilesFromTemplates(string moduleName, Guid?projectGuid)
        {
            string modulePath     = HostingEnvironment.MapPath("~/Modules/" + moduleName + "/");
            string propertiesPath = modulePath + "Properties";
            var    content        = new HashSet <string>();
            var    folders        = new HashSet <string>();

            foreach (var folder in _moduleDirectories)
            {
                Directory.CreateDirectory(modulePath + folder);
                if (!String.IsNullOrEmpty(folder))
                {
                    folders.Add(modulePath + folder);
                }
            }

            File.WriteAllText(modulePath + "Web.config", File.ReadAllText(_codeGenTemplatePath + "ModuleRootWebConfig.txt"));
            content.Add(modulePath + "Web.config");
            File.WriteAllText(modulePath + "Scripts\\Web.config", File.ReadAllText(_codeGenTemplatePath + "StaticFilesWebConfig.txt"));
            content.Add(modulePath + "Scripts\\Web.config");
            File.WriteAllText(modulePath + "Styles\\Web.config", File.ReadAllText(_codeGenTemplatePath + "StaticFilesWebConfig.txt"));
            content.Add(modulePath + "Styles\\Web.config");

            var assemblyInfoTemplate = new ModuleAssemblyInfo();

            assemblyInfoTemplate.Session = new Dictionary <string, object>();
            assemblyInfoTemplate.Session["ModuleName"]        = moduleName;
            assemblyInfoTemplate.Session["ModuleTypeLibGuid"] = Guid.NewGuid();
            assemblyInfoTemplate.Initialize();
            string templateText = assemblyInfoTemplate.TransformText();

            File.WriteAllText(propertiesPath + "\\AssemblyInfo.cs", templateText);
            content.Add(propertiesPath + "\\AssemblyInfo.cs");

            var moduleMainfestTemplate = new ModuleManifest();

            moduleMainfestTemplate.Session = new Dictionary <string, object>();
            moduleMainfestTemplate.Session["ModuleName"] = moduleName;
            moduleMainfestTemplate.Initialize();
            templateText = moduleMainfestTemplate.TransformText();
            File.WriteAllText(modulePath + "Module.txt", templateText, System.Text.Encoding.UTF8);
            content.Add(modulePath + "Module.txt");

            var itemGroup = CreateProjectItemGroup(modulePath, content, folders);

            File.WriteAllText(modulePath + moduleName + ".csproj", CreateCsProject(moduleName, projectGuid, itemGroup));
        }
Esempio n. 21
0
        public ModulePackage GetModule(string moduleUniqueName)
        {
            IEnumerable <WebModulePackageInfo> packageInfo =
                _packagesCollection.Where(x => x.Manifest.ModuleName.Equals(moduleUniqueName));

            string url = packageInfo.Select(x => x.Url).Single();



            ModuleManifest manifest = packageInfo.Select(x => x.Manifest).Single();

            byte[] data = _webClient.DownloadData(url);

            return(new ModulePackage {
                ModuleManifest = manifest, ModuleZip = data
            });
        }
Esempio n. 22
0
        /// <summary>
        ///     Generates the manifest based on passed parameters and <c>saves manifest to file system</c>
        /// </summary>
        /// <remarks>
        ///     Performs the signing of the manifest file.
        /// </remarks>
        /// <returns>The newly created manifest.</returns>
        public ModuleManifest CreateAndPublish()
        {
            // perform creation
            ModuleManifest manifest = Create();

            byte[] manifestSerialized = XmlSerializerHelper.Serialize(manifest);

            //  sign the manifest
            string manifestPath = string.Format("{0}{1}", GetAssemblyPath(),
                                                ModuleManifest.ManifestFileNameSuffix);

            File.WriteAllBytes(manifestPath, manifestSerialized);
            File.WriteAllBytes(manifestPath + ModuleManifest.ManifestSignatureFileNameSuffix,
                               _signatureAlgorithm.Sign(File.ReadAllBytes(manifestPath)));

            return(manifest);
        }
Esempio n. 23
0
        /// <summary>
        ///     Initializes new instance of the <see cref="ModuleInfo"/> class.
        /// </summary>
        /// <param name="assemblyPath">Full or relative path to the assembly file containing module's code</param>
        /// <param name="manifest">Module Manifest connected with assembly file defined in <paramref name="assemblyPath"/>. Can be null.</param>
        /// <param name="factory">IModuleManifest factory that connects the concrete implementation of ModuleManifest with in program ModuleManifest. Can be null</param>
        /// <exception cref="ArgumentException">
        /// When <paramref name="assemblyPath"/> is <c>null</c> or empty.
        /// When <paramref name="manifest"/> or <paramref name="factory"/> is <c>null</c>.
        /// </exception>
        public ModuleInfo(string assemblyPath, ModuleManifest manifest,
                          IModuleManifestFactory factory)
        {
            if (string.IsNullOrEmpty(assemblyPath))
            {
                throw new ArgumentException("assemblyPath is required", assemblyPath);
            }

            if (manifest == null && factory == null)
            {
                throw new ArgumentException("manifest OR factory is required");
            }

            _assemblyPath          = assemblyPath;
            _manifest              = manifest;
            _moduleManifestFactory = factory;
        }
Esempio n. 24
0
    public void ChangeProjectVersion(string prefix = null, string suffix = null)
    {
        //module.manifest
        if (IsModule)
        {
            var manifest = ModuleManifest.Clone();
            if (!String.IsNullOrEmpty(prefix))
            {
                manifest.Version = prefix;
            }
            if (!String.IsNullOrEmpty(suffix))
            {
                manifest.VersionTag = suffix;
            }
            using (var writer = new Utf8StringWriter())
            {
                XmlSerializer xml = new XmlSerializer(typeof(ModuleManifest));
                xml.Serialize(writer, manifest);
                File.WriteAllText(ModuleManifestFile, writer.ToString(), Encoding.UTF8);
            }
        }

        //directory.Build.Props
        var xmlDoc = new XmlDocument()
        {
            PreserveWhitespace = true
        };

        xmlDoc.LoadXml(File.ReadAllText(DirectoryBuildPropsPath));
        if (!String.IsNullOrEmpty(prefix))
        {
            var prefixNodex = xmlDoc.GetElementsByTagName("VersionPrefix");
            prefixNodex[0].InnerText = prefix;
        }
        if (String.IsNullOrEmpty(VersionSuffix) && !String.IsNullOrEmpty(suffix))
        {
            var suffixNodes = xmlDoc.GetElementsByTagName("VersionSuffix");
            suffixNodes[0].InnerText = suffix;
        }
        using (var writer = new Utf8StringWriter())
        {
            xmlDoc.Save(writer);
            File.WriteAllText(DirectoryBuildPropsPath, writer.ToString());
        }
    }
Esempio n. 25
0
        private async Task <string> UploadTemplateFileAsync(ModuleManifest manifest, string description)
        {
            var moduleInfo = manifest.ModuleInfo;

            // rewrite artifacts in manifest to have an absolute path
            manifest.Artifacts = manifest.Artifacts
                                 .OrderBy(artifact => artifact)
                                 .Select(artifact => moduleInfo.GetArtifactPath(artifact)).ToList();

            // add template to list of artifacts
            var destinationKey = manifest.GetModuleTemplatePath();

            manifest.Artifacts.Insert(0, destinationKey);

            // update cloudformation template with manifest and minify it
            var template = File.ReadAllText(SourceFilename)
                           .Replace(ModuleInfo.MODULE_ORIGIN_PLACEHOLDER, moduleInfo.Origin ?? throw new ApplicationException("missing Origin information"));
            var cloudformation = JObject.Parse(template);

            ((JObject)cloudformation["Metadata"])["LambdaSharp::Manifest"] = JObject.FromObject(manifest, new JsonSerializer {
                NullValueHandling = NullValueHandling.Ignore
            });
            var minified = JsonConvert.SerializeObject(cloudformation, new JsonSerializerSettings {
                Formatting        = Formatting.None,
                NullValueHandling = NullValueHandling.Ignore
            });

            // upload minified json
            if (_forcePublish || !await DoesS3ObjectExistsAsync(destinationKey))
            {
                Console.WriteLine($"=> Uploading {description}: s3://{Settings.DeploymentBucketName}/{destinationKey}");
                var request = new TransferUtilityUploadRequest {
                    InputStream = new MemoryStream(Encoding.UTF8.GetBytes(minified)),
                    BucketName  = Settings.DeploymentBucketName,
                    ContentType = "application/json",
                    Key         = destinationKey
                };
                request.Metadata[AMAZON_METADATA_ORIGIN] = Settings.DeploymentBucketName;
                await _transferUtility.UploadAsync(request);

                _changesDetected = true;
            }
            return(destinationKey);
        }
Esempio n. 26
0
        public void set_up()
        {
            _moduleName = "test_module.dll";
            var moduleVersion = new Nomad.Utils.Version("0.1.1.0");

            _moduleManifest = new ModuleManifest {
                ModuleName = _moduleName, ModuleVersion = moduleVersion
            };

            // sick creating of dependency checker
            IEnumerable <ModuleInfo> outter = new List <ModuleInfo>();

            DependencyChecker.Setup(
                x =>
                x.CheckModules(It.IsAny <IEnumerable <ModuleInfo> >(),
                               It.IsAny <IEnumerable <ModuleInfo> >(),
                               out outter))
            .Returns(true);
        }
Esempio n. 27
0
        public IModuleInfo GenerateModuleInfo()
        {
            AssemblyName asmName = AssemblyName.GetAssemblyName(AssemblyFilePath);

            var manifest = new ModuleManifest
            {
                ModuleName    = asmName.Name,
                ModuleVersion = new Version(asmName.Version),
            };

            // get the moduleInfo but so called virtual implementation
            ModuleInfo = new ModuleInfo
            {
                Manifest   = manifest,
                ModuleData = File.ReadAllBytes(AssemblyFilePath),
            };

            return(ModuleInfo);
        }
        //--- Methods ---
        public bool TryLoadFromFile(string filepath, out ModuleManifest manifest)
        {
            JObject cloudformation;

            try {
                // load cloudformation template
                var template = File.ReadAllText(filepath);
                cloudformation = JObject.Parse(template);
            } catch (Exception) {
                LogError($"invalid CloudFormation template: {filepath}");
                manifest       = null;
                cloudformation = null;
                return(false);
            }

            // extract manifest
            manifest = GetManifest(cloudformation);
            return(manifest != null);
        }
Esempio n. 29
0
    /**
     * Save state to manifest
     */
    public InventoryManifest CreateManifest()
    {
        InventoryManifest manifest = new InventoryManifest(this);

        foreach (var slot in slots)
        {
            if (slot.module == null)
            {
                continue;
            }
            var            slotManifest   = new InventorySlotManifest();
            ModuleManifest moduleManifest = slot.module.manifest;
            slotManifest.module = moduleManifest;
            slotManifest.count  = slot.number;
            moduleManifest.inventorySlotIndex = slots.FindIndex((x) => x == slot);
            moduleManifest.type = (ModuleType)slot.module.GetType().GetField("type").GetRawConstantValue();
            manifest.slots.Add(slotManifest);
        }
        return(manifest);
    }
Esempio n. 30
0
        public void Compare_ModuleManifest_with_added_module_to_old_returns_difference()
        {
            var oldModuleManifest = new ModuleManifest(new Module[0]);

            Module module;
            var newModuleManifest = new ModuleManifest(new[]
            {
                module = new Module(
                    @"scripts/module-a",
                    new Resource[0],
                    new string[0],
                    null
                )
            });

            var differences = newModuleManifest.CompareTo(oldModuleManifest);
            differences.Length.ShouldEqual(1);
            differences[0].Type.ShouldEqual(ModuleDifferenceType.Added);
            differences[0].Module.ShouldEqual(module);
        }
Esempio n. 31
0
        private static void RegisterModuleDependencies(IServiceCollection serviceCollection, bool isConfigureModuleAlone)
        {
            var assemblies = DefaultAssemblyPartDiscoveryProvider.DiscoverAssemblyParts(Globals.EntryPointAssembly);

            var moduleConfiguratorType = typeof(IModuleConfigurator);
            var moduleConfigurators    = assemblies.GetDerivedTypeInfos(moduleConfiguratorType); //new List<TypeInfo>();
            var moduleRegistry         = InternalServiceProvider.Instance.ServiceProvider.GetService <IModuleRegistry>();

            //var registerServiceMethodInfo = moduleConfiguratorType.GetMethod("ConfigureServices");

            if (moduleConfigurators.Count <= 0)
            {
                return;
            }

            foreach (var moduleConfigurator in moduleConfigurators)
            {
                var moduleManifest = new ModuleManifest();
                moduleManifest.ModuleMetaInfo.ModuleAssemblyFullName = moduleConfigurator.Assembly.FullName;
                if (Activator.CreateInstance(moduleConfigurator) is IModuleConfigurator moduleConfig)
                {
                    moduleConfig.ConfigureModule(moduleManifest);
                    moduleManifest.ModuleMetaInfo.AdminConfiguratorTypeInfo =
                        GetAdminConfiguratorInModule(moduleConfigurator.Assembly);
                    moduleRegistry.TryRegisterModule(moduleManifest.ModuleMetaInfo);

                    if (isConfigureModuleAlone)
                    {
                        continue;
                    }

                    moduleConfig.ConfigureServices(serviceCollection);
                }

                if (!isConfigureModuleAlone)
                {
                    //RegisterModuleDbContexts
                    RegisterModuleDbContexts(moduleConfigurator.Assembly, serviceCollection);
                }
            }
        }
        XDocument CreateManifestXml(ModuleManifest moduleContainer)
        {
            return new XDocument(
                new XElement("manifest",
                    from module in moduleContainer.Modules
                    select new XElement("module",
                        new XAttribute("path", module.Path),
                        module.Location != null ? new XAttribute("location", module.Location) : null,

                        from resource in module.Resources
                        select new XElement("resource",
                            new XAttribute("path", resource.Path),
                            new XAttribute("hash", resource.Hash.ToHexString())
                        ),

                        from reference in module.References
                        select new XElement("reference",
                            new XAttribute("path", reference)
                        )
                    )
                )
            );
        }
Esempio n. 33
0
        public void Compare_ModuleManifest_with_changed_module_to_old_returns_Add_and_Delete_differences()
        {
            Module oldModule;
            var oldModuleManifest = new ModuleManifest(new[]
            {
                oldModule = new Module(
                    @"scripts/module-a",
                    new Resource[]
                    {
                        new Resource(@"scripts/module-a/test.js", new byte[] { 1 }, new string[0])
                    },
                    new string[0],
                    null
                )
            });

            Module changedModule;
            var newModuleManifest = new ModuleManifest(new[]
            {
                changedModule = new Module(
                    @"scripts/module-a",
                    new Resource[]
                    {
                        new Resource(@"scripts/module-a/test.js", new byte[] { 2 }, new string[0])
                    },
                    new string[0],
                    null
                )
            });

            var differences = newModuleManifest.CompareTo(oldModuleManifest);
            differences.Length.ShouldEqual(2);
            differences[0].Type.ShouldEqual(ModuleDifferenceType.Deleted);
            differences[0].Module.ShouldEqual(oldModule);
            differences[1].Type.ShouldEqual(ModuleDifferenceType.Added);
            differences[1].Module.ShouldEqual(changedModule);
        }
Esempio n. 34
0
        public void Identical_ModuleManifests_have_no_differences()
        {
            var oldModuleManifest = new ModuleManifest(new[]
            {
                new Module(
                    @"scripts/module-a",
                    new Resource[]
                    {
                        new Resource(@"scripts/module-a/test.js", new byte[0], new string[0])
                    },
                    new string[0],
                    null
                ),
                new Module(@"scripts/module-b", new Resource[0], new string[0], null)
            });

            var newModuleManifest = new ModuleManifest(new[]
            {
                new Module(
                    @"scripts/module-a",
                    new Resource[]
                    {
                        new Resource(@"scripts/module-a/test.js", new byte[0], new string[0])
                    },
                    new string[0],
                    null
                ),
                new Module(@"scripts/module-b", new Resource[0], new string[0], null)
            });

            var differences = newModuleManifest.CompareTo(oldModuleManifest);
            differences.Length.ShouldEqual(0);
        }
 public void Write(ModuleManifest manifest)
 {
     CreateManifestXml(manifest).Save(stream);
 }