protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // SupportActionBar.Hide(); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); txt = FindViewById <TextView>(Resource.Id.txt); string accessToken = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext) .GetString("ACCESS_TOKEN", String.Empty); string code = GetAccessToken(); string openId = await GetOpenId(accessToken, code); StringBuilder gatewayUserInfoSb = new StringBuilder(UrlConstants.GATEWAY_USERINFO_URL); gatewayUserInfoSb.Append("?AccessToken=") .Append(accessToken) .Append("&OpenId=") .Append(openId); string result = await HttpClientUtils.GetJson(gatewayUserInfoSb.ToString()); txt.Text = result; }
private async Task <string> GetOpenId(string accessToken, string code) { StringBuilder gatewayOpenIdSb = new StringBuilder(UrlConstants.GATEWAY_OPENID_URL); gatewayOpenIdSb.Append("?AccessToken=") .Append(accessToken) .Append("&Code=") .Append(code); string result = await HttpClientUtils.GetJson(gatewayOpenIdSb.ToString()); CodeToOpenIdViewModel openId = JsonConvert.DeserializeObject <CodeToOpenIdViewModel>(result); return(openId.OpenId); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.activity_welcome); FindViewById <TextView>(Resource.Id.btnLogin).Click += async(o, e) => { StringBuilder archonUrlSb = new StringBuilder(UrlConstants.ARCHON_AUTH_URL); archonUrlSb.Append("?appId=") .Append(LocalProperties.APP_ID) .Append("&appSecret=") .Append(LocalProperties.APP_SECRET); string result = await HttpClientUtils.GetJson(archonUrlSb.ToString()); AccessTokenViewModel requestToken = JsonConvert.DeserializeObject <AccessTokenViewModel>(result); var memes = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext).Edit(); memes.PutString("ACCESS_TOKEN", requestToken.AccessToken).Apply(); memes.Commit(); StringBuilder gatewayUrlSb = new StringBuilder(UrlConstants.GATEWAY_AUTH_URL); gatewayUrlSb.Append("?appId=") .Append(LocalProperties.APP_ID) .Append("&redirect_uri=") .Append(UrlConstants.APP_URL) .Append("&state=/"); StartActivity(new Intent(Intent.ActionView, Uri.Parse(gatewayUrlSb.ToString()))); }; FindViewById <TextView>(Resource.Id.btnRegister).Click += (o, e) => { StringBuilder gatewayUrlSb = new StringBuilder(UrlConstants.GATEWAY_REGISTER_URL); gatewayUrlSb.Append("?appId=") .Append(LocalProperties.APP_ID) .Append("&redirect_uri=") .Append(UrlConstants.APP_URL) .Append("&state=/"); StartActivity(new Intent(Intent.ActionView, Uri.Parse(gatewayUrlSb.ToString()))); }; }
/// <summary> /// 等待JenkinsBuildTask并返回任务结果 /// </summary> /// <param name="appName">应用名称</param> /// <param name="environment">所属环境</param> /// <param name="logDirName">日志输出文件夹名</param> /// <returns>Tuple bool--是否编译成功, string--成功则为任务id 则是异常信息或空, string--编译的SVN的版本 </returns> private static Tuple <bool, string, string> WaitJkbtAndGetResult(string appName, string environment, string logDirName) { var jkbtId = ""; try { //第一步:检查Jenkins的任务队列是否有等待执行的任务,没人排队任务则继续第二步 var jenkinsQueueUrl = GetJenkinsConfig("JenkinsQueueApiUrl", ""); LogInfoWriter.GetInstance(logDirName).Info($"start check jenkins build task queue is empty, JenkinsQueueApiUrl:{jenkinsQueueUrl}"); var isJkQueueEmpty = ExecExtensions.RetryUntilTrueWithTimeout(() => { var queueInfo = HttpClientUtils.GetJson(jenkinsQueueUrl); var queueInfoJObj = JObject.Parse(queueInfo); Console.WriteLine("jenkins build task queue is not empty"); return(!queueInfoJObj["items"].Values <JObject>().Any()); }, ConfigManager.GetConfigObject("JenkinsQueueCheckTimeout", 5) * OneMinute); if (!isJkQueueEmpty) { throw new Exception("wait jenkins build task finish error; ErrorMsg:check wether jenkins build task queue is empty timout"); } LogInfoWriter.GetInstance(logDirName).Info("check jenkins build task queue is empty end"); //第二步:获取Jenkins的编译任务Id var getJkbtNumberUrl = GetJenkinsConfig("JenkinsGetBuildTaskIdApiUrl", ""); getJkbtNumberUrl = String.Format(getJkbtNumberUrl, appName, environment); LogInfoWriter.GetInstance(logDirName).Info($"start get jenkins build task id, JenkinsGetBuildTaskIdApiUrl:{getJkbtNumberUrl}"); var jkbtNumberInfo = HttpClientUtils.Get(getJkbtNumberUrl); jkbtId = GetJenkinsXmlValue(jkbtNumberInfo); if (String.IsNullOrWhiteSpace(jkbtId)) { throw new Exception("get jenkins build task id error,the jenkins build task id is null or empty!"); } LogInfoWriter.GetInstance(logDirName).Info($"get jenkins build task id:{jkbtId} end"); //第三步:根据Jenkins的编译任务Id获取其执行结果 var getJkbtResultUrl = GetJenkinsConfig("JenkinsGetBuildTaskResultApiUrl", ""); getJkbtResultUrl = String.Format(getJkbtResultUrl, appName, environment, jkbtId); LogInfoWriter.GetInstance(logDirName).Info($"start get jenkins build task:{jkbtId} result, JenkinsGetBuildTaskResultApiUrl:{getJkbtResultUrl}"); var isJkbtFinish = ExecExtensions.RetryUntilTrueWithTimeout(() => { if (String.Equals(JkbtResultSuccess, HttpClientUtils.Get(getJkbtResultUrl), StringComparison.OrdinalIgnoreCase)) { return(ExecExtensions.ResultType.Success); } if (String.Equals(JkbtResultFailure, HttpClientUtils.Get(getJkbtResultUrl), StringComparison.OrdinalIgnoreCase)) { return(ExecExtensions.ResultType.Failure); } return(ExecExtensions.ResultType.Continue); }, ConfigManager.GetConfigObject("JenkinsGetBuildTaskResultTimeout", 10) * OneMinute); LogInfoWriter.GetInstance(logDirName).Info($"get jenkins build task:{jkbtId} result end"); //第四步:根据Jenkins编译任务结果返回最终结果 switch (isJkbtFinish) { case ExecExtensions.ResultType.Success: var getJkbtSvnNumberUrl = GetJenkinsConfig("JenkinsGetBuildTaskSvnNumberUrl", ""); getJkbtSvnNumberUrl = String.Format(getJkbtSvnNumberUrl, appName, environment, jkbtId); LogInfoWriter.GetInstance(logDirName).Info($"start get jenkins build task:{jkbtId} svn number,JenkinsGetBuildTaskSvnNumberUrl:{getJkbtSvnNumberUrl}"); var jkbtSvnNumberInfo = HttpClientUtils.Get(getJkbtSvnNumberUrl); var jkbtSvnNumber = GetJenkinsXmlValue(jkbtSvnNumberInfo); if (String.IsNullOrWhiteSpace(jkbtSvnNumber)) { throw new Exception("$the jenkins build task:{jkbtId} svn number is null or empty!"); } return(Tuple.Create(true, jkbtId, jkbtSvnNumber)); case ExecExtensions.ResultType.Failure: return(Tuple.Create(false, jkbtId, "jenkins build task failure")); case ExecExtensions.ResultType.Timeout: return(Tuple.Create(false, jkbtId, "jenkins build task timeout")); } } catch (Exception ex) { return(Tuple.Create(false, jkbtId, ex.ToString())); } return(Tuple.Create(false, jkbtId, "unknow error")); }