예제 #1
0
 private void Init()
 {
     RpcRoot.GetAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, RpcRoot.GetControllerName <INTMinerWalletController>(), nameof(INTMinerWalletController.NTMinerWallets), null, (DataResponse <List <NTMinerWalletData> > response, Exception e) => {
         if (response.IsSuccess() && response.Data != null && response.Data.Count != 0)
         {
             var ethWallets = response.Data.Where(a => "ETH".Equals(a.CoinCode, StringComparison.OrdinalIgnoreCase)).ToArray();
             if (ethWallets.Length != 0)
             {
                 _ethWallets.Clear();
                 _ethWallets.AddRange(ethWallets.Select(a => a.Wallet));
             }
         }
     });
 }
예제 #2
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            base.OnActionExecuting(actionContext);
            var    queryString = new NameValueCollection();
            string query       = actionContext.Request.RequestUri.Query;

            if (!string.IsNullOrEmpty(query))
            {
                query = query.Substring(1);
                string[] parts = query.Split('&');
                foreach (var item in parts)
                {
                    string[] pair = item.Split('=');
                    if (pair.Length == 2)
                    {
                        queryString.Add(pair[0], pair[1]);
                    }
                }
            }
            long   timestamp = 0;
            string t         = queryString["timestamp"];

            if (!string.IsNullOrEmpty(t))
            {
                long.TryParse(t, out timestamp);
            }
            string loginName = queryString["loginName"];

            if (!string.IsNullOrEmpty(loginName))
            {
                loginName = HttpUtility.UrlDecode(loginName);
            }
            ClientSignData clientSign       = new ClientSignData(loginName, queryString["sign"], timestamp);
            ISignableData  data             = null;
            var            actionDescripter = actionContext.ActionDescriptor;
            var            actionParameters = actionDescripter.GetParameters();
            bool           isLoginAction    = actionDescripter.ActionName == nameof(UserController.Login) &&
                                              actionDescripter.ControllerDescriptor.ControllerName == RpcRoot.GetControllerName <UserController>();

            if (actionParameters.Count == 1 && typeof(ISignableData).IsAssignableFrom(actionParameters[0].ParameterType))
            {
                data = (ISignableData)actionContext.ActionArguments.First().Value;
            }
            string message = null;
            bool   isValid = IsValidUser(clientSign, data, isLoginAction, out ResponseBase response, out UserData user);

            if (isValid)
            {
                isValid = OnAuthorization(user, out message);
            }
            if (!isValid)
            {
                if (response != null && !string.IsNullOrEmpty(message))
                {
                    response.Description = message;
                }
                Type returnType          = actionContext.ActionDescriptor.ReturnType;
                var  httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK);
                if (returnType == typeof(HttpResponseMessage))
                {
                    httpResponseMessage.Content = new ByteArrayContent(VirtualRoot.BinarySerializer.Serialize(response));
                    httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg");
                }
                else
                {
                    httpResponseMessage.Content = new StringContent(VirtualRoot.JsonSerializer.Serialize(response), Encoding.UTF8, "application/json");
                }
                actionContext.Response = httpResponseMessage;
            }
            else
            {
                actionContext.ControllerContext.RouteData.Values["_user"] = user;
            }
        }
예제 #3
0
 protected override void UpdateWsStateAsync(string description, bool toOut)
 {
     if (VirtualRoot.DaemonOperation.IsNTMinerOpened())
     {
         var state = base.GetState();
         if (!string.IsNullOrEmpty(description))
         {
             state.Description = description;
         }
         state.ToOut = toOut;
         RpcRoot.JsonRpc.FirePostAsync(NTKeyword.Localhost, NTKeyword.MinerClientPort, RpcRoot.GetControllerName <IMinerClientController>(), nameof(IMinerClientController.ReportWsDaemonState), null, state, timeountMilliseconds: 3000);
     }
 }
예제 #4
0
 public void GetControllerNameTest()
 {
     Assert.AreEqual("FileUrl", RpcRoot.GetControllerName <IFileUrlController>());
 }