public async Task GetChanges() { try { string name = ""; do { Console.Write("Please provide the name of the repo you want to pull:"); name = Console.ReadLine(); } while (string.IsNullOrEmpty(name)); RepositorySerialized repos = GetLocalRepository(name); if (repos == null) { throw new Exception("Reposiory doesn't exist locally"); } if (!Directory.Exists(repos.Path)) { throw new Exception("There is no path associated with this repo"); } if (!_contractService.ContractDeployed("RepositoryService")) { throw new Exception("Repository not deployed"); } string ad = _contractService.GetAddressDeployedContract("RepositoryService"); Web3 user = _userService.GetUser(); var handler = user.Eth.GetContractQueryHandler <CheckIfRepoExistsFunction>(); bool exists = await handler.QueryAsync <bool>(ad, new CheckIfRepoExistsFunction() { Name = name }); if (!exists) { throw new Exception("The specified repository doesn't exist"); } GetRepositoryFunction getRepoFunction = new GetRepositoryFunction() { Name = name }; var getRepoHandler = user.Eth.GetContractQueryHandler <GetRepositoryFunction>(); string contractAd = await getRepoHandler.QueryAsync <string>(ad, getRepoFunction); if (string.IsNullOrEmpty(contractAd)) { throw new Exception("Something went wrong with the execution of this function"); } GetCidOfRepo repoFunction = new GetCidOfRepo(); var getCidHandler = user.Eth.GetContractQueryHandler <GetCidOfRepo>(); string cid = await getCidHandler.QueryAsync <string>(contractAd, repoFunction); Directory.Delete(repos.Path, true); await _ipfsService.GetDirectoryFromIPFS(repos.Path, cid); ChangeCid(repos, cid); Console.WriteLine("Succesfully got new version of repository: " + repos.Name); } catch (Exception e) { _logger.LogError("Something went wrong {0}", e.Message); Console.WriteLine("Something went wrong with the execution of this function"); Console.Beep(); } }
public async Task GetRepositoriesByUser(string username) { try { _logger.LogInformation("Getting repositories for user {0}", username); Web3 client = _userService.GetUser(); ReturnUserFunction getRepoFunc = new ReturnUserFunction() { Username = username }; string addressuserservice = _contractService.GetAddressDeployedContract("UserService"); var contractHandler = client.Eth.GetContractHandler(addressuserservice); ReturnUserOutputDTO user = await contractHandler.QueryDeserializingToObjectAsync <ReturnUserFunction, ReturnUserOutputDTO>(getRepoFunc); if (user.ReturnValue1.Repositories.Count == 0) { Console.WriteLine("There are no repos for the user: "******"local" : "remote"; if (localExist) { bool update = cid.Equals(_ipfsService.GetCid(name)); FileStream stream = File.OpenRead(repoFile); using (StreamReader reader = new StreamReader(stream)) { string json = reader.ReadToEnd(); List <RepositorySerialized> repos = new List <RepositorySerialized>(); if (json.Replace("{", "").Replace("}", "").Trim().Length != 0) { repos = JsonConvert.DeserializeObject <List <RepositorySerialized> >(json); } var repo = repos.First(r => r.Name.Equals(name)); string localCid = await _ipfsService.GetCid(repo.Path); string notUpToDate = localCid.Equals(cid) ? "up-to-date" : "please pull new changes"; Console.WriteLine(string.Format("id:{0} - name:{1} - cid:{2} - status:{3} - clean? {4}" , id, name, cid, status, notUpToDate)); } } else { Console.WriteLine(string.Format("id:{0} - name:{1} - cid:{2} - status:{3}" , id, name, cid, status)); } } } } catch (RpcResponseException e) { Web3 client = _userService.GetUser(); _logger.LogError("Something went wrong with the GetRepositoriesByUserFunction {0}", e.Message); Console.WriteLine("Something went wrong with the execution of this function"); Console.Beep(); } }