/// <summary> /// Deserializes the dependency. /// </summary> /// <param name="xmlReader">The XML text reader.</param> /// <param name="xmlStack">The XML stack.</param> private void DeserializeDependency(XmlReader xmlReader, Stack <string> xmlStack) { xmlStack.Push(XmlConstants.MetadataConstants.Dependency); if (_metadata.Dependencies == null) { _metadata.Dependencies = new List <SolutionDependency>( ); } SolutionDependency dependency = new SolutionDependency( ); AdvanceReader(xmlReader, xmlStack, null, XmlConstants.MetadataConstants.Dependency, (reader, stack) => DeserializeDependencyFields(dependency, reader)); _metadata.Dependencies.Add(dependency); }
/// <summary> /// Deserializes the dependency fields. /// </summary> /// <param name="dependency">The dependency.</param> /// <param name="xmlReader">The XML text reader.</param> private void DeserializeDependencyFields(SolutionDependency dependency, XmlReader xmlReader) { switch (xmlReader.Name) { case XmlConstants.MetadataConstants.Name: string name = xmlReader.ReadElementContentAsString( ); dependency.Name = name; break; case XmlConstants.MetadataConstants.DependencyName: string dependencyName = xmlReader.ReadElementContentAsString( ); dependency.DependencyName = dependencyName; break; case XmlConstants.MetadataConstants.ApplicationId: string applicationId = xmlReader.ReadElementContentAsString( ); Guid appId; if (string.IsNullOrEmpty(applicationId) || !Guid.TryParse(applicationId, out appId)) { Context.WriteError("Invalid dependency id."); return; } dependency.DependencyApplication = appId; break; case XmlConstants.MetadataConstants.MinimumVersion: string minimumVersion = xmlReader.ReadElementContentAsString( ); Version minVersion; if (string.IsNullOrEmpty(minimumVersion) || minimumVersion.Equals("any", StringComparison.InvariantCultureIgnoreCase) || !System.Version.TryParse(minimumVersion, out minVersion)) { minVersion = null; } dependency.MinimumVersion = minVersion; break; case XmlConstants.MetadataConstants.MaximumVersion: string maximumVersion = xmlReader.ReadElementContentAsString( ); Version maxVersion; if (string.IsNullOrEmpty(maximumVersion) || maximumVersion.Equals("any", StringComparison.InvariantCultureIgnoreCase) || !System.Version.TryParse(maximumVersion, out maxVersion)) { maxVersion = null; } dependency.MaximumVersion = maxVersion; break; case XmlConstants.MetadataConstants.IsRequired: string isRequired = xmlReader.ReadElementContentAsString( ); bool required = true; if (!string.IsNullOrEmpty(isRequired)) { bool.TryParse(isRequired, out required); } dependency.IsRequired = required; break; } }
/// <summary> /// Loads the application metadata. /// </summary> /// <param name="context"></param> /// <returns></returns> public Metadata GetMetadata(IProcessingContext context) { Entity solutionEntity = GetActiveSolutionEntity( ); string name = null; string description = null; string publisher = null; string publisherUrl = null; Guid appId = Guid.Empty; DateTime releaseDate = DateTime.UtcNow; string version = null; if (solutionEntity != null) { ///// // Get the member values. ///// name = GetMemberValue(solutionEntity, "core", "name"); description = GetMemberValue(solutionEntity, "core", "description"); publisher = GetMemberValue(solutionEntity, "core", "solutionPublisher"); publisherUrl = GetMemberValue(solutionEntity, "core", "solutionPublisherUrl"); version = GetMemberValue(solutionEntity, "core", "solutionVersionString"); string releaseDateString = GetMemberValue(solutionEntity, "core", "solutionReleaseDate"); if (!string.IsNullOrEmpty(releaseDateString)) { releaseDate = DateTime.Parse(releaseDateString); } appId = solutionEntity.Guid; } ///// // Calculate the fallback values. ///// if (string.IsNullOrEmpty(name)) { name = SolutionDocument.ReadString("/resource/name"); } if (appId == Guid.Empty) { appId = SolutionDocument.ReadGuid("/resource/solutionId"); } if (string.IsNullOrEmpty(version)) { version = SolutionDocument.ReadString("/resource/version", "1.0"); } Guid dependentApplicationGuid = new Guid("{8f2ed791-a613-4e9c-a6d4-694a8c56dba1}"); Guid dependencyApplicationGuid = new Guid("{d7fe48a6-3ad9-494d-8740-086f432aaaa4}"); Guid nameGuid = new Guid("{f8def406-90a1-4580-94f4-1b08beac87af}"); Guid minimumVersionGuid = new Guid("{f2c90c9e-92a0-4461-a49c-ee601776f468}"); Guid maximumVersionnameGuid = new Guid("{f00f048e-6aab-479e-9981-19a7506c20db}"); Guid isRequiredGuid = new Guid("{1f7dd780-a123-4ec6-9722-5189d107eb8f}"); List <SolutionDependency> dependencies = new List <SolutionDependency>( ); List <Relationship> dependentRelationships = Relationships.Where(r => r.SolutionEntity.Guid == appId && r.Type.Guid == dependentApplicationGuid && r.To.Guid == appId).ToList( ); foreach (Relationship relationship in dependentRelationships) { List <Relationship> dependencyRelationships = Relationships.Where(r => r.SolutionEntity.Guid == appId && r.Type.Guid == dependencyApplicationGuid && r.From.Guid == relationship.From.Guid).ToList( ); foreach (Relationship dependencyRelationship in dependencyRelationships) { Entity details = Entities.FirstOrDefault(e => e.Guid == dependencyRelationship.From.Guid); Member nameMember = details.Members.FirstOrDefault(m => m.MemberDefinition.Entity.Guid == nameGuid); Member minimumVersionMember = details.Members.FirstOrDefault(m => m.MemberDefinition.Entity.Guid == minimumVersionGuid); Member maximumVersionMember = details.Members.FirstOrDefault(m => m.MemberDefinition.Entity.Guid == maximumVersionnameGuid); Member isRequiredMember = details.Members.FirstOrDefault(m => m.MemberDefinition.Entity.Guid == isRequiredGuid); Entity dependencyApplication = Entities.FirstOrDefault(e => e.Guid == dependencyRelationship.To.Guid); Member dependencyNameMember = null; if (dependencyApplication != null) { dependencyNameMember = dependencyApplication.Members.FirstOrDefault(m => m.MemberDefinition.Entity.Guid == nameGuid); } Version minVersion; if (string.IsNullOrEmpty(minimumVersionMember?.Value) || minimumVersionMember.Value.Equals("any", StringComparison.InvariantCultureIgnoreCase) || !Version.TryParse(minimumVersionMember.Value, out minVersion)) { minVersion = null; } Version maxVersion; if (string.IsNullOrEmpty(maximumVersionMember?.Value) || maximumVersionMember.Value.Equals("any", StringComparison.InvariantCultureIgnoreCase) || !Version.TryParse(maximumVersionMember.Value, out maxVersion)) { maxVersion = null; } bool required; if (string.IsNullOrEmpty(isRequiredMember?.Value) || !bool.TryParse(isRequiredMember.Value, out required)) { required = true; } SolutionDependency dependency = new SolutionDependency(dependencyRelationship.To.Guid, nameMember?.Value, dependencyNameMember?.Value, minVersion, maxVersion, required); dependencies.Add(dependency); } } _packageId = GenerateAppVerId(name, version); ///// // Return the metadata. ///// return(new Metadata { AppId = appId, AppName = name, AppVerId = _packageId, Description = description, Dependencies = dependencies, Name = name, Publisher = publisher, PublisherUrl = publisherUrl, ReleaseDate = releaseDate, Version = version, Type = SourceType.AppPackage, PlatformVersion = null }); }