Example #1
0
        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();
            }
        }
Example #2
0
        public async Task GetEarlierVersion()
        {
            try {
                string name = "";

                do
                {
                    Console.Write("Please provide the name of the repo you want to revert to an earlier version:");
                    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");
                }

                GetAllVersionCount countFunction = new GetAllVersionCount();
                var getAmountOfVersionHandler    = user.Eth.GetContractQueryHandler <GetAllVersionCount>();
                int allVersions = await getAmountOfVersionHandler.QueryAsync <int>(contractAd, countFunction) - 1;

                if (allVersions == 1)
                {
                    Console.WriteLine("there is no earlier version");
                    return;
                }

                Console.WriteLine("There are " + allVersions + " versions available");

                int versionToRevertTo = 0;
                do
                {
                    Console.Write("Please enter the number of the version you want to revert to: ");
                    versionToRevertTo = int.Parse(Console.ReadLine());
                } while (versionToRevertTo < 1 || versionToRevertTo > allVersions);


                GetVersionFunction getVersionFunction = new GetVersionFunction()
                {
                    Indx = versionToRevertTo
                };
                var    getVersionFunctionHandler = user.Eth.GetContractQueryHandler <GetVersionFunction>();
                string cid = await getVersionFunctionHandler.QueryAsync <string>(contractAd, getVersionFunction);

                Directory.Delete(repos.Path, true);
                await _ipfsService.GetDirectoryFromIPFS(repos.Path, cid);

                ChangeCid(repos, cid);
                Console.WriteLine("Succesfully got old 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();
            }
        }
Example #3
0
        public async Task CloneRepository()
        {
            try {
                string name = "";

                do
                {
                    Console.Write("Please provide a name for the repository you want to clone: ");
                    name = Console.ReadLine();
                } while (string.IsNullOrEmpty(name));

                CheckIfRepoExistsFunction checkIfRepoExistsFunction = new CheckIfRepoExistsFunction()
                {
                    Name = name
                };

                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, checkIfRepoExistsFunction);

                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");
                }

                var    cidHandler = user.Eth.GetContractQueryHandler <GetCidOfRepo>();
                string cid        = await cidHandler.QueryAsync <string>(contractAd, new GetCidOfRepo());

                if (string.IsNullOrEmpty(cid))
                {
                    throw new Exception("Something went wrong with the execution of this function");
                }

                string path = $"C:\\" + name;
                await _ipfsService.GetDirectoryFromIPFS(path, cid);

                Console.WriteLine(string.Format("repository {0} succefully cloned to {1}", name, path));

                RepositorySerialized repos = new RepositorySerialized()
                {
                    Name = name,
                    CID  = cid,
                    Path = path
                };

                WriteToRepositoryFile(repos);
            } catch (Exception e) {
                _logger.LogError("Something went wrong with the GetLocalRepository {0}", e.Message);
                Console.WriteLine(e.Message);
                Console.Beep();
            }
        }