private async Task <UnityLicenseStatusCheck> RunUnityToFinaliseLicense() { var executor = new UnityExecutor(); for (var i = 0; i < 30; i++) { var response = await executor.ExecuteAsync(new UnityExecutorRequest { UnityExecutablePath = _request.UnityExecutablePath, ArgumentList = { "-quit", "-batchmode", "-nographics", "-username", _request.Username, "-password", _request.Password, "-force-free" } }); if (response.Result == UnityExecutorResponseResult.Success) { return(new UnityLicenseStatusCheck { IsActivated = true, }); } else if (response.Result == UnityExecutorResponseResult.Error) { throw new InvalidOperationException(response.Output); } } throw new InvalidOperationException("Unity didn't provide us with machine keys after 30 licensing attempts..."); }
private async Task <UnityLicenseStatusCheck> RunUnityAndCaptureMachineKeys() { var executor = new UnityExecutor(); for (var i = 0; i < 30; i++) { var response = await executor.ExecuteAsync(new UnityExecutorRequest { UnityExecutablePath = _request.UnityExecutablePath, ArgumentList = { "-quit", "-batchmode", "-nographics", "-username", _request.Username, "-password", _request.Password, "-force-free" }, CustomBufferHandler = (buffer) => { if (_noPermissionsCheck.IsMatch(buffer)) { return(Task.FromResult((UnityExecutorResponseResult?)UnityExecutorResponseResult.Retry)); } if (_machineKeyCapture.IsMatch(buffer)) { return(Task.FromResult((UnityExecutorResponseResult?)UnityExecutorResponseResult.Retry)); } if (_nextLicenseCheck.IsMatch(buffer)) { return(Task.FromResult((UnityExecutorResponseResult?)UnityExecutorResponseResult.Success)); } return(Task.FromResult((UnityExecutorResponseResult?)null)); } }); if (response.Result == UnityExecutorResponseResult.Retry && _machineKeyCapture.IsMatch(response.Output)) { Console.WriteLine("Capturing machine keys response required for license requests..."); return(new UnityLicenseStatusCheck { IsActivated = false, PostedLicenseAttemptXml = _machineKeyCapture.Match(response.Output).Groups[1].Value, }); } else if (response.Result == UnityExecutorResponseResult.Retry && _noPermissionsCheck.IsMatch(response.Output)) { Console.WriteLine("Unity couldn't login to authentication servers to generate machine keys, retrying in 30 seconds..."); await Task.Delay(30000); } else if (response.Result == UnityExecutorResponseResult.Success) { return(new UnityLicenseStatusCheck { IsActivated = true, }); } else if (response.Result == UnityExecutorResponseResult.Error) { Console.WriteLine("Error encountered!"); throw new InvalidOperationException(response.Output); } } throw new InvalidOperationException("Unity didn't provide us with machine keys after 30 licensing attempts..."); }