Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/documentation/xml-autogenerated/microsoft-update-partition.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion src/microsoft-update-partition/Metadata/Parsers/UpdateParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,23 @@ public static string GetDescription(XPathNavigator metadataNavigator, XmlNamespa
}
}

public static string GetTitle(XPathNavigator metadataNavigator, XmlNamespaceManager namespaceManager)
public static string GetCreationDate(XPathNavigator metadataNavigator, XmlNamespaceManager namespaceManager)
{
XPathExpression updateTypeQuery = metadataNavigator.Compile("upd:Update/upd:Properties/@CreationDate");
updateTypeQuery.SetContext(namespaceManager);

var result = metadataNavigator.Evaluate(updateTypeQuery) as XPathNodeIterator;

if (result.Count == 0)
{
throw new Exception("Invalid XML");
}

result.MoveNext();
return result.Current.Value;
}

public static string GetTitle(XPathNavigator metadataNavigator, XmlNamespaceManager namespaceManager)
{
XPathExpression titleQuery = metadataNavigator.Compile("upd:Update/upd:LocalizedPropertiesCollection/upd:LocalizedProperties[upd:Language='en']/upd:Title");
titleQuery.SetContext(namespaceManager);
Expand Down
82 changes: 65 additions & 17 deletions src/microsoft-update-partition/Metadata/UpdateBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,26 +164,68 @@ public string Description
{
get
{
if (_MetadataLoaded)
if (_DescriptionLoaded)
{
return _Description;
}
else
{
LoadNonIndexedMetadataBase();
return _Description;
}
}
else if (_FastLookupSource != null)
{
_FastLookupSource.TrySimpleKeyLookup<string>(_Id, Storage.Index.AvailableIndexes.DescriptionsIndexName, out string description);
return description;
}
else if (_MetadataSource != null)
{
LoadNonIndexedMetadataBase();
_DescriptionLoaded = true;
return _Description;
}
else
{
return null;
}
}
}
private string _Description = null;

/// <summary>
/// Gets the list of files (content) for update
/// </summary>
/// <value>
/// List of content files
/// </value>
public IEnumerable<IContentFile> Files
private bool _DescriptionLoaded;
private string _Description = null;

/// <summary>
/// Get the category or update creation date
/// </summary>
public string CreationDate
{
get
{
if (_CreationDateLoaded)
{
return _CreationDate;
}
else if (_FastLookupSource != null)
{
_FastLookupSource.TrySimpleKeyLookup<string>(_Id, Storage.Index.AvailableIndexes.CreationDatesIndexName, out string creationdate);
return creationdate;
}
else if (_MetadataSource != null)
{
LoadNonIndexedMetadataBase();
_CreationDateLoaded = true;
return _CreationDate;
}
else
{
return null;
}
}
}
private bool _CreationDateLoaded;
private string _CreationDate = null;

/// <summary>
/// Gets the list of files (content) for update
/// </summary>
/// <value>
/// List of content files
/// </value>
public IEnumerable<IContentFile> Files
{
get
{
Expand Down Expand Up @@ -464,6 +506,11 @@ internal MicrosoftUpdatePackage(MicrosoftUpdatePackageIdentity id, XPathNavigato
_TitleLoaded = true;

_Description = UpdateParser.GetDescription(metadataNavigator, namespaceManager);
_DescriptionLoaded = true;

_CreationDate = UpdateParser.GetCreationDate(metadataNavigator, namespaceManager);
_CreationDateLoaded = true;

_MetadataLoaded = true;

_Prerequisites = PrerequisiteParser.FromXml(metadataNavigator, namespaceManager);
Expand Down Expand Up @@ -585,7 +632,8 @@ internal void LoadNonIndexedMetadataBase()
manager.AddNamespace("wsi", "http://schemas.microsoft.com/msus/2002/12/UpdateHandlers/WindowsSetup");

_Description = UpdateParser.GetDescription(navigator, manager);
_Title = UpdateParser.GetTitle(navigator, manager);
_CreationDate = UpdateParser.GetCreationDate(navigator, manager);
_Title = UpdateParser.GetTitle(navigator, manager);

LoadNonIndexedMetadata(navigator, manager);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public interface IPackage
/// </summary>
string Description { get; }

/// <summary>
/// Get the package creation date
/// </summary>
string CreationDate { get; }

/// <summary>
/// Gets the list of files (content) for a package
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.PackageGraph.MicrosoftUpdate;
using Microsoft.PackageGraph.ObjectModel;
using Microsoft.PackageGraph.Storage.Index;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.PackageGraph.Partitions
{
class PartitionRegistration
{
using Microsoft.PackageGraph.ObjectModel;
using Microsoft.PackageGraph.Storage.Index;
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.PackageGraph.Partitions
{
class PartitionRegistration
{
internal static Dictionary<string, PartitionDefinition> KnownPartitionsIndex =
new()
new()
{
{
"",
new PartitionDefinition()
{
Factory = null,
HasExternalContentFileMetadata = false,
Indexes = new List<IndexDefinition>() { TitlesIndex.TitlesIndexDefinition },
Indexes = new List<IndexDefinition>() { TitlesIndex.TitlesIndexDefinition, DescriptionsIndex.DescriptionsIndexDefinition, CreationDatesIndex.CreationDatesIndexDefinition },
HandlesIdentities = false,
}
},
Expand All @@ -45,59 +45,59 @@ class PartitionRegistration
}
}
}
};

public static void RegisterPartition(PartitionDefinition partitionDefinition)
{
lock(KnownPartitionsIndex)
{
KnownPartitionsIndex.Add(partitionDefinition.Name, partitionDefinition);
}
}

public static bool TryGetPartition(string partitionName, out PartitionDefinition partitionDefinition)
{
lock(KnownPartitionsIndex)
{
return KnownPartitionsIndex.TryGetValue(partitionName, out partitionDefinition);
}
}

public static bool TryGetPartitionFromPackage(IPackage package, out PartitionDefinition partitionDefinition)
{
lock (KnownPartitionsIndex)
{
return KnownPartitionsIndex.TryGetValue(package.Id.Partition, out partitionDefinition);
}
}

public static bool TryGetPartitionFromPackageId(IPackageIdentity packageId, out PartitionDefinition partitionDefinition)
{
lock (KnownPartitionsIndex)
{
return KnownPartitionsIndex.TryGetValue(packageId.Partition, out partitionDefinition);
}
}

public static List<PartitionDefinition> GetAllPartitions()
{
lock (KnownPartitionsIndex)
{
return KnownPartitionsIndex.Values.ToList();
}
}

public static IPackage TryCreatePackageFromUri(string sourceUri)
{
foreach(var partition in KnownPartitionsIndex.Values)
{
if (partition.Factory.CanCreatePackageFromSource(sourceUri))
{
return partition.Factory.FromSource(sourceUri);
}
}

return null;
}
}
}
};
public static void RegisterPartition(PartitionDefinition partitionDefinition)
{
lock(KnownPartitionsIndex)
{
KnownPartitionsIndex.Add(partitionDefinition.Name, partitionDefinition);
}
}
public static bool TryGetPartition(string partitionName, out PartitionDefinition partitionDefinition)
{
lock(KnownPartitionsIndex)
{
return KnownPartitionsIndex.TryGetValue(partitionName, out partitionDefinition);
}
}
public static bool TryGetPartitionFromPackage(IPackage package, out PartitionDefinition partitionDefinition)
{
lock (KnownPartitionsIndex)
{
return KnownPartitionsIndex.TryGetValue(package.Id.Partition, out partitionDefinition);
}
}
public static bool TryGetPartitionFromPackageId(IPackageIdentity packageId, out PartitionDefinition partitionDefinition)
{
lock (KnownPartitionsIndex)
{
return KnownPartitionsIndex.TryGetValue(packageId.Partition, out partitionDefinition);
}
}
public static List<PartitionDefinition> GetAllPartitions()
{
lock (KnownPartitionsIndex)
{
return KnownPartitionsIndex.Values.ToList();
}
}
public static IPackage TryCreatePackageFromUri(string sourceUri)
{
foreach(var partition in KnownPartitionsIndex.Values)
{
if (partition.Factory.CanCreatePackageFromSource(sourceUri))
{
return partition.Factory.FromSource(sourceUri);
}
}
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.PackageGraph.ObjectModel;

namespace Microsoft.PackageGraph.Storage.Index
{
class CreationDatesIndex : SimpleIndex<int, string>, ISimpleMetadataIndex<int, string>
{
internal static readonly IndexDefinition CreationDatesIndexDefinition =
new()
{
Name = AvailableIndexes.CreationDatesIndexName,
PartitionName = null,
Version = CreationDatesIndex.CurrentVersion,
Factory = new InternalIndexFactory(),
Tag = "stream"
};

public override IndexDefinition Definition => CreationDatesIndexDefinition;

public CreationDatesIndex(IIndexContainer container) : base(container, AvailableIndexes.CreationDatesIndexName)
{
}

public override void IndexPackage(IPackage package, int packageIndex)
{
Add(packageIndex, package.CreationDate);
}

public new bool TryGet(int packageIndex, out string creationDate)
{
return base.TryGet(packageIndex, out creationDate);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.PackageGraph.ObjectModel;

namespace Microsoft.PackageGraph.Storage.Index
{
class DescriptionsIndex : SimpleIndex<int, string>, ISimpleMetadataIndex<int, string>
{
internal static readonly IndexDefinition DescriptionsIndexDefinition =
new()
{
Name = AvailableIndexes.DescriptionsIndexName,
PartitionName = null,
Version = DescriptionsIndex.CurrentVersion,
Factory = new InternalIndexFactory(),
Tag = "stream"
};

public override IndexDefinition Definition => DescriptionsIndexDefinition;

public DescriptionsIndex(IIndexContainer container) : base(container, AvailableIndexes.TitlesIndexName)
{
}

public override void IndexPackage(IPackage package, int packageIndex)
{
Add(packageIndex, package.Description);
}

public new bool TryGet(int packageIndex, out string description)
{
return base.TryGet(packageIndex, out description);
}
}
}
Loading