public unsafe static bool TryParse(string value, out KeyParse key)
 {
     if (string.IsNullOrEmpty(value))
     {
         key = null;
         return(false);
     }
     try
     {
         byte[] preData = Convert.FromBase64String(value);
         byte[] deData  = EncryptTEAHelper.Decrypt(preData);
         fixed(byte *pByte = deData)
         {
             key = new KeyParse {
                 CoinType = (CoinTypes)(*(pByte)), PlatformType = (PlatformTypes)(*(pByte + 1))
             };
             return(true);
         }
     }
     catch (Exception ex)
     {
         _tracing.Error(ex, null);
         key = null;
         return(false);
     }
 }
Exemple #2
0
 /// <summary>
 ///     从数据库中获取Ticker数据
 /// </summary>
 public IExecuteResult <Ticker> GetDataFromDataBase(string key)
 {
     try
     {
         KeyParse keyParse;
         KeyParse.TryParse(key, out keyParse);
         CoinTypes     coinType     = keyParse.CoinType;
         PlatformTypes platformType = keyParse.PlatformType;
         string        sqlStr       = string.Format("SELECT * FROM `coin`.`trades` WHERE `CoinId` ={0} AND `PlatformId` = {1} ORDER BY `NowTime` DESC LIMIT 1"
                                                    , (int)coinType, (int)platformType);
         DataTable dt = QueryData(sqlStr);
         if (dt == null || dt.Rows.Count == 0)
         {
             return(ExecuteResult <Ticker> .Fail(SystemErrors.Unknown, "没有获取到数据"));
         }
         Ticker ticker = new Ticker
         {
             BuyPrice  = double.Parse(dt.Rows[0]["BuyPrice"].ToString()),
             SellPrice = double.Parse(dt.Rows[0]["SellPrice"].ToString()),
             HignPrice = double.Parse(dt.Rows[0]["HighPrice"].ToString()),
             LowPrice  = double.Parse(dt.Rows[0]["LowPrice"].ToString()),
             LastPrice = double.Parse(dt.Rows[0]["LastPrice"].ToString()),
             Vol       = double.Parse(dt.Rows[0]["TradeVol"].ToString())
         };
         //Tradescs tradesc = new Tradescs(coinType, ticker, platformType, ((MySqlDateTime)dt.Rows[0]["NowTime"]).GetDateTime());
         return(ExecuteResult <Ticker> .Succeed(ticker));
     }
     catch (Exception ex)
     {
         _tracing.Error(ex, null);
         return(ExecuteResult <Ticker> .Fail(SystemErrors.Unknown, ex.Message));
     }
 }