public void Constructor_String_InitializesDocumentName() { const string documentName = "TheDocument.pdf"; var solutionDocument = new SolutionDocument(documentName); solutionDocument.Name.Should().Be(documentName); }
/// <summary> /// Gets the entities that should not be removed as part of an upgrade operation. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public IEnumerable <Guid> GetDoNotRemove(IProcessingContext context) { string xpath = $"//doNotRemove[@solution='{ActiveSolution}']/leaveEntity/@id"; var nodes = SolutionDocument.SelectNodes(xpath); var guids = nodes.Cast <XmlAttribute>().Select(attr => new Guid((attr).Value)).ToList( ); return(guids); }
/// <summary> /// Generates the applications version id. This is composed of the hash from the xml file along with the applications /// name /// </summary> /// <returns></returns> private Guid GenerateAppVerId(string name, string version) { if (name == null) { name = string.Empty; } if (version == null) { version = string.Empty; } ///// // Get the hash from the xml file. ///// string xmlHash = SolutionDocument.ReadString("/resource/@hash", null); ///// // If there is no hash, simply return a brand new application version id. ///// if (xmlHash == null) { return(Guid.NewGuid( )); } ///// // Specify the string as a concatenation of the xml hash-code, the solution name and the solution version. ///// string hashSource = $"{xmlHash}_{name}_{version}"; MD5 md5 = MD5.Create( ); ///// // Use the hash string as the source for the GUID. ///// return(new Guid(md5.ComputeHash(Encoding.Default.GetBytes(hashSource)))); }
/// <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 }); }