private void ExecuteFunctionThread() { while (true) { try { WaitHandle[] handles = new WaitHandle[] { _executeFunctionThreadExit, _executeFunctionThreadQueueEvent }; int signal = WaitHandle.WaitAny(handles, 30000); if (signal == 0) { Console.WriteLine("Here"); return; } else if (signal == 1) { Function f = null; lock (_executeFunctionThreadQueueLock) { f = _executeFunctionThreadQueue.Dequeue(); } ErrorLog.WriteLine("Invoking function " + f.Name + "..."); try { f.Invoke(_connectionHandle); ErrorLog.WriteLine("Request Bytes: " + f.RequestByteString); ErrorLog.WriteLine("Response Bytes: " + f.ResponseByteString); ErrorLog.WriteLine("Return Value: " + f.ReturnValueString); } catch (Exception ex) { f.ReturnValueString = "Exception Occurred - " + ex.Message; ErrorLog.WriteLine("Return Value: " + f.ReturnValueString); } finally { FunctionInvokeComplete(f); } } else if (signal == WaitHandle.WaitTimeout) { // Send GetVersion function every 30 seconds to keep connection open GetVersionFunction gvf = new GetVersionFunction(); gvf.Invoke(_connectionHandle); } else { // TODO: ERROR } } catch (Exception ex) { ErrorLog.LogException(ex); } } }
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(); } }