Beispiel #1
0
        private static async Task DownloadVLatestVulcanVersion(Process process)
        {
            Log.Information("Pobieramy najnowsza wersje Vulcana");

            var releases = await GhClient.Repository.Release.GetAll("Qwizi", "Vulcan-Client-2");

            var latest = releases[0];
            var assets = latest.Assets;

            foreach (var asset in assets)
            {
                if (asset.Name == "binaries.zip")
                {
                    string zipName            = asset.Name;
                    string BrowserDownloadUrl = asset.BrowserDownloadUrl;

                    using (HttpResponseMessage res = await HClient.GetAsync(BrowserDownloadUrl,
                                                                            HttpCompletionOption.ResponseHeadersRead))
                    {
                        res.EnsureSuccessStatusCode();
                        string filePath    = $"{CurrentDir}/{zipName}";
                        var    extractPath = $"{CurrentDir}/client/";
                        Log.Information("Pobieramy klienta");
                        using (Stream stream = await res.Content.ReadAsStreamAsync())
                        {
                            using (Stream streamToWrite = File.Open(filePath, System.IO.FileMode.Create))
                            {
                                await stream.CopyToAsync(streamToWrite);
                            }
                        }

                        await Task.Run(() =>
                        {
                            Log.Information("Rozpakowujemy klienta");
                            ZipFile.ExtractToDirectory(filePath, extractPath, true);
                            Log.Information("Klient rozpakowany");
                        });

                        await Task.Run(() =>
                        {
                            Log.Information("Usuwamy zipa");
                            File.Delete(filePath);
                            Log.Information("Zip usuniety");
                        });

                        Log.Information("Uruchamiany klienta");
                        process.Start();
                        Log.Information("Klient uruchomiony");
                    }
                }
            }
        }
        /// <summary>
        /// 提交get请求,并返回json结果
        /// </summary>
        /// <param name="url">提交eSight的url</param>
        /// <param name="isOpenAgain">重新打开连接,获取eSight openid</param>
        /// <returns>返回JObject的eSight返回结果</returns>
        public JObject HCGet(string url, bool isOpenAgain)
        {
            if (isOpenAgain)
            {
                Open();
            }
            string abUrl = GetFullURL(url);

            InitHCHead();
            JObject retObj = null;

            try
            {
                for (int i = 0; i <= 1; i++)
                {
                    LogUtil.HWLogger.API.DebugFormat("Send json by get:{0}", url);
                    HttpResponseMessage hrm = HClient.GetAsync(abUrl).Result;
                    retObj = HCCheckResult(abUrl, hrm);
                    if (!string.Equals(GetJObjectPropVal <string>(retObj, "code"), Const.ConstMgr.ErrorCode.HW_LOGIN_AUTH))
                    {
                        break;
                    }
                    else
                    {
                        if (isOpenAgain)
                        {
                            LogUtil.HWLogger.API.WarnFormat("Login agin,Retry..");
                            TryOpen();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            catch (System.AggregateException ae)
            {
                HandleException(ae);
            }
            catch (Exception ae)
            {
                LogUtil.HWLogger.API.Error(ae);
                throw;
            }
            return(retObj);
        }