Добрый день!
У меня есть коллекция, в которую вводиться содержимое файла json. В файле есть два свойства hash и url.
И есть два метода, один метод выводит hash с этой коллекции,
второй метод берёт url с этой коллекции и выводит hash с удалённого сервера.
Простым языком, выводиться hash с локального файла, и hash с сервера (с помощью url, который берётся с коллекции).
Мне нужно сравнить эти hash-ы (удалённые и локальные) на идентичность. Но я не могу понять как мне их сравнить.
Вот код:
class RepoInfo : Process
{
public Uri url { get; set; }
public string hash { get; set; }
public string GetRemoteHashMethod(string url)
{
string repourl = Convert.ToString(url);
var hash = Repository.ListRemoteReferences(repourl).FirstOrDefault() as SymbolicReference;
return hash.Target.TargetIdentifier;
}
public void PrintLocalHashMethod()
{
Process GetHashFromFile = new Process();
var repos = GetHashFromFile.GetAllFromFile();
Console.WriteLine("LocalHash:");
foreach (var item in repos)
{
Console.WriteLine(item.hash);
}
}
public void PrintRemoteHashMethod()
{
Process GetHashFromFile = new Process();
var repos = GetHashFromFile.GetAllFromFile();
Console.WriteLine("Remote Hash Commit: ");
foreach (var item in repos)
{
RepoInfo PrintRemoteHash = new RepoInfo();
var PrintRemoteHashCommit = PrintRemoteHash.GetRemoteHashMethod(item.url.ToString());
Console.WriteLine(PrintRemoteHashCommit);
}
Console.WriteLine();
}
}
class Process
{
public IEnumerable<RepoInfo> GetAllFromFile()
{
StreamReader jsonfile = new StreamReader("repo.json");
string json = jsonfile.ReadToEnd();
IEnumerable<RepoInfo> repos = JsonConvert.DeserializeObject<IEnumerable<RepoInfo>>(json);
return repos;
}
}
class Program
{
static void Main(string[] args)
{
RepoInfo PrintRH = new RepoInfo();
PrintRH.PrintRemoteHashMethod();
RepoInfo PrintLH = new RepoInfo();
PrintLH.PrintLocalHashMethod();
Console.ReadKey();
}
}
Сам файл json:
[
{
"hash": "2abead42b6a632e29433b043b11d8eec156394b9",
"url": "https://github.com/VladislavsGeidans/wikicar.git"
},
{
"hash": "bed322e3aa9cbcdeebac7a2d963c2e693a783c2a",
"url": "https://github.com/OpenExoplanetCatalogue/open_exoplanet_catalogue.git"
},
{
"hash": "0cf7da012e23b64c8aadba49b051542d3d5f47ab",
"url": "https://github.com/openaddresses/openaddresses.git"
},
{
"hash": "c798444a83795a5f245dc29ccd82872e61206ad5",
"url": "https://github.com/GSA/data.git"
},
{
"hash": "a45c4cd79a127296acc32aaa8152ebfb49b20640",
"url": "https://github.com/unitedstates/congress-legislators.git"
},
{
"hash": "e92bc448678ef499cfeabb3df93ea7adad47f747",
"url": "https://github.com/APIs-guru/openapi-directory.git"
}
]
RepoInfo printRH = new RepoInfo();
ru.wikipedia.org/wiki/CamelCase – koks_rs 20 фев '17 в 12:59