Skip to content

Commit

Permalink
Merge pull request #33 from salihozkara/salihozkara/path
Browse files Browse the repository at this point in the history
Add AdvancedPath package
  • Loading branch information
salihozkara authored Jan 23, 2023
2 parents ec663c9 + 08e5a39 commit 1e8ef69
Show file tree
Hide file tree
Showing 20 changed files with 4,780 additions and 5,038 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using MetricHunter.Core.Paths;
using AdvancedPath;
using Octokit;

namespace MetricHunter.Application.Git;

public class CloneRepositorySuccessEventArgs
{
public CloneRepositorySuccessEventArgs(Repository repository, DirectoryPath localPath)
public CloneRepositorySuccessEventArgs(Repository repository, DirectoryPathString localPath)
{
Repository = repository;
LocalPath = localPath;
}

public Repository Repository { get; set; }

public DirectoryPath LocalPath { get; set; }
public DirectoryPathString LocalPath { get; set; }
}
11 changes: 6 additions & 5 deletions src/MetricHunter.Application.Shared/Resources/Resource.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System.Reflection;
using AdvancedPath;
using MetricHunter.Core;
using MetricHunter.Core.Paths;

namespace MetricHunter.Application.Resources;

// TODO: Refactor
public static class Resource
{
private static readonly DirectoryPath ResFolder = "Res";
private static readonly DirectoryPathString ResFolder = "Res";

private static readonly DirectoryPath DynamicResFolder = AppDomain.CurrentDomain.BaseDirectory + ResFolder;
private static readonly DirectoryPathString DynamicResFolder =
(AppDomain.CurrentDomain.BaseDirectory + ResFolder).ToDirectoryPathString();

private static string GetOrCreateResFolder()
{
Expand All @@ -34,8 +35,8 @@ private static string GetOrCreateResFolder()

public static class SourceMonitor
{
public static readonly FilePath TemplateXml = $"{DynamicResFolder}/SourceMonitor/template.xml";
public static readonly FilePathString TemplateXml = $"{DynamicResFolder}/SourceMonitor/template.xml";

public static FilePath SourceMonitorExe => $"{DynamicResFolder}/SourceMonitor/SourceMonitor.exe";
public static FilePathString SourceMonitorExe => $"{DynamicResFolder}/SourceMonitor/SourceMonitor.exe";
}
}
7 changes: 4 additions & 3 deletions src/MetricHunter.Application/Git/GitProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MetricHunter.Core.DependencyProcesses;
using AdvancedPath;
using MetricHunter.Core.DependencyProcesses;
using MetricHunter.Core.Jsons;
using MetricHunter.Core.Paths;
using MetricHunter.Core.Processes;
Expand Down Expand Up @@ -170,9 +171,9 @@ protected virtual void OnCloneRepositorySuccess(CloneRepositorySuccessEventArgs
CloneRepositorySuccess?.Invoke(this, e);
}

private async void AddRepositoryInfoFile(DirectoryPath repositoryPath, Repository repository)
private async void AddRepositoryInfoFile(DirectoryPathString repositoryPath, Repository repository)
{
FilePath repositoryInfoFilePath = (repositoryPath + GitConsts.RepositoryInfoFileExtension)!;
var repositoryInfoFilePath = (repositoryPath + GitConsts.RepositoryInfoFileExtension).ToFilePathString();
await JsonHelper.AppendJsonAsync(repository, repositoryInfoFilePath, r => r.Id);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Reflection;
using System.Text.RegularExpressions;
using System.Xml;
using AdvancedPath;
using MetricHunter.Application.Git;
using MetricHunter.Application.Metrics.SourceMonitor.SourceMonitorMetrics;
using MetricHunter.Application.Resources;
Expand Down Expand Up @@ -78,12 +79,13 @@ public Task<IResult[]> CalculateMetricsByLocalResultsAsync(List<Repository> repo
cancellationToken.ThrowIfCancellationRequested();
if (string.IsNullOrEmpty(baseDirectoryPath))
baseDirectoryPath = PathHelper.TempPath;
DirectoryPath path = baseDirectoryPath;
var files = path.DirectoryInfo.GetFiles($"*.{FileExtension}", SearchOption.AllDirectories);
DirectoryPathString path = baseDirectoryPath;

var files = new DirectoryInfo(path).GetFiles($"*.{FileExtension}", SearchOption.AllDirectories);
var tasks = repositories.Select(repository => Task.Run<IResult>(() =>
{
var fileName = $"id_{repository.Id}_{repository.Name}.xml";
FilePath filePath = files.FirstOrDefault(file => file.Name == fileName)!;
FilePathString filePath = files.FirstOrDefault(file => file.Name == fileName)!;
if (filePath.Exists)
{
_logger.LogError($"SourceMonitor reports file not found for {repository.FullName}");
Expand Down Expand Up @@ -140,12 +142,12 @@ private static string GetMetricListValue(IEnumerable<IMetric> metrics, string[]
return metric?.Value ?? "0";
}

private static void FileNameChange(Repository repository, FilePath reportsPath)
private static void FileNameChange(Repository repository, FilePathString reportsPath)
{
// file name change
var fileInfo = new FileInfo(reportsPath);
var newFileName = $"id_{repository.Id}_{fileInfo.Name}";
var newFilePath = reportsPath.ParentDirectory / newFileName;
var newFilePath = reportsPath.ParentDirectory + newFileName;
if (File.Exists(newFilePath))
File.Delete(newFilePath);
fileInfo.MoveTo(newFilePath);
Expand Down Expand Up @@ -175,7 +177,8 @@ private async Task ProcessRepositoryAsync(Repository repository, CancellationTok
await CalculateStatisticsUsingSourceMonitorAsync(repository, reportPath.ParentDirectory, cancellationToken);
}

private async Task CalculateStatisticsUsingSourceMonitorAsync(Repository repository, DirectoryPath workingDirectory,
private async Task CalculateStatisticsUsingSourceMonitorAsync(Repository repository,
DirectoryPathString workingDirectory,
CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
Expand Down
14 changes: 7 additions & 7 deletions src/MetricHunter.Core.Shared/Jsons/JsonHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections;
using System.Globalization;
using AdvancedPath;
using JsonNet.ContractResolvers;
using MetricHunter.Core.Paths;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -35,15 +35,15 @@ public static class JsonHelper
ContractResolver = new PrivateSetterContractResolver()
};

public static Task WriteJsonAsync<T>(T obj, FilePath path, CancellationToken cancellationToken = default)
public static Task WriteJsonAsync<T>(T obj, FilePathString path, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
var json = JsonConvert.SerializeObject(obj);
path.CreateDirectoryIfNotExists();
path.ParentDirectory.CreateIfNotExists();
return File.WriteAllTextAsync(path, json, cancellationToken);
}

public static async Task<T?> ReadJsonAsync<T>(FilePath path, CancellationToken cancellationToken = default)
public static async Task<T?> ReadJsonAsync<T>(FilePathString path, CancellationToken cancellationToken = default)
where T : class
{
cancellationToken.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -84,7 +84,7 @@ public static Task WriteJsonAsync<T>(T obj, FilePath path, CancellationToken can
}
}

public static async Task AppendJsonAsync<T, TKey>(T obj, FilePath path, Func<T, TKey>? distinctBy,
public static async Task AppendJsonAsync<T, TKey>(T obj, FilePathString path, Func<T, TKey>? distinctBy,
CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -106,13 +106,13 @@ public static async Task AppendJsonAsync<T, TKey>(T obj, FilePath path, Func<T,
await WriteJsonAsync(obj, path, cancellationToken);
}

public static Task AppendJsonAsync<T>(T obj, FilePath path, CancellationToken cancellationToken = default)
public static Task AppendJsonAsync<T>(T obj, FilePathString path, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
return AppendJsonAsync<T, object>(obj, path, null, cancellationToken);
}

public static async Task AppendRangeJsonAsync<T>(IEnumerable<T> obj, FilePath path,
public static async Task AppendRangeJsonAsync<T>(IEnumerable<T> obj, FilePathString path,
CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AdvancedPath" Version="1.0.0"/>
<PackageReference Include="JsonNet.ContractResolvers" Version="2.0.0"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2"/>
<PackageReference Include="Serilog" Version="2.12.0"/>
Expand Down
107 changes: 0 additions & 107 deletions src/MetricHunter.Core.Shared/Paths/BasePath.cs

This file was deleted.

50 changes: 0 additions & 50 deletions src/MetricHunter.Core.Shared/Paths/DirectoryPath.cs

This file was deleted.

Loading

0 comments on commit 1e8ef69

Please sign in to comment.