Skip to content

Commit

Permalink
Sort version strings correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
lunOptics committed Apr 18, 2021
1 parent 15064d7 commit 1964c62
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
40 changes: 37 additions & 3 deletions VisualTeensy/ViewModel/LibrariesTab/LibraryVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using vtCore;
using System.Linq;
using vtCore.Interfaces;
using System;

namespace ViewModel
{
Expand All @@ -13,15 +14,48 @@ public class LibraryVM : BaseViewModel
//public string parentRepository { get; }

public ILibrary selectedVersion { get; set; }


public LibraryVM(IEnumerable<ILibrary> lib/*, string repositoryName*/)
{
//parentRepository = string.IsNullOrWhiteSpace(repositoryName) ? "?" : repositoryName;
this.versions = lib.OrderBy(v => v.version).ToList();
selectedVersion = this.versions.LastOrDefault();
this.versions = lib.OrderByDescending(v => v.v).ToList();


selectedVersion = this.versions.FirstOrDefault();
}

public override string ToString() => name;



}
}

//public class SortPara : IComparable<SortPara>
//{
// public List<int> numbers { get; set; }
// public string strNumbers { get; set; }
// public SortPara(string strNumbers)
// {
// this.strNumbers = strNumbers;
// numbers = strNumbers.Split(new char[] { '.' }).Select(x => int.Parse(x)).ToList();

// }
// public int CompareTo(SortPara other)
// {
// int shortest = this.numbers.Count < other.numbers.Count ? this.numbers.Count : other.numbers.Count;
// int results = 0;
// for (int i = 0; i < shortest; i++)
// {
// if (this.numbers[i] != other.numbers[i])
// {
// results = this.numbers[i].CompareTo(other.numbers[i]);
// break;
// }
// }
// return results;
// }
//}


18 changes: 15 additions & 3 deletions vtCore/Implementation/Libraries/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@
namespace vtCore
{
public class Library : ILibrary
{
{
public string name { get; set; } // name, can contain spaces
public string version { get; set; } // more than one version of the lib can be found in repos
public Version v // experimental, replace version string by version if this works out
{
get
{
if(Version.TryParse(version, out Version ver))
{
return ver;
}
return new Version();
}
}

public string author { get; set; } // no format requirements
public string maintainer { get; set; } // no format requirements
public string sentence { get; set; } // short description
Expand All @@ -30,8 +42,8 @@ public class Library : ILibrary

protected Library(ILibrary copyMe)
{
Type t = copyMe.GetType();
foreach (PropertyInfo propInf in t.GetProperties().Where(p=>p.SetMethod != null))
Type t = copyMe.GetType();
foreach (PropertyInfo propInf in t.GetProperties().Where(p => p.SetMethod != null))
{
propInf.SetValue(this, propInf.GetValue(copyMe));
}
Expand Down
2 changes: 1 addition & 1 deletion vtCore/Implementation/Libraries/LibraryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static ILookup<string, ILibrary> parseIndexJsonRepository(string library_
var ret = jsonLibs.Select(t => new Library()
{
name = t.name,
version = t.version,
version = t.version,
author = t.author,
maintainer = t.maintainer,
sentence = t.sentence,
Expand Down
1 change: 1 addition & 0 deletions vtCore/Interfaces/ILibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface ILibrary
Uri sourceUri { get; }
List<string> types { get; }
string version { get; }
Version v { get; }
string website { get; }
string ToString();
}
Expand Down

0 comments on commit 1964c62

Please sign in to comment.