Skip to content

Highest version filtering for extensions.#1051

Merged
singhsarab merged 12 commits intomicrosoft:masterfrom
singhsarab:HighestFileVersion
Sep 11, 2017
Merged

Highest version filtering for extensions.#1051
singhsarab merged 12 commits intomicrosoft:masterfrom
singhsarab:HighestFileVersion

Conversation

@singhsarab
Copy link
Contributor

Changes for filtering in case multiple extensions with same name are found. Keep only the highest versioned extensions.

Pending: Unit tests.

…found. Keep only the highest versioned extensions.
{
Dictionary<string, Tuple<Version, string>> extensionMap = new Dictionary<string, Tuple<Version, string>>();

foreach (var extensionFullPath in extensions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foreach (var extensionFullPath in extensions) [](start = 12, length = 45)

Please try group by, and then get the highest file version within the group if the group size > 1


/// <inheritdoc/>
public Version GetFileVersion(string path)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: null check not required

/// <inheritdoc/>
public Version GetFileVersion(string path)
{
var currentFileVersion = FileVersionInfo.GetVersionInfo(path)?.FileVersion;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not work in UAP. We should move to PlatformAbstraction otherwise.

/// <param name="extensions">Entire list of extensions</param>
/// <returns>Filtered list of extensions</returns>
private IEnumerable<string> FilterExtensionsBasedOnVersion(IEnumerable<string> extensions)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add logging

var filteredExtensions = new List<string>();

var extensionGroups = extensions.GroupBy(ext => Path.GetFileNameWithoutExtension(ext));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optimize

[TestMethod]
public void GetTestPlatformExtensionsShouldReturnPathToSingleFileExtensionOfATypeIfVersionsAreSame()
{
List<string> sourcesDir = new List<string> { "C:\\Source1", "C:\\Source2" };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY

foreach (var extensionGroup in extensionGroups)
{
if (extensionGroup.Count() > 1)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log message here.


private Version GetAndLogFileVersion(string path)
{
var fileVersion = this.fileHelper.GetFileVersion(path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if logging enabled.

@singhsarab singhsarab merged commit 9d3fbce into microsoft:master Sep 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants