public void GetLatestSnapshots(
     int limit,
     List <string> coinCodes,
     Action <GetCoinSnapshotsResponse> callback)
 {
     Task.Factory.StartNew(() => {
         Guid messageId = Guid.NewGuid();
         try {
             using (var service = CreateService()) {
                 GetCoinSnapshotsRequest request = new GetCoinSnapshotsRequest {
                     MessageId = messageId,
                     LoginName = LoginName,
                     Limit     = limit,
                     CoinCodes = coinCodes,
                     Timestamp = DateTime.Now
                 };
                 request.SignIt(Password);
                 GetCoinSnapshotsResponse response = service.GetLatestSnapshots(request);
                 callback?.Invoke(response);
             }
         }
         catch (CommunicationException e) {
             Global.DebugLine(e.Message, ConsoleColor.Red);
             callback?.Invoke(GetCoinSnapshotsResponse.ClientError(messageId, e.Message));
         }
         catch (Exception e) {
             Global.Logger.Error(e.Message, e);
             callback?.Invoke(GetCoinSnapshotsResponse.ClientError(messageId, e.Message));
         }
     });
 }
Ejemplo n.º 2
0
 public void GetLatestSnapshotsAsync(int limit, Action <GetCoinSnapshotsResponse, Exception> callback)
 {
     try {
         List <CoinSnapshotData> data = _coinSnapshotSet.GetLatestSnapshots(
             limit,
             out int totalMiningCount,
             out int totalOnlineCount) ?? new List <CoinSnapshotData>();
         callback?.Invoke(GetCoinSnapshotsResponse.Ok(data, totalMiningCount, totalOnlineCount), null);
     }
     catch (Exception e) {
         callback?.Invoke(ResponseBase.ServerError <GetCoinSnapshotsResponse>(e.Message), e);
     }
 }
Ejemplo n.º 3
0
 public GetCoinSnapshotsResponse LatestSnapshots([FromBody] GetCoinSnapshotsRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput <GetCoinSnapshotsResponse>("参数错误"));
     }
     try {
         List <CoinSnapshotData> data = WebApiRoot.CoinSnapshotSet.GetLatestSnapshots(
             request.Limit,
             out int totalMiningCount,
             out int totalOnlineCount) ?? new List <CoinSnapshotData>();
         return(GetCoinSnapshotsResponse.Ok(data, totalMiningCount, totalOnlineCount));
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError <GetCoinSnapshotsResponse>(e.Message));
     }
 }
 public GetCoinSnapshotsResponse GetLatestSnapshots(GetCoinSnapshotsRequest request)
 {
     if (request == null)
     {
         return(GetCoinSnapshotsResponse.InvalidInput(Guid.Empty, "参数错误"));
     }
     try {
         if (string.IsNullOrEmpty(request.LoginName))
         {
             return(GetCoinSnapshotsResponse.InvalidInput(request.MessageId, "登录名不能为空"));
         }
         if (!HostRoot.Current.UserSet.TryGetKey(request.LoginName, out IUser key))
         {
             return(GetCoinSnapshotsResponse.Forbidden(request.MessageId));
         }
         if (!request.Timestamp.IsInTime())
         {
             return(GetCoinSnapshotsResponse.Expired(request.MessageId));
         }
         if (request.Sign != request.GetSign(key.Password))
         {
             return(GetCoinSnapshotsResponse.Forbidden(request.MessageId, "签名验证未通过"));
         }
         int totalMiningCount;
         int totalOnlineCount;
         List <CoinSnapshotData> data = HostRoot.Current.CoinSnapshotSet.GetLatestSnapshots(
             request.Limit,
             request.CoinCodes,
             out totalMiningCount,
             out totalOnlineCount) ?? new List <CoinSnapshotData>();
         return(new GetCoinSnapshotsResponse(data)
         {
             TotalMiningCount = totalMiningCount,
             TotalOnlineCount = totalOnlineCount
         });
     }
     catch (Exception e) {
         Global.Logger.ErrorDebugLine(e.Message, e);
         return(GetCoinSnapshotsResponse.ServerError(request.MessageId, e.Message));
     }
 }
Ejemplo n.º 5
0
 public GetCoinSnapshotsResponse LatestSnapshots([FromBody] GetCoinSnapshotsRequest request)
 {
     if (request == null)
     {
         return(ResponseBase.InvalidInput <GetCoinSnapshotsResponse>("参数错误"));
     }
     try {
         if (!request.IsValid(User, Sign, Timestamp, base.ClientIp, out GetCoinSnapshotsResponse response))
         {
             return(response);
         }
         List <CoinSnapshotData> data = HostRoot.Instance.CoinSnapshotSet.GetLatestSnapshots(
             request.Limit,
             out int totalMiningCount,
             out int totalOnlineCount) ?? new List <CoinSnapshotData>();
         return(GetCoinSnapshotsResponse.Ok(data, totalMiningCount, totalOnlineCount));
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
         return(ResponseBase.ServerError <GetCoinSnapshotsResponse>(e.Message));
     }
 }