Exemplo n.º 1
0
        public bool UpdateMarketPriceToDB()
        {
            var apiAddress = ConfigurationManager.AppSettings["APIAddress"];
            var url        = $"{apiAddress}/Wallet/UpdateMarketPriceToDB";
            var result     = RestUtilities.GetJson(url);

            if (result == "\"Success\"")
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        public bool CheckBlobRouters(string ServerAddress, string ClientKey, string SecretKey)
        {
            var token = GenerateToken(ClientKey, SecretKey);
            var url   = $"{ServerAddress}/Security/Check";
            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Authorization", "Bearer " + token);
            var result = RestUtilities.GetJson(url, headers);

            if (result == "\"OK\"")
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        public static string GetToGateway(string apiName)
        {
            string baseUrl   = ConfigurationManager.AppSettings["Gateway_URL"];
            string clientKey = ConfigurationManager.AppSettings["GatewayClientKey"];
            string secretKey = ConfigurationManager.AppSettings["GatewaySecretKey"];

            string strHttpUrl = $"{baseUrl.TrimEnd('/')}/{apiName.TrimStart('/')}";

            Dictionary <string, string> header = new Dictionary <string, string>();

            header.Add("Authorization", "bearer " + GenerateToken(clientKey, secretKey));

            string result = RestUtilities.GetJson(strHttpUrl, header);

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 生成已上传图片的缩略图
        /// </summary>
        /// <param name="fileId"></param>
        /// <returns></returns>
        public Guid UploadWithCompress(Guid fileId)
        {
            if (string.IsNullOrEmpty(blob_URL))
            {
                throw new ArgumentException("Blob_URL not found");
            }

            var url    = blob_URL.TrimEnd('/') + $"/File/UploadWithCompress?fileId={fileId}";
            var token  = GenerateToken();
            var result = RestUtilities.GetJson(url, new Dictionary <string, string> {
                { "Authorization", "bearer " + token }
            });
            var data = JsonConvert.DeserializeObject <ServiceResult <Guid> >(result);

            return(data.Data);
        }
Exemplo n.º 5
0
        public byte[] Download(string id)
        {
            if (string.IsNullOrEmpty(blob_URL))
            {
                throw new ArgumentException("Blob_URL not found");
            }

            if (_images.ContainsKey(id))
            {
                return(_images[id]);
            }

            var url   = blob_URL.TrimEnd('/') + "/File/Download?id=" + id;
            var token = GenerateToken();

            try
            {
                var resultStr = RestUtilities.GetJson(url, new Dictionary <string, string> {
                    { "Authorization", "bearer " + token }
                });

                if (string.IsNullOrWhiteSpace(resultStr))
                {
                    // _log.ErrorFormat("Download master image error. url = {0},id = {1}", url, id);
                    return(null);
                }
                var responseJson = JsonConvert.DeserializeObject <ServiceResult <object> >(resultStr);
                if (responseJson.Code != 0)
                {
                    throw new ApplicationException(responseJson.Message);
                }
                var b = Convert.FromBase64String(responseJson.Data.ToString());

                if (!_images.ContainsKey(id))
                {
                    _images.Add(id, b);
                }
                return(b);
            }
            catch (Exception exception)
            {
                //_log.Error(exception);
            }

            return(null);
        }
Exemplo n.º 6
0
        private ServiceResult <string> DownloadImage(string id)
        {
            var url = _router.ServerAddress + "/File/Download?id=" + id;

            var resultStr = RestUtilities.GetJson(url, GetHeaders());

            if (string.IsNullOrWhiteSpace(resultStr))
            {
                _log.Error($"Download region image error. url = {url}, profile route = {_router}");
            }
            var responseJson = JsonConvert.DeserializeObject <ServiceResult <string> >(resultStr);

            if (responseJson == null)
            {
                throw new ApplicationException();
            }

            if (responseJson.Code != 0)
            {
                throw new ApplicationException(responseJson.Data);
            }

            return(responseJson);
        }
Exemplo n.º 7
0
        public void UpdateMarketPriceFrmCoinMarketCapToDB(short currencyId)
        {
            // Get all Cryptocurrencies
            List <Cryptocurrency> crypto = new List <Cryptocurrency>();

            //List<PriceInfo> priceinfolist = new List<PriceInfo>();

            //Janet change get cryptocurrencies list without transaction setting
            //crypto = cryptoCurrDAC.GetAllCurrencies();
            crypto = cryptoCurrDAC.List();

            Currencies fiatcurrencyitem = new Currencies();

            fiatcurrencyitem = currenciesDAC.GetByID(currencyId);

            //priceinfolist = priceInfoDAC.GetAll();

            string apiURL = string.Format(CoinMarketCapV2_URL, fiatcurrencyitem.Code.ToUpper());

            //string colName = "price_" + fiatcurrencyitem.Code.ToLower();  // "price_eur"
            //string colName = currency.ToUpper();  // "EUR"

            //HttpClient client = new HttpClient();
            //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            //HttpResponseMessage response = client.GetAsync(apiURL).Result;

            var data = RestUtilities.GetJson(apiURL);
            //data = data.Replace(colName, "price_curr");

            CoinMarketCapPriceDetailV2 priceList = JsonConvert.DeserializeObject <CoinMarketCapPriceDetailV2>(data);
            //BittrexModels priceList = JsonConvert.DeserializeObject<BittrexModels>(data);
            //List<Welcome> priceList = JsonConvert.DeserializeObject<List<Welcome>>(data);

            var query = (from cryptoitem in crypto
                         join priceitem in priceList.Data on cryptoitem.Code equals priceitem.Value.Symbol
                         where priceitem.Value.Quotes != null
                         where priceitem.Value.Quotes.Any(x => string.Compare(x.Key, fiatcurrencyitem.Code, true) == 0)
                         select new PriceInfo
            {
                CryptoID = cryptoitem.Id,
                CurrencyID = fiatcurrencyitem.ID,
                //Price = priceitem.Value.Quotes.Select(x => Convert.ToDecimal(x.Value.Price.Value)).First()
                Price = (decimal)priceitem.Value.Quotes
                        .Where(x => string.Compare(x.Key, fiatcurrencyitem.Code, true) == 0).Select(x => x)
                        .FirstOrDefault().Value.Price
            }).ToList();

            if (query.Count > 0)
            {
                foreach (var item in query)
                {
                    var priceinfolist  = PriceInfoDac.GetAll();
                    var existpriceinfo = priceinfolist.SingleOrDefault(x =>
                                                                       x.CryptoID == item.CryptoID && x.CurrencyID == item.CurrencyID);

                    if (existpriceinfo != null)
                    {
                        existpriceinfo.Price          = item.Price;
                        existpriceinfo.LastUpdateDate = DateTime.UtcNow;
                        PriceInfoDac.UpdatePriceInfo(existpriceinfo);

                        Log.Info(MethodBase.GetCurrentMethod().Name + "(): " +
                                 "Succcess updating PriceInfo for CrypoID : " + existpriceinfo.CryptoID +
                                 " to CurrencyID : " + existpriceinfo.CurrencyID);
                    }
                    else
                    {
                        item.LastUpdateDate = DateTime.UtcNow;
                        PriceInfoDac.CreatePriceInfo(item);

                        Log.Info(MethodBase.GetCurrentMethod().Name + "(): " +
                                 "Succcess creating PriceInfo for CrypoID : " + item.CryptoID + " to CurrencyID : " +
                                 item.CurrencyID);
                    }

                    var cryptoCurr2 = (from x in crypto
                                       where string.Compare(x.Code, "BTC", StringComparison.OrdinalIgnoreCase) == 0
                                       select x).SingleOrDefault();
                    var fiatCurr2 = currenciesDAC.GetByCode("USD");
                    if (cryptoCurr2 != null && fiatCurr2 != null && item.CryptoID == cryptoCurr2.Id &&
                        item.CurrencyID == fiatCurr2.ID)
                    {
                        BTCToUSD = item.Price;
                    }
                }
            }
        }