Skip to content

Commit

Permalink
Merge pull request #6 from samsmithnz/AddingAggregations
Browse files Browse the repository at this point in the history
Added new aggregations
  • Loading branch information
samsmithnz authored Jul 31, 2022
2 parents a5fbdc2 + c7cb807 commit 4a54d6b
Show file tree
Hide file tree
Showing 19 changed files with 441 additions and 231 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
build:
name: Build job
runs-on: windows-latest
runs-on: ubuntu-latest
outputs:
Version: ${{ steps.gitversion.outputs.SemVer }}
CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}
Expand All @@ -33,18 +33,18 @@ jobs:
with:
dotnet-version: 6.0.x
- name: .NET test
run: dotnet test src/DotnetCensus.Tests/DotnetCensus.Tests.csproj -c Release
run: dotnet test src/DotNetCensus.Tests/DotNetCensus.Tests.csproj -c Release
- name: .NET publish
run: dotnet publish src/DotnetCensus/DotnetCensus.csproj -c Release -p:Version='${{ steps.gitversion.outputs.SemVer }}'
run: dotnet publish src/DotNetCensus.Core/DotNetCensus.Core.csproj -c Release -p:Version='${{ steps.gitversion.outputs.SemVer }}'
- name: Upload package back to GitHub
uses: actions/upload-artifact@v3
with:
name: drop
path: src/DotnetCensus/bin/Release
path: src/DotNetCensus/bin/Release

release:
name: Release job
runs-on: windows-latest
runs-on: ubuntu-latest
needs:
- build
if: github.ref == 'refs/heads/main'
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# DotnetCensus
[![CI/CD](https://github.com/samsmithnz/DotnetCensus/actions/workflows/workflow.yml/badge.svg)](https://github.com/samsmithnz/DotnetCensus/actions/workflows/workflow.yml)
# DotNetCensus
[![CI/CD](https://github.com/samsmithnz/DotNetCensus/actions/workflows/workflow.yml/badge.svg)](https://github.com/samsmithnz/DotNetCensus/actions/workflows/workflow.yml)

**A tool to conduct a census, to count different .NET versions, on a folder and/or repo.**

Expand All @@ -11,3 +11,4 @@ Currently supports:
- Unity3d projects
- VB6 (!!!)

- Currently only works on folders. In the future will support GitHub repo scanning too.
93 changes: 93 additions & 0 deletions src/DotNetCensus.Core/Census.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using DotNetCensus.Core.Models;

namespace DotNetCensus.Core
{
public static class Census
{
public static List<FrameworkSummary> AggregateFrameworks(List<Project> projects, bool includeTotal)
{
int total = 0;
List<FrameworkSummary> frameworkSummary = new();
foreach (Project project in projects)
{
project.Family = DotNetProjectScanning.GetFrameworkFamily(project.Framework);
if (string.IsNullOrEmpty(project.Framework) == true)
{
project.Framework = "(Unknown framework)";
}

//Process each indvidual framework
FrameworkSummary? framework = frameworkSummary.Find(i => i.Framework == project.Framework);

//If this framework isn't in the current list, create a new one
if (framework == null)
{
frameworkSummary.Add(new FrameworkSummary
{
Framework = project.Framework,
FrameworkFamily = project.Family,
Count = 1 //it's the first time, start with a count of 1
});
}
else
{
//There is an existing entry, increment the count
framework.Count++;
}
total++;
}

//Sort the result
List<FrameworkSummary> sortedFrameworks = frameworkSummary.OrderBy(o => o.Framework).ToList();

//Add a total line if we need one
if (includeTotal == true)
{
sortedFrameworks.Add(new FrameworkSummary { Framework = "total frameworks", Count = total });
}
return sortedFrameworks;
}

public static List<LanguageSummary> AggregateLanguages(List<Project> projects, bool includeTotal)
{
int total = 0;
List<LanguageSummary> languageSummary = new();
foreach (Project project in projects)
{
if (string.IsNullOrEmpty(project.Language) == true)
{
project.Language = "(Unknown language)";
}

//Process each indvidual language
LanguageSummary? language = languageSummary.Find(i => i.Language == project.Language);

//If this language isn't in the current list, create a new one
if (language == null)
{
languageSummary.Add(new LanguageSummary
{
Language = project.Language,
Count = 1 //it's the first time, start with a count of 1
});
}
else
{
//There is an existing entry, increment the count
language.Count++;
}
total++;
}

//Sort the result
List<LanguageSummary> sortedLanguages = languageSummary.OrderBy(o => o.Language).ToList();

//Add a total line if we need one
if (includeTotal == true)
{
sortedLanguages.Add(new LanguageSummary { Language = "total languages", Count = total });
}
return sortedLanguages;
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using DotNetCensus.Core.Models;

namespace DotNetCensus
namespace DotNetCensus.Core
{
public static class DotNetProjectScanning
{
Expand Down Expand Up @@ -46,8 +46,8 @@ private static List<Project> ProcessDotNetProjectFile(string filePath, string la
//Setup the project object
Project project = new()
{
Path = filePath,
FileName = new FileInfo(filePath).Name,
Path = filePath,
Language = language
};

Expand Down Expand Up @@ -82,8 +82,8 @@ private static List<Project> ProcessDotNetProjectFile(string filePath, string la
{
Project additionalProject = new()
{
Path = filePath,
FileName = new FileInfo(filePath).Name,
Path = filePath,
Language = language,
Framework = frameworkList[i]
};
Expand Down Expand Up @@ -118,43 +118,43 @@ private static List<Project> ProcessDotNetProjectFile(string filePath, string la
return projects;
}

//private static string? GetFrameworkFamily(string framework)
//{
// if (framework == null)
// {
// return null;
// }
// else if (framework.StartsWith("netcoreapp"))
// {
// return ".NET Core";
// }
// else if (framework.StartsWith("netstandard"))
// {
// return ".NET Standard";
// }
// else if (framework.StartsWith("v1.") ||
// framework.StartsWith("v2.") ||
// framework.StartsWith("v3.") ||
// framework.StartsWith("v4.") ||
// framework.StartsWith("net4"))
// {
// return ".NET Framework";
// }
// else if (framework.StartsWith("net")) //net5.0, net6.0, etc
// {
// return ".NET";
// }
// else if (framework.StartsWith("vb6"))
// {
// return "Visual Basic 6";
// }
// else
// {
// return null;
// }
//}

private static string? GetHistoricalFrameworkVersion(string line)
public static string GetFrameworkFamily(string framework)
{
if (string.IsNullOrEmpty(framework) == true)
{
return "";
}
else if (framework.StartsWith("netcoreapp"))
{
return ".NET Core";
}
else if (framework.StartsWith("netstandard"))
{
return ".NET Standard";
}
else if (framework.StartsWith("v1.") ||
framework.StartsWith("v2.") ||
framework.StartsWith("v3.") ||
framework.StartsWith("v4.") ||
framework.StartsWith("net4"))
{
return ".NET Framework";
}
else if (framework.StartsWith("net")) //net5.0, net6.0, etc
{
return ".NET";
}
else if (framework.StartsWith("vb6"))
{
return "Visual Basic 6";
}
else
{
return "";
}
}

private static string GetHistoricalFrameworkVersion(string line)
{
string productVersion = line.Replace("<ProductVersion>", "").Replace("</ProductVersion>", "").Replace("ProductVersion = ", "").Replace("\"", "").Trim();
//https://en.wikipedia.org/wiki/Microsoft_Visual_Studio#History
Expand Down Expand Up @@ -187,18 +187,22 @@ private static List<Project> ProcessDotNetProjectFile(string filePath, string la
}
else
{
return null;
return "";
}
}

private static string? GetUnityFrameworkVersion(string line)
private static string GetUnityFrameworkVersion(string line)
{
//An example of what to expect:
//m_EditorVersion: 2020.3.12f1
//m_EditorVersionWithRevision: 2020.3.12f1(b3b2c6512326)
string fullVersion = line.Replace("m_EditorVersion:", "").Trim();
string[] splitVersion = fullVersion.Split('.');
string unityVersion = "Unity3d v" + splitVersion[0] + "." + splitVersion[1];
string unityVersion = "";
if (splitVersion.Length >= 2)
{
unityVersion = "Unity3d v" + splitVersion[0] + "." + splitVersion[1];
}

return unityVersion;
}
Expand Down
9 changes: 9 additions & 0 deletions src/DotNetCensus.Core/Models/FrameworkSummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DotNetCensus.Core.Models
{
public class FrameworkSummary
{
public string Framework { get; set; } = "";
public string FrameworkFamily { get; set; } = "";
public int Count { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/DotNetCensus.Core/Models/LanguageSummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace DotNetCensus.Core.Models
{
public class LanguageSummary
{
public string Language { get; set; } = "";
public int Count { get; set; }
}
}
22 changes: 22 additions & 0 deletions src/DotNetCensus.Core/Models/Project.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace DotNetCensus.Core.Models
{
public class Project
{
//public Project(string fileName, string path, string framework)
//{
// FileName = fileName;
// Path = path;
// Framework = framework;
//}

public string FileName { get; set; } = "";
public string Path { get; set; } = "";
public string Framework { get; set; } = "";
public string? Language { get; set; }
public string? Family { get; set; }
public string? Color { get; set; }

//public string? Content { get; set; }

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
global using DotNetCensus.Core.Models;
global using DotNetCensus.Core;
global using DotNetCensus.Core.Models;
global using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DotNetCensus.Tests
Expand Down
Loading

0 comments on commit 4a54d6b

Please sign in to comment.