Example #1
0
        protected override ProjectInfo GetInfo(string manifestFilePath)
        {
            try
            {
                this.logger.Debug($"Reading Project Info from manifest - {manifestFilePath}");
                XDocument document = XDocument.Load(manifestFilePath);

                this.ProjectInfoEnrichers.EnrichManifestXml(manifestFilePath, document, manifestFilePath);

                ProjectInfo info = ManifestDeserializer.DeserializeProjectInfo(document.Root);
                if (info != null)
                {
                    this.ProjectInfoEnrichers.EnrichProject(manifestFilePath, info, manifestFilePath, document);

                    this.logger.Debug($"Loaded project info. {manifestFilePath}.");
                    return(info);
                }
            }
            catch (Exception ex)
            {
                this.logger.Error($"Unexpected error while loading project info for [{manifestFilePath}] {ex.Message}. Details in DEBUG mode.");
                this.logger.Debug($"Error details: {ex}.");
            }
            return(null);
        }
        private ProjectInfo GetInfoWithManifest(string projectUri, ProjectItem manifestInclude, Project project)
        {
            this.logger.Debug($"Reading manifest - {manifestInclude.ResolvedIncludePath}");
            XDocument manifest = XDocument.Load(manifestInclude.ResolvedIncludePath);

            this.ProjectInfoEnrichers.EnrichManifestXml(projectUri, manifest, manifestInclude.ResolvedIncludePath);

            ProjectInfo projectInfoFromManifest = ManifestDeserializer.DeserializeProjectInfo(manifest.Root);

            this.SynchronizeProjectInfos(projectInfoFromManifest, projectUri, project);
            return(projectInfoFromManifest);
        }
        public void SampleManifest_MultipleComponents_WorksOK()
        {
            string text = File.ReadAllText(TestContext.CurrentContext.TestDirectory +
                                           "\\SampleManifestFiles\\SampleManifest.RepoCat.xml");

            var manifest = ManifestDeserializer.DeserializeProjectInfo(XElement.Parse(text));

            manifest.ProjectName.Should().Be("OptionallyProvidedProjectName");
            manifest.Tags.Should().BeEquivalentTo(new[] { "These", "Tags", "Are", "Optional" });
            manifest.Properties.Should()
            .ContainEquivalentOf(new Property("EntireProjectProperties", "AreAlsoOptional"));
        }
Example #4
0
        public void TestSchema_SampleFiles_AllAreValid()
        {
            Dictionary <string, List <string> > filesAndErrors = new Dictionary <string, List <string> >();
            IEnumerable <string> manifests = Directory
                                             .EnumerateFiles(Path.Combine(TestContext.CurrentContext.TestDirectory, "SampleManifestFiles"))
                                             .Concat(Directory.EnumerateFiles(
                                                         Path.Combine(TestContext.CurrentContext.TestDirectory, "SampleScriptsRepository"),
                                                         "*.*", SearchOption.AllDirectories).Where(x =>
                                                                                                   x.EndsWith(Strings.ManifestSuffix, StringComparison.OrdinalIgnoreCase)));

            foreach (string manifestPath in manifests)
            {
                string          text      = File.ReadAllText(manifestPath);
                XDocument       xDoc      = XDocument.Parse(text);
                SchemaValidator validator = new SchemaValidator();
                List <string>   errors    = validator.ValidateManifest(xDoc);
                try
                {
                    var _ = ManifestDeserializer.DeserializeProjectInfo(xDoc.Root);
                }
                catch (Exception ex)
                {
                    errors.Add(ex.ToString());
                }

                filesAndErrors.Add(manifestPath, errors);
            }

            filesAndErrors.Count.Should().BeGreaterOrEqualTo(8);

            if (filesAndErrors.SelectMany(x => x.Value).Any())
            {
                StringBuilder sb = new StringBuilder();
                foreach (KeyValuePair <string, List <string> > fileAndError in filesAndErrors)
                {
                    if (fileAndError.Value.Any())
                    {
                        sb.AppendLine($"File {fileAndError.Key} errors: \r\n\r\n{string.Join("\r\n", fileAndError.Value)}");
                    }
                }
                Assert.Fail(sb.ToString());
            }
        }
        public void Serialization_BackAndForth()
        {
            ProjectInfo info = SampleManifestXmlProvider.GetSampleProjectInfo();

            info.Properties.Add("Collection", new List <string>()
            {
                "First", "Second"
            });
            info.Components[0].Properties.Add("ComponentCollection", new List <string>()
            {
                "Third", "Second"
            });

            XElement projectInfoSerialized = ManifestSerializer.SerializeProjectInfo(info);

            ProjectInfo projectInfoDeserialized = ManifestDeserializer.DeserializeProjectInfo(projectInfoSerialized);


            projectInfoDeserialized.Should().BeEquivalentTo(info);
        }
        public void SampleManifest_CheckComponents()
        {
            string text = File.ReadAllText(TestContext.CurrentContext.TestDirectory + "\\SampleManifestFiles\\SampleManifest.RepoCat.xml");

            var manifest   = ManifestDeserializer.DeserializeProjectInfo(XElement.Parse(text));
            var components = manifest.Components;

            components.Count.Should().Be(2);
            var first  = components[0];
            var second = components[1];

            first.Name.Should().Be("PneumaticPick");
            first.Description.Should().Be("You don't even know you need it");
            first.Properties["Author"].Should().Be("JimBeam");
            first.Properties["Weight"].Should().Be("25kg");
            first.DocumentationUri.Should().Be("http://google.com");
            first.Tags.Should().BeEquivalentTo(new [] { "Hygiene", "Teeth", "Mining" });

            second.Name.Should().Be("SteamPick");
            second.Properties["Author"].Should().Be("Jack Black");

            second.Tags.Should().BeEquivalentTo(new[] { "Coal", "Steam", "Injury" });
        }
Example #7
0
#pragma warning disable 1998
        public async Task <IActionResult> AddProject([FromBody] AddProjectModel project)
#pragma warning restore 1998
        {
            if (!this.ModelState.IsValid || project == null)
            {
                this.TempData["error"] = "Incorrect input.";
                return(this.Json(this.Url.Action("AddProject")));
            }

            try
            {
                var validator = new SchemaValidator();

                var errors = validator.ValidateManifest(project.EmptyManifestXml, out XDocument _);

                if (errors.Count > 0)
                {
                    this.TempData["error"] = "Schema validation errors:\r\n" + string.Join("\r\n", errors);
                    return(this.Json(this.Url.Action("AddProject")));
                }
                else
                {
                    ProjectInfo projectInfo = ManifestDeserializer.DeserializeProjectInfo(XElement.Parse(project.EmptyManifestXml));

                    var upsertedProject = await this.repositoryService.Upsert(projectInfo).ConfigureAwait(false);

                    this.TempData["success"] = $"Added project to catalog. Internal ID: {upsertedProject.Id}";

                    return(this.Json(this.Url.Action("AddProject")));
                }
            }
            catch (Exception ex)
            {
                this.TempData["error"] = $"Error: {ex.Message}";
                return(this.Json(this.Url.Action("AddProject")));
            }
        }