Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1443ddda68 | |||
| 1e0990fe6a | |||
| f765becf06 | |||
| 9acc18e1fa | |||
| 7125bbc537 | |||
| 1f893c30bb | |||
| 2ba101f261 |
@@ -3,6 +3,7 @@
|
|||||||
// /media/omegaleo/Development/Library Dev/HelperLib
|
// /media/omegaleo/Development/Library Dev/HelperLib
|
||||||
|
|
||||||
using GameDevLibrary.Extensions;
|
using GameDevLibrary.Extensions;
|
||||||
|
using GameDevLibrary.Helpers;
|
||||||
using LibGit2Sharp;
|
using LibGit2Sharp;
|
||||||
using OmegaLeo.HelperLib.Git;
|
using OmegaLeo.HelperLib.Git;
|
||||||
using OmegaLeo.HelperLib.Git.Models;
|
using OmegaLeo.HelperLib.Git.Models;
|
||||||
@@ -17,51 +18,57 @@ if (repo.IsNullOrEmpty())
|
|||||||
|
|
||||||
var git = new GitClient(repo);
|
var git = new GitClient(repo);
|
||||||
|
|
||||||
var changes = git.GetChanges();
|
var result = BenchmarkUtility.Record(() =>
|
||||||
|
|
||||||
if (changes.FolderName.IsNotNullOrEmpty())
|
|
||||||
{
|
{
|
||||||
RecursiveOutput(new List<ChangeFolder>() { changes });
|
var changes = git.GetChanges();
|
||||||
|
|
||||||
var option = 99;
|
if (changes.FolderName.IsNotNullOrEmpty())
|
||||||
|
|
||||||
while (option != 0)
|
|
||||||
{
|
{
|
||||||
ShowOptions();
|
RecursiveOutput(new List<ChangeFolder>() { changes });
|
||||||
if (option != 99)
|
|
||||||
|
var option = 99;
|
||||||
|
|
||||||
|
while (option != 0)
|
||||||
{
|
{
|
||||||
switch (option)
|
ShowOptions();
|
||||||
|
if (option != 99)
|
||||||
{
|
{
|
||||||
case 1:
|
switch (option)
|
||||||
Console.WriteLine("Write the commit message");
|
{
|
||||||
var msg = Console.ReadLine();
|
case 1:
|
||||||
|
Console.WriteLine("Write the commit message");
|
||||||
|
var msg = Console.ReadLine();
|
||||||
|
|
||||||
while (msg.IsNullOrEmpty())
|
while (msg.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
Console.WriteLine("Empty message detected, please write a commit message...");
|
Console.WriteLine("Empty message detected, please write a commit message...");
|
||||||
msg = Console.ReadLine();
|
msg = Console.ReadLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
var signature = new Signature("Nuno 'Omega Leo' Diogo", "nunodiogo@omegaleo.pt", DateTimeOffset.Now);
|
var signature = new Signature("Nuno 'Omega Leo' Diogo", "nunodiogo@omegaleo.pt",
|
||||||
git.Commit(msg, signature);
|
DateTimeOffset.Now);
|
||||||
|
git.Commit(msg, signature);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
git.Push();
|
git.Push();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine("Invalid Option!");
|
Console.WriteLine("Invalid Option!");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int.TryParse(Console.ReadLine(), out option);
|
int.TryParse(Console.ReadLine(), out option);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
Console.WriteLine("No changes found in specified repository");
|
||||||
Console.WriteLine("No changes found in specified repository");
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
Console.WriteLine($"Time for checking for changes: {result} ms");
|
||||||
|
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace GameDevLibrary.Extensions
|
namespace GameDevLibrary.Extensions
|
||||||
{
|
{
|
||||||
@@ -117,5 +118,30 @@ namespace GameDevLibrary.Extensions
|
|||||||
{
|
{
|
||||||
return array[currentIndex++ % array.Count];
|
return array[currentIndex++ % array.Count];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shuffle around items in a list.
|
||||||
|
/// Code obtained from https://stackoverflow.com/a/1262619
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="list"></param>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
public static IList<T> Shuffle<T>(this IList<T> list)
|
||||||
|
{
|
||||||
|
RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
|
||||||
|
int n = list.Count;
|
||||||
|
while (n > 1)
|
||||||
|
{
|
||||||
|
byte[] box = new byte[1];
|
||||||
|
do provider.GetBytes(box);
|
||||||
|
while (!(box[0] < n * (Byte.MaxValue / n)));
|
||||||
|
int k = (box[0] % n);
|
||||||
|
n--;
|
||||||
|
(list[k], list[n]) = (list[n], list[k]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace GameDevLibrary.Helpers
|
||||||
|
{
|
||||||
|
public class BenchmarkUtility
|
||||||
|
{
|
||||||
|
private static Dictionary<string, List<long>> _benchmarks = new Dictionary<string, List<long>>();
|
||||||
|
private static Dictionary<string, Stopwatch> _stopwatches = new Dictionary<string, Stopwatch>();
|
||||||
|
|
||||||
|
private static Stopwatch GetStopwatch(string key)
|
||||||
|
{
|
||||||
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
|
|
||||||
|
if (_stopwatches.TryGetValue(key, out stopwatch))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stopwatch = new Stopwatch();
|
||||||
|
_stopwatches.Add(key, stopwatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
return stopwatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long Record(Action actionToRecord)
|
||||||
|
{
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
stopwatch.Start();
|
||||||
|
|
||||||
|
actionToRecord.Invoke();
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
return stopwatch.ElapsedMilliseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long RecordAndSaveToResults(string key, Action actionToRecord)
|
||||||
|
{
|
||||||
|
var stopwatch = new Stopwatch();
|
||||||
|
stopwatch.Start();
|
||||||
|
|
||||||
|
actionToRecord.Invoke();
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
|
||||||
|
if (!_benchmarks.ContainsKey(key))
|
||||||
|
{
|
||||||
|
_benchmarks[key] = new List<long>();
|
||||||
|
}
|
||||||
|
|
||||||
|
_benchmarks[key].Add(stopwatch.ElapsedMilliseconds);
|
||||||
|
|
||||||
|
return stopwatch.ElapsedMilliseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Start(string key)
|
||||||
|
{
|
||||||
|
GetStopwatch(key).Restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Stop(string key)
|
||||||
|
{
|
||||||
|
if (!_benchmarks.ContainsKey(key))
|
||||||
|
{
|
||||||
|
_benchmarks[key] = new List<long>();
|
||||||
|
}
|
||||||
|
|
||||||
|
GetStopwatch(key).Stop();
|
||||||
|
_benchmarks[key].Add(GetStopwatch(key).ElapsedMilliseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<long> GetResults(string key)
|
||||||
|
{
|
||||||
|
return _benchmarks.ContainsKey(key) ? _benchmarks[key] : new List<long>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ClearResults()
|
||||||
|
{
|
||||||
|
_benchmarks.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dictionary<string, List<long>> GetAllResults()
|
||||||
|
{
|
||||||
|
return new Dictionary<string, List<long>>(_benchmarks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace GameDevLibrary.Models
|
||||||
|
{
|
||||||
|
public abstract class InstancedObject<T> where T : class
|
||||||
|
{
|
||||||
|
public static T Instance { get; private set; }
|
||||||
|
|
||||||
|
protected InstancedObject()
|
||||||
|
{
|
||||||
|
if (Instance != null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"An instance of {typeof(T).Name} already exists.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Instance = this as T;
|
||||||
|
if (Instance == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"Failed to cast {GetType().Name} to {typeof(T).Name}.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~InstancedObject()
|
||||||
|
{
|
||||||
|
if (Instance == this)
|
||||||
|
{
|
||||||
|
Instance = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,9 +82,12 @@ namespace GameDevLibrary.Models
|
|||||||
public NeoDictionaryItem<TKey, TValue>? LastOrDefault(Func<NeoDictionaryItem<TKey, TValue>, bool> predicate) =>
|
public NeoDictionaryItem<TKey, TValue>? LastOrDefault(Func<NeoDictionaryItem<TKey, TValue>, bool> predicate) =>
|
||||||
Items.LastOrDefault(predicate);
|
Items.LastOrDefault(predicate);
|
||||||
|
|
||||||
public IEnumerable<NeoDictionaryItem<TKey, TValue>> Select<TResult>(Func<NeoDictionaryItem<TKey, TValue>, NeoDictionaryItem<TKey, TValue>> selector) =>
|
public IEnumerable<NeoDictionaryItem<TKey, TValue>> Select(Func<NeoDictionaryItem<TKey, TValue>, NeoDictionaryItem<TKey, TValue>> selector) =>
|
||||||
Items.Select(selector);
|
Items.Select(selector);
|
||||||
|
|
||||||
|
public int IndexOf(NeoDictionaryItem<TKey, TValue> selector) =>
|
||||||
|
Items.IndexOf(selector);
|
||||||
|
|
||||||
public void Remove(TKey key)
|
public void Remove(TKey key)
|
||||||
{
|
{
|
||||||
var index = Items.FindIndex(x => x.Key.Equals(key));
|
var index = Items.FindIndex(x => x.Key.Equals(key));
|
||||||
|
|||||||
Reference in New Issue
Block a user